Mercurial > emacs
annotate lisp/generic.el @ 21068:cb35e7350402
Use browse-url directly.
author | Per Abrahamsen <abraham@dina.kvl.dk> |
---|---|
date | Wed, 04 Mar 1998 10:48:19 +0000 |
parents | 9b9c929675eb |
children | 4b5c8a2ce0b2 |
rev | line source |
---|---|
21013
adb28ace7f33
Provide generic, not generic-mode.
Richard M. Stallman <rms@gnu.org>
parents:
20459
diff
changeset
|
1 ;;; generic.el --- Defining simple major modes with comment and font-lock. |
18254 | 2 ;; |
3 ;; Copyright (C) 1997 Free Software Foundation, Inc. | |
4 ;; | |
21045 | 5 ;; Author: Peter Breton <pbreton@i-kinetics.com> |
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 ;; Purpose: | |
27 | |
28 ;; Meta-mode to create simple major modes | |
29 ;; with basic comment and font-lock support | |
30 | |
31 ;;; Commentary: | |
32 | |
33 ;; INTRODUCTION: | |
34 | |
35 ;; Generic-mode is a meta-mode which can be used to define small modes | |
21014 | 36 ;; which provide basic comment and font-lock support. These modes are |
18254 | 37 ;; intended for the many configuration files and such which are too small |
38 ;; for a "real" mode, but still have a regular syntax, comment characters | |
39 ;; and the like. | |
40 ;; | |
41 ;; Each generic mode can define the following: | |
42 ;; | |
21014 | 43 ;; * List of comment-characters. The entries in this list should be |
18254 | 44 ;; either a character, a one or two character string or a cons pair. |
45 ;; If the entry is a character or a one-character string | |
46 ;; LIMITATIONS: Emacs does not support comment strings of more than | |
47 ;; two characters in length. | |
48 ;; | |
21014 | 49 ;; * List of keywords to font-lock. Each keyword should be a string. |
18254 | 50 ;; If you have additional keywords which should be highlighted in a face |
51 ;; different from 'font-lock-keyword-face', you can use the convenience | |
52 ;; function 'generic-make-keywords-list' (which see), and add the | |
53 ;; result to the following list: | |
54 ;; | |
21014 | 55 ;; * Additional expressions to font-lock. This should be a list of |
18254 | 56 ;; expressions, each of which should be of the same form |
57 ;; as those in 'font-lock-defaults-alist'. | |
58 ;; | |
59 ;; * List of regular expressions to be placed in auto-mode-alist. | |
60 ;; | |
61 ;; * List of functions to call to do some additional setup | |
62 ;; | |
63 ;; This should pretty much cover basic functionality; if you need much | |
64 ;; more than this, or you find yourself writing extensive customizations, | |
65 ;; perhaps you should be writing a major mode instead! | |
66 ;; | |
67 ;; LOCAL VARIABLES: | |
68 ;; | |
69 ;; To put a file into generic mode using local variables, use a line | |
70 ;; like this in a Local Variables block: | |
71 ;; | |
72 ;; mode: default-generic | |
73 ;; | |
74 ;; Do NOT use "mode: generic"! | |
75 ;; See also "AUTOMATICALLY ENTERING GENERIC MODE" below. | |
76 ;; | |
77 ;; DEFINING NEW GENERIC MODES: | |
78 ;; | |
79 ;; Use the 'define-generic-mode' function to define new modes. | |
80 ;; For example: | |
81 ;; | |
82 ;; (require 'generic-mode) | |
83 ;; (define-generic-mode 'foo-generic-mode | |
84 ;; (list ?% ) | |
85 ;; (list "keyword") | |
86 ;; nil | |
87 ;; (list "\.FOO") | |
88 ;; (list 'foo-setup-function)) | |
89 ;; | |
90 ;; defines a new generic-mode 'foo-generic-mode', which has '%' as a | |
21014 | 91 ;; comment character, and "keyword" as a keyword. When files which end in |
18254 | 92 ;; '.FOO' are loaded, Emacs will go into foo-generic-mode and call |
93 ;; foo-setup-function. You can also use the function 'foo-generic-mode' | |
94 ;; (which is interactive) to put a buffer into foo-generic-mode. | |
95 ;; | |
96 ;; AUTOMATICALLY ENTERING GENERIC MODE: | |
97 ;; | |
98 ;; Generic-mode provides a hook which automatically puts a | |
99 ;; file into default-generic-mode if the first few lines of a file in | |
21014 | 100 ;; fundamental mode start with a hash comment character. To disable |
18254 | 101 ;; this functionality, set the variable 'generic-use-find-file-hook' |
21014 | 102 ;; to nil BEFORE loading generic-mode. See the variables |
18254 | 103 ;; 'generic-lines-to-scan' and 'generic-find-file-regexp' for customization |
104 ;; options. | |
105 ;; | |
106 ;; GOTCHAS: | |
107 ;; | |
21014 | 108 ;; Be careful that your font-lock definitions are correct. Getting them |
18254 | 109 ;; wrong can cause emacs to continually attempt to fontify! This problem |
110 ;; is not specific to generic-mode. | |
111 ;; | |
112 | |
21057 | 113 ;; Credit for suggestions, brainstorming, help with debugging: |
18254 | 114 ;; ACorreir@pervasive-sw.com (Alfred Correira) |
115 | |
116 ;;; Code: | |
117 | |
118 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
119 ;; Variables | |
120 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
121 | |
122 (make-variable-buffer-local | |
123 (defvar generic-font-lock-defaults nil | |
124 "Global defaults for font-lock in a generic mode.")) | |
125 | |
126 (make-variable-buffer-local | |
127 (defvar generic-mode-name 'default-generic-mode | |
128 "The name of the generic mode. | |
129 This is the car of one of the items in `generic-mode-alist'. | |
130 This variable is buffer-local.")) | |
131 | |
132 (make-variable-buffer-local | |
133 (defvar generic-comment-list nil | |
134 "List of comment characters for a generic mode.")) | |
135 | |
136 (make-variable-buffer-local | |
137 (defvar generic-keywords-list nil | |
138 "List of keywords for a generic mode.")) | |
139 | |
140 (make-variable-buffer-local | |
141 (defvar generic-font-lock-expressions nil | |
142 "List of font-lock expressions for a generic mode.")) | |
143 | |
144 (make-variable-buffer-local | |
145 (defvar generic-mode-function-list nil | |
146 "List of customization functions to call for a generic mode.")) | |
147 | |
148 (make-variable-buffer-local | |
149 (defvar generic-mode-syntax-table nil | |
150 "Syntax table for use in a generic mode.")) | |
151 | |
152 (defvar generic-mode-alist nil | |
153 "An association list for generic-mode. | |
154 Each entry in the list looks like this: | |
155 | |
156 NAME COMMENT-LIST KEYWORD-LIST FONT-LOCK-LIST AUTO-MODE-LIST FUNCTION-LIST. | |
157 | |
158 Do not add entries to this list directly; use `define-generic-mode' | |
159 instead (which see).") | |
160 | |
161 (defvar generic-use-find-file-hook t | |
162 "*If non-nil, add a hook to enter default-generic-mode automatically | |
163 if the first few lines of a file in fundamental mode start with a hash | |
164 comment character.") | |
165 | |
166 (defvar generic-lines-to-scan 3 | |
167 "*Number of lines that `generic-mode-find-file-hook' looks at | |
168 when deciding whether to enter generic-mode automatically. | |
169 This variable should be set to a small positive number.") | |
170 | |
171 (defvar generic-find-file-regexp "#.*\n\\(.*\n\\)?" | |
172 "*Regular expression used by `generic-mode-find-file-hook' | |
173 to determine if files in fundamental mode should be put into | |
174 `default-generic-mode' instead.") | |
175 | |
176 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
177 ;; Inline functions | |
178 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
179 | |
180 (defsubst generic-read-type () | |
181 (completing-read | |
182 "Generic Type: " | |
183 (mapcar | |
184 '(lambda (elt) (list (symbol-name (car elt)))) | |
185 generic-mode-alist) nil t)) | |
186 | |
187 ;; Basic sanity checks. It does *not* check whether the elements of the lists | |
188 ;; are of the correct type. | |
189 (defsubst generic-mode-sanity-check (name comment-list keyword-list | |
190 font-lock-list auto-mode-list | |
191 function-list &optional description) | |
192 (if (not (symbolp name)) | |
193 (error "%s is not a symbol" (princ name))) | |
194 | |
195 (mapcar '(lambda (elt) | |
196 (if (not (listp elt)) | |
197 (error "%s is not a list" (princ elt)))) | |
198 (list comment-list keyword-list font-lock-list | |
199 auto-mode-list function-list)) | |
200 | |
201 (if (not (or (null description) (stringp description))) | |
202 (error "Description must be a string or nil")) | |
203 ) | |
204 | |
205 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
206 ;; Functions | |
207 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
208 | |
209 ;;;### autoload | |
210 (defun define-generic-mode (name comment-list keyword-list font-lock-list | |
211 auto-mode-list function-list | |
212 &optional description) | |
213 "Create a new generic mode with NAME. | |
214 NAME should be a symbol; its string representation is used as the function | |
215 name. If DESCRIPTION is provided, it is used as the docstring for the new | |
216 function. | |
217 | |
218 COMMENT-LIST is a list, whose entries are either a single character, | |
219 a one or two character string or a cons pair. If the entry is a character | |
220 or a one-character string, it is added to the mode's syntax table with | |
221 comment-start syntax. If the entry is a cons pair, the elements of the | |
222 pair are considered to be comment-start and comment-end respectively. | |
223 Note that Emacs has limitations regarding comment characters. | |
224 | |
225 KEYWORD-LIST is a list of keywords to highlight with `font-lock-keyword-face'. | |
226 Each keyword should be a string. | |
227 | |
228 FONT-LOCK-LIST is a list of additional expressions to highlight. Each entry | |
229 in the list should have the same form as an entry in `font-lock-defaults-alist' | |
230 | |
231 AUTO-MODE-LIST is a list of regular expressions to add to auto-mode-alist. | |
232 These regexps are added to auto-mode-alist as soon as `define-generic-mode' | |
21014 | 233 is called; any old regexps with the same name are removed. |
18254 | 234 |
235 FUNCTION-LIST is a list of functions to call to do some additional setup. | |
236 | |
21014 | 237 See the file generic-x.el for some examples of `define-generic-mode'." |
18254 | 238 |
239 ;; Basic sanity check | |
240 (generic-mode-sanity-check name | |
241 comment-list keyword-list font-lock-list | |
242 auto-mode-list function-list description) | |
243 | |
244 ;; Remove any old entry | |
245 (setq generic-mode-alist | |
246 (delq (assq name generic-mode-alist) | |
247 generic-mode-alist)) | |
248 | |
249 ;; Add a new entry | |
250 (setq generic-mode-alist | |
251 (append | |
252 (list | |
253 (list | |
254 name comment-list keyword-list font-lock-list | |
255 auto-mode-list function-list | |
256 )) | |
257 generic-mode-alist)) | |
258 | |
259 ;; Add it to auto-mode-alist | |
260 (generic-add-to-auto-mode name auto-mode-list t) | |
261 | |
262 ;; Define a function for it | |
263 (generic-create-generic-function name description) | |
264 ) | |
265 | |
266 (defun generic-add-to-auto-mode (mode auto-mode-list | |
267 &optional remove-old prepend) | |
268 "Add the entries for mode to `auto-mode-alist'. | |
269 If remove-old is non-nil, removes old entries first. If prepend is | |
270 non-nil, prepends entries to auto-mode-alist; otherwise, appends them." | |
271 | |
272 (if (not (listp auto-mode-list)) | |
273 (error "%s is not a list" (princ auto-mode-list))) | |
274 | |
275 (let ((new-mode (intern (symbol-name mode)))) | |
276 (if remove-old | |
277 (let ((auto-mode-entry)) | |
278 (while (setq auto-mode-entry (rassq new-mode auto-mode-alist)) | |
279 (setq auto-mode-alist | |
280 (delq auto-mode-entry | |
281 auto-mode-alist))))) | |
282 | |
283 (mapcar '(lambda (entry) | |
284 (generic-add-auto-mode-entry new-mode entry prepend)) | |
285 auto-mode-list))) | |
286 | |
287 (defun generic-add-auto-mode-entry (name entry &optional prepend) | |
288 "Add a new entry to the end of auto-mode-alist. | |
289 If prepend is non-nil, add the entry to the front of the list." | |
290 (let ((new-entry (list (cons entry name)))) | |
291 (setq auto-mode-alist | |
292 (if prepend | |
293 (append new-entry auto-mode-alist) | |
294 (append auto-mode-alist new-entry))))) | |
295 | |
296 (defun generic-create-generic-function (name &optional description) | |
297 "Create a generic mode function with NAME. | |
298 If DESCRIPTION is provided, it is used as the docstring." | |
299 (let ((symname (symbol-name name))) | |
300 (fset (intern symname) | |
301 (list 'lambda nil | |
302 (or description | |
303 (concat "Generic mode for type " symname)) | |
304 (list 'interactive) | |
305 (list 'generic-mode-with-type (list 'quote name)))))) | |
306 | |
307 (defun generic-mode-with-type (&optional mode) | |
308 "Go into the generic-mode MODE." | |
309 (let* ((type (or mode generic-mode-name)) | |
310 (generic-mode-list (assoc type generic-mode-alist)) | |
311 ) | |
312 | |
313 (if (not generic-mode-list) | |
314 (error "Can't find generic-mode information for type %s" | |
315 (princ generic-mode-name))) | |
316 | |
317 ;; Put this after the point where we read generic-mode-name! | |
318 (kill-all-local-variables) | |
319 | |
320 (setq | |
321 generic-mode-name type | |
322 generic-comment-list (nth 1 generic-mode-list) | |
323 generic-keywords-list (nth 2 generic-mode-list) | |
324 generic-font-lock-expressions (nth 3 generic-mode-list) | |
325 generic-mode-function-list (nth 5 generic-mode-list) | |
326 major-mode 'generic-mode | |
327 mode-name (symbol-name type) | |
328 ) | |
329 | |
330 (generic-mode-set-comments generic-comment-list) | |
331 | |
332 ;; Font-lock functionality | |
333 ;; Font-lock-defaults are always set even if there are no keywords | |
334 ;; or font-lock expressions, so comments can be highlighted. | |
335 (setq generic-font-lock-defaults nil) | |
336 (generic-mode-set-font-lock generic-keywords-list | |
337 generic-font-lock-expressions) | |
338 (make-local-variable 'font-lock-defaults) | |
339 (setq font-lock-defaults (list 'generic-font-lock-defaults nil)) | |
340 | |
341 ;; Call a list of functions | |
342 (if generic-mode-function-list | |
343 (mapcar 'funcall generic-mode-function-list)) | |
344 ) | |
345 ) | |
346 | |
347 ;;;###autoload | |
348 (defun generic-mode (type) | |
349 "A mode to do basic comment and font-lock functionality | |
350 for files which are too small to warrant their own mode, but have | |
351 comment characters, keywords, and the like. | |
352 | |
353 To define a generic-mode, use the function `define-generic-mode'. | |
21014 | 354 Some generic modes are defined in `generic-x.el'." |
18254 | 355 (interactive |
356 (list (generic-read-type))) | |
357 (generic-mode-with-type (intern type))) | |
358 | |
359 ;;; Comment Functionality | |
360 (defun generic-mode-set-comments (comment-list) | |
361 "Set up comment functionality for generic mode." | |
362 (if (null comment-list) | |
363 nil | |
364 (let ((generic-mode-syntax-table (make-syntax-table))) | |
365 (make-local-variable 'comment-start) | |
366 (make-local-variable 'comment-start-skip) | |
367 (make-local-variable 'comment-end) | |
368 (mapcar 'generic-mode-set-a-comment comment-list) | |
369 (set-syntax-table generic-mode-syntax-table)))) | |
370 | |
371 (defun generic-mode-set-a-comment (comment) | |
372 (and (char-or-string-p comment) | |
373 (if (stringp comment) | |
374 (cond | |
375 ((eq (length comment) 1) | |
376 (generic-mode-set-comment-char | |
377 (string-to-char comment))) | |
378 ((eq (length comment) 2) | |
379 (generic-mode-set-comment-string comment)) | |
380 (t | |
381 (error "Character string %s must be one or two characters long" | |
382 comment)) | |
383 ) | |
384 (generic-mode-set-comment-char comment))) | |
385 (if (consp comment) | |
386 (generic-mode-set-comment-pair comment))) | |
387 | |
388 (defun generic-mode-set-comment-char (comment-char) | |
389 "Set the given character as a comment character for generic mode." | |
390 (if (not comment-char) | |
391 nil | |
392 (setq | |
393 comment-end "" | |
394 comment-start (char-to-string comment-char) | |
395 comment-start-skip (concat comment-start "+ *") | |
396 ) | |
397 | |
398 (modify-syntax-entry comment-char "<" | |
399 generic-mode-syntax-table) | |
400 (modify-syntax-entry ?\n ">" | |
401 generic-mode-syntax-table))) | |
402 | |
403 (defun generic-mode-set-comment-string (comment-string) | |
404 "Set the given string as a comment string for generic mode." | |
405 (if (not comment-string) | |
406 nil | |
407 (setq | |
408 comment-end "" | |
409 comment-start comment-string | |
410 comment-start-skip (concat comment-start " *") | |
411 ) | |
412 | |
413 (let ((first (elt comment-string 0)) | |
414 (second (elt comment-string 1))) | |
415 ;; C++ style comments | |
416 (if (char-equal first second) | |
417 (progn | |
418 (modify-syntax-entry first "<12b" | |
419 generic-mode-syntax-table) | |
420 (modify-syntax-entry ?\n ">b" | |
421 generic-mode-syntax-table))) | |
422 ;; Some other two character string | |
423 (modify-syntax-entry first "<1" | |
424 generic-mode-syntax-table) | |
425 (modify-syntax-entry second "<2" | |
426 generic-mode-syntax-table) | |
427 (modify-syntax-entry ?\n ">" | |
428 generic-mode-syntax-table)))) | |
429 | |
430 (defun generic-mode-set-comment-pair (comment-pair) | |
431 "Set the given comment pair as a comment start and end for generic mode." | |
432 (let ((generic-comment-start (car comment-pair)) | |
433 (generic-comment-end (cdr comment-pair)) | |
434 ) | |
435 (setq | |
436 comment-end generic-comment-end | |
437 comment-start generic-comment-start | |
438 comment-start-skip (concat generic-comment-start " *") | |
439 ) | |
440 | |
441 ;; Sanity checks | |
442 (if (not (and (stringp generic-comment-start) | |
443 (stringp generic-comment-end))) | |
444 (error "Elements of cons pair must be strings")) | |
445 (if (not (and (equal (length generic-comment-start) 2) | |
446 (equal (length generic-comment-end) 2))) | |
447 (error "Start and end must be exactly two characters long")) | |
448 | |
449 (let ((first (elt generic-comment-start 0)) | |
450 (second (elt generic-comment-start 1)) | |
451 (third (elt generic-comment-end 0)) | |
452 (fourth (elt generic-comment-end 1)) | |
453 ) | |
454 | |
455 (modify-syntax-entry first ". 1" generic-mode-syntax-table) | |
456 (modify-syntax-entry second ". 2" generic-mode-syntax-table) | |
457 | |
458 (modify-syntax-entry | |
459 third | |
460 (concat | |
461 "." | |
462 (cond | |
463 ((char-equal first third) " 13") | |
464 ((char-equal second third) " 23") | |
465 (t " 3")) | |
466 ) | |
467 generic-mode-syntax-table) | |
468 | |
469 (modify-syntax-entry | |
470 fourth | |
471 (concat | |
472 "." | |
473 (cond | |
474 ((char-equal first fourth) " 14") | |
475 ((char-equal second fourth) " 24") | |
476 (t " 4")) | |
477 ) | |
478 generic-mode-syntax-table) | |
479 ))) | |
480 | |
481 (defun generic-mode-set-font-lock (keywords font-lock-expressions) | |
482 "Set up font-lock functionality for generic mode." | |
483 (let ((generic-font-lock-expressions)) | |
484 ;; Keywords | |
485 (if keywords | |
486 (setq | |
487 generic-font-lock-expressions | |
488 (append | |
489 (list | |
490 (list | |
491 (concat | |
492 "\\(\\<" | |
493 (mapconcat 'identity keywords "\\>\\|\\<") | |
494 "\\>\\)") | |
495 1 'font-lock-keyword-face)) | |
496 generic-font-lock-expressions))) | |
497 ;; Other font-lock expressions | |
498 (if font-lock-expressions | |
499 (setq generic-font-lock-expressions | |
500 (append | |
501 font-lock-expressions | |
502 generic-font-lock-expressions))) | |
503 (if (not (or font-lock-expressions keywords)) | |
504 nil | |
505 (setq generic-font-lock-defaults generic-font-lock-expressions)) | |
506 )) | |
507 | |
508 ;; Support for [KEYWORD] constructs found in INF, INI and Samba files | |
509 (defun generic-bracket-support () | |
510 (setq imenu-generic-expression | |
20459 | 511 '((nil "^\\[\\(.*\\)\\]" 1)) |
512 imenu-case-fold-search t)) | |
18254 | 513 |
514 ;; This generic mode is always defined | |
515 (define-generic-mode 'default-generic-mode (list ?#) nil nil nil nil) | |
516 | |
517 ;; A more general solution would allow us to enter generic-mode for | |
518 ;; *any* comment character, but would require us to synthesize a new | |
519 ;; generic-mode on the fly. I think this gives us most of what we | |
520 ;; want. | |
521 (defun generic-mode-find-file-hook () | |
522 "Hook to enter default-generic-mode automatically | |
523 if the first few lines of a file in fundamental-mode start with a hash | |
524 comment character. This hook will be installed if the variable | |
525 `generic-use-find-file-hook' is non-nil. The variable `generic-lines-to-scan' | |
526 determines the number of lines to look at." | |
527 (if (not (eq major-mode 'fundamental-mode)) | |
528 nil | |
529 (if (or (> 1 generic-lines-to-scan) | |
530 (< 50 generic-lines-to-scan)) | |
531 (error "Variable `generic-lines-to-scan' should be set to a small" | |
532 " positive number")) | |
533 (let ((comment-regexp "") | |
534 (count 0) | |
535 ) | |
536 (while (< count generic-lines-to-scan) | |
537 (setq comment-regexp (concat comment-regexp | |
538 generic-find-file-regexp)) | |
539 (setq count (1+ count))) | |
540 (save-excursion | |
541 (goto-char (point-min)) | |
542 (if (looking-at comment-regexp) | |
543 (generic-mode-with-type 'default-generic-mode)))))) | |
544 | |
545 (defun generic-mode-ini-file-find-file-hook () | |
546 "Hook to enter default-generic-mode automatically | |
547 if the first few lines of a file in fundamental-mode look like an INI file. | |
548 This hook is NOT installed by default." | |
549 (if (not (eq major-mode 'fundamental-mode)) | |
550 nil | |
551 (save-excursion | |
552 (goto-char (point-min)) | |
553 (if (looking-at "^\\s-*\\[.*\\]") | |
554 (generic-mode-with-type 'ini-generic-mode))))) | |
555 | |
556 (and generic-use-find-file-hook | |
557 (add-hook 'find-file-hooks 'generic-mode-find-file-hook)) | |
558 | |
559 (defun generic-make-keywords-list (keywords-list face &optional prefix suffix) | |
560 "Return a regular expression matching the specified keywords. | |
561 The regexp is highlighted with FACE." | |
562 ;; Sanity checks | |
563 ;; Don't check here; face may not be defined yet | |
564 ;; (if (not (facep face)) | |
565 ;; (error "Face %s is not defined" (princ face))) | |
566 (if (not (listp keywords-list)) | |
567 (error "Keywords argument must be a list of strings")) | |
568 (list | |
569 (concat | |
570 (or prefix "") | |
571 "\\(\\<" | |
572 (mapconcat 'identity keywords-list "\\>\\|\\<") | |
573 "\\>\\)" | |
574 (or suffix "") | |
575 ) 1 face)) | |
576 | |
21013
adb28ace7f33
Provide generic, not generic-mode.
Richard M. Stallman <rms@gnu.org>
parents:
20459
diff
changeset
|
577 (provide 'generic) |
18254 | 578 |
21013
adb28ace7f33
Provide generic, not generic-mode.
Richard M. Stallman <rms@gnu.org>
parents:
20459
diff
changeset
|
579 ;;; generic.el ends here |