annotate lisp/emacs-lisp/generic.el @ 64794:950e3342b9d7

(xml-att-def-re): Add defvar.
author Richard M. Stallman <rms@gnu.org>
date Tue, 09 Aug 2005 02:52:15 +0000
parents 5b1a238fcbb4
children 45df3993d950
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
61521
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
1 ;;; generic.el --- defining simple major modes with comment and font-lock
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
2 ;;
64751
5b1a238fcbb4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64085
diff changeset
3 ;; Copyright (C) 1997, 1999, 2002, 2003, 2004,
5b1a238fcbb4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64085
diff changeset
4 ;; 2005 Free Software Foundation, Inc.
61521
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
5 ;;
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
6 ;; Author: Peter Breton <pbreton@cs.umb.edu>
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
7 ;; Created: Fri Sep 27 1996
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
8 ;; Keywords: generic, comment, font-lock
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
9
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
11
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
15 ;; any later version.
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
16
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
21
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 62260
diff changeset
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 62260
diff changeset
25 ;; Boston, MA 02110-1301, USA.
61521
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
26
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
28
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
29 ;; INTRODUCTION:
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
30 ;;
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
31 ;; The macro `define-generic-mode' can be used to define small modes
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
32 ;; which provide basic comment and font-lock support. These modes are
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
33 ;; intended for the many configuration files and such which are too
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
34 ;; small for a "real" mode, but still have a regular syntax, comment
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
35 ;; characters and the like.
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
36 ;;
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
37 ;; Each generic mode can define the following:
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
38 ;;
61931
f3e1b2ceffd2 Improve commentary section.
Lute Kamstra <lute@gnu.org>
parents: 61916
diff changeset
39 ;; * List of comment-characters. The elements of this list should be
f3e1b2ceffd2 Improve commentary section.
Lute Kamstra <lute@gnu.org>
parents: 61916
diff changeset
40 ;; either a character, a one or two character string, or a cons
f3e1b2ceffd2 Improve commentary section.
Lute Kamstra <lute@gnu.org>
parents: 61916
diff changeset
41 ;; cell. If the entry is a character or a string, it is added to
f3e1b2ceffd2 Improve commentary section.
Lute Kamstra <lute@gnu.org>
parents: 61916
diff changeset
42 ;; the mode's syntax table with "comment starter" syntax. If the
f3e1b2ceffd2 Improve commentary section.
Lute Kamstra <lute@gnu.org>
parents: 61916
diff changeset
43 ;; entry is a cons cell, the `car' and `cdr' of the pair are
f3e1b2ceffd2 Improve commentary section.
Lute Kamstra <lute@gnu.org>
parents: 61916
diff changeset
44 ;; considered the "comment starter" and "comment ender"
f3e1b2ceffd2 Improve commentary section.
Lute Kamstra <lute@gnu.org>
parents: 61916
diff changeset
45 ;; respectively. (The latter should be nil if you want comments to
f3e1b2ceffd2 Improve commentary section.
Lute Kamstra <lute@gnu.org>
parents: 61916
diff changeset
46 ;; end at the end of the line.) Emacs does not support comment
f3e1b2ceffd2 Improve commentary section.
Lute Kamstra <lute@gnu.org>
parents: 61916
diff changeset
47 ;; strings of more than two characters in length.
61521
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
48 ;;
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
49 ;; * List of keywords to font-lock. Each keyword should be a string.
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
50 ;; If you have additional keywords which should be highlighted in a
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
51 ;; face different from `font-lock-keyword-face', you can use the
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
52 ;; convenience function `generic-make-keywords-list' (which see),
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
53 ;; and add the result to the following list:
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
54 ;;
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
55 ;; * Additional expressions to font-lock. This should be a list of
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
56 ;; expressions, each of which should be of the same form as those in
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
57 ;; `font-lock-keywords'.
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
58 ;;
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
59 ;; * List of regular expressions to be placed in auto-mode-alist.
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
60 ;;
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
61 ;; * List of functions to call to do some additional setup
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
62 ;;
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
63 ;; This should pretty much cover basic functionality; if you need much
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
64 ;; more than this, or you find yourself writing extensive customizations,
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
65 ;; perhaps you should be writing a major mode instead!
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
66 ;;
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
67 ;; EXAMPLE:
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
68 ;;
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
69 ;; You can use `define-generic-mode' like this:
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
70 ;;
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
71 ;; (define-generic-mode 'foo-generic-mode
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
72 ;; (list ?%)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
73 ;; (list "keyword")
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
74 ;; nil
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
75 ;; (list "\\.FOO\\'")
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
76 ;; (list 'foo-setup-function))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
77 ;;
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
78 ;; to define a new generic-mode `foo-generic-mode', which has '%' as a
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
79 ;; comment character, and "keyword" as a keyword. When files which
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
80 ;; end in '.FOO' are loaded, Emacs will go into foo-generic-mode and
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
81 ;; call foo-setup-function. You can also use the function
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
82 ;; `foo-generic-mode' (which is interactive) to put a buffer into
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
83 ;; foo-generic-mode.
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
84 ;;
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
85 ;; GOTCHAS:
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
86 ;;
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
87 ;; Be careful that your font-lock definitions are correct. Getting
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
88 ;; them wrong can cause Emacs to continually attempt to fontify! This
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
89 ;; problem is not specific to generic-mode.
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
90
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
91 ;; Credit for suggestions, brainstorming, help with debugging:
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
92 ;; ACorreir@pervasive-sw.com (Alfred Correira)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
93 ;; Extensive cleanup by:
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
94 ;; Stefan Monnier (monnier+gnu/emacs@flint.cs.yale.edu)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
95
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
96 ;;; Code:
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
97
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
98 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
99 ;; Internal Variables
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
100 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
101
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
102 (defvar generic-font-lock-keywords nil
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
103 "Keywords for `font-lock-defaults' in a generic mode.")
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
104 (make-variable-buffer-local 'generic-font-lock-keywords)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
105 (defvaralias 'generic-font-lock-defaults 'generic-font-lock-keywords)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
106 (make-obsolete-variable 'generic-font-lock-defaults 'generic-font-lock-keywords "22.1")
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
107
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
108 ;;;###autoload
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
109 (defvar generic-mode-list nil
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
110 "A list of mode names for `generic-mode'.
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
111 Do not add entries to this list directly; use `define-generic-mode'
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
112 instead (which see).")
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
113
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
114 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
115 ;; Functions
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
116 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
117
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
118 ;;;###autoload
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
119 (defmacro define-generic-mode (mode comment-list keyword-list
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
120 font-lock-list auto-mode-list
62260
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
121 function-list &optional docstring)
61521
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
122 "Create a new generic mode MODE.
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
123
62260
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
124 MODE is the name of the command for the generic mode; don't quote it.
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
125 The optional DOCSTRING is the documentation for the mode command. If
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
126 you do not supply it, `define-generic-mode' uses a default
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
127 documentation string instead.
61521
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
128
62260
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
129 COMMENT-LIST is a list in which each element is either a character, a
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
130 string of one or two characters, or a cons cell. A character or a
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
131 string is set up in the mode's syntax table as a \"comment starter\".
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
132 If the entry is a cons cell, the `car' is set up as a \"comment
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
133 starter\" and the `cdr' as a \"comment ender\". (Use nil for the
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
134 latter if you want comments to end at the end of the line.) Note that
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
135 the syntax table has limitations about what comment starters and
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
136 enders are actually possible.
61521
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
137
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
138 KEYWORD-LIST is a list of keywords to highlight with
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
139 `font-lock-keyword-face'. Each keyword should be a string.
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
140
62260
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
141 FONT-LOCK-LIST is a list of additional expressions to highlight. Each
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
142 element of this list should have the same form as an element of
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
143 `font-lock-keywords'.
61521
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
144
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
145 AUTO-MODE-LIST is a list of regular expressions to add to
62260
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
146 `auto-mode-alist'. These regular expressions are added when Emacs
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
147 runs the macro expansion.
61521
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
148
62260
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
149 FUNCTION-LIST is a list of functions to call to do some additional
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
150 setup. The mode command calls these functions just before it runs the
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
151 mode hook `MODE-hook'.
61521
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
152
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
153 See the file generic-x.el for some examples of `define-generic-mode'."
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
154 (declare (debug (sexp def-form def-form def-form form def-form
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
155 [&optional stringp] &rest [keywordp form]))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
156 (indent 1))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
157
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
158 ;; Backward compatibility.
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
159 (when (eq (car-safe mode) 'quote)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
160 (setq mode (eval mode)))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
161
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
162 (let* ((name (symbol-name mode))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
163 (pretty-name (capitalize (replace-regexp-in-string
62260
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
164 "-mode\\'" "" name))))
61521
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
165
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
166 `(progn
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
167 ;; Add a new entry.
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
168 (add-to-list 'generic-mode-list ,name)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
169
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
170 ;; Add it to auto-mode-alist
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
171 (dolist (re ,auto-mode-list)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
172 (add-to-list 'auto-mode-alist (cons re ',mode)))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
173
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
174 (defun ,mode ()
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
175 ,(or docstring
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
176 (concat pretty-name " mode.\n"
62260
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
177 "This a generic mode defined with `define-generic-mode'.\n"
a0af6e05c03a (define-generic-mode): Don't generate a defcustom for the mode hook
Lute Kamstra <lute@gnu.org>
parents: 61931
diff changeset
178 "It runs `" name "-hook' as the last thing it does."))
61521
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
179 (interactive)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
180 (generic-mode-internal ',mode ,comment-list ,keyword-list
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
181 ,font-lock-list ,function-list)))))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
182
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
183 ;;;###autoload
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
184 (defun generic-mode-internal (mode comment-list keyword-list
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
185 font-lock-list function-list)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
186 "Go into the generic mode MODE."
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
187 (let* ((name (symbol-name mode))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
188 (pretty-name (capitalize (replace-regexp-in-string
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
189 "-mode\\'" "" name)))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
190 (mode-hook (intern (concat name "-hook"))))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
191
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
192 (kill-all-local-variables)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
193
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
194 (setq major-mode mode
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
195 mode-name pretty-name)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
196
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
197 (generic-mode-set-comments comment-list)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
198
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
199 ;; Font-lock functionality.
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
200 ;; Font-lock-defaults is always set even if there are no keywords
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
201 ;; or font-lock expressions, so comments can be highlighted.
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
202 (setq generic-font-lock-keywords font-lock-list)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
203 (when keyword-list
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
204 (push (concat "\\_<" (regexp-opt keyword-list t) "\\_>")
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
205 generic-font-lock-keywords))
61904
114b2859d567 (generic-mode-internal): Simplify font-lock-defaults.
Lute Kamstra <lute@gnu.org>
parents: 61521
diff changeset
206 (setq font-lock-defaults '(generic-font-lock-keywords))
61521
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
207
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
208 ;; Call a list of functions
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
209 (mapcar 'funcall function-list)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
210
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
211 (run-mode-hooks mode-hook)))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
212
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
213 ;;;###autoload
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
214 (defun generic-mode (mode)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
215 "Enter generic mode MODE.
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
216
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
217 Generic modes provide basic comment and font-lock functionality
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
218 for \"generic\" files. (Files which are too small to warrant their
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
219 own mode, but have comment characters, keywords, and the like.)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
220
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
221 To define a generic-mode, use the function `define-generic-mode'.
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
222 Some generic modes are defined in `generic-x.el'."
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
223 (interactive
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
224 (list (completing-read "Generic mode: " generic-mode-list nil t)))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
225 (funcall (intern mode)))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
226
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
227 ;;; Comment Functionality
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
228 (defun generic-mode-set-comments (comment-list)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
229 "Set up comment functionality for generic mode."
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
230 (let ((st (make-syntax-table))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
231 (chars nil)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
232 (comstyles))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
233 (make-local-variable 'comment-start)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
234 (make-local-variable 'comment-start-skip)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
235 (make-local-variable 'comment-end)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
236
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
237 ;; Go through all the comments
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
238 (dolist (start comment-list)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
239 (let (end (comstyle ""))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
240 ;; Normalize
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
241 (when (consp start)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
242 (setq end (cdr start))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
243 (setq start (car start)))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
244 (when (char-valid-p start) (setq start (char-to-string start)))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
245 (cond
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
246 ((char-valid-p end) (setq end (char-to-string end)))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
247 ((zerop (length end)) (setq end "\n")))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
248
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
249 ;; Setup the vars for `comment-region'
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
250 (if comment-start
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
251 ;; We have already setup a comment-style, so use style b
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
252 (progn
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
253 (setq comstyle "b")
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
254 (setq comment-start-skip
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
255 (concat comment-start-skip "\\|" (regexp-quote start) "+\\s-*")))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
256 ;; First comment-style
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
257 (setq comment-start start)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
258 (setq comment-end (if (string-equal end "\n") "" end))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
259 (setq comment-start-skip (concat (regexp-quote start) "+\\s-*")))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
260
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
261 ;; Reuse comstyles if necessary
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
262 (setq comstyle
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
263 (or (cdr (assoc start comstyles))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
264 (cdr (assoc end comstyles))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
265 comstyle))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
266 (push (cons start comstyle) comstyles)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
267 (push (cons end comstyle) comstyles)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
268
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
269 ;; Setup the syntax table
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
270 (if (= (length start) 1)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
271 (modify-syntax-entry (string-to-char start)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
272 (concat "< " comstyle) st)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
273 (let ((c0 (elt start 0)) (c1 (elt start 1)))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
274 ;; Store the relevant info but don't update yet
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
275 (push (cons c0 (concat (cdr (assoc c0 chars)) "1")) chars)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
276 (push (cons c1 (concat (cdr (assoc c1 chars))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
277 (concat "2" comstyle))) chars)))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
278 (if (= (length end) 1)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
279 (modify-syntax-entry (string-to-char end)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
280 (concat ">" comstyle) st)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
281 (let ((c0 (elt end 0)) (c1 (elt end 1)))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
282 ;; Store the relevant info but don't update yet
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
283 (push (cons c0 (concat (cdr (assoc c0 chars))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
284 (concat "3" comstyle))) chars)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
285 (push (cons c1 (concat (cdr (assoc c1 chars)) "4")) chars)))))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
286
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
287 ;; Process the chars that were part of a 2-char comment marker
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
288 (dolist (cs (nreverse chars))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
289 (modify-syntax-entry (car cs)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
290 (concat (char-to-string (char-syntax (car cs)))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
291 " " (cdr cs))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
292 st))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
293 (set-syntax-table st)))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
294
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
295 (defun generic-bracket-support ()
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
296 "Imenu support for [KEYWORD] constructs found in INF, INI and Samba files."
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
297 (setq imenu-generic-expression
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
298 '((nil "^\\[\\(.*\\)\\]" 1))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
299 imenu-case-fold-search t))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
300
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
301 ;;;###autoload
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
302 (defun generic-make-keywords-list (keyword-list face &optional prefix suffix)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
303 "Return a `font-lock-keywords' construct that highlights KEYWORD-LIST.
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
304 KEYWORD-LIST is a list of keyword strings that should be
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
305 highlighted with face FACE. This function calculates a regular
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
306 expression that matches these keywords and concatenates it with
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
307 PREFIX and SUFFIX. Then it returns a construct based on this
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
308 regular expression that can be used as an element of
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
309 `font-lock-keywords'."
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
310 (unless (listp keyword-list)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
311 (error "Keywords argument must be a list of strings"))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
312 (list (concat prefix "\\_<"
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
313 ;; Use an optimized regexp.
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
314 (regexp-opt keyword-list t)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
315 "\\_>" suffix)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
316 1
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
317 face))
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
318
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
319 (provide 'generic)
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
320
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
321 ;; arch-tag: 239c1fc4-1303-48d9-9ac0-657d655669ea
2f8b7bd746aa Move here from parent dir.
Lute Kamstra <lute@gnu.org>
parents:
diff changeset
322 ;;; generic.el ends here