annotate lisp/generic.el @ 20616:b382c9ca6c39

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