annotate lisp/generic.el @ 28577:a9671bbcef78

*** empty log message ***
author Gerd Moellmann <gerd@gnu.org>
date Thu, 13 Apr 2000 19:17:06 +0000
parents 218b7edb9baf
children c443d63bec69
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:
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
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'.
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;;
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.
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;;
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
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;; (list "\.FOO")
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.
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 ;;
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.
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 ;;
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)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 ;;; Code:
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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
119 ;; Internal Variables
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (defvar generic-font-lock-defaults nil
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
123 "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
124 (make-variable-buffer-local 'generic-font-lock-defaults)
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 (defvar generic-mode-name 'default-generic-mode
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
127 "The name of the generic mode.
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
128 This is the car of one of the items in `generic-mode-alist'.
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
129 This variable is buffer-local.")
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
130 (make-variable-buffer-local 'generic-mode-name)
18254
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 (defvar generic-comment-list nil
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
133 "List of comment characters for a generic mode.")
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
134 (make-variable-buffer-local 'generic-comment-list)
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (defvar generic-keywords-list nil
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
137 "List of keywords for a generic mode.")
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
138 (make-variable-buffer-local 'generic-keywords-list)
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (defvar generic-font-lock-expressions nil
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
141 "List of font-lock expressions for a generic mode.")
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
142 (make-variable-buffer-local 'generic-font-lock-expressions)
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (defvar generic-mode-function-list nil
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
145 "List of customization functions to call for a generic mode.")
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
146 (make-variable-buffer-local 'generic-mode-function-list)
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (defvar generic-mode-syntax-table nil
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
149 "Syntax table for use in a generic mode.")
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
150 (make-variable-buffer-local 'generic-mode-syntax-table)
18254
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 (defvar generic-mode-alist nil
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
153 "An association list for `generic-mode'.
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
154 Each entry in the list looks like this:
18254
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 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
157
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
158 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
159 instead (which see).")
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160
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
161 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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
162 ;; 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
163 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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
21879
14316c9ecdac (generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents: 21182
diff changeset
165 (defgroup generic nil
14316c9ecdac (generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents: 21182
diff changeset
166 "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
167 :prefix "generic-"
14316c9ecdac (generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents: 21182
diff changeset
168 :group 'extensions)
14316c9ecdac (generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents: 21182
diff changeset
169
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
170 (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
171 "*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
172 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
173 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
174 :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
175 :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
176 )
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177
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
178 (defcustom generic-lines-to-scan 3
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
179 "*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
180 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
181 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
182 :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
183 :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
184 )
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185
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
186 (defcustom generic-find-file-regexp "#.*\n\\(.*\n\\)?"
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
187 "*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
188 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
189 `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
190 :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
191 :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
192 )
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193
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 ;; Inline functions
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (defsubst generic-read-type ()
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (completing-read
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 "Generic Type: "
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (mapcar
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 '(lambda (elt) (list (symbol-name (car elt))))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 generic-mode-alist) nil t))
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 ;; 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
206 ;; are of the correct type.
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
207 (defsubst generic-mode-sanity-check (name comment-list keyword-list
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
208 font-lock-list auto-mode-list
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 function-list &optional description)
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
210 (and (not (symbolp name))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (error "%s is not a symbol" (princ name)))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
213 (mapcar '(lambda (elt)
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (if (not (listp elt))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (error "%s is not a list" (princ elt))))
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
216 (list comment-list keyword-list font-lock-list
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 auto-mode-list function-list))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218
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
219 (and (not (or (null description) (stringp description)))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (error "Description must be a string or nil"))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 )
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222
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 ;; Functions
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226
22347
f53740d7d40d *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 21928
diff changeset
227 ;;;###autoload
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
228 (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
229 auto-mode-list function-list
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 &optional description)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 "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
232
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
233 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
234 FUNCTION-LIST &optional DESCRIPTION)
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
235
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
236 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
237 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
238 function.
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
240 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
241 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
242 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
243 comment-start syntax. If the entry is a cons pair, the elements of the
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
244 pair are considered to be comment-start and comment-end respectively.
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 Note that Emacs has limitations regarding comment characters.
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 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
248 Each keyword should be a string.
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 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
251 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
252
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 AUTO-MODE-LIST is a list of regular expressions to add to auto-mode-alist.
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
254 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
255 is called; any old regexps with the same name are removed.
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 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
258
21014
e3e68c9d2e35 Several doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 21013
diff changeset
259 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
260
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 ;; Basic sanity check
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
262 (generic-mode-sanity-check name
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
263 comment-list keyword-list font-lock-list
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 auto-mode-list function-list description)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 ;; Remove any old entry
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (setq generic-mode-alist
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
268 (delq (assq name generic-mode-alist)
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 generic-mode-alist))
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 ;; Add a new entry
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (setq generic-mode-alist
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (append
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 (list
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 (list
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
276 name comment-list keyword-list font-lock-list
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 auto-mode-list function-list
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 generic-mode-alist))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 ;; Add it to auto-mode-alist
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (generic-add-to-auto-mode name auto-mode-list t)
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 ;; Define a function for it
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (generic-create-generic-function name description)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 )
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
288 (defun generic-add-to-auto-mode (mode auto-mode-list
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 &optional remove-old prepend)
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
290 "Add the entries for MODE to `auto-mode-alist', supplied as AUTO-MODE-ALIST.
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 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
292 non-nil, prepends entries to auto-mode-alist; otherwise, appends them."
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 (if (not (listp auto-mode-list))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (error "%s is not a list" (princ auto-mode-list)))
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 (let ((new-mode (intern (symbol-name mode))))
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
298 (and remove-old
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
299 (let ((auto-mode-entry))
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
300 (while (setq auto-mode-entry (rassq new-mode auto-mode-alist))
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
301 (setq auto-mode-alist
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
302 (delq auto-mode-entry
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
303 auto-mode-alist)))))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
305 (mapcar '(lambda (entry)
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 (generic-add-auto-mode-entry new-mode entry prepend))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 auto-mode-list)))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 (defun generic-add-auto-mode-entry (name entry &optional prepend)
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
310 "Add a new NAME regexp with ENTRY to the end of `auto-mode-alist'.
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 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
312 (let ((new-entry (list (cons entry name))))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 (setq auto-mode-alist
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 (if prepend
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 (append new-entry auto-mode-alist)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 (append auto-mode-alist new-entry)))))
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 (defun generic-create-generic-function (name &optional description)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 "Create a generic mode function with NAME.
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 If DESCRIPTION is provided, it is used as the docstring."
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 (let ((symname (symbol-name name)))
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
322 ;; Use `defalias', not `fset' to make the mode appear on
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
323 ;; load-history.
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
324 (defalias (intern symname)
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
325 (list 'lambda nil
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
326 (or description
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
327 (concat "Generic mode for type " symname))
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
328 (list 'interactive)
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
329 (list 'generic-mode-with-type (list 'quote name))))))
18254
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-mode-with-type (&optional mode)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 "Go into the generic-mode MODE."
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 (let* ((type (or mode generic-mode-name))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (generic-mode-list (assoc type generic-mode-alist))
23392
d86ad410d285 (generic-mode-with-type): Added hooks for generic-modes.
Karl Heuer <kwzh@gnu.org>
parents: 22402
diff changeset
335 (generic-mode-hooks (intern (concat (symbol-name type) "-hooks")))
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
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
338 (and (not generic-mode-list)
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
339 (error "Can't find generic-mode information for type %s"
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
340 (princ generic-mode-name)))
18254
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 ;; Put this after the point where we read generic-mode-name!
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 (kill-all-local-variables)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
345 (setq
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 generic-mode-name type
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 generic-comment-list (nth 1 generic-mode-list)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 generic-keywords-list (nth 2 generic-mode-list)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 generic-font-lock-expressions (nth 3 generic-mode-list)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 generic-mode-function-list (nth 5 generic-mode-list)
22402
bb03a020d02c *** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents: 22347
diff changeset
351 major-mode type
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 mode-name (symbol-name type)
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
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (generic-mode-set-comments generic-comment-list)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 ;; Font-lock functionality
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 ;; Font-lock-defaults are always set even if there are no keywords
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 ;; or font-lock expressions, so comments can be highlighted.
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 (setq generic-font-lock-defaults nil)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 (generic-mode-set-font-lock generic-keywords-list
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 generic-font-lock-expressions)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 (make-local-variable 'font-lock-defaults)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 (setq font-lock-defaults (list 'generic-font-lock-defaults nil))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 ;; Call a list of functions
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
367 (and generic-mode-function-list
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
368 (mapcar 'funcall generic-mode-function-list))
23392
d86ad410d285 (generic-mode-with-type): Added hooks for generic-modes.
Karl Heuer <kwzh@gnu.org>
parents: 22402
diff changeset
369
d86ad410d285 (generic-mode-with-type): Added hooks for generic-modes.
Karl Heuer <kwzh@gnu.org>
parents: 22402
diff changeset
370 (run-hooks generic-mode-hooks)
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 )
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 )
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 ;;;###autoload
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 (defun generic-mode (type)
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
376 "Basic comment and font-lock functionality for `generic' files.
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
377 (Files which are too small to warrant their own mode, but have
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
378 comment characters, keywords, and the like.)
18254
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 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
381 Some generic modes are defined in `generic-x.el'."
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 (interactive
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 (list (generic-read-type)))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 (generic-mode-with-type (intern type)))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 ;;; Comment Functionality
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 (defun generic-mode-set-comments (comment-list)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 "Set up comment functionality for generic mode."
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 (if (null comment-list)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 nil
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 (let ((generic-mode-syntax-table (make-syntax-table)))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 (make-local-variable 'comment-start)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 (make-local-variable 'comment-start-skip)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 (make-local-variable 'comment-end)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 (mapcar 'generic-mode-set-a-comment comment-list)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 (set-syntax-table generic-mode-syntax-table))))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 (defun generic-mode-set-a-comment (comment)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 (and (char-or-string-p comment)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 (if (stringp comment)
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
401 (cond
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 ((eq (length comment) 1)
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
403 (generic-mode-set-comment-char
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 (string-to-char comment)))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 ((eq (length comment) 2)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 (generic-mode-set-comment-string comment))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 (t
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (error "Character string %s must be one or two characters long"
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 comment))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 )
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 (generic-mode-set-comment-char comment)))
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
412 (and (consp comment)
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
413 (generic-mode-set-comment-pair comment)))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 (defun generic-mode-set-comment-char (comment-char)
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
416 "Set COMMENT-CHAR as a comment character for generic mode."
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 (if (not comment-char)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 nil
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
419 (setq
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 comment-end ""
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 comment-start (char-to-string comment-char)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 comment-start-skip (concat comment-start "+ *")
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 )
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 (modify-syntax-entry comment-char "<"
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 generic-mode-syntax-table)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 (modify-syntax-entry ?\n ">"
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 generic-mode-syntax-table)))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 (defun generic-mode-set-comment-string (comment-string)
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
431 "Set COMMENT-STRING as a comment string for generic mode."
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 (if (not comment-string)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 nil
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
434 (setq
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 comment-end ""
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 comment-start comment-string
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 comment-start-skip (concat comment-start " *")
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 )
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 (let ((first (elt comment-string 0))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 (second (elt comment-string 1)))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 ;; C++ style comments
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 (if (char-equal first second)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 (progn
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 (modify-syntax-entry first "<12b"
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 generic-mode-syntax-table)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 (modify-syntax-entry ?\n ">b"
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 generic-mode-syntax-table)))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 ;; Some other two character string
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 (modify-syntax-entry first "<1"
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 generic-mode-syntax-table)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 (modify-syntax-entry second "<2"
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 generic-mode-syntax-table)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 (modify-syntax-entry ?\n ">"
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 generic-mode-syntax-table))))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 (defun generic-mode-set-comment-pair (comment-pair)
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
458 "Set COMMENT-PAIR as a comment start and end for generic mode."
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 (let ((generic-comment-start (car comment-pair))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 (generic-comment-end (cdr comment-pair))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 )
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
462 (setq
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 comment-end generic-comment-end
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 comment-start generic-comment-start
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 comment-start-skip (concat generic-comment-start " *")
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
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 ;; Sanity checks
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
469 (and (not (and (stringp generic-comment-start)
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
470 (stringp generic-comment-end)))
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
471 (error "Elements of cons pair must be strings"))
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
472 (and (not (and (equal (length generic-comment-start) 2)
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
473 (equal (length generic-comment-end) 2)))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 (error "Start and end must be exactly two characters long"))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 (let ((first (elt generic-comment-start 0))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 (second (elt generic-comment-start 1))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 (third (elt generic-comment-end 0))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 (fourth (elt generic-comment-end 1))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 )
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 (modify-syntax-entry first ". 1" generic-mode-syntax-table)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 (modify-syntax-entry second ". 2" generic-mode-syntax-table)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
485 (modify-syntax-entry
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
486 third
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
487 (concat
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 "."
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
489 (cond
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 ((char-equal first third) " 13")
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 ((char-equal second third) " 23")
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 (t " 3"))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 )
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 generic-mode-syntax-table)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
496 (modify-syntax-entry
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
497 fourth
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
498 (concat
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 "."
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
500 (cond
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 ((char-equal first fourth) " 14")
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 ((char-equal second fourth) " 24")
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 (t " 4"))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 )
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 generic-mode-syntax-table)
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
506 )))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 (defun generic-mode-set-font-lock (keywords font-lock-expressions)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 "Set up font-lock functionality for generic mode."
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 (let ((generic-font-lock-expressions))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 ;; Keywords
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
512 (and keywords
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 (setq
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 generic-font-lock-expressions
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 (append
21879
14316c9ecdac (generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents: 21182
diff changeset
516 (list (let ((regexp (regexp-opt keywords)))
14316c9ecdac (generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents: 21182
diff changeset
517 (list (concat "\\<\\(" regexp "\\)\\>")
14316c9ecdac (generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents: 21182
diff changeset
518 1
14316c9ecdac (generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents: 21182
diff changeset
519 'font-lock-keyword-face)))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 generic-font-lock-expressions)))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 ;; Other font-lock expressions
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
522 (and font-lock-expressions
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 (setq generic-font-lock-expressions
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 (append
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 font-lock-expressions
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526 generic-font-lock-expressions)))
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
527 (and (or font-lock-expressions keywords)
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
528 (setq generic-font-lock-defaults generic-font-lock-expressions))
18254
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
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 ;; Support for [KEYWORD] constructs found in INF, INI and Samba files
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 (defun generic-bracket-support ()
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
533 (setq imenu-generic-expression
20459
90f306f86f5d Use imenu-case-fold-search.
Dave Love <fx@gnu.org>
parents: 18254
diff changeset
534 '((nil "^\\[\\(.*\\)\\]" 1))
90f306f86f5d Use imenu-case-fold-search.
Dave Love <fx@gnu.org>
parents: 18254
diff changeset
535 imenu-case-fold-search t))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 ;; This generic mode is always defined
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 (define-generic-mode 'default-generic-mode (list ?#) nil nil nil nil)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 ;; A more general solution would allow us to enter generic-mode for
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 ;; *any* comment character, but would require us to synthesize a new
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 ;; 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
543 ;; want.
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544 (defun generic-mode-find-file-hook ()
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
545 "Hook function to enter default-generic-mode automatically.
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
546 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
547 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
548 `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
549 `generic-lines-to-scan' determines the number of lines to look at."
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 (if (not (eq major-mode 'fundamental-mode))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 nil
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
552 (and (or (> 1 generic-lines-to-scan)
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
553 (< 50 generic-lines-to-scan))
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
554 (error "Variable `generic-lines-to-scan' should be set to a small"
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
555 " positive number"))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 (let ((comment-regexp "")
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 (count 0)
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 )
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559 (while (< count generic-lines-to-scan)
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
560 (setq comment-regexp (concat comment-regexp
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561 generic-find-file-regexp))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 (setq count (1+ count)))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 (save-excursion
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564 (goto-char (point-min))
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
565 (and (looking-at comment-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
566 (generic-mode-with-type 'default-generic-mode))))))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568 (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
569 "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
570 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
571 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
572 (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
573 (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
574 (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
575 (and (looking-at "^\\s-*\\[.*\\]")
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
576 (generic-mode-with-type 'ini-generic-mode)))))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578 (and generic-use-find-file-hook
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579 (add-hook 'find-file-hooks 'generic-mode-find-file-hook))
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581 (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
582 "Return a regular expression matching the specified KEYWORDS-LIST.
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583 The regexp is highlighted with FACE."
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
584 (and (not (listp keywords-list))
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
585 (error "Keywords argument must be a list of strings"))
21879
14316c9ecdac (generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents: 21182
diff changeset
586 (list (concat (or prefix "")
14316c9ecdac (generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents: 21182
diff changeset
587 "\\<\\("
14316c9ecdac (generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents: 21182
diff changeset
588 ;; Use an optimized regexp.
14316c9ecdac (generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents: 21182
diff changeset
589 (regexp-opt keywords-list t)
14316c9ecdac (generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents: 21182
diff changeset
590 "\\)\\>"
14316c9ecdac (generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents: 21182
diff changeset
591 (or suffix ""))
14316c9ecdac (generic): Added defgroup declaration.
Richard M. Stallman <rms@gnu.org>
parents: 21182
diff changeset
592 1
21928
42fa0da05721 (generic-make-keywords-list): Delete spurious paren.
Richard M. Stallman <rms@gnu.org>
parents: 21879
diff changeset
593 face))
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594
21013
adb28ace7f33 Provide generic, not generic-mode.
Richard M. Stallman <rms@gnu.org>
parents: 20459
diff changeset
595 (provide 'generic)
18254
5364d9d625b4 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596
24022
218b7edb9baf Re-write `(make-variable-buffer-local (defvar ...'
Dave Love <fx@gnu.org>
parents: 23392
diff changeset
597 ;;; generic.el ends here