annotate lisp/generic.el @ 35009:d80f2bfd0e05

Add `radio' type. User variable doc strings and backquote in defcustom.
author Dave Love <fx@gnu.org>
date Tue, 02 Jan 2001 23:23:24 +0000
parents ce9ed5ad8fa2
children 5eb6597319ec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21013
adb28ace7f33 Provide generic, not generic-mode.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
1 ;;; generic.el --- Defining simple major modes with comment and font-lock.
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 ;;
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
3 ;; Copyright (C) 1997, 1999 Free Software Foundation, Inc.
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 ;;
21182
9049fbf96317 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 21077
diff changeset
5 ;; Author: Peter Breton <pbreton@cs.umb.edu>
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Created: Fri Sep 27 1996
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Keywords: generic, comment, font-lock
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; 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
13 ;; the Free Software Foundation; either version 2, or (at your option)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; any later version.
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; 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
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;; Purpose:
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; Meta-mode to create simple major modes
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; with basic comment and font-lock support
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;;; Commentary:
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; INTRODUCTION:
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;; Generic-mode is a meta-mode which can be used to define small modes
21014
e3e68c9d2e35 Several doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 21013
diff changeset
36 ;; which provide basic comment and font-lock support. These modes are
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; intended for the many configuration files and such which are too small
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; for a "real" mode, but still have a regular syntax, comment characters
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; and the like.
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;;
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;; Each generic mode can define the following:
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;;
21014
e3e68c9d2e35 Several doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 21013
diff changeset
43 ;; * List of comment-characters. The entries in this list should be
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;; 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
45 ;; If the entry is a character or a one-character string
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;; LIMITATIONS: Emacs does not support comment strings of more than
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;; two characters in length.
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;;
21014
e3e68c9d2e35 Several doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 21013
diff changeset
49 ;; * List of keywords to font-lock. Each keyword should be a string.
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;; If you have additional keywords which should be highlighted in a face
21182
9049fbf96317 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 21077
diff changeset
51 ;; different from `font-lock-keyword-face', you can use the convenience
9049fbf96317 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 21077
diff changeset
52 ;; function `generic-make-keywords-list' (which see), and add the
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;; result to the following list:
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
54 ;;
21014
e3e68c9d2e35 Several doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 21013
diff changeset
55 ;; * Additional expressions to font-lock. This should be a list of
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;; expressions, each of which should be of the same form
21182
9049fbf96317 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 21077
diff changeset
57 ;; as those in `font-lock-defaults-alist'.
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
58 ;;
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;; * List of regular expressions to be placed in auto-mode-alist.
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;;
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;; * List of functions to call to do some additional setup
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;;
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;; This should pretty much cover basic functionality; if you need much
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;; more than this, or you find yourself writing extensive customizations,
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;; perhaps you should be writing a major mode instead!
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;;
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;; LOCAL VARIABLES:
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;;
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;; 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
70 ;; like this in a Local Variables block:
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;;
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ;; mode: default-generic
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;;
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;; Do NOT use "mode: generic"!
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;; See also "AUTOMATICALLY ENTERING GENERIC MODE" below.
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
76 ;;
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;; DEFINING NEW GENERIC MODES:
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;;
21182
9049fbf96317 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 21077
diff changeset
79 ;; Use the `define-generic-mode' function to define new modes.
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;; For example:
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;;
21182
9049fbf96317 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 21077
diff changeset
82 ;; (require 'generic)
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;; (define-generic-mode 'foo-generic-mode
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 ;; (list ?% )
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 ;; (list "keyword")
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 ;; nil
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
87 ;; (list "\\.FOO\\'")
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 ;; (list 'foo-setup-function))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;;
21182
9049fbf96317 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 21077
diff changeset
90 ;; defines a new generic-mode `foo-generic-mode', which has '%' as a
9049fbf96317 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 21077
diff changeset
91 ;; comment character, and "keyword" as a keyword. When files which end in
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 ;; '.FOO' are loaded, Emacs will go into foo-generic-mode and call
21182
9049fbf96317 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 21077
diff changeset
93 ;; foo-setup-function. You can also use the function `foo-generic-mode'
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ;; (which is interactive) to put a buffer into foo-generic-mode.
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ;;
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 ;; AUTOMATICALLY ENTERING GENERIC MODE:
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 ;;
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 ;; Generic-mode provides a hook which automatically puts a
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 ;; file into default-generic-mode if the first few lines of a file in
21182
9049fbf96317 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 21077
diff changeset
100 ;; fundamental mode start with a hash comment character. To disable
9049fbf96317 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 21077
diff changeset
101 ;; this functionality, set the variable `generic-use-find-file-hook'
9049fbf96317 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 21077
diff changeset
102 ;; to nil BEFORE loading generic-mode. See the variables
9049fbf96317 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 21077
diff changeset
103 ;; `generic-lines-to-scan' and `generic-find-file-regexp' for customization
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 ;; options.
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
105 ;;
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 ;; GOTCHAS:
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 ;;
21014
e3e68c9d2e35 Several doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 21013
diff changeset
108 ;; Be careful that your font-lock definitions are correct. Getting them
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 ;; wrong can cause emacs to continually attempt to fontify! This problem
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 ;; is not specific to generic-mode.
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
111 ;;
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112
21057
9b9c929675eb Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 21045
diff changeset
113 ;; Credit for suggestions, brainstorming, help with debugging:
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 ;; ACorreir@pervasive-sw.com (Alfred Correira)
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
115 ;; Extensive cleanup by:
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
116 ;; Stefan Monnier (monnier+gnu/emacs@flint.cs.yale.edu)
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
117 ;;
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
118 ;;; Code:
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
120 (eval-when-compile
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
121 (require 'cl))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
21077
4b5c8a2ce0b2 (generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents: 21057
diff changeset
124 ;; Internal Variables
18254
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
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (defvar generic-font-lock-defaults nil
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
128 "Global defaults for font-lock in a generic mode.")
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
129 (make-variable-buffer-local 'generic-font-lock-defaults)
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
131 (defvar generic-mode-list nil
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
132 "A list of mode names for `generic-mode'.
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
133 Do not add entries to this list directly; use `define-generic-mode'
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 instead (which see).")
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135
21077
4b5c8a2ce0b2 (generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents: 21057
diff changeset
136 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4b5c8a2ce0b2 (generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents: 21057
diff changeset
137 ;; Customization Variables
4b5c8a2ce0b2 (generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents: 21057
diff changeset
138 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4b5c8a2ce0b2 (generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents: 21057
diff changeset
139
21879
14316c9ecdac (generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents: 21182
diff changeset
140 (defgroup generic nil
14316c9ecdac (generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents: 21182
diff changeset
141 "Define simple major modes with comment and font-lock support."
14316c9ecdac (generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents: 21182
diff changeset
142 :prefix "generic-"
14316c9ecdac (generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents: 21182
diff changeset
143 :group 'extensions)
14316c9ecdac (generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents: 21182
diff changeset
144
21077
4b5c8a2ce0b2 (generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents: 21057
diff changeset
145 (defcustom generic-use-find-file-hook t
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
146 "*If non-nil, add a hook to enter default-generic-mode automatically.
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
147 This is done if the first few lines of a file in fundamental mode start
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
148 with a hash comment character."
21077
4b5c8a2ce0b2 (generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents: 21057
diff changeset
149 :group 'generic
4b5c8a2ce0b2 (generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents: 21057
diff changeset
150 :type 'boolean
4b5c8a2ce0b2 (generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents: 21057
diff changeset
151 )
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152
21077
4b5c8a2ce0b2 (generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents: 21057
diff changeset
153 (defcustom generic-lines-to-scan 3
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
154 "*Number of lines that `generic-mode-find-file-hook' looks at.
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
155 Relevant when deciding whether to enter `generic-mode' automatically.
21077
4b5c8a2ce0b2 (generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents: 21057
diff changeset
156 This variable should be set to a small positive number."
4b5c8a2ce0b2 (generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents: 21057
diff changeset
157 :group 'generic
4b5c8a2ce0b2 (generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents: 21057
diff changeset
158 :type 'integer
4b5c8a2ce0b2 (generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents: 21057
diff changeset
159 )
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
161 (defcustom generic-find-file-regexp "^#"
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
162 "*Regular expression used by `generic-mode-find-file-hook'.
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
163 Used to determine if files in fundamental mode should be put into
21077
4b5c8a2ce0b2 (generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents: 21057
diff changeset
164 `default-generic-mode' instead."
4b5c8a2ce0b2 (generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents: 21057
diff changeset
165 :group 'generic
4b5c8a2ce0b2 (generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents: 21057
diff changeset
166 :type 'regexp
4b5c8a2ce0b2 (generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents: 21057
diff changeset
167 )
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168
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 ;; Functions
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172
22347
f53740d7d40d *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 21928
diff changeset
173 ;;;###autoload
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
174 (defun define-generic-mode (name comment-list keyword-list font-lock-list
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
175 auto-mode-list function-list
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 &optional description)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 "Create a new generic mode with NAME.
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
178
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
179 Args: (NAME COMMENT-LIST KEYWORD-LIST FONT-LOCK-LIST AUTO-MODE-LIST
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
180 FUNCTION-LIST &optional DESCRIPTION)
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
181
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
182 NAME should be a symbol; its string representation is used as the function
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
183 name. If DESCRIPTION is provided, it is used as the docstring for the new
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 function.
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
186 COMMENT-LIST is a list, whose entries are either a single character,
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
187 a one or two character string or a cons pair. If the entry is a character
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 or a one-character string, it is added to the mode's syntax table with
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
189 `comment-start' syntax. If the entry is a cons pair, the elements of the
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
190 pair are considered to be `comment-start' and `comment-end' respectively.
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 Note that Emacs has limitations regarding comment characters.
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 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
194 Each keyword should be a string.
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 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
197 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
198
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
199 AUTO-MODE-LIST is a list of regular expressions to add to `auto-mode-alist'.
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
200 These regexps are added to `auto-mode-alist' as soon as `define-generic-mode'
21014
e3e68c9d2e35 Several doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 21013
diff changeset
201 is called; any old regexps with the same name are removed.
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 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
204
21014
e3e68c9d2e35 Several doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 21013
diff changeset
205 See the file generic-x.el for some examples of `define-generic-mode'."
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 ;; Add a new entry
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
208 (unless (assq name generic-mode-list)
34814
ce9ed5ad8fa2 (generic-read-type): Undo last change, inline into
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 34793
diff changeset
209 (push (list (symbol-name name)) generic-mode-list))
18254
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 ;; Add it to auto-mode-alist
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
212 (dolist (re auto-mode-list)
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
213 (add-to-list 'auto-mode-alist (cons re name)))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
214
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
215 ;; Define a function for it using `defalias' (not `fset') to make
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
216 ;; the mode appear on load-history.
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
217 (defalias name
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
218 `(lambda nil
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
219 ,(or description (concat "Generic mode for type " (symbol-name name)))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
220 (interactive)
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
221 (generic-mode-internal ',name ',comment-list ',keyword-list
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
222 ',font-lock-list ',function-list)))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 )
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
225 (defun generic-mode-internal (mode comments keywords font-lock-list funs)
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 "Go into the generic-mode MODE."
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
227 (let* ((generic-mode-hooks (intern (concat (symbol-name mode) "-hook")))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
228 (modename (symbol-name mode))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
229 (name (if (string-match "-mode\\'" modename)
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
230 (substring modename 0 (match-beginning 0))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
231 modename))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 )
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 ;; Put this after the point where we read generic-mode-name!
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (kill-all-local-variables)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
237 (setq
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
238 major-mode mode
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
239 mode-name (capitalize name)
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 )
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
242 (generic-mode-set-comments comments)
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 ;; Font-lock functionality
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 ;; Font-lock-defaults are always set even if there are no keywords
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 ;; or font-lock expressions, so comments can be highlighted.
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (setq generic-font-lock-defaults nil)
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
248 (generic-mode-set-font-lock keywords font-lock-list)
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (make-local-variable 'font-lock-defaults)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (setq font-lock-defaults (list 'generic-font-lock-defaults nil))
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 ;; Call a list of functions
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
253 (mapcar 'funcall funs)
23392
d86ad410d285 (generic-mode-with-type): Added hooks for generic-modes.
Karl Heuer <kwzh@gnu.org>
parents: 22402
diff changeset
254
d86ad410d285 (generic-mode-with-type): Added hooks for generic-modes.
Karl Heuer <kwzh@gnu.org>
parents: 22402
diff changeset
255 (run-hooks generic-mode-hooks)
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 )
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 )
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 ;;;###autoload
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (defun generic-mode (type)
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
261 "Basic comment and font-lock functionality for `generic' files.
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
262 \(Files which are too small to warrant their own mode, but have
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
263 comment characters, keywords, and the like.)
18254
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 To define a generic-mode, use the function `define-generic-mode'.
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
266 Some generic modes are defined in `generic-x.el'."
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (interactive
34814
ce9ed5ad8fa2 (generic-read-type): Undo last change, inline into
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 34793
diff changeset
268 (list (completing-read "Generic Type: " generic-mode-list nil t)))
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
269 (funcall (intern type)))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 ;;; Comment Functionality
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (defun generic-mode-set-comments (comment-list)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 "Set up comment functionality for generic mode."
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
274 (let ((st (make-syntax-table))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
275 (chars nil)
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
276 (comstyles))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
277 (make-local-variable 'comment-start)
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
278 (make-local-variable 'comment-start-skip)
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
279 (make-local-variable 'comment-end)
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
281 ;; Go through all the comments
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
282 (dolist (start comment-list)
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
283 (let ((end ?\n) (comstyle ""))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
284 ;; Normalize
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
285 (when (consp start)
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
286 (setq end (or (cdr start) end))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
287 (setq start (car start)))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
288 (when (char-valid-p start) (setq start (char-to-string start)))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
289 (when (char-valid-p end) (setq end (char-to-string end)))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
291 ;; Setup the vars for `comment-region'
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
292 (if comment-start
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
293 ;; We have already setup a comment-style, so use style b
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
294 (progn
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
295 (setq comstyle "b")
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
296 (setq comment-start-skip
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
297 (concat comment-start-skip "\\|" (regexp-quote start) "+\\s-*")))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
298 ;; First comment-style
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
299 (setq comment-start start)
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
300 (setq comment-end (unless (string-equal end "\n") end))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
301 (setq comment-start-skip (concat (regexp-quote start) "+\\s-*")))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
303 ;; Reuse comstyles if necessary
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
304 (setq comstyle
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
305 (or (cdr (assoc start comstyles))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
306 (cdr (assoc end comstyles))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
307 comstyle))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
308 (push (cons start comstyle) comstyles)
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
309 (push (cons end comstyle) comstyles)
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
311 ;; Setup the syntax table
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
312 (if (= (length start) 1)
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
313 (modify-syntax-entry (string-to-char start)
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
314 (concat "< " comstyle) st)
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
315 (let ((c0 (elt start 0)) (c1 (elt start 1)))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
316 ;; Store the relevant info but don't update yet
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
317 (push (cons c0 (concat (cdr (assoc c0 chars)) "1")) chars)
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
318 (push (cons c1 (concat (cdr (assoc c1 chars))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
319 (concat "2" comstyle))) chars)))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
320 (if (= (length end) 1)
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
321 (modify-syntax-entry (string-to-char end)
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
322 (concat ">" comstyle) st)
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
323 (let ((c0 (elt end 0)) (c1 (elt end 1)))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
324 ;; Store the relevant info but don't update yet
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
325 (push (cons c0 (concat (cdr (assoc c0 chars))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
326 (concat "3" comstyle))) chars)
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
327 (push (cons c1 (concat (cdr (assoc c1 chars)) "4")) chars)))))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
329 ;; Process the chars that were part of a 2-char comment marker
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
330 (dolist (cs (nreverse chars))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
331 (modify-syntax-entry (car cs)
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
332 (concat (char-to-string (char-syntax (car cs)))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
333 " " (cdr cs))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
334 st))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
335 (set-syntax-table st)))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 (defun generic-mode-set-font-lock (keywords font-lock-expressions)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 "Set up font-lock functionality for generic mode."
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
339 (setq generic-font-lock-defaults
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
340 (append
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
341 (when keywords
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
342 (list (generic-make-keywords-list keywords font-lock-keyword-face)))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
343 font-lock-expressions)))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 ;; Support for [KEYWORD] constructs found in INF, INI and Samba files
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 (defun generic-bracket-support ()
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
347 (setq imenu-generic-expression
20459
90f306f86f5d Use imenu-case-fold-search.
Dave Love <fx@gnu.org>
parents: 18254
diff changeset
348 '((nil "^\\[\\(.*\\)\\]" 1))
90f306f86f5d Use imenu-case-fold-search.
Dave Love <fx@gnu.org>
parents: 18254
diff changeset
349 imenu-case-fold-search t))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 ;; This generic mode is always defined
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 (define-generic-mode 'default-generic-mode (list ?#) nil nil nil nil)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 ;; A more general solution would allow us to enter generic-mode for
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 ;; *any* comment character, but would require us to synthesize a new
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 ;; 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
357 ;; want.
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 (defun generic-mode-find-file-hook ()
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
359 "Hook function to enter `default-generic-mode' automatically.
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
360 Done if the first few lines of a file in `fundamental-mode' start with
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
361 a hash comment character. This hook will be installed if the variable
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
362 `generic-use-find-file-hook' is non-nil. The variable
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
363 `generic-lines-to-scan' determines the number of lines to look at."
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
364 (when (eq major-mode 'fundamental-mode)
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
365 (save-excursion
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
366 (goto-char (point-min))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
367 (when (re-search-forward generic-find-file-regexp
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
368 (save-excursion
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
369 (forward-line generic-lines-to-scan)
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
370 (point)) t)
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 (goto-char (point-min))
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
372 (default-generic-mode)))))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 (defun generic-mode-ini-file-find-file-hook ()
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
375 "Hook function to enter default-generic-mode automatically for INI files.
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
376 Done if the first few lines of a file in `fundamental-mode' look like an
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
377 INI file. This hook is NOT installed by default."
21077
4b5c8a2ce0b2 (generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents: 21057
diff changeset
378 (and (eq major-mode 'fundamental-mode)
4b5c8a2ce0b2 (generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents: 21057
diff changeset
379 (save-excursion
4b5c8a2ce0b2 (generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents: 21057
diff changeset
380 (goto-char (point-min))
4b5c8a2ce0b2 (generic-mode-ini-file-find-file-hook): Use and-s instead of if-s.
Richard M. Stallman <rms@gnu.org>
parents: 21057
diff changeset
381 (and (looking-at "^\\s-*\\[.*\\]")
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
382 (ini-generic-mode)))))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 (and generic-use-find-file-hook
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 (add-hook 'find-file-hooks 'generic-mode-find-file-hook))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 (defun generic-make-keywords-list (keywords-list face &optional prefix suffix)
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
388 "Return a regular expression matching the specified KEYWORDS-LIST.
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 The regexp is highlighted with FACE."
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
390 (unless (listp keywords-list)
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
391 (error "Keywords argument must be a list of strings"))
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
392 (list (concat prefix "\\<"
21879
14316c9ecdac (generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents: 21182
diff changeset
393 ;; Use an optimized regexp.
14316c9ecdac (generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents: 21182
diff changeset
394 (regexp-opt keywords-list t)
32120
c443d63bec69 * generic.el:
Peter Breton <pbreton@attbi.com>
parents: 24022
diff changeset
395 "\\>" suffix)
21879
14316c9ecdac (generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents: 21182
diff changeset
396 1
21928
42fa0da05721 (generic-make-keywords-list): Delete spurious paren.
Richard M. Stallman <rms@gnu.org>
parents: 21879
diff changeset
397 face))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398
21013
adb28ace7f33 Provide generic, not generic-mode.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
399 (provide 'generic)
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
401 ;;; generic.el ends here