Mercurial > emacs
annotate lisp/generic.el @ 61468:2bf41f67cb04
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 11 Apr 2005 16:46:05 +0000 |
parents | 995a77d66d87 |
children | ae95ab9b4867 |
rev | line source |
---|---|
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37058
diff
changeset
|
1 ;;; generic.el --- defining simple major modes with comment and font-lock |
18254 | 2 ;; |
60595
b392b963c10b
(define-generic-mode): Let generic-mode-list be a list of strings;
Lute Kamstra <lute@gnu.org>
parents:
58587
diff
changeset
|
3 ;; Copyright (C) 1997, 1999, 2004, 2005 Free Software Foundation, Inc. |
18254 | 4 ;; |
21182 | 5 ;; Author: Peter Breton <pbreton@cs.umb.edu> |
18254 | 6 ;; Created: Fri Sep 27 1996 |
7 ;; Keywords: generic, comment, font-lock | |
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 ;; INTRODUCTION: | |
61455 | 29 ;; |
30 ;; The macro `define-generic-mode' can be used to define small modes | |
21014 | 31 ;; which provide basic comment and font-lock support. These modes are |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
32 ;; intended for the many configuration files and such which are too |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
33 ;; small for a "real" mode, but still have a regular syntax, comment |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
34 ;; characters and the like. |
18254 | 35 ;; |
36 ;; Each generic mode can define the following: | |
37 ;; | |
21014 | 38 ;; * List of comment-characters. The entries in this list should be |
18254 | 39 ;; either a character, a one or two character string or a cons pair. |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
40 ;; If the entry is a character or a string, it is added to the |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
41 ;; mode's syntax table with `comment-start' syntax. If the entry is |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
42 ;; a cons pair, the elements of the pair are considered to be |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
43 ;; `comment-start' and `comment-end' respectively. (The latter |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
44 ;; should be nil if you want comments to end at end of line.) |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
45 ;; LIMITATIONS: Emacs does not support comment strings of more than |
18254 | 46 ;; two characters in length. |
47 ;; | |
21014 | 48 ;; * List of keywords to font-lock. Each keyword should be a string. |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
49 ;; If you have additional keywords which should be highlighted in a |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
50 ;; face different from `font-lock-keyword-face', you can use the |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
51 ;; convenience function `generic-make-keywords-list' (which see), |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
52 ;; and add the result to the following list: |
32120 | 53 ;; |
21014 | 54 ;; * Additional expressions to font-lock. This should be a list of |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
55 ;; expressions, each of which should be of the same form as those in |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
56 ;; `font-lock-keywords'. |
32120 | 57 ;; |
18254 | 58 ;; * List of regular expressions to be placed in auto-mode-alist. |
59 ;; | |
60 ;; * List of functions to call to do some additional setup | |
61 ;; | |
62 ;; This should pretty much cover basic functionality; if you need much | |
63 ;; more than this, or you find yourself writing extensive customizations, | |
64 ;; perhaps you should be writing a major mode instead! | |
65 ;; | |
61455 | 66 ;; EXAMPLE: |
18254 | 67 ;; |
61455 | 68 ;; You can use `define-generic-mode' like this: |
18254 | 69 ;; |
70 ;; (define-generic-mode 'foo-generic-mode | |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
71 ;; (list ?%) |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
72 ;; (list "keyword") |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
73 ;; nil |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
74 ;; (list "\\.FOO\\'") |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
75 ;; (list 'foo-setup-function)) |
18254 | 76 ;; |
61455 | 77 ;; to define a new generic-mode `foo-generic-mode', which has '%' as a |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
78 ;; comment character, and "keyword" as a keyword. When files which |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
79 ;; end in '.FOO' are loaded, Emacs will go into foo-generic-mode and |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
80 ;; call foo-setup-function. You can also use the function |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
81 ;; `foo-generic-mode' (which is interactive) to put a buffer into |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
82 ;; foo-generic-mode. |
18254 | 83 ;; |
84 ;; GOTCHAS: | |
85 ;; | |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
86 ;; Be careful that your font-lock definitions are correct. Getting |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
87 ;; them wrong can cause Emacs to continually attempt to fontify! This |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
88 ;; problem is not specific to generic-mode. |
18254 | 89 |
21057 | 90 ;; Credit for suggestions, brainstorming, help with debugging: |
18254 | 91 ;; ACorreir@pervasive-sw.com (Alfred Correira) |
32120 | 92 ;; Extensive cleanup by: |
93 ;; Stefan Monnier (monnier+gnu/emacs@flint.cs.yale.edu) | |
61455 | 94 |
32120 | 95 ;;; Code: |
18254 | 96 |
97 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
21077
4b5c8a2ce0b2
(generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents:
21057
diff
changeset
|
98 ;; Internal Variables |
18254 | 99 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
100 | |
60870
92071f8a7671
(generic-font-lock-defaults): Make it obsolete.
Lute Kamstra <lute@gnu.org>
parents:
60849
diff
changeset
|
101 (defvar generic-font-lock-keywords nil |
92071f8a7671
(generic-font-lock-defaults): Make it obsolete.
Lute Kamstra <lute@gnu.org>
parents:
60849
diff
changeset
|
102 "Keywords for `font-lock-defaults' in a generic mode.") |
92071f8a7671
(generic-font-lock-defaults): Make it obsolete.
Lute Kamstra <lute@gnu.org>
parents:
60849
diff
changeset
|
103 (make-variable-buffer-local 'generic-font-lock-keywords) |
92071f8a7671
(generic-font-lock-defaults): Make it obsolete.
Lute Kamstra <lute@gnu.org>
parents:
60849
diff
changeset
|
104 (defvaralias 'generic-font-lock-defaults 'generic-font-lock-keywords) |
92071f8a7671
(generic-font-lock-defaults): Make it obsolete.
Lute Kamstra <lute@gnu.org>
parents:
60849
diff
changeset
|
105 (make-obsolete-variable 'generic-font-lock-defaults 'generic-font-lock-keywords "22.1") |
18254 | 106 |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
107 ;;;###autoload |
32120 | 108 (defvar generic-mode-list nil |
109 "A list of mode names for `generic-mode'. | |
24022
218b7edb9baf
Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents:
23392
diff
changeset
|
110 Do not add entries to this list directly; use `define-generic-mode' |
18254 | 111 instead (which see).") |
112 | |
21077
4b5c8a2ce0b2
(generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents:
21057
diff
changeset
|
113 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
18254 | 114 ;; Functions |
115 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
116 | |
22347
f53740d7d40d
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
21928
diff
changeset
|
117 ;;;###autoload |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
118 (defmacro define-generic-mode (mode comment-list keyword-list |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
119 font-lock-list auto-mode-list |
61241
3f688bd09fa4
(define-generic-mode): Add argument to specify keywords for defcustom.
Lute Kamstra <lute@gnu.org>
parents:
61183
diff
changeset
|
120 function-list &optional docstring |
3f688bd09fa4
(define-generic-mode): Add argument to specify keywords for defcustom.
Lute Kamstra <lute@gnu.org>
parents:
61183
diff
changeset
|
121 &rest custom-keyword-args) |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
122 "Create a new generic mode MODE. |
24022
218b7edb9baf
Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents:
23392
diff
changeset
|
123 |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
124 MODE is the name of the command for the generic mode; it need not |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
125 be quoted. The optional DOCSTRING is the documentation for the |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
126 mode command. If you do not supply it, a default documentation |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
127 string will be used instead. |
18254 | 128 |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
129 COMMENT-LIST is a list, whose entries are either a single |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
130 character, a one or two character string or a cons pair. If the |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
131 entry is a character or a string, it is added to the mode's |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
132 syntax table with `comment-start' syntax. If the entry is a cons |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
133 pair, the elements of the pair are considered to be |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
134 `comment-start' and `comment-end' respectively. (The latter |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
135 should be nil if you want comments to end at end of line.) Note |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
136 that Emacs has limitations regarding comment characters. |
18254 | 137 |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
138 KEYWORD-LIST is a list of keywords to highlight with |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
139 `font-lock-keyword-face'. Each keyword should be a string. |
18254 | 140 |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
141 FONT-LOCK-LIST is a list of additional expressions to highlight. |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
142 Each entry in the list should have the same form as an entry in |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
143 `font-lock-keywords'. |
18254 | 144 |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
145 AUTO-MODE-LIST is a list of regular expressions to add to |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
146 `auto-mode-alist'. These regexps are added to `auto-mode-alist' |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
147 as soon as `define-generic-mode' is called. |
18254 | 148 |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
149 FUNCTION-LIST is a list of functions to call to do some |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
150 additional setup. |
18254 | 151 |
61241
3f688bd09fa4
(define-generic-mode): Add argument to specify keywords for defcustom.
Lute Kamstra <lute@gnu.org>
parents:
61183
diff
changeset
|
152 The optional CUSTOM-KEYWORD-ARGS are pairs of keywords and |
3f688bd09fa4
(define-generic-mode): Add argument to specify keywords for defcustom.
Lute Kamstra <lute@gnu.org>
parents:
61183
diff
changeset
|
153 values. They will be passed to the generated `defcustom' form of |
61317
0aa94186ae69
(define-generic-mode): Don't use custom-current-group.
Lute Kamstra <lute@gnu.org>
parents:
61241
diff
changeset
|
154 the mode hook variable MODE-hook. Defaults to MODE without the |
0aa94186ae69
(define-generic-mode): Don't use custom-current-group.
Lute Kamstra <lute@gnu.org>
parents:
61241
diff
changeset
|
155 possible trailing \"-mode\". (This default may not be a valid |
0aa94186ae69
(define-generic-mode): Don't use custom-current-group.
Lute Kamstra <lute@gnu.org>
parents:
61241
diff
changeset
|
156 customization group defined with `defgroup'. Make sure it is.) |
0aa94186ae69
(define-generic-mode): Don't use custom-current-group.
Lute Kamstra <lute@gnu.org>
parents:
61241
diff
changeset
|
157 You can specify keyword arguments without specifying a docstring. |
61241
3f688bd09fa4
(define-generic-mode): Add argument to specify keywords for defcustom.
Lute Kamstra <lute@gnu.org>
parents:
61183
diff
changeset
|
158 |
21014 | 159 See the file generic-x.el for some examples of `define-generic-mode'." |
61183
20df42e1599e
(define-generic-mode): Add indentation rule.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
61169
diff
changeset
|
160 (declare (debug (sexp def-form def-form def-form form def-form |
61325
3b2c29df4165
(generic-mode-internal): Fix 2005-03-31 change.
Lute Kamstra <lute@gnu.org>
parents:
61317
diff
changeset
|
161 [&optional stringp] &rest [keywordp form])) |
61183
20df42e1599e
(define-generic-mode): Add indentation rule.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
61169
diff
changeset
|
162 (indent 1)) |
61169
e2b959792f0f
(define-generic-mode): Add debug declaration. Add defcustom for the
Lute Kamstra <lute@gnu.org>
parents:
60902
diff
changeset
|
163 |
e2b959792f0f
(define-generic-mode): Add debug declaration. Add defcustom for the
Lute Kamstra <lute@gnu.org>
parents:
60902
diff
changeset
|
164 ;; Backward compatibility. |
e2b959792f0f
(define-generic-mode): Add debug declaration. Add defcustom for the
Lute Kamstra <lute@gnu.org>
parents:
60902
diff
changeset
|
165 (when (eq (car-safe mode) 'quote) |
e2b959792f0f
(define-generic-mode): Add debug declaration. Add defcustom for the
Lute Kamstra <lute@gnu.org>
parents:
60902
diff
changeset
|
166 (setq mode (eval mode))) |
61241
3f688bd09fa4
(define-generic-mode): Add argument to specify keywords for defcustom.
Lute Kamstra <lute@gnu.org>
parents:
61183
diff
changeset
|
167 |
3f688bd09fa4
(define-generic-mode): Add argument to specify keywords for defcustom.
Lute Kamstra <lute@gnu.org>
parents:
61183
diff
changeset
|
168 (when (and docstring (not (stringp docstring))) |
3f688bd09fa4
(define-generic-mode): Add argument to specify keywords for defcustom.
Lute Kamstra <lute@gnu.org>
parents:
61183
diff
changeset
|
169 ;; DOCSTRING is not a string so we assume that it's actually the |
3f688bd09fa4
(define-generic-mode): Add argument to specify keywords for defcustom.
Lute Kamstra <lute@gnu.org>
parents:
61183
diff
changeset
|
170 ;; first keyword of CUSTOM-KEYWORD-ARGS. |
3f688bd09fa4
(define-generic-mode): Add argument to specify keywords for defcustom.
Lute Kamstra <lute@gnu.org>
parents:
61183
diff
changeset
|
171 (push docstring custom-keyword-args) |
3f688bd09fa4
(define-generic-mode): Add argument to specify keywords for defcustom.
Lute Kamstra <lute@gnu.org>
parents:
61183
diff
changeset
|
172 (setq docstring nil)) |
3f688bd09fa4
(define-generic-mode): Add argument to specify keywords for defcustom.
Lute Kamstra <lute@gnu.org>
parents:
61183
diff
changeset
|
173 |
61325
3b2c29df4165
(generic-mode-internal): Fix 2005-03-31 change.
Lute Kamstra <lute@gnu.org>
parents:
61317
diff
changeset
|
174 (let* ((name (symbol-name mode)) |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
175 (pretty-name (capitalize (replace-regexp-in-string |
61325
3b2c29df4165
(generic-mode-internal): Fix 2005-03-31 change.
Lute Kamstra <lute@gnu.org>
parents:
61317
diff
changeset
|
176 "-mode\\'" "" name))) |
3b2c29df4165
(generic-mode-internal): Fix 2005-03-31 change.
Lute Kamstra <lute@gnu.org>
parents:
61317
diff
changeset
|
177 (mode-hook (intern (concat name "-hook")))) |
18254 | 178 |
61241
3f688bd09fa4
(define-generic-mode): Add argument to specify keywords for defcustom.
Lute Kamstra <lute@gnu.org>
parents:
61183
diff
changeset
|
179 (unless (plist-get custom-keyword-args :group) |
3f688bd09fa4
(define-generic-mode): Add argument to specify keywords for defcustom.
Lute Kamstra <lute@gnu.org>
parents:
61183
diff
changeset
|
180 (setq custom-keyword-args |
3f688bd09fa4
(define-generic-mode): Add argument to specify keywords for defcustom.
Lute Kamstra <lute@gnu.org>
parents:
61183
diff
changeset
|
181 (plist-put custom-keyword-args |
61317
0aa94186ae69
(define-generic-mode): Don't use custom-current-group.
Lute Kamstra <lute@gnu.org>
parents:
61241
diff
changeset
|
182 :group `',(intern (replace-regexp-in-string |
61325
3b2c29df4165
(generic-mode-internal): Fix 2005-03-31 change.
Lute Kamstra <lute@gnu.org>
parents:
61317
diff
changeset
|
183 "-mode\\'" "" name))))) |
61241
3f688bd09fa4
(define-generic-mode): Add argument to specify keywords for defcustom.
Lute Kamstra <lute@gnu.org>
parents:
61183
diff
changeset
|
184 |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
185 `(progn |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
186 ;; Add a new entry. |
61325
3b2c29df4165
(generic-mode-internal): Fix 2005-03-31 change.
Lute Kamstra <lute@gnu.org>
parents:
61317
diff
changeset
|
187 (add-to-list 'generic-mode-list ,name) |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
188 |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
189 ;; Add it to auto-mode-alist |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
190 (dolist (re ,auto-mode-list) |
61169
e2b959792f0f
(define-generic-mode): Add debug declaration. Add defcustom for the
Lute Kamstra <lute@gnu.org>
parents:
60902
diff
changeset
|
191 (add-to-list 'auto-mode-alist (cons re ',mode))) |
32120 | 192 |
61169
e2b959792f0f
(define-generic-mode): Add debug declaration. Add defcustom for the
Lute Kamstra <lute@gnu.org>
parents:
60902
diff
changeset
|
193 (defcustom ,mode-hook nil |
e2b959792f0f
(define-generic-mode): Add debug declaration. Add defcustom for the
Lute Kamstra <lute@gnu.org>
parents:
60902
diff
changeset
|
194 ,(concat "Hook run when entering " pretty-name " mode.") |
e2b959792f0f
(define-generic-mode): Add debug declaration. Add defcustom for the
Lute Kamstra <lute@gnu.org>
parents:
60902
diff
changeset
|
195 :type 'hook |
61241
3f688bd09fa4
(define-generic-mode): Add argument to specify keywords for defcustom.
Lute Kamstra <lute@gnu.org>
parents:
61183
diff
changeset
|
196 ,@custom-keyword-args) |
61169
e2b959792f0f
(define-generic-mode): Add debug declaration. Add defcustom for the
Lute Kamstra <lute@gnu.org>
parents:
60902
diff
changeset
|
197 |
e2b959792f0f
(define-generic-mode): Add debug declaration. Add defcustom for the
Lute Kamstra <lute@gnu.org>
parents:
60902
diff
changeset
|
198 (defun ,mode () |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
199 ,(or docstring |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
200 (concat pretty-name " mode.\n" |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
201 "This a generic mode defined with `define-generic-mode'.")) |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
202 (interactive) |
61169
e2b959792f0f
(define-generic-mode): Add debug declaration. Add defcustom for the
Lute Kamstra <lute@gnu.org>
parents:
60902
diff
changeset
|
203 (generic-mode-internal ',mode ,comment-list ,keyword-list |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
204 ,font-lock-list ,function-list))))) |
18254 | 205 |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
206 ;;;###autoload |
61169
e2b959792f0f
(define-generic-mode): Add debug declaration. Add defcustom for the
Lute Kamstra <lute@gnu.org>
parents:
60902
diff
changeset
|
207 (defun generic-mode-internal (mode comment-list keyword-list |
e2b959792f0f
(define-generic-mode): Add debug declaration. Add defcustom for the
Lute Kamstra <lute@gnu.org>
parents:
60902
diff
changeset
|
208 font-lock-list function-list) |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
209 "Go into the generic mode MODE." |
61325
3b2c29df4165
(generic-mode-internal): Fix 2005-03-31 change.
Lute Kamstra <lute@gnu.org>
parents:
61317
diff
changeset
|
210 (let* ((name (symbol-name mode)) |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
211 (pretty-name (capitalize (replace-regexp-in-string |
61325
3b2c29df4165
(generic-mode-internal): Fix 2005-03-31 change.
Lute Kamstra <lute@gnu.org>
parents:
61317
diff
changeset
|
212 "-mode\\'" "" name))) |
3b2c29df4165
(generic-mode-internal): Fix 2005-03-31 change.
Lute Kamstra <lute@gnu.org>
parents:
61317
diff
changeset
|
213 (mode-hook (intern (concat name "-hook")))) |
18254 | 214 |
215 (kill-all-local-variables) | |
216 | |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
217 (setq major-mode mode |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
218 mode-name pretty-name) |
18254 | 219 |
61169
e2b959792f0f
(define-generic-mode): Add debug declaration. Add defcustom for the
Lute Kamstra <lute@gnu.org>
parents:
60902
diff
changeset
|
220 (generic-mode-set-comments comment-list) |
18254 | 221 |
60870
92071f8a7671
(generic-font-lock-defaults): Make it obsolete.
Lute Kamstra <lute@gnu.org>
parents:
60849
diff
changeset
|
222 ;; Font-lock functionality. |
92071f8a7671
(generic-font-lock-defaults): Make it obsolete.
Lute Kamstra <lute@gnu.org>
parents:
60849
diff
changeset
|
223 ;; Font-lock-defaults is always set even if there are no keywords |
18254 | 224 ;; or font-lock expressions, so comments can be highlighted. |
60870
92071f8a7671
(generic-font-lock-defaults): Make it obsolete.
Lute Kamstra <lute@gnu.org>
parents:
60849
diff
changeset
|
225 (setq generic-font-lock-keywords |
92071f8a7671
(generic-font-lock-defaults): Make it obsolete.
Lute Kamstra <lute@gnu.org>
parents:
60849
diff
changeset
|
226 (append |
61169
e2b959792f0f
(define-generic-mode): Add debug declaration. Add defcustom for the
Lute Kamstra <lute@gnu.org>
parents:
60902
diff
changeset
|
227 (when keyword-list |
e2b959792f0f
(define-generic-mode): Add debug declaration. Add defcustom for the
Lute Kamstra <lute@gnu.org>
parents:
60902
diff
changeset
|
228 (list (generic-make-keywords-list keyword-list |
e2b959792f0f
(define-generic-mode): Add debug declaration. Add defcustom for the
Lute Kamstra <lute@gnu.org>
parents:
60902
diff
changeset
|
229 font-lock-keyword-face))) |
60870
92071f8a7671
(generic-font-lock-defaults): Make it obsolete.
Lute Kamstra <lute@gnu.org>
parents:
60849
diff
changeset
|
230 font-lock-list)) |
92071f8a7671
(generic-font-lock-defaults): Make it obsolete.
Lute Kamstra <lute@gnu.org>
parents:
60849
diff
changeset
|
231 (setq font-lock-defaults '(generic-font-lock-keywords nil)) |
18254 | 232 |
233 ;; Call a list of functions | |
61169
e2b959792f0f
(define-generic-mode): Add debug declaration. Add defcustom for the
Lute Kamstra <lute@gnu.org>
parents:
60902
diff
changeset
|
234 (mapcar 'funcall function-list) |
23392
d86ad410d285
(generic-mode-with-type): Added hooks for generic-modes.
Karl Heuer <kwzh@gnu.org>
parents:
22402
diff
changeset
|
235 |
61169
e2b959792f0f
(define-generic-mode): Add debug declaration. Add defcustom for the
Lute Kamstra <lute@gnu.org>
parents:
60902
diff
changeset
|
236 (run-mode-hooks mode-hook))) |
18254 | 237 |
238 ;;;###autoload | |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
239 (defun generic-mode (mode) |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
240 "Enter generic mode MODE. |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
241 |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
242 Generic modes provide basic comment and font-lock functionality |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
243 for \"generic\" files. (Files which are too small to warrant their |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
244 own mode, but have comment characters, keywords, and the like.) |
18254 | 245 |
246 To define a generic-mode, use the function `define-generic-mode'. | |
24022
218b7edb9baf
Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents:
23392
diff
changeset
|
247 Some generic modes are defined in `generic-x.el'." |
18254 | 248 (interactive |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
249 (list (completing-read "Generic mode: " generic-mode-list nil t))) |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
250 (funcall (intern mode))) |
18254 | 251 |
252 ;;; Comment Functionality | |
253 (defun generic-mode-set-comments (comment-list) | |
254 "Set up comment functionality for generic mode." | |
32120 | 255 (let ((st (make-syntax-table)) |
256 (chars nil) | |
257 (comstyles)) | |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
258 (make-local-variable 'comment-start) |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
259 (make-local-variable 'comment-start-skip) |
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
260 (make-local-variable 'comment-end) |
18254 | 261 |
32120 | 262 ;; Go through all the comments |
263 (dolist (start comment-list) | |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
264 (let (end (comstyle "")) |
32120 | 265 ;; Normalize |
266 (when (consp start) | |
60773
1771db839aa6
Fix commentary section. Don't require cl for compilation.
Lute Kamstra <lute@gnu.org>
parents:
60595
diff
changeset
|
267 (setq end (cdr start)) |
32120 | 268 (setq start (car start))) |
269 (when (char-valid-p start) (setq start (char-to-string start))) | |
58473
9aacf8e5ae58
(generic-mode-set-comments): Accept an empty comment-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57113
diff
changeset
|
270 (cond |
9aacf8e5ae58
(generic-mode-set-comments): Accept an empty comment-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57113
diff
changeset
|
271 ((char-valid-p end) (setq end (char-to-string end))) |
9aacf8e5ae58
(generic-mode-set-comments): Accept an empty comment-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57113
diff
changeset
|
272 ((zerop (length end)) (setq end "\n"))) |
18254 | 273 |
32120 | 274 ;; Setup the vars for `comment-region' |
275 (if comment-start | |
276 ;; We have already setup a comment-style, so use style b | |
277 (progn | |
278 (setq comstyle "b") | |
279 (setq comment-start-skip | |
280 (concat comment-start-skip "\\|" (regexp-quote start) "+\\s-*"))) | |
281 ;; First comment-style | |
282 (setq comment-start start) | |
37058
a2e5f00c1254
(generic-mode-set-comments): Use "" rather than nil for comment-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
36124
diff
changeset
|
283 (setq comment-end (if (string-equal end "\n") "" end)) |
32120 | 284 (setq comment-start-skip (concat (regexp-quote start) "+\\s-*"))) |
18254 | 285 |
32120 | 286 ;; Reuse comstyles if necessary |
287 (setq comstyle | |
288 (or (cdr (assoc start comstyles)) | |
289 (cdr (assoc end comstyles)) | |
290 comstyle)) | |
291 (push (cons start comstyle) comstyles) | |
292 (push (cons end comstyle) comstyles) | |
18254 | 293 |
32120 | 294 ;; Setup the syntax table |
295 (if (= (length start) 1) | |
296 (modify-syntax-entry (string-to-char start) | |
297 (concat "< " comstyle) st) | |
298 (let ((c0 (elt start 0)) (c1 (elt start 1))) | |
299 ;; Store the relevant info but don't update yet | |
300 (push (cons c0 (concat (cdr (assoc c0 chars)) "1")) chars) | |
301 (push (cons c1 (concat (cdr (assoc c1 chars)) | |
302 (concat "2" comstyle))) chars))) | |
303 (if (= (length end) 1) | |
304 (modify-syntax-entry (string-to-char end) | |
305 (concat ">" comstyle) st) | |
306 (let ((c0 (elt end 0)) (c1 (elt end 1))) | |
307 ;; Store the relevant info but don't update yet | |
308 (push (cons c0 (concat (cdr (assoc c0 chars)) | |
309 (concat "3" comstyle))) chars) | |
310 (push (cons c1 (concat (cdr (assoc c1 chars)) "4")) chars))))) | |
18254 | 311 |
32120 | 312 ;; Process the chars that were part of a 2-char comment marker |
313 (dolist (cs (nreverse chars)) | |
314 (modify-syntax-entry (car cs) | |
315 (concat (char-to-string (char-syntax (car cs))) | |
316 " " (cdr cs)) | |
317 st)) | |
318 (set-syntax-table st))) | |
18254 | 319 |
320 (defun generic-bracket-support () | |
60870
92071f8a7671
(generic-font-lock-defaults): Make it obsolete.
Lute Kamstra <lute@gnu.org>
parents:
60849
diff
changeset
|
321 "Imenu support for [KEYWORD] constructs found in INF, INI and Samba files." |
24022
218b7edb9baf
Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents:
23392
diff
changeset
|
322 (setq imenu-generic-expression |
20459 | 323 '((nil "^\\[\\(.*\\)\\]" 1)) |
324 imenu-case-fold-search t)) | |
18254 | 325 |
60849
cb4033032773
(generic-make-keywords-list): Add autoload cookie.
Lute Kamstra <lute@gnu.org>
parents:
60773
diff
changeset
|
326 ;;;###autoload |
18254 | 327 (defun generic-make-keywords-list (keywords-list face &optional prefix suffix) |
24022
218b7edb9baf
Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents:
23392
diff
changeset
|
328 "Return a regular expression matching the specified KEYWORDS-LIST. |
18254 | 329 The regexp is highlighted with FACE." |
32120 | 330 (unless (listp keywords-list) |
331 (error "Keywords argument must be a list of strings")) | |
57113
5bd3a1e1dfe5
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-549
Miles Bader <miles@gnu.org>
parents:
55555
diff
changeset
|
332 (list (concat prefix "\\_<" |
21879
14316c9ecdac
(generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents:
21182
diff
changeset
|
333 ;; Use an optimized regexp. |
14316c9ecdac
(generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents:
21182
diff
changeset
|
334 (regexp-opt keywords-list t) |
57113
5bd3a1e1dfe5
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-549
Miles Bader <miles@gnu.org>
parents:
55555
diff
changeset
|
335 "\\_>" suffix) |
21879
14316c9ecdac
(generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents:
21182
diff
changeset
|
336 1 |
21928
42fa0da05721
(generic-make-keywords-list): Delete spurious paren.
Richard M. Stallman <rms@gnu.org>
parents:
21879
diff
changeset
|
337 face)) |
18254 | 338 |
21013
adb28ace7f33
Provide generic, not generic-mode.
Richard M. Stallman <rms@gnu.org>
parents:
20459
diff
changeset
|
339 (provide 'generic) |
18254 | 340 |
58473
9aacf8e5ae58
(generic-mode-set-comments): Accept an empty comment-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
57113
diff
changeset
|
341 ;; arch-tag: 239c1fc4-1303-48d9-9ac0-657d655669ea |
24022
218b7edb9baf
Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents:
23392
diff
changeset
|
342 ;;; generic.el ends here |