Mercurial > emacs
annotate lisp/progmodes/cfengine.el @ 110305:b10051866f51
New syntax-propertize functionality.
* lisp/font-lock.el (font-lock-syntactic-keywords): Make obsolete.
(font-lock-fontify-syntactic-keywords-region): Move handling of
font-lock-syntactically-fontified to...
(font-lock-default-fontify-region): ...here.
Let syntax-propertize-function take precedence.
(font-lock-fontify-syntactically-region): Cal syntax-propertize.
* lisp/emacs-lisp/regexp-opt.el (regexp-opt-depth): Skip named groups.
* lisp/emacs-lisp/syntax.el (syntax-propertize-function)
(syntax-propertize-chunk-size, syntax-propertize--done)
(syntax-propertize-extend-region-functions): New vars.
(syntax-propertize-wholelines, syntax-propertize-multiline)
(syntax-propertize--shift-groups, syntax-propertize-via-font-lock)
(syntax-propertize): New functions.
(syntax-propertize-rules): New macro.
(syntax-ppss-flush-cache): Set syntax-propertize--done.
(syntax-ppss): Call syntax-propertize.
* lisp/progmodes/ada-mode.el (ada-set-syntax-table-properties)
(ada-after-change-function, ada-initialize-syntax-table-properties)
(ada-handle-syntax-table-properties): Only define when
syntax-propertize is not available.
(ada-mode): Use syntax-propertize-function.
* lisp/progmodes/autoconf.el (autoconf-mode):
Use syntax-propertize-function.
(autoconf-font-lock-syntactic-keywords): Remove.
* lisp/progmodes/cfengine.el (cfengine-mode):
Use syntax-propertize-function.
(cfengine-font-lock-syntactic-keywords): Remove.
* lisp/progmodes/cperl-mode.el (cperl-mode): Use syntax-propertize-function.
* lisp/progmodes/fortran.el (fortran-mode): Use syntax-propertize-function.
(fortran--font-lock-syntactic-keywords): New var.
(fortran-line-length): Update syntax-propertize-function and
fortran--font-lock-syntactic-keywords.
* lisp/progmodes/gud.el (gdb-script-syntax-propertize-function): New var;
replaces gdb-script-font-lock-syntactic-keywords.
(gdb-script-mode): Use it.
* lisp/progmodes/js.el (js--regexp-literal): Define while compiling.
(js-syntax-propertize-function): New var; replaces
js-font-lock-syntactic-keywords.
(js-mode): Use it.
* lisp/progmodes/make-mode.el (makefile-syntax-propertize-function):
New var; replaces makefile-font-lock-syntactic-keywords.
(makefile-mode): Use it.
(makefile-imake-mode): Adjust.
* lisp/progmodes/mixal-mode.el (mixal-syntax-propertize-function): New var;
replaces mixal-font-lock-syntactic-keywords.
(mixal-mode): Use it.
* lisp/progmodes/octave-mod.el (octave-syntax-propertize-sqs): New function
to replace octave-font-lock-close-quotes.
(octave-syntax-propertize-function): New function to replace
octave-font-lock-syntactic-keywords.
(octave-mode): Use it.
* lisp/progmodes/perl-mode.el (perl-syntax-propertize-function): New fun to
replace perl-font-lock-syntactic-keywords.
(perl-syntax-propertize-special-constructs): New fun to replace
perl-font-lock-special-syntactic-constructs.
(perl-font-lock-syntactic-face-function): New fun.
(perl-mode): Use it.
* lisp/progmodes/python.el (python-syntax-propertize-function): New var to
replace python-font-lock-syntactic-keywords.
(python-mode): Use it.
(python-quote-syntax): Simplify and adjust to new use.
* lisp/progmodes/ruby-mode.el (ruby-here-doc-beg-re):
Define while compiling.
(ruby-here-doc-end-re, ruby-here-doc-beg-match)
(ruby-font-lock-syntactic-keywords, ruby-comment-beg-syntax)
(syntax-ppss, ruby-in-ppss-context-p, ruby-in-here-doc-p)
(ruby-here-doc-find-end, ruby-here-doc-beg-syntax)
(ruby-here-doc-end-syntax): Only define when
syntax-propertize is not available.
(ruby-syntax-propertize-function, ruby-syntax-propertize-heredoc):
New functions.
(ruby-in-ppss-context-p): Update to new syntax of heredocs.
(electric-indent-chars): Silence bytecompiler.
(ruby-mode): Use prog-mode, syntax-propertize-function, and
electric-indent-chars.
* lisp/progmodes/sh-script.el (sh-st-symbol): Remove.
(sh-font-lock-close-heredoc, sh-font-lock-open-heredoc): Add eol arg.
(sh-font-lock-flush-syntax-ppss-cache, sh-font-lock-here-doc): Remove.
(sh-font-lock-quoted-subshell): Assume we've already matched $(.
(sh-font-lock-paren): Set syntax-multiline.
(sh-font-lock-syntactic-keywords): Remove.
(sh-syntax-propertize-function): New function to replace it.
(sh-mode): Use it.
* lisp/progmodes/simula.el (simula-syntax-propertize-function): New var to
replace simula-font-lock-syntactic-keywords.
(simula-mode): Use it.
* lisp/progmodes/tcl.el (tcl-syntax-propertize-function): New var to
replace tcl-font-lock-syntactic-keywords.
(tcl-mode): Use it.
* lisp/progmodes/vhdl-mode.el (vhdl-mode): Use syntax-propertize-function
if available.
(vhdl-fontify-buffer): Adjust.
* lisp/textmodes/bibtex.el (bibtex-mode): Use syntax-propertize-function.
* lisp/textmodes/reftex.el (font-lock-syntactic-keywords): Don't declare
since we don't use it.
* lisp/textmodes/sgml-mode.el (sgml-syntax-propertize-function): New var to
replace sgml-font-lock-syntactic-keywords.
(sgml-mode): Use it.
* lisp/textmodes/tex-mode.el (tex-common-initialization, doctex-mode):
Use syntax-propertize-function.
* lisp/textmodes/texinfo.el (texinfo-syntax-propertize-function): New fun
to replace texinfo-font-lock-syntactic-keywords.
(texinfo-mode): Use it.
* test/indent/octave.m: Remove some `fixindent' not needed any more.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Sat, 11 Sep 2010 01:13:42 +0200 |
parents | 1d1d5d9bd884 |
children | b47e85affa59 |
rev | line source |
---|---|
52888 | 1 ;;; cfengine.el --- mode for editing Cfengine files |
2 | |
106815 | 3 ;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
68773
dc49655f57ae
Update copyright for 2006.
Nick Roberts <nickrob@snap.net.nz>
parents:
64699
diff
changeset
|
4 ;; Free Software Foundation, Inc. |
52888 | 5 |
6 ;; Author: Dave Love <fx@gnu.org> | |
7 ;; Keywords: languages | |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79717
diff
changeset
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
52888 | 12 ;; it under the terms of the GNU General Public License as published by |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79717
diff
changeset
|
13 ;; the Free Software Foundation, either version 3 of the License, or |
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79717
diff
changeset
|
14 ;; (at your option) any later version. |
52888 | 15 |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79717
diff
changeset
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
52888 | 23 |
24 ;;; Commentary: | |
25 | |
26 ;; Provides support for editing GNU Cfengine files, including | |
27 ;; font-locking, Imenu and indention, but with no special keybindings. | |
28 | |
29 ;; Possible customization for auto-mode selection: | |
30 ;; (push '(("^cfagent.conf\\'" . cfengine-mode)) auto-mode-alist) | |
31 ;; (push '(("^cf\\." . cfengine-mode)) auto-mode-alist) | |
32 | |
33 ;; This is not the same as the mode written by Rolf Ebert | |
34 ;; <ebert@waporo.muc.de>, distributed with cfengine-2.0.5. It does | |
35 ;; better fontification and indentation, inter alia. | |
36 | |
37 ;;; Code: | |
38 | |
39 (defgroup cfengine () | |
40 "Editing Cfengine files." | |
41 :group 'languages) | |
42 | |
43 (defcustom cfengine-indent 2 | |
44 "*Size of a Cfengine indentation step in columns." | |
45 :group 'cfengine | |
46 :type 'integer) | |
47 | |
48 (defcustom cfengine-mode-abbrevs nil | |
49 "Abbrevs for Cfengine mode." | |
50 :group 'cfengine | |
51 :type '(repeat (list (string :tag "Name") | |
52 (string :tag "Expansion") | |
53 (choice :tag "Hook" (const nil) function)))) | |
54 | |
55 ;; Taken from the doc for pre-release 2.1. | |
56 (eval-and-compile | |
57 (defconst cfengine-actions | |
58 '("acl" "alerts" "binservers" "broadcast" "control" "classes" "copy" | |
59 "defaultroute" "disks" "directories" "disable" "editfiles" "files" | |
60 "filters" "groups" "homeservers" "ignore" "import" "interfaces" | |
61 "links" "mailserver" "methods" "miscmounts" "mountables" | |
62 "processes" "packages" "rename" "required" "resolve" | |
63 "shellcommands" "tidy" "unmount" | |
64 ;; cfservd | |
65 "admit" "grant" "deny") | |
66 "List of the action keywords supported by Cfengine. | |
67 This includes those for cfservd as well as cfagent.")) | |
68 | |
69 (defvar cfengine-font-lock-keywords | |
70 `(;; Actions. | |
71 ;; List the allowed actions explicitly, so that errors are more obvious. | |
72 (,(concat "^[ \t]*" (eval-when-compile | |
73 (regexp-opt cfengine-actions t)) | |
74 ":") | |
75 1 font-lock-keyword-face) | |
76 ;; Classes. | |
77 ("^[ \t]*\\([[:alnum:]_().|!]+\\)::" 1 font-lock-function-name-face) | |
78 ;; Variables. | |
79 ("$(\\([[:alnum:]_]+\\))" 1 font-lock-variable-name-face) | |
80 ("${\\([[:alnum:]_]+\\)}" 1 font-lock-variable-name-face) | |
81 ;; Variable definitions. | |
82 ("\\<\\([[:alnum:]_]+\\)[ \t]*=[ \t]*(" 1 font-lock-variable-name-face) | |
83 ;; File, acl &c in group: { token ... } | |
84 ("{[ \t]*\\([^ \t\n]+\\)" 1 font-lock-constant-face))) | |
85 | |
86 (defvar cfengine-imenu-expression | |
87 `((nil ,(concat "^[ \t]*" (eval-when-compile | |
88 (regexp-opt cfengine-actions t)) | |
89 ":[^:]") | |
90 1) | |
91 ("Variables/classes" "\\<\\([[:alnum:]_]+\\)[ \t]*=[ \t]*(" 1) | |
92 ("Variables/classes" "\\<define=\\([[:alnum:]_]+\\)" 1) | |
93 ("Variables/classes" "\\<DefineClass\\>[ \t]+\\([[:alnum:]_]+\\)" 1)) | |
94 "`imenu-generic-expression' for Cfengine mode.") | |
95 | |
96 (defun cfengine-outline-level () | |
97 "`outline-level' function for Cfengine mode." | |
98 (if (looking-at "[^:]+\\(?:[:]+\\)$") | |
99 (length (match-string 1)))) | |
100 | |
101 (defun cfengine-beginning-of-defun () | |
102 "`beginning-of-defun' function for Cfengine mode. | |
103 Treats actions as defuns." | |
55239
1af59a842b93
(cfengine-beginning-of-defun, cfengine-end-of-defun):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54460
diff
changeset
|
104 (unless (<= (current-column) (current-indentation)) |
1af59a842b93
(cfengine-beginning-of-defun, cfengine-end-of-defun):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54460
diff
changeset
|
105 (end-of-line)) |
52888 | 106 (if (re-search-backward "^[[:alpha:]]+: *$" nil t) |
107 (beginning-of-line) | |
108 (goto-char (point-min))) | |
109 t) | |
110 | |
111 (defun cfengine-end-of-defun () | |
112 "`end-of-defun' function for Cfengine mode. | |
113 Treats actions as defuns." | |
114 (end-of-line) | |
115 (if (re-search-forward "^[[:alpha:]]+: *$" nil t) | |
55239
1af59a842b93
(cfengine-beginning-of-defun, cfengine-end-of-defun):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54460
diff
changeset
|
116 (beginning-of-line) |
52888 | 117 (goto-char (point-max))) |
118 t) | |
119 | |
120 ;; Fixme: Should get an extra indent step in editfiles BeginGroup...s. | |
121 | |
122 (defun cfengine-indent-line () | |
123 "Indent a line in Cfengine mode. | |
124 Intended as the value of `indent-line-function'." | |
125 (let ((pos (- (point-max) (point)))) | |
126 (save-restriction | |
127 (narrow-to-defun) | |
128 (back-to-indentation) | |
129 (cond | |
130 ;; Action selectors aren't indented; class selectors are | |
131 ;; indented one step. | |
132 ((looking-at "[[:alnum:]_().|!]+:\\(:\\)?") | |
133 (if (match-string 1) | |
134 (indent-line-to cfengine-indent) | |
135 (indent-line-to 0))) | |
136 ;; Outdent leading close brackets one step. | |
137 ((or (eq ?\} (char-after)) | |
138 (eq ?\) (char-after))) | |
139 (condition-case () | |
140 (indent-line-to (save-excursion | |
141 (forward-char) | |
142 (backward-sexp) | |
143 (current-column))) | |
144 (error nil))) | |
145 ;; Inside brackets/parens: indent to start column of non-comment | |
146 ;; token on line following open bracket or by one step from open | |
147 ;; bracket's column. | |
148 ((condition-case () | |
149 (progn (indent-line-to (save-excursion | |
150 (backward-up-list) | |
151 (forward-char) | |
152 (skip-chars-forward " \t") | |
153 (if (looking-at "[^\n#]") | |
154 (current-column) | |
155 (skip-chars-backward " \t") | |
156 (+ (current-column) -1 | |
157 cfengine-indent)))) | |
158 t) | |
159 (error nil))) | |
160 ;; Indent by two steps after a class selector. | |
161 ((save-excursion | |
162 (re-search-backward "^[ \t]*[[:alnum:]_().|!]+::" nil t)) | |
163 (indent-line-to (* 2 cfengine-indent))) | |
164 ;; Indent by one step if we're after an action header. | |
165 ((save-excursion | |
166 (goto-char (point-min)) | |
167 (looking-at "[[:alpha:]]+:[ \t]*$")) | |
168 (indent-line-to cfengine-indent)) | |
169 ;; Else don't indent. | |
170 (t | |
171 (indent-line-to 0)))) | |
172 ;; If initial point was within line's indentation, | |
173 ;; position after the indentation. Else stay at same point in text. | |
174 (if (> (- (point-max) pos) (point)) | |
175 (goto-char (- (point-max) pos))))) | |
176 | |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
59241
diff
changeset
|
177 ;; This doesn't work too well in Emacs 21.2. See 22.1 development |
52888 | 178 ;; code. |
179 (defun cfengine-fill-paragraph (&optional justify) | |
180 "Fill `paragraphs' in Cfengine code." | |
181 (interactive "P") | |
182 (or (if (fboundp 'fill-comment-paragraph) | |
183 (fill-comment-paragraph justify) ; post Emacs 21.3 | |
184 ;; else do nothing in a comment | |
185 (nth 4 (parse-partial-sexp (save-excursion | |
186 (beginning-of-defun) | |
187 (point)) | |
188 (point)))) | |
189 (let ((paragraph-start | |
190 ;; Include start of parenthesized block. | |
191 "\f\\|[ \t]*$\\|.*\(") | |
192 (paragraph-separate | |
193 ;; Include action and class lines, start and end of | |
194 ;; bracketed blocks and end of parenthesized blocks to | |
195 ;; avoid including these in fill. This isn't ideal. | |
196 "[ \t\f]*$\\|.*#\\|.*[\){}]\\|\\s-*[[:alpha:]_().|!]+:") | |
197 fill-paragraph-function) | |
198 (fill-paragraph justify)) | |
199 t)) | |
200 | |
201 ;;;###autoload | |
202 (define-derived-mode cfengine-mode fundamental-mode "Cfengine" | |
203 "Major mode for editing cfengine input. | |
204 There are no special keybindings by default. | |
205 | |
206 Action blocks are treated as defuns, i.e. \\[beginning-of-defun] moves | |
207 to the action header." | |
208 (modify-syntax-entry ?# "<" cfengine-mode-syntax-table) | |
209 (modify-syntax-entry ?\n ">#" cfengine-mode-syntax-table) | |
210 ;; Shell commands can be quoted by single, double or back quotes. | |
211 ;; It's debatable whether we should define string syntax, but it | |
212 ;; should avoid potential confusion in some cases. | |
213 (modify-syntax-entry ?\" "\"" cfengine-mode-syntax-table) | |
214 (modify-syntax-entry ?\' "\"" cfengine-mode-syntax-table) | |
215 (modify-syntax-entry ?\` "\"" cfengine-mode-syntax-table) | |
216 ;; variable substitution: | |
217 (modify-syntax-entry ?$ "." cfengine-mode-syntax-table) | |
218 ;; Doze path separators: | |
72799
ff69721bef4a
(cfengine-font-lock-syntactic-keywords): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
219 (modify-syntax-entry ?\\ "." cfengine-mode-syntax-table) |
52888 | 220 ;; Otherwise, syntax defaults seem OK to give reasonable word |
221 ;; movement. | |
222 | |
223 (set (make-local-variable 'parens-require-spaces) nil) | |
59241
685fd8697e78
(cfengine-mode): Use mode-require-final-newline.
Richard M. Stallman <rms@gnu.org>
parents:
55239
diff
changeset
|
224 (set (make-local-variable 'require-final-newline) mode-require-final-newline) |
52888 | 225 (set (make-local-variable 'comment-start) "# ") |
226 (set (make-local-variable 'comment-start-skip) | |
227 "\\(\\(?:^\\|[^\\\\\n]\\)\\(?:\\\\\\\\\\)*\\)#+[ \t]*") | |
228 (set (make-local-variable 'indent-line-function) #'cfengine-indent-line) | |
229 (set (make-local-variable 'outline-regexp) "[ \t]*\\(\\sw\\|\\s_\\)+:+") | |
230 (set (make-local-variable 'outline-level) #'cfengine-outline-level) | |
231 (set (make-local-variable 'fill-paragraph-function) | |
232 #'cfengine-fill-paragraph) | |
233 (define-abbrev-table 'cfengine-mode-abbrev-table cfengine-mode-abbrevs) | |
234 (setq font-lock-defaults | |
110305
b10051866f51
New syntax-propertize functionality.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106815
diff
changeset
|
235 '(cfengine-font-lock-keywords nil nil nil beginning-of-line)) |
b10051866f51
New syntax-propertize functionality.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106815
diff
changeset
|
236 ;; Fixme: set the args of functions in evaluated classes to string |
b10051866f51
New syntax-propertize functionality.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106815
diff
changeset
|
237 ;; syntax, and then obey syntax properties. |
b10051866f51
New syntax-propertize functionality.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106815
diff
changeset
|
238 (set (make-local-variable 'syntax-propertize-function) |
b10051866f51
New syntax-propertize functionality.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106815
diff
changeset
|
239 ;; In the main syntax-table, \ is marked as a punctuation, because |
b10051866f51
New syntax-propertize functionality.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106815
diff
changeset
|
240 ;; of its use in DOS-style directory separators. Here we try to |
b10051866f51
New syntax-propertize functionality.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106815
diff
changeset
|
241 ;; recognize the cases where \ is used as an escape inside strings. |
b10051866f51
New syntax-propertize functionality.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106815
diff
changeset
|
242 (syntax-propertize-rules ("\\(\\(?:\\\\\\)+\\)\"" (1 "\\")))) |
52888 | 243 (setq imenu-generic-expression cfengine-imenu-expression) |
244 (set (make-local-variable 'beginning-of-defun-function) | |
245 #'cfengine-beginning-of-defun) | |
54460
82f7cd1ab4eb
(cfengine-mode): Set parse-sexp-ignore-comments.
Juanma Barranquero <lekktu@gmail.com>
parents:
52910
diff
changeset
|
246 (set (make-local-variable 'end-of-defun-function) #'cfengine-end-of-defun) |
82f7cd1ab4eb
(cfengine-mode): Set parse-sexp-ignore-comments.
Juanma Barranquero <lekktu@gmail.com>
parents:
52910
diff
changeset
|
247 ;; Like Lisp mode. Without this, we lose with, say, |
82f7cd1ab4eb
(cfengine-mode): Set parse-sexp-ignore-comments.
Juanma Barranquero <lekktu@gmail.com>
parents:
52910
diff
changeset
|
248 ;; `backward-up-list' when there's an unbalanced quote in a |
82f7cd1ab4eb
(cfengine-mode): Set parse-sexp-ignore-comments.
Juanma Barranquero <lekktu@gmail.com>
parents:
52910
diff
changeset
|
249 ;; preceding comment. |
82f7cd1ab4eb
(cfengine-mode): Set parse-sexp-ignore-comments.
Juanma Barranquero <lekktu@gmail.com>
parents:
52910
diff
changeset
|
250 (set (make-local-variable 'parse-sexp-ignore-comments) t)) |
52888 | 251 |
252 (provide 'cfengine) | |
253 | |
72799
ff69721bef4a
(cfengine-font-lock-syntactic-keywords): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
254 ;; arch-tag: 6b931be2-1505-4124-afa6-9675971e26d4 |
52888 | 255 ;;; cfengine.el ends here |