summaryrefslogtreecommitdiff
path: root/evol-mode.el
diff options
context:
space:
mode:
authorJoseph Botosh <rumly111@gmail.com>2015-09-03 17:14:10 +0300
committerJoseph Botosh <rumly111@gmail.com>2015-09-03 17:14:10 +0300
commit454ad75aaae91c0dac1d26b013c9e65c6734dda3 (patch)
treef38cb0ca2ddb36cc59b1984d4b76064dee0272ae /evol-mode.el
parent0ea4f2de0b2d45ee219a9f8988b727a0d7aa56a0 (diff)
downloadevol-tools-454ad75aaae91c0dac1d26b013c9e65c6734dda3.tar.gz
evol-tools-454ad75aaae91c0dac1d26b013c9e65c6734dda3.tar.bz2
evol-tools-454ad75aaae91c0dac1d26b013c9e65c6734dda3.tar.xz
evol-tools-454ad75aaae91c0dac1d26b013c9e65c6734dda3.zip
improve evol-mode for emacs
Diffstat (limited to 'evol-mode.el')
-rw-r--r--evol-mode.el143
1 files changed, 82 insertions, 61 deletions
diff --git a/evol-mode.el b/evol-mode.el
index 1831050..e74207c 100644
--- a/evol-mode.el
+++ b/evol-mode.el
@@ -4,14 +4,24 @@
(require 'cl)
-(defvar evol-all-dir "~/Stuff/src/evol-all"
- "Directory containing server-code and server-data subdirectories")
+(defgroup evol nil
+ "Settings for evol-mode."
+ :prefix "evol-"
+ :group 'emacs)
+
+(defcustom evol-all-dir ""
+ "Directory containing server-code and server-data subdirectories"
+ :group 'evol
+ :type 'string)
+
+(defvar evol-mode-constants nil "List of all Evol constants")
+(defvar evol-mode-functions nil "List of Evol functions")
(defun evol-mode-parse-const-db (dbfile)
(interactive "fPath to const.txt: ")
(with-temp-buffer
+ (message "Loading Evol constants from %s" dbfile)
(insert-file-contents dbfile)
- (beginning-of-buffer)
(let ((constants))
(while (not (eobp))
(let ((line (buffer-substring-no-properties
@@ -30,7 +40,6 @@
(interactive "fPath to map_index.txt: ")
(with-temp-buffer
(insert-file-contents dbfile)
- (beginning-of-buffer)
(let ((maps))
(while (not (eobp))
(let ((line (buffer-substring-no-properties
@@ -50,7 +59,6 @@
(interactive "fPath to skill_db.txt: ")
(with-temp-buffer
(insert-file-contents dbfile)
- (beginning-of-buffer)
(let ((skills))
(while (not (eobp))
(let ((line (buffer-substring-no-properties
@@ -69,8 +77,8 @@
(defun evol-mode-parse-mob-db (dbfile)
(interactive "fPath to mob_db.txt: ")
(with-temp-buffer
+ (message "Loading mob_db from %s" dbfile)
(insert-file-contents dbfile)
- (beginning-of-buffer)
(let ((mobs))
(while (not (eobp))
(let ((line (buffer-substring-no-properties
@@ -89,8 +97,8 @@
(defun evol-mode-parse-item-db (dbfile)
(interactive "fPath to item_db.txt: ")
(with-temp-buffer
+ (message "Loading item_db from %s" dbfile)
(insert-file-contents dbfile)
- (beginning-of-buffer)
(let ((items))
(while (not (eobp))
(let ((line (buffer-substring-no-properties
@@ -109,8 +117,8 @@
(defun evol-mode-parse-atcommand-c (cfile)
(interactive "fPath to src/map/atcommand.c: ")
(with-temp-buffer
+ (message "Loading functions from from %s" cfile)
(insert-file-contents cfile)
- (beginning-of-buffer)
(let ((commands))
(while (not (eobp))
(let ((line (buffer-substring-no-properties
@@ -135,8 +143,8 @@
(defun evol-mode-parse-init-c (cfile)
(interactive "fPath to evol/src/emap/init.c: ")
(with-temp-buffer
+ (message "Loading functions from from %s" cfile)
(insert-file-contents cfile)
- (beginning-of-buffer)
(let ((commands))
(while (not (eobp))
(let ((line (buffer-substring-no-properties
@@ -153,10 +161,10 @@
commands)))
(defun evol-mode-parse-script-c (cfile)
- (interactive "fPath to src/map/atcommand.c: ")
+ (interactive "fPath to src/map/script.c: ")
(with-temp-buffer
+ (message "Loading functions from from %s" cfile)
(insert-file-contents cfile)
- (beginning-of-buffer)
(let ((commands))
(while (not (eobp))
(let ((line (buffer-substring-no-properties
@@ -172,54 +180,67 @@
(forward-line 1))
commands)))
-(setq evol-mode-constants
- (append
- (evol-mode-parse-const-db
- (concat evol-all-dir "/server-data/db/const.txt"))
- (evol-mode-parse-mob-db
- (concat evol-all-dir "/server-data/db/re/mob_db.txt"))
- (evol-mode-parse-skill-db
- (concat evol-all-dir "/server-data/db/re/skill_db.txt"))
- ;; (evol-mode-parse-map-index-db
- ;; (concat evol-all-dir "/server-data/db/map_index.txt"))
- (evol-mode-parse-item-db
- (concat evol-all-dir "/server-data/db/re/item_db.conf"))
- ))
-
-(setq evol-mode-functions
- (append
- (list "mesq" "mesn")
- (evol-mode-parse-script-c
- (concat evol-all-dir "/server-code/src/map/script.c"))
- (evol-mode-parse-atcommand-c
- (concat evol-all-dir "/server-code/src/map/atcommand.c"))
- (evol-mode-parse-init-c
- (concat evol-all-dir "/server-code/src/evol/src/emap/init.c"))))
-
-(setq evol-mode-functions-regex
- (regexp-opt (delete-dups evol-mode-functions)
- 'words))
-
-(setq evol-mode-constants-regex
- (regexp-opt (delete-dups evol-mode-constants)
- 'words))
-
-(defun make-regex-list (consts &optional max-length)
- (let ((result)
- (len (length consts))
- (start 0) (end)
- (diff (or max-length 1000)))
- (while (< start len)
- (setq end (min (+ start diff) len))
- (push (subseq consts start end) result)
- (setq start (+ start diff)))
- result))
+
+(defun evol-mode-setup-syntax-table ()
+ (let ((st (standard-syntax-table)))
+ (modify-syntax-entry ?_ "w" st)
+ (modify-syntax-entry ?# "w" st)
+ (modify-syntax-entry ?$ "w" st)
+ (modify-syntax-entry ?@ "w" st)
+ (modify-syntax-entry ?. "w" st)
+ (modify-syntax-entry ?/ ". 124b" st)
+ (modify-syntax-entry ?* ". 23" st)
+ (modify-syntax-entry ?\n "> b" st)
+ (set-syntax-table st)))
(defun evol-mode-setup-font-lock ()
- (dolist (lst (make-regex-list (sort evol-mode-constants 'string-lessp)))
- (let ((rx (regexp-opt lst 'words)))
+
+ (defun make-regex-list (consts &optional max-length)
+ (let ((result)
+ (len (length consts))
+ (start 0) (end)
+ (diff (or max-length 1000)))
+ (while (< start len)
+ (setq end (min (+ start diff) len))
+ (push (subseq consts start end) result)
+ (setq start (+ start diff)))
+ result))
+
+ (let ((evol-mode-functions-regex))
+ (unless evol-mode-constants
+ (setq evol-mode-constants
+ (append
+ (evol-mode-parse-const-db
+ (concat evol-all-dir "/server-data/db/const.txt"))
+ (evol-mode-parse-mob-db
+ (concat evol-all-dir "/server-data/db/re/mob_db.txt"))
+ (evol-mode-parse-skill-db
+ (concat evol-all-dir "/server-data/db/re/skill_db.txt"))
+ ;; (evol-mode-parse-map-index-db
+ ;; (concat evol-all-dir "/server-data/db/map_index.txt"))
+ (evol-mode-parse-item-db
+ (concat evol-all-dir "/server-data/db/re/item_db.conf"))
+ )))
+
+ (unless evol-mode-functions
+ (setq evol-mode-functions
+ (append
+ (list "mesq" "mesn")
+ (evol-mode-parse-script-c
+ (concat evol-all-dir "/server-code/src/map/script.c"))
+ (evol-mode-parse-atcommand-c
+ (concat evol-all-dir "/server-code/src/map/atcommand.c"))
+ (evol-mode-parse-init-c
+ (concat evol-all-dir "/server-code/src/evol/src/emap/init.c")))))
+
+ (let ((regex (regexp-opt evol-mode-functions 'words)))
(font-lock-add-keywords 'evol-mode
- `((,rx . font-lock-constant-face))))))
+ `((,regex . font-lock-function-name-face))))
+
+ (dolist (lst (make-regex-list (sort evol-mode-constants 'string-lessp)))
+ (let ((rx (regexp-opt lst 'words)))
+ (font-lock-add-keywords 'evol-mode
+ `((,rx . font-lock-constant-face)))))))
(define-generic-mode evol-mode
@@ -231,15 +252,15 @@
("function[\t ]+\\([a-zA-Z][a-zA-Z0-9_]*\\)[\t\n ]{" 1 font-lock-function-name-face)
("\\<[0-9]+\\>" . font-lock-constant-face)
("[,;]" . font-lock-builtin-face)
- ("On\\(Init\\|Timer[0-9]+\\|Touch\\|\\(Minute\\|Hour\\)[0-9]\\{2\\}\\|Day[0-9]\\|\\(Day\\|Clock\\|Sun\\|Mon\\|Tue\\|Wed\\|Thu\\|Fri\\|Sat\\)[0-9]\\{4\\}\\|\\(Buy\\|Sell\\)Item\\|TimerQuit\\|InstanceInit\\|TouchNPC\\|\\(Count\\|Pay\\)Funds\\|PC\\(Die\\|Kill\\|Login\\|Logout\\|LoadMap\\|BaseLvUp\\|JobLvUp\\)Event\\):" . font-lock-constant-face)
+ ;; ("^On\\(Init\\|Timer[0-9]+\\|Touch\\|\\(Minute\\|Hour\\)[0-9]\\{2\\}\\|Day[0-9]\\|\\(Day\\|Clock\\|Sun\\|Mon\\|Tue\\|Wed\\|Thu\\|Fri\\|Sat\\)[0-9]\\{4\\}\\|\\(Buy\\|Sell\\)Item\\|TimerQuit\\|InstanceInit\\|TouchNPC\\|\\(Count\\|Pay\\)Funds\\|PC\\(Die\\|Kill\\|Login\\|Logout\\|LoadMap\\|BaseLvUp\\|JobLvUp\\)Event\\):" . font-lock-constant-face)
("^[A-Za-z][A-Za-z0-9_]+:" . font-lock-constant-face)
- (,evol-mode-functions-regex . font-lock-function-name-face)
- ("\\(@\\|$\\|$@\\|.\\|.@\\|'\\|#\\|##\\)\\([a-zA-Z][a-zA-Z0-9_]+\\)$\\{0,1\\}" . font-lock-variable-name-face)
- ;; (,evol-mode-constants-regex . font-lock-constant-face)
+ ("\\<\\(@\\|$\\|$@\\|.\\|.@\\|'\\|#\\|##\\)\\([a-zA-Z][a-zA-Z0-9_]*\\)$\\{0,1\\}\\>" . font-lock-variable-name-face)
)
nil
;; nil
- '(evol-mode-setup-font-lock)
+ '(evol-mode-setup-font-lock
+ evol-mode-setup-syntax-table
+ (lambda () (setq indent-tabs-mode nil)))
"Major mode for syntax highlighting of Evol Scripts")
(add-to-list 'magic-mode-alist '("^// Evol scripts." . evol-mode))