aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2013-08-07 11:50:16 -0400
committerStefan Monnier2013-08-07 11:50:16 -0400
commit312b1740c24f3a26b93fb6ea3a8d53f15e3edd91 (patch)
tree5d999a7b3c57ee4a5140d59e761c516acca7075c
parent400a3178cb749fe9cdbad59871aa0786babd434e (diff)
downloademacs-312b1740c24f3a26b93fb6ea3a8d53f15e3edd91.tar.gz
emacs-312b1740c24f3a26b93fb6ea3a8d53f15e3edd91.zip
* lisp/progmodes/dos.el (auto-mode-alist): Add entries for dos-mode.
(dos-mode): Use setq-local. Add space after "rem". (dos-mode-syntax-table): Don't use "w" for symbol chars. (dos-font-lock-keywords): Try to adjust font-lock rules accordingly.
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/progmodes/dos.el58
2 files changed, 40 insertions, 25 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index de2b79577e1..6ccb8d61836 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
12013-08-07 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * progmodes/dos.el (auto-mode-alist): Add entries for dos-mode.
4 (dos-mode): Use setq-local. Add space after "rem".
5 (dos-mode-syntax-table): Don't use "w" for symbol chars.
6 (dos-font-lock-keywords): Try to adjust font-lock rules accordingly.
7
12013-08-07 Arni Magnusson <arnima@hafro.is> 82013-08-07 Arni Magnusson <arnima@hafro.is>
2 9
3 * progmodes/dos.el: New file. 10 * progmodes/dos.el: New file.
diff --git a/lisp/progmodes/dos.el b/lisp/progmodes/dos.el
index 57b137f97fb..adc94f201a6 100644
--- a/lisp/progmodes/dos.el
+++ b/lisp/progmodes/dos.el
@@ -22,9 +22,9 @@
22 22
23;;; Commentary: 23;;; Commentary:
24;; 24;;
25;; Major mode for editing Dos scripts (batch files). Provides syntax 25;; Major mode for editing Dos scripts (batch files). Provides syntax
26;; highlighting, a basic template, access to Dos help pages, imenu/outline 26;; highlighting, a basic template, access to Dos help pages, imenu/outline
27;; navigation, and the ability to run scripts from within Emacs. The syntax 27;; navigation, and the ability to run scripts from within Emacs. The syntax
28;; groups for highlighting are: 28;; groups for highlighting are:
29;; 29;;
30;; Face Example 30;; Face Example
@@ -79,24 +79,25 @@
79 "goto" "gtr" "if" "in" "leq" "lss" "neq" "not" "start")) 79 "goto" "gtr" "if" "in" "leq" "lss" "neq" "not" "start"))
80 (LINUX 80 (LINUX
81 '("cat" "cp" "ls" "mv" "rm"))) 81 '("cat" "cp" "ls" "mv" "rm")))
82 (list 82 `(("\\<_\\(call\\|goto\\)\\_>[ \t]+%?\\([A-Za-z0-9-_\\:.]+\\)%?"
83 '("\\<\\(call\\|goto\\)\\>[ \t]+%?\\([A-Za-z0-9-_\\:.]+\\)%?"
84 (2 font-lock-constant-face t)) 83 (2 font-lock-constant-face t))
85 '("^[ \t]*\\(@?rem\\>\\|::\\).*" 84 ("^[ \t]*\\(@?rem\\_>\\|::\\).*"
86 (0 font-lock-comment-face t)) 85 (0 font-lock-comment-face t))
87 '("^:[^:].*" 86 ("^:[^:].*"
88 . 'dos-label-face) 87 . 'dos-label-face)
89 '("\\<\\(defined\\|set\\)\\>[ \t]*\\(\\w+\\)" 88 ("\\<_\\(defined\\|set\\)\\_>[ \t]*\\(\\w+\\)"
90 (2 font-lock-variable-name-face)) 89 (2 font-lock-variable-name-face))
91 '("%\\(\\w+\\)%?" 90 ("%\\(\\w+\\)%?"
92 (1 font-lock-variable-name-face)) 91 (1 font-lock-variable-name-face))
93 '("!\\(\\w+\\)!?" ; delayed-expansion !variable! 92 ("!\\(\\w+\\)!?" ; delayed-expansion !variable!
94 (1 font-lock-variable-name-face)) 93 (1 font-lock-variable-name-face))
95 '("[ =][-/]+\\(\\w+\\)" 94 ("[ =][-/]+\\(\\w+\\)"
96 (1 font-lock-type-face append)) 95 (1 font-lock-type-face append))
97 (cons (regexp-opt COMMANDS 'words) font-lock-builtin-face) 96 (,(concat "\\_<" (regexp-opt COMMANDS) "\\_>") . font-lock-builtin-face)
98 (cons (regexp-opt CONTROLFLOW 'words) font-lock-keyword-face) 97 (,(concat "\\_<" (regexp-opt CONTROLFLOW) "\\_>")
99 (cons (regexp-opt LINUX 'words) font-lock-warning-face))))) 98 . font-lock-keyword-face)
99 (,(concat "\\_<" (regexp-opt LINUX) "\\_>")
100 . font-lock-warning-face)))))
100 101
101(defvar dos-menu 102(defvar dos-menu
102 '("Dos" 103 '("Dos"
@@ -114,7 +115,7 @@
114 (let ((map (make-sparse-keymap))) 115 (let ((map (make-sparse-keymap)))
115 (easy-menu-define nil map nil dos-menu) 116 (easy-menu-define nil map nil dos-menu)
116 (define-key map [?\C-c ?\C-.] 'dos-mode-help) 117 (define-key map [?\C-c ?\C-.] 'dos-mode-help)
117 (define-key map [?\C-c ?\C-/] 'dos-cmd-help) 118 (define-key map [?\C-c ?\C-/] 'dos-cmd-help) ;FIXME: Why not C-c C-? ?
118 (define-key map [?\C-c ?\C-a] 'dos-run-args) 119 (define-key map [?\C-c ?\C-a] 'dos-run-args)
119 (define-key map [?\C-c ?\C-c] 'dos-run) 120 (define-key map [?\C-c ?\C-c] 'dos-run)
120 (define-key map [?\C-c ?\C-t] 'dos-template) 121 (define-key map [?\C-c ?\C-t] 'dos-template)
@@ -123,21 +124,24 @@
123 124
124(defvar dos-mode-syntax-table 125(defvar dos-mode-syntax-table
125 (let ((table (make-syntax-table))) 126 (let ((table (make-syntax-table)))
126 (modify-syntax-entry ?~ "w" table) 127 ;; Beware: `w' should not be used for non-alphabetic chars.
128 (modify-syntax-entry ?~ "_" table)
127 (modify-syntax-entry ?% "." table) 129 (modify-syntax-entry ?% "." table)
128 (modify-syntax-entry ?- "w" table) 130 (modify-syntax-entry ?- "_" table)
129 (modify-syntax-entry ?_ "w" table) 131 (modify-syntax-entry ?_ "_" table)
130 (modify-syntax-entry ?{ "w" table) 132 ;; FIXME: { and } can appear in identifiers? Really?
131 (modify-syntax-entry ?} "w" table) 133 (modify-syntax-entry ?{ "_" table)
134 (modify-syntax-entry ?} "_" table)
132 (modify-syntax-entry ?\\ "." table) 135 (modify-syntax-entry ?\\ "." table)
133 table)) 136 table))
134 137
135;; 4 User functions 138;; 4 User functions
136 139
137(defun dos-cmd-help (cmd) 140(defun dos-cmd-help (cmd)
138 "Show help for Dos command." 141 "Show help for Dos command CMD."
139 (interactive "sHelp: ") 142 (interactive "sHelp: ")
140 (if (string-equal cmd "net") 143 (if (string-equal cmd "net")
144 ;; FIXME: liable to quoting nightmare. Use call-process?
141 (shell-command "net /?") (shell-command (concat "help " cmd)))) 145 (shell-command "net /?") (shell-command (concat "help " cmd))))
142 146
143(defun dos-mode-help () 147(defun dos-mode-help ()
@@ -149,11 +153,13 @@
149(defun dos-run () 153(defun dos-run ()
150 "Run Dos script." 154 "Run Dos script."
151 (interactive) 155 (interactive)
156 ;; FIXME: liable to quoting nightmare. Use call/start-process?
152 (save-buffer) (shell-command buffer-file-name)) 157 (save-buffer) (shell-command buffer-file-name))
153 158
154(defun dos-run-args (args) 159(defun dos-run-args (args)
155 "Run Dos script with ARGS." 160 "Run Dos script with ARGS."
156 (interactive "sArgs: ") 161 (interactive "sArgs: ")
162 ;; FIXME: Use `compile'?
157 (shell-command (concat buffer-file-name " " args))) 163 (shell-command (concat buffer-file-name " " args)))
158 164
159(defun dos-template () 165(defun dos-template ()
@@ -161,6 +167,9 @@
161 (interactive) 167 (interactive)
162 (goto-char (point-min)) (insert "@echo off\nsetlocal\n\n")) 168 (goto-char (point-min)) (insert "@echo off\nsetlocal\n\n"))
163 169
170;;;###autoload
171(add-to-list 'auto-mode-alist '("\\.\\(bat\\|cmd\\)\\'" . dos-mode))
172
164;; 5 Main function 173;; 5 Main function
165 174
166;;;###autoload 175;;;###autoload
@@ -171,12 +180,11 @@ Start a new script from `dos-template'. Read help pages for Dos commands with
171`dos-cmd-help'. Navigate between sections using `imenu'. Run script using 180`dos-cmd-help'. Navigate between sections using `imenu'. Run script using
172`dos-run' and `dos-run-args'.\n 181`dos-run' and `dos-run-args'.\n
173\\{dos-mode-map}" 182\\{dos-mode-map}"
174 (set (make-local-variable 'comment-start) "rem") 183 (setq-local comment-start "rem ")
175 (set (make-local-variable 'font-lock-defaults) 184 (setq-local font-lock-defaults
176 '(dos-font-lock-keywords nil t)) ; case-insensitive keywords 185 '(dos-font-lock-keywords nil t)) ; case-insensitive keywords
177 (set (make-local-variable 'imenu-generic-expression) '((nil "^:[^:].*" 0))) 186 (setq-local imenu-generic-expression '((nil "^:[^:].*" 0)))
178 (set (make-local-variable 'outline-regexp) ":[^:]") 187 (setq-local outline-regexp ":[^:]"))
179 (set-syntax-table dos-mode-syntax-table))
180 188
181(provide 'dos) 189(provide 'dos)
182 190