annotate generic-mode.el @ 18:2a3055313d1e

*** empty log message ***
author ht
date Sat, 19 Apr 2008 19:10:28 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
1 ;;; generic-mode.el --- A meta-mode which makes it easy to create small
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
2 ;; modes with basic comment and font-lock support
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
3 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
4 ;; Author: Peter Breton
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
5 ;; Created: Fri Sep 27 1996
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
6 ;; Version: $Header$
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
7 ;; Keywords: generic, comment, font-lock
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
8 ;; Time-stamp: <97/03/25 10:10:19 pbreton>
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
9 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
10 ;; Copyright (C) Peter Breton 01Nov96
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
11 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
12 ;; This is free software; you can redistribute it and/or modify
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
15 ;; any later version.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
16 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
17 ;; generic-mode.el is distributed in the hope that it will be useful,
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
20 ;; General Public License for more details.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
21 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
25 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
26 ;; LCD Archive Entry:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
27 ;; generic-mode|Peter Breton|pbreton@i-kinetics.com|
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
28 ;; Meta-mode to create small modes with basic comment and font-lock support|
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
29 ;; 01-Nov-1996|1.0|~/misc/generic-mode.el.gz|
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
30 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
31 ;; Purpose:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
32 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
33 ;; Meta-mode to create small modes with basic comment and font-lock support
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
34 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
35 ;;; Commentary:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
36 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
37 ;; INTRODUCTION:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
38 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
39 ;; Generic-mode is a meta-mode which can be used to define small modes
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
40 ;; which provide basic comment and font-lock support. These modes are
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
41 ;; intended for the many configuration files and such which are too small
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
42 ;; for a "real" mode, but still have a regular syntax, comment characters
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
43 ;; and the like.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
44 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
45 ;; Each generic mode can define the following:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
46 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
47 ;; * List of comment-characters. The entries in this list should be
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
48 ;; either a character, a one or two character string or a cons pair.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
49 ;; If the entry is a character or a one-character string
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
50 ;; LIMITATIONS: Emacs does not support comment strings of more than
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
51 ;; two characters in length.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
52 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
53 ;; * List of keywords to font-lock. Each keyword should be a string.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
54 ;; If you have additional keywords which should be highlighted in a face
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
55 ;; different from 'font-lock-keyword-face', you can use the convenience
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
56 ;; function 'generic-make-keywords-list' (which see), and add the
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
57 ;; result to the following list:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
58 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
59 ;; * Additional expressions to font-lock. This should be a list of
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
60 ;; expressions, each of which should be of the same form
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
61 ;; as those in 'font-lock-defaults-alist'.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
62 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
63 ;; * List of regular expressions to be placed in auto-mode-alist.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
64 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
65 ;; * List of functions to call to do some additional setup
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
66 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
67 ;; This should pretty much cover basic functionality; if you need much
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
68 ;; more than this, or you find yourself writing extensive customizations,
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
69 ;; perhaps you should be writing a major mode instead!
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
70 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
71 ;; INSTALLATION:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
72 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
73 ;; Place the following in your .emacs file:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
74 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
75 ;; (require 'generic-mode)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
76 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
77 ;; If you want to use some pre-defined generic modes, add:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
78 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
79 ;; (require 'generic-extras)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
80 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
81 ;; Loading these generic modes will cause some new entries to be placed in
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
82 ;; your auto-mode-alist. See 'generic-extras.el' for details.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
83 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
84 ;; LOCAL VARIABLES:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
85 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
86 ;; To put a file into generic mode using local variables, use a line
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
87 ;; like this in a Local Variables block:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
88 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
89 ;; mode: default-generic
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
90 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
91 ;; Do NOT use "mode: generic"!
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
92 ;; See also "AUTOMATICALLY ENTERING GENERIC MODE" below.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
93 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
94 ;; DEFINING NEW GENERIC MODES:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
95 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
96 ;; Use the 'define-generic-mode' function to define new modes.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
97 ;; For example:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
98 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
99 ;; (require 'generic-mode)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
100 ;; (define-generic-mode 'foo-generic-mode
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
101 ;; (list ?% )
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
102 ;; (list "keyword")
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
103 ;; nil
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
104 ;; (list "\.FOO")
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
105 ;; (list 'foo-setup-function))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
106 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
107 ;; defines a new generic-mode 'foo-generic-mode', which has '%' as a
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
108 ;; comment character, and "keyword" as a keyword. When files which end in
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
109 ;; '.FOO' are loaded, Emacs will go into foo-generic-mode and call
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
110 ;; foo-setup-function. You can also use the function 'foo-generic-mode'
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
111 ;; (which is interactive) to put a buffer into foo-generic-mode.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
112 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
113 ;; ALTERING EXISTING MODES:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
114 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
115 ;; To alter an existing generic-mode, use the convenience functions:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
116 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
117 ;; (alter-generic-mode-comments MODE COMMENT-LIST HOW-TO-ALTER)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
118 ;; (alter-generic-mode-keywords MODE KEYWORD-LIST HOW-TO-ALTER)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
119 ;; (alter-generic-mode-font-lock MODE FONT-LOCK-LIST HOW-TO-ALTER)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
120 ;; (alter-generic-mode-auto-mode MODE AUTO-MODE-LIST HOW-TO-ALTER)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
121 ;; (alter-generic-mode-functions MODE FUNCTION-LIST HOW-TO-ALTER)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
122 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
123 ;; HOW-TO-ALTER should be one of the following symbols: 'append, 'prepend,
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
124 ;; or 'overwrite. If it is omitted, 'append is assumed.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
125 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
126 ;; AUTOMATICALLY ENTERING GENERIC MODE:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
127 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
128 ;; Generic-mode provides a hook which automatically puts a
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
129 ;; file into default-generic-mode if the first few lines of a file in
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
130 ;; fundamental mode start with a hash comment character. To disable
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
131 ;; this functionality, set the variable 'generic-use-find-file-hook'
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
132 ;; to nil BEFORE loading generic-mode. See the variables
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
133 ;; 'generic-lines-to-scan' and 'generic-find-file-regexp' for customization
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
134 ;; options.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
135 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
136 ;; GOTCHAS:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
137 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
138 ;; Be careful that your font-lock definitions are correct. Getting them
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
139 ;; wrong can cause emacs to continually attempt to fontify! This problem
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
140 ;; is not specific to generic-mode.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
141 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
142
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
143 ;; Credit for suggestions, brainstorming, patches and bug-fixes:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
144 ;; ACorreir@pervasive-sw.com (Alfred Correira)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
145
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
146 ;;; Change log:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
147 ;; $Log$
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
148 ;; Revision 1.1 2008/04/19 18:10:28 ht
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
149 ;; *** empty log message ***
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
150 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
151 ; Revision 1.2 1997/04/02 07:02:38 voelker
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
152 ; *** empty log message ***
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
153 ;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
154 ;; Revision 1.6 1996/11/01 17:27:47 peter
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
155 ;; Changed the function generic-function-name to return a string instead
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
156 ;; of a symbol. Generic-mode now uses this for the mode's name
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
157 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
158 ;; Revision 1.5 1996/11/01 16:45:20 peter
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
159 ;; Added GPL and LCD information.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
160 ;; Updated documentation
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
161 ;; Added generic-find-file-regexp variable
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
162 ;; Added generic-make-keywords-list function
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
163 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
164 ;; Revision 1.4 1996/10/19 12:16:59 peter
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
165 ;; Small bug fixes: fontlock -> font-lock
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
166 ;; New entries are added to the end of auto-mode-alist
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
167 ;; Generic-font-lock-defaults are set to nil, not (list nil)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
168 ;; Comment-regexp in generic-mode-find-file-hook changed to allow optional
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
169 ;; blank lines
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
170 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
171 ;; Revision 1.3 1996/10/17 08:24:25 peter
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
172 ;; Added generic-mode-find-file-hook and associated variables
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
173 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
174 ;; Revision 1.2 1996/10/17 01:00:45 peter
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
175 ;; Moved from a data-centered approach (generic-mode-alist) to
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
176 ;; a function-based one (define-generic-mode)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
177 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
178 ;; Revision 1.1 1996/10/10 11:37:36 peter
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
179 ;; Initial revision
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
180 ;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
181
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
182 ;;; Code:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
183
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
184 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
185 ;; Variables
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
187
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
188 (make-variable-buffer-local
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
189 (defvar generic-font-lock-defaults nil
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
190 "Global defaults for font-lock in a generic mode."))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
191
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
192 (make-variable-buffer-local
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
193 (defvar generic-mode-name 'default-generic-mode
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
194 "The name of the generic mode.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
195 This is the car of one of the items in `generic-mode-alist'.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
196 This variable is buffer-local."))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
197
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
198 (make-variable-buffer-local
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
199 (defvar generic-comment-list nil
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
200 "List of comment characters for a generic mode."))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
201
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
202 (make-variable-buffer-local
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
203 (defvar generic-keywords-list nil
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
204 "List of keywords for a generic mode."))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
205
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
206 (make-variable-buffer-local
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
207 (defvar generic-font-lock-expressions nil
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
208 "List of font-lock expressions for a generic mode."))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
209
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
210 (make-variable-buffer-local
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
211 (defvar generic-mode-function-list nil
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
212 "List of customization functions to call for a generic mode."))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
213
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
214 (make-variable-buffer-local
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
215 (defvar generic-mode-syntax-table nil
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
216 "Syntax table for use in a generic mode."))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
217
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
218 (defvar generic-mode-alist nil
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
219 "An association list for generic-mode.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
220 Each entry in the list looks like this:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
221
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
222 NAME COMMENT-LIST KEYWORD-LIST FONT-LOCK-LIST AUTO-MODE-LIST FUNCTION-LIST.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
223
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
224 Do not add entries to this list directly; use `define-generic-mode'
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
225 instead (which see).
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
226
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
227 To alter an already existing generic-mode, use
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
228 one of the `alter-generic-mode-' convenience functions (which see)"
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
229 )
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
230
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
231 (defvar generic-use-find-file-hook t
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
232 "*If non-nil, add a hook to enter default-generic-mode automatically
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
233 if the first few lines of a file in fundamental mode start with a hash
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
234 comment character.")
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
235
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
236 (defvar generic-lines-to-scan 3
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
237 "*Number of lines that `generic-mode-find-file-hook' looks at
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
238 when deciding whether to enter generic-mode automatically.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
239 This variable should be set to a small positive number.")
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
240
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
241 (defvar generic-find-file-regexp "#.*\n\\(.*\n\\)?"
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
242 "*Regular expression used by `generic-mode-find-file-hook'
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
243 to determine if files in fundamental mode should be put into
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
244 `default-generic-mode' instead.")
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
245
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
246 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
247 ;; Inline functions
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
248 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
249
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
250 (defsubst generic-read-type ()
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
251 (completing-read
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
252 "Generic Type: "
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
253 (mapcar
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
254 '(lambda (elt) (list (symbol-name (car elt))))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
255 generic-mode-alist) nil t))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
256
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
257 ;; Basic sanity checks. It does *not* check whether the elements of the lists
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
258 ;; are of the correct type.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
259 (defsubst generic-mode-sanity-check (name comment-list keyword-list
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
260 font-lock-list auto-mode-list
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
261 function-list &optional description)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
262 (if (not (symbolp name))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
263 (error "%s is not a symbol" (princ name)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
264
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
265 (mapcar '(lambda (elt)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
266 (if (not (listp elt))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
267 (error "%s is not a list" (princ elt))))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
268 (list comment-list keyword-list font-lock-list
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
269 auto-mode-list function-list))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
270
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
271 (if (not (or (null description) (stringp description)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
272 (error "Description must be a string or nil"))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
273 )
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
274
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
275 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
276 ;; Functions
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
277 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
278
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
279 ;;;### autoload
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
280 (defun define-generic-mode (name comment-list keyword-list font-lock-list
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
281 auto-mode-list function-list
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
282 &optional description)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
283 "Create a new generic mode with NAME.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
284 NAME should be a symbol; its string representation is used as the function
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
285 name. If DESCRIPTION is provided, it is used as the docstring for the new
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
286 function.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
287
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
288 COMMENT-LIST is a list, whose entries are either a single character,
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
289 a one or two character string or a cons pair. If the entry is a character
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
290 or a one-character string, it is added to the mode's syntax table with
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
291 comment-start syntax. If the entry is a cons pair, the elements of the
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
292 pair are considered to be comment-start and comment-end respectively.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
293 Note that Emacs has limitations regarding comment characters.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
294
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
295 KEYWORD-LIST is a list of keywords to highlight with `font-lock-keyword-face'.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
296 Each keyword should be a string.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
297
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
298 FONT-LOCK-LIST is a list of additional expressions to highlight. Each entry
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
299 in the list should have the same form as an entry in `font-lock-defaults-alist'
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
300
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
301 AUTO-MODE-LIST is a list of regular expressions to add to auto-mode-alist.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
302 These regexps are added to auto-mode-alist as soon as `define-generic-mode'
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
303 is called; any old regexps with the same name are removed. To modify the
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
304 auto-mode-alist expressions, use `alter-generic-mode-auto-mode' (which see).
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
305
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
306 FUNCTION-LIST is a list of functions to call to do some additional setup.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
307
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
308 See the file generic-extras.el for some examples of `define-generic-mode'."
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
309
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
310 ;; Basic sanity check
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
311 (generic-mode-sanity-check name
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
312 comment-list keyword-list font-lock-list
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
313 auto-mode-list function-list description)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
314
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
315 ;; Remove any old entry
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
316 (setq generic-mode-alist
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
317 (delq (assq name generic-mode-alist)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
318 generic-mode-alist))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
319
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
320 ;; Add a new entry
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
321 (setq generic-mode-alist
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
322 (append
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
323 (list
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
324 (list
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
325 name comment-list keyword-list font-lock-list
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
326 auto-mode-list function-list
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
327 ))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
328 generic-mode-alist))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
329
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
330 ;; Add it to auto-mode-alist
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
331 (generic-add-to-auto-mode name auto-mode-list t)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
332
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
333 ;; Define a function for it
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
334 (generic-create-generic-function name description)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
335 )
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
336
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
337 (defun generic-add-to-auto-mode (mode auto-mode-list
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
338 &optional remove-old prepend)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
339 "Add the entries for mode to `auto-mode-alist'.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
340 If remove-old is non-nil, removes old entries first. If prepend is
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
341 non-nil, prepends entries to auto-mode-alist; otherwise, appends them."
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
342
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
343 (if (not (listp auto-mode-list))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
344 (error "%s is not a list" (princ auto-mode-list)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
345
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
346 (let ((new-mode (intern (symbol-name mode))))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
347 (if remove-old
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
348 (let ((auto-mode-entry))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
349 (while (setq auto-mode-entry (rassq new-mode auto-mode-alist))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
350 (setq auto-mode-alist
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
351 (delq auto-mode-entry
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
352 auto-mode-alist)))))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
353
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
354 (mapcar '(lambda (entry)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
355 (generic-add-auto-mode-entry new-mode entry prepend))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
356 auto-mode-list)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
357
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
358 (defun generic-add-auto-mode-entry (name entry &optional prepend)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
359 "Add a new entry to the end of auto-mode-alist.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
360 If prepend is non-nil, add the entry to the front of the list."
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
361 (let ((new-entry (list (cons entry name))))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
362 (setq auto-mode-alist
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
363 (if prepend
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
364 (append new-entry auto-mode-alist)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
365 (append auto-mode-alist new-entry)))))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
366
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
367 (defun generic-create-generic-function (name &optional description)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
368 "Create a generic mode function with NAME.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
369 If DESCRIPTION is provided, it is used as the docstring."
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
370 (let ((symname (symbol-name name)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
371 (fset (intern symname)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
372 (list 'lambda nil
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
373 (or description
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
374 (concat "Generic mode for type " symname))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
375 (list 'interactive)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
376 (list 'generic-mode-with-type (list 'quote name))))))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
377
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
378 (defun generic-mode-with-type (&optional mode)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
379 "Go into the generic-mode MODE."
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
380 (let* ((type (or mode generic-mode-name))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
381 (generic-mode-list (assoc type generic-mode-alist))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
382 )
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
383
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
384 (if (not generic-mode-list)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
385 (error "Can't find generic-mode information for type %s"
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
386 (princ generic-mode-name)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
387
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
388 ;; Put this after the point where we read generic-mode-name!
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
389 (kill-all-local-variables)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
390
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
391 (setq
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
392 generic-mode-name type
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
393 generic-comment-list (nth 1 generic-mode-list)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
394 generic-keywords-list (nth 2 generic-mode-list)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
395 generic-font-lock-expressions (nth 3 generic-mode-list)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
396 generic-mode-function-list (nth 5 generic-mode-list)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
397 major-mode 'generic-mode
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
398 mode-name (symbol-name type)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
399 )
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
400
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
401 (generic-mode-set-comments generic-comment-list)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
402
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
403 ;; Font-lock functionality
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
404 ;; Font-lock-defaults are always set even if there are no keywords
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
405 ;; or font-lock expressions, so comments can be highlighted.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
406 (setq generic-font-lock-defaults nil)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
407 (generic-mode-set-font-lock generic-keywords-list
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
408 generic-font-lock-expressions)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
409 (make-local-variable 'font-lock-defaults)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
410 (setq font-lock-defaults (list 'generic-font-lock-defaults nil))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
411
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
412 ;; Call a list of functions
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
413 (if generic-mode-function-list
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
414 (mapcar 'funcall generic-mode-function-list))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
415 )
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
416 )
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
417
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
418 ;;;###autoload
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
419 (defun generic-mode (type)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
420 "A mode to do basic comment and font-lock functionality
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
421 for files which are too small to warrant their own mode, but have
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
422 comment characters, keywords, and the like.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
423
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
424 To define a generic-mode, use the function `define-generic-mode'.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
425 To alter an existing generic-mode, use the `alter-generic-mode-'
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
426 convenience functions.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
427 Some generic modes are defined in generic-extras.el"
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
428 (interactive
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
429 (list (generic-read-type)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
430 (generic-mode-with-type (intern type)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
431
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
432 ;;; Comment Functionality
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
433 (defun generic-mode-set-comments (comment-list)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
434 "Set up comment functionality for generic mode."
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
435 (if (null comment-list)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
436 nil
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
437 (let ((generic-mode-syntax-table (make-syntax-table)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
438 (make-local-variable 'comment-start)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
439 (make-local-variable 'comment-start-skip)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
440 (make-local-variable 'comment-end)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
441 (mapcar 'generic-mode-set-a-comment comment-list)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
442 (set-syntax-table generic-mode-syntax-table))))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
443
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
444 (defun generic-mode-set-a-comment (comment)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
445 (and (char-or-string-p comment)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
446 (if (stringp comment)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
447 (cond
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
448 ((eq (length comment) 1)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
449 (generic-mode-set-comment-char
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
450 (string-to-char comment)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
451 ((eq (length comment) 2)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
452 (generic-mode-set-comment-string comment))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
453 (t
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
454 (error "Character string %s must be one or two characters long"
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
455 comment))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
456 )
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
457 (generic-mode-set-comment-char comment)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
458 (if (consp comment)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
459 (generic-mode-set-comment-pair comment)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
460
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
461 (defun generic-mode-set-comment-char (comment-char)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
462 "Set the given character as a comment character for generic mode."
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
463 (if (not comment-char)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
464 nil
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
465 (setq
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
466 comment-end ""
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
467 comment-start (char-to-string comment-char)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
468 comment-start-skip (concat comment-start "+ *")
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
469 )
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
470
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
471 (modify-syntax-entry comment-char "<"
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
472 generic-mode-syntax-table)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
473 (modify-syntax-entry ?\n ">"
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
474 generic-mode-syntax-table)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
475
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
476 (defun generic-mode-set-comment-string (comment-string)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
477 "Set the given string as a comment string for generic mode."
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
478 (if (not comment-string)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
479 nil
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
480 (setq
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
481 comment-end ""
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
482 comment-start comment-string
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
483 comment-start-skip (concat comment-start " *")
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
484 )
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
485
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
486 (let ((first (elt comment-string 0))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
487 (second (elt comment-string 1)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
488 ;; C++ style comments
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
489 (if (char-equal first second)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
490 (progn
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
491 (modify-syntax-entry first "<12b"
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
492 generic-mode-syntax-table)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
493 (modify-syntax-entry ?\n ">b"
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
494 generic-mode-syntax-table)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
495 ;; Some other two character string
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
496 (modify-syntax-entry first "<1"
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
497 generic-mode-syntax-table)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
498 (modify-syntax-entry second "<2"
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
499 generic-mode-syntax-table)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
500 (modify-syntax-entry ?\n ">"
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
501 generic-mode-syntax-table))))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
502
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
503 (defun generic-mode-set-comment-pair (comment-pair)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
504 "Set the given comment pair as a comment start and end for generic mode."
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
505 (let ((generic-comment-start (car comment-pair))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
506 (generic-comment-end (cdr comment-pair))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
507 )
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
508 (setq
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
509 comment-end generic-comment-end
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
510 comment-start generic-comment-start
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
511 comment-start-skip (concat generic-comment-start " *")
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
512 )
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
513
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
514 ;; Sanity checks
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
515 (if (not (and (stringp generic-comment-start)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
516 (stringp generic-comment-end)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
517 (error "Elements of cons pair must be strings"))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
518 (if (not (and (equal (length generic-comment-start) 2)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
519 (equal (length generic-comment-end) 2)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
520 (error "Start and end must be exactly two characters long"))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
521
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
522 (let ((first (elt generic-comment-start 0))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
523 (second (elt generic-comment-start 1))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
524 (third (elt generic-comment-end 0))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
525 (fourth (elt generic-comment-end 1))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
526 )
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
527
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
528 (modify-syntax-entry first ". 1" generic-mode-syntax-table)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
529 (modify-syntax-entry second ". 2" generic-mode-syntax-table)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
530
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
531 (modify-syntax-entry
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
532 third
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
533 (concat
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
534 "."
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
535 (cond
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
536 ((char-equal first third) " 13")
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
537 ((char-equal second third) " 23")
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
538 (t " 3"))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
539 )
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
540 generic-mode-syntax-table)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
541
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
542 (modify-syntax-entry
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
543 fourth
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
544 (concat
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
545 "."
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
546 (cond
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
547 ((char-equal first fourth) " 14")
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
548 ((char-equal second fourth) " 24")
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
549 (t " 4"))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
550 )
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
551 generic-mode-syntax-table)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
552 )))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
553
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
554 (defun generic-mode-set-font-lock (keywords font-lock-expressions)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
555 "Set up font-lock functionality for generic mode."
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
556 (let ((generic-font-lock-expressions))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
557 ;; Keywords
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
558 (if keywords
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
559 (setq
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
560 generic-font-lock-expressions
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
561 (append
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
562 (list
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
563 (list
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
564 (concat
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
565 "\\(\\<"
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
566 (mapconcat 'identity keywords "\\>\\|\\<")
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
567 "\\>\\)")
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
568 1 'font-lock-keyword-face))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
569 generic-font-lock-expressions)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
570 ;; Other font-lock expressions
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
571 (if font-lock-expressions
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
572 (setq generic-font-lock-expressions
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
573 (append
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
574 font-lock-expressions
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
575 generic-font-lock-expressions)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
576 (if (not (or font-lock-expressions keywords))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
577 nil
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
578 (setq generic-font-lock-defaults generic-font-lock-expressions))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
579 ))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
580
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
581 (defun alter-generic-mode (mode alter-list &optional how-to-alter)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
582 "Alter the specified generic mode.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
583 How-to-alter, if specified, should be one of the following symbols:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
584 `append', `prepend', `overwrite'. The default is `append'."
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
585 (let ((generic-mode-list (assoc mode generic-mode-alist))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
586 (item-number 0)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
587 (current-elt)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
588 (current-list)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
589 (alter-elt)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
590 (alter-method (or how-to-alter 'append))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
591 )
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
592 (if (not generic-mode-list)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
593 (error "Can't find generic-mode information for type %s"
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
594 (princ mode)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
595 ;; Ignore the name
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
596 (setq generic-mode-list (cdr generic-mode-list))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
597 (while (< item-number (length alter-list))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
598 (setq current-list (nthcdr item-number generic-mode-list)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
599 current-elt (nth item-number generic-mode-list)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
600 alter-elt (nth item-number alter-list))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
601 (cond
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
602 ;; Ignore items with value t
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
603 ((eq alter-elt 't)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
604 nil)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
605 ((eq alter-method 'overwrite)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
606 (setcar current-list alter-elt))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
607 ((eq alter-method 'prepend)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
608 (setcar current-list (append alter-elt current-elt)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
609 ((eq alter-method 'append)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
610 (setcar current-list (append current-elt alter-elt)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
611 (t
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
612 (error "Optional argument %s not understood" (princ alter-method))))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
613 (setq item-number (1+ item-number))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
614 )
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
615 )
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
616 )
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
617
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
618 ;; Convenience functions
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
619 (defun alter-generic-mode-comments (mode comment-list &optional how-to-alter)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
620 "Alter comments in the specified generic mode.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
621 How-to-alter, if specified, should be one of the following symbols:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
622 `append', `prepend', `overwrite'. The default is `append'."
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
623 (alter-generic-mode mode (list comment-list t t t t) how-to-alter))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
624
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
625 (defun alter-generic-mode-keywords (mode keyword-list &optional how-to-alter)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
626 "Alter keywords in the specified generic mode.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
627 How-to-alter, if specified, should be one of the following symbols:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
628 `append', `prepend', `overwrite'. The default is `append'."
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
629 (alter-generic-mode mode (list t keyword-list t t t) how-to-alter))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
630
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
631 (defun alter-generic-mode-font-lock (mode font-lock-list &optional how-to-alter)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
632 "Alter font-lock expressions in the specified generic mode.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
633 How-to-alter, if specified, should be one of the following symbols:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
634 `append', `prepend', `overwrite'. The default is `append'."
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
635 (alter-generic-mode mode (list t t font-lock-list t t) how-to-alter))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
636
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
637 (defun alter-generic-mode-functions (mode function-list &optional how-to-alter)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
638 "Alter functions in the specified generic mode.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
639 How-to-alter, if specified, should be one of the following symbols:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
640 `append', `prepend', `overwrite'. The default is `append'."
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
641 (alter-generic-mode mode (list t t t t function-list) how-to-alter))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
642
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
643 ;; This one is different because it takes effect immediately
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
644 ;; Appending or Prepending to auto-mode-alist is ignored,
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
645 ;; since the effect is the same either way
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
646 (defun alter-generic-mode-auto-mode
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
647 (mode auto-mode-list &optional how-to-alter)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
648 "Alter auto-mode-alist regular expressions in the specified generic mode.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
649 How-to-alter, if specified, should be one of the following symbols:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
650 `append', `prepend', `overwrite'. The default is `append'."
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
651 (alter-generic-mode mode (list t t t auto-mode-list t) how-to-alter)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
652 (let ((alter-method (or how-to-alter 'append)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
653 (cond ((eq alter-method 'overwrite)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
654 (generic-add-to-auto-mode mode auto-mode-list t))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
655 ((eq alter-method 'append)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
656 (generic-add-to-auto-mode mode auto-mode-list nil))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
657 ((eq alter-method 'prepend)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
658 (generic-add-to-auto-mode mode auto-mode-list nil t))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
659 (t
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
660 (error "Optional argument %s not understood" (princ alter-method))))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
661 ))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
662
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
663 ;; Support for [KEYWORD] constructs found in INF, INI and Samba files
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
664 (defun generic-bracket-support ()
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
665 (setq imenu-generic-expression
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
666 '((nil "^\\[\\(.*\\)\\]" 1))))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
667
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
668 ;; This generic mode is always defined
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
669 (define-generic-mode 'default-generic-mode (list ?#) nil nil nil nil)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
670
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
671 ;; A more general solution would allow us to enter generic-mode for
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
672 ;; *any* comment character, but would require us to synthesize a new
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
673 ;; generic-mode on the fly. I think this gives us most of what we
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
674 ;; want.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
675 (defun generic-mode-find-file-hook ()
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
676 "Hook to enter default-generic-mode automatically
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
677 if the first few lines of a file in fundamental-mode start with a hash
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
678 comment character. This hook will be installed if the variable
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
679 `generic-use-find-file-hook' is non-nil. The variable `generic-lines-to-scan'
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
680 determines the number of lines to look at."
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
681 (if (not (eq major-mode 'fundamental-mode))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
682 nil
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
683 (if (or (> 1 generic-lines-to-scan)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
684 (< 50 generic-lines-to-scan))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
685 (error "Variable `generic-lines-to-scan' should be set to a small"
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
686 " positive number"))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
687 (let ((comment-regexp "")
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
688 (count 0)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
689 )
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
690 (while (< count generic-lines-to-scan)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
691 (setq comment-regexp (concat comment-regexp
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
692 generic-find-file-regexp))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
693 (setq count (1+ count)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
694 (save-excursion
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
695 (goto-char (point-min))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
696 (if (looking-at comment-regexp)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
697 (generic-mode-with-type 'default-generic-mode))))))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
698
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
699 (if generic-use-find-file-hook
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
700 (add-hook 'find-file-hooks 'generic-mode-find-file-hook))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
701
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
702 (defun generic-make-keywords-list (keywords-list face &optional prefix suffix)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
703 "Return a regular expression matching the specified keywords.
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
704 The regexp is highlighted with FACE."
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
705 ;; Sanity checks
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
706 ;; Don't check here; face may not be defined yet
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
707 ;; (if (not (facep face))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
708 ;; (error "Face %s is not defined" (princ face)))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
709 (if (not (listp keywords-list))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
710 (error "Keywords argument must be a list of strings"))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
711 (list
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
712 (concat
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
713 (or prefix "")
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
714 "\\(\\<"
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
715 (mapconcat 'identity keywords-list "\\>\\|\\<")
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
716 "\\>\\)"
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
717 (or suffix "")
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
718 ) 1 face))
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
719
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
720 (provide 'generic-mode)
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
721
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
722 ;;; generic-mode.el ends here
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
723
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
724 ;; Local Variables:
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
725 ;; autocompile: t
2a3055313d1e *** empty log message ***
ht
parents:
diff changeset
726 ;; End: