Commit | Line | Data |
---|---|---|
68e58405 RS |
1 | ;;; batmode.el --- Simple mode for Windows BAT files |
2 | ||
3 | ;; Copyright (C) 1996 Free Software Foundation, Inc. | |
4 | ||
5 | ;; Author: Peter Breton <pbreton@i-kinetics.com> | |
6 | ;; Created: Thu Jul 25 1996 | |
7 | ;; Keywords: BAT, DOS, Windows | |
8 | ||
9 | ;; This file is part of GNU Emacs. | |
10 | ||
11 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 | ;; it under the terms of the GNU General Public License as published by | |
13 | ;; the Free Software Foundation; either version 2, or (at your option) | |
14 | ;; any later version. | |
15 | ||
16 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
22 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
23 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 | ;; Boston, MA 02111-1307, USA. | |
25 | ||
26 | ;;; Commentary: | |
27 | ;; | |
28 | ;; USAGE: Byte-compile this file, and add the following lines to your | |
29 | ;; emacs initialization file (.emacs/_emacs): | |
30 | ;; | |
31 | ;; (setq auto-mode-alist | |
32 | ;; (append | |
33 | ;; (list (cons "\\.[bB][aA][tT]$" 'bat-mode)) | |
34 | ;; ;; For DOS init files | |
35 | ;; (list (cons "CONFIG\\." 'bat-mode)) | |
36 | ;; (list (cons "AUTOEXEC\\." 'bat-mode)) | |
37 | ;; auto-mode-alist)) | |
38 | ;; | |
39 | ;; (autoload 'bat-mode "batmode" | |
40 | ;; "DOS and WIndows BAT files" t) | |
41 | ||
42 | ;; TODO: | |
43 | ;; | |
44 | ;; Support "compiles" ? | |
45 | ;; Imenu? Don't have real functions..... | |
46 | ||
47 | ;;; Change log: | |
48 | ;; $Log: batmode.el,v $ | |
49 | ;; Revision 1.3 1996/08/22 02:31:47 peter | |
50 | ;; Added Usage message, credit to folks from NTEmacs mailing list, | |
51 | ;; Syntax table, New font-lock keywords | |
52 | ;; | |
53 | ;; Revision 1.2 1996/08/18 16:27:13 peter | |
54 | ;; Added preliminary global-font-lock support | |
55 | ;; | |
56 | ;; Revision 1.1 1996/08/18 16:14:18 peter | |
57 | ;; Initial revision | |
58 | ;; | |
59 | ||
60 | ;; Credit for suggestions, patches and bug-fixes: | |
61 | ;; Robert Brodersen <rbrodersen@siebel.com> | |
62 | ;; ACorreir@pervasive-sw.com (Alfred Correira) | |
63 | ||
64 | ;;; Code: | |
65 | ||
66 | (defvar bat-mode-map nil "Local keymap for bat-mode buffers.") | |
67 | ||
68 | ;; Make this lowercase if you like | |
69 | (defvar bat-mode-comment-start "REM " | |
70 | "Comment string to use in BAT mode") | |
71 | ||
72 | (defvar bat-mode-syntax-table nil | |
73 | "Syntax table in use in Bat-mode buffers.") | |
74 | ||
75 | (if bat-mode-map | |
76 | nil | |
77 | (setq bat-mode-map (copy-keymap global-map)) | |
78 | ) | |
79 | ||
80 | ;; Make underscores count as words | |
81 | (if bat-mode-syntax-table | |
82 | () | |
83 | (setq bat-mode-syntax-table (make-syntax-table)) | |
84 | (modify-syntax-entry ?_ "w" bat-mode-syntax-table) | |
85 | ) | |
86 | ||
87 | (defun bat-mode () | |
88 | "Mode for DOS and Windows BAT files" | |
89 | (interactive) | |
90 | (kill-all-local-variables) | |
91 | (use-local-map bat-mode-map) | |
92 | (set-syntax-table bat-mode-syntax-table) | |
93 | ||
94 | (make-local-variable 'parse-sexp-ignore-comments) | |
95 | (make-local-variable 'comment-start) | |
96 | (make-local-variable 'comment-start-skip) | |
97 | (make-local-variable 'comment-end) | |
98 | (make-local-variable 'executable-command) | |
99 | (make-local-variable 'font-lock-defaults) | |
100 | ||
101 | (setq major-mode 'bat-mode | |
102 | mode-name "bat" | |
103 | ||
104 | comment-end "" | |
105 | ||
106 | comment-start bat-mode-comment-start | |
107 | comment-start-skip "[Rr][Ee][Mm] *" | |
108 | ||
109 | parse-sexp-ignore-comments t | |
110 | ||
111 | ) | |
112 | ||
113 | ;; Global font-lock support | |
114 | ;; (setq font-lock-defaults (list 'bat-font-lock-keywords nil t nil nil)) | |
115 | (setq font-lock-defaults (list 'bat-font-lock-keywords nil)) | |
116 | ||
117 | (run-hooks 'bat-mode-hook)) | |
118 | ||
119 | (defvar bat-font-lock-keywords | |
120 | (list | |
121 | ;; Make this one first in the list, otherwise comments will | |
122 | ;; be over-written by other variables | |
123 | (list "^[@ \t]*\\([rR][eE][mM].*\\)" 1 'font-lock-comment-face t) | |
124 | (list "^[ \t]*\\(::-.*\\)" 1 'font-lock-comment-face t) | |
125 | (list | |
126 | (concat "\\(\\<" | |
127 | (mapconcat 'identity | |
128 | '( | |
129 | "call" | |
130 | "echo" | |
131 | "exist" | |
132 | "errorlevel" | |
133 | "for" | |
134 | "goto" | |
135 | "if" | |
136 | "not" | |
137 | "path" | |
138 | "pause" | |
139 | "prompt" | |
140 | "set" | |
141 | "start" | |
142 | ) | |
143 | "\\>\\|\\<") | |
144 | "\\>\\)") 1 'font-lock-keyword-face) | |
145 | (list "^[ \t]*\\(:\\sw+\\)" 1 'font-lock-function-name-face t) | |
146 | (list "\\(%\\sw+%\\)" 1 'font-lock-reference-face) | |
147 | (list "\\(%[0-9]\\)" 1 'font-lock-reference-face) | |
148 | (list "\\(/[^/ \t\n]+\\)" 1 'font-lock-type-face) | |
149 | (list "\\<\\(goto\\)\\>[ \t]*\\(\\sw+\\)?" | |
150 | '(1 font-lock-keyword-face) | |
151 | '(2 font-lock-function-name-face nil t)) | |
152 | ||
153 | ) | |
154 | "Keywords to hilight in BAT mode") | |
155 | ||
156 | ;;; don't do it in Win-Emacs | |
157 | (if (boundp 'font-lock-defaults-alist) | |
158 | (add-to-list | |
159 | 'font-lock-defaults-alist | |
160 | (cons 'bat-mode | |
161 | (list 'bat-font-lock-keywords nil t nil nil)))) | |
162 | ||
163 | (provide 'bat-mode) | |
164 | ||
165 | ;;; batmode.el ends here |