annotate lisp/progmodes/cfengine.el @ 87253:6df659d50dc9

Add declare-function compatibility definition. Require gnus-sum not just when compiling. (nnvirtual-find-group-art): Declare as a function.
author Glenn Morris <rgm@gnu.org>
date Tue, 11 Dec 2007 05:47:37 +0000
parents c1ec1c8a8d2e
children a1342e6e097a f55f9811f5d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52888
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
1 ;;; cfengine.el --- mode for editing Cfengine files
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
2
75347
e3694f1cb928 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 75047
diff changeset
3 ;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
68773
dc49655f57ae Update copyright for 2006.
Nick Roberts <nickrob@snap.net.nz>
parents: 64699
diff changeset
4 ;; Free Software Foundation, Inc.
52888
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
5
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
6 ;; Author: Dave Love <fx@gnu.org>
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
7 ;; Keywords: languages
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
8
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
10
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
78234
c1ec1c8a8d2e Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 75347
diff changeset
13 ;; the Free Software Foundation; either version 3, or (at your option)
52888
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
14 ;; any later version.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
15
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
20
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 59996
diff changeset
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 59996
diff changeset
24 ;; Boston, MA 02110-1301, USA.
52888
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
25
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
27
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
28 ;; Provides support for editing GNU Cfengine files, including
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
29 ;; font-locking, Imenu and indention, but with no special keybindings.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
30
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
31 ;; Possible customization for auto-mode selection:
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
32 ;; (push '(("^cfagent.conf\\'" . cfengine-mode)) auto-mode-alist)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
33 ;; (push '(("^cf\\." . cfengine-mode)) auto-mode-alist)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
34
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
35 ;; This is not the same as the mode written by Rolf Ebert
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
36 ;; <ebert@waporo.muc.de>, distributed with cfengine-2.0.5. It does
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
37 ;; better fontification and indentation, inter alia.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
38
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
39 ;;; Code:
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
40
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
41 (defgroup cfengine ()
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
42 "Editing Cfengine files."
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
43 :group 'languages)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
44
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
45 (defcustom cfengine-indent 2
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
46 "*Size of a Cfengine indentation step in columns."
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
47 :group 'cfengine
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
48 :type 'integer)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
49
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
50 (defcustom cfengine-mode-abbrevs nil
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
51 "Abbrevs for Cfengine mode."
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
52 :group 'cfengine
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
53 :type '(repeat (list (string :tag "Name")
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
54 (string :tag "Expansion")
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
55 (choice :tag "Hook" (const nil) function))))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
56
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
57 ;; Taken from the doc for pre-release 2.1.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
58 (eval-and-compile
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
59 (defconst cfengine-actions
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
60 '("acl" "alerts" "binservers" "broadcast" "control" "classes" "copy"
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
61 "defaultroute" "disks" "directories" "disable" "editfiles" "files"
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
62 "filters" "groups" "homeservers" "ignore" "import" "interfaces"
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
63 "links" "mailserver" "methods" "miscmounts" "mountables"
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
64 "processes" "packages" "rename" "required" "resolve"
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
65 "shellcommands" "tidy" "unmount"
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
66 ;; cfservd
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
67 "admit" "grant" "deny")
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
68 "List of the action keywords supported by Cfengine.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
69 This includes those for cfservd as well as cfagent."))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
70
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
71 (defvar cfengine-font-lock-keywords
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
72 `(;; Actions.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
73 ;; List the allowed actions explicitly, so that errors are more obvious.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
74 (,(concat "^[ \t]*" (eval-when-compile
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
75 (regexp-opt cfengine-actions t))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
76 ":")
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
77 1 font-lock-keyword-face)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
78 ;; Classes.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
79 ("^[ \t]*\\([[:alnum:]_().|!]+\\)::" 1 font-lock-function-name-face)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
80 ;; Variables.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
81 ("$(\\([[:alnum:]_]+\\))" 1 font-lock-variable-name-face)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
82 ("${\\([[:alnum:]_]+\\)}" 1 font-lock-variable-name-face)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
83 ;; Variable definitions.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
84 ("\\<\\([[:alnum:]_]+\\)[ \t]*=[ \t]*(" 1 font-lock-variable-name-face)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
85 ;; File, acl &c in group: { token ... }
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
86 ("{[ \t]*\\([^ \t\n]+\\)" 1 font-lock-constant-face)))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
87
72799
ff69721bef4a (cfengine-font-lock-syntactic-keywords): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68773
diff changeset
88 (defconst cfengine-font-lock-syntactic-keywords
ff69721bef4a (cfengine-font-lock-syntactic-keywords): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68773
diff changeset
89 ;; In the main syntax-table, backslash is marked as a punctuation, because
ff69721bef4a (cfengine-font-lock-syntactic-keywords): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68773
diff changeset
90 ;; of its use in DOS-style directory separators. Here we try to recognize
ff69721bef4a (cfengine-font-lock-syntactic-keywords): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68773
diff changeset
91 ;; the cases where backslash is used as an escape inside strings.
75047
0e3ea59d0acd (cfengine-font-lock-syntactic-keywords): Fix format of value.
Richard M. Stallman <rms@gnu.org>
parents: 72799
diff changeset
92 '(("\\(\\(?:\\\\\\)+\\)\"" 1 "\\")))
72799
ff69721bef4a (cfengine-font-lock-syntactic-keywords): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68773
diff changeset
93
52888
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
94 (defvar cfengine-imenu-expression
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
95 `((nil ,(concat "^[ \t]*" (eval-when-compile
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
96 (regexp-opt cfengine-actions t))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
97 ":[^:]")
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
98 1)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
99 ("Variables/classes" "\\<\\([[:alnum:]_]+\\)[ \t]*=[ \t]*(" 1)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
100 ("Variables/classes" "\\<define=\\([[:alnum:]_]+\\)" 1)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
101 ("Variables/classes" "\\<DefineClass\\>[ \t]+\\([[:alnum:]_]+\\)" 1))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
102 "`imenu-generic-expression' for Cfengine mode.")
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
103
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
104 (defun cfengine-outline-level ()
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
105 "`outline-level' function for Cfengine mode."
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
106 (if (looking-at "[^:]+\\(?:[:]+\\)$")
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
107 (length (match-string 1))))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
108
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
109 (defun cfengine-beginning-of-defun ()
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
110 "`beginning-of-defun' function for Cfengine mode.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
111 Treats actions as defuns."
55239
1af59a842b93 (cfengine-beginning-of-defun, cfengine-end-of-defun):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54460
diff changeset
112 (unless (<= (current-column) (current-indentation))
1af59a842b93 (cfengine-beginning-of-defun, cfengine-end-of-defun):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54460
diff changeset
113 (end-of-line))
52888
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
114 (if (re-search-backward "^[[:alpha:]]+: *$" nil t)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
115 (beginning-of-line)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
116 (goto-char (point-min)))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
117 t)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
118
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
119 (defun cfengine-end-of-defun ()
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
120 "`end-of-defun' function for Cfengine mode.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
121 Treats actions as defuns."
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
122 (end-of-line)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
123 (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
124 (beginning-of-line)
52888
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
125 (goto-char (point-max)))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
126 t)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
127
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
128 ;; Fixme: Should get an extra indent step in editfiles BeginGroup...s.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
129
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
130 (defun cfengine-indent-line ()
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
131 "Indent a line in Cfengine mode.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
132 Intended as the value of `indent-line-function'."
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
133 (let ((pos (- (point-max) (point))))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
134 (save-restriction
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
135 (narrow-to-defun)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
136 (back-to-indentation)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
137 (cond
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
138 ;; Action selectors aren't indented; class selectors are
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
139 ;; indented one step.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
140 ((looking-at "[[:alnum:]_().|!]+:\\(:\\)?")
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
141 (if (match-string 1)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
142 (indent-line-to cfengine-indent)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
143 (indent-line-to 0)))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
144 ;; Outdent leading close brackets one step.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
145 ((or (eq ?\} (char-after))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
146 (eq ?\) (char-after)))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
147 (condition-case ()
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
148 (indent-line-to (save-excursion
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
149 (forward-char)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
150 (backward-sexp)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
151 (current-column)))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
152 (error nil)))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
153 ;; Inside brackets/parens: indent to start column of non-comment
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
154 ;; token on line following open bracket or by one step from open
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
155 ;; bracket's column.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
156 ((condition-case ()
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
157 (progn (indent-line-to (save-excursion
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
158 (backward-up-list)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
159 (forward-char)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
160 (skip-chars-forward " \t")
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
161 (if (looking-at "[^\n#]")
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
162 (current-column)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
163 (skip-chars-backward " \t")
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
164 (+ (current-column) -1
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
165 cfengine-indent))))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
166 t)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
167 (error nil)))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
168 ;; Indent by two steps after a class selector.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
169 ((save-excursion
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
170 (re-search-backward "^[ \t]*[[:alnum:]_().|!]+::" nil t))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
171 (indent-line-to (* 2 cfengine-indent)))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
172 ;; Indent by one step if we're after an action header.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
173 ((save-excursion
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
174 (goto-char (point-min))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
175 (looking-at "[[:alpha:]]+:[ \t]*$"))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
176 (indent-line-to cfengine-indent))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
177 ;; Else don't indent.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
178 (t
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
179 (indent-line-to 0))))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
180 ;; If initial point was within line's indentation,
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
181 ;; position after the indentation. Else stay at same point in text.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
182 (if (> (- (point-max) pos) (point))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
183 (goto-char (- (point-max) pos)))))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
184
59996
aac0a33f5772 Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents: 59241
diff changeset
185 ;; This doesn't work too well in Emacs 21.2. See 22.1 development
52888
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
186 ;; code.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
187 (defun cfengine-fill-paragraph (&optional justify)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
188 "Fill `paragraphs' in Cfengine code."
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
189 (interactive "P")
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
190 (or (if (fboundp 'fill-comment-paragraph)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
191 (fill-comment-paragraph justify) ; post Emacs 21.3
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
192 ;; else do nothing in a comment
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
193 (nth 4 (parse-partial-sexp (save-excursion
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
194 (beginning-of-defun)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
195 (point))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
196 (point))))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
197 (let ((paragraph-start
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
198 ;; Include start of parenthesized block.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
199 "\f\\|[ \t]*$\\|.*\(")
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
200 (paragraph-separate
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
201 ;; Include action and class lines, start and end of
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
202 ;; bracketed blocks and end of parenthesized blocks to
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
203 ;; avoid including these in fill. This isn't ideal.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
204 "[ \t\f]*$\\|.*#\\|.*[\){}]\\|\\s-*[[:alpha:]_().|!]+:")
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
205 fill-paragraph-function)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
206 (fill-paragraph justify))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
207 t))
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
208
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
209 ;;;###autoload
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
210 (define-derived-mode cfengine-mode fundamental-mode "Cfengine"
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
211 "Major mode for editing cfengine input.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
212 There are no special keybindings by default.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
213
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
214 Action blocks are treated as defuns, i.e. \\[beginning-of-defun] moves
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
215 to the action header."
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
216 (modify-syntax-entry ?# "<" cfengine-mode-syntax-table)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
217 (modify-syntax-entry ?\n ">#" cfengine-mode-syntax-table)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
218 ;; Shell commands can be quoted by single, double or back quotes.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
219 ;; It's debatable whether we should define string syntax, but it
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
220 ;; should avoid potential confusion in some cases.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
221 (modify-syntax-entry ?\" "\"" cfengine-mode-syntax-table)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
222 (modify-syntax-entry ?\' "\"" cfengine-mode-syntax-table)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
223 (modify-syntax-entry ?\` "\"" cfengine-mode-syntax-table)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
224 ;; variable substitution:
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
225 (modify-syntax-entry ?$ "." cfengine-mode-syntax-table)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
226 ;; Doze path separators:
72799
ff69721bef4a (cfengine-font-lock-syntactic-keywords): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68773
diff changeset
227 (modify-syntax-entry ?\\ "." cfengine-mode-syntax-table)
52888
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
228 ;; Otherwise, syntax defaults seem OK to give reasonable word
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
229 ;; movement.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
230
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
231 (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
232 (set (make-local-variable 'require-final-newline) mode-require-final-newline)
52888
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
233 (set (make-local-variable 'comment-start) "# ")
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
234 (set (make-local-variable 'comment-start-skip)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
235 "\\(\\(?:^\\|[^\\\\\n]\\)\\(?:\\\\\\\\\\)*\\)#+[ \t]*")
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
236 (set (make-local-variable 'indent-line-function) #'cfengine-indent-line)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
237 (set (make-local-variable 'outline-regexp) "[ \t]*\\(\\sw\\|\\s_\\)+:+")
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
238 (set (make-local-variable 'outline-level) #'cfengine-outline-level)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
239 (set (make-local-variable 'fill-paragraph-function)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
240 #'cfengine-fill-paragraph)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
241 (define-abbrev-table 'cfengine-mode-abbrev-table cfengine-mode-abbrevs)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
242 ;; Fixme: Use `font-lock-syntactic-keywords' to set the args of
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
243 ;; functions in evaluated classes to string syntax, and then obey
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
244 ;; syntax properties.
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
245 (setq font-lock-defaults
72799
ff69721bef4a (cfengine-font-lock-syntactic-keywords): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68773
diff changeset
246 '(cfengine-font-lock-keywords nil nil nil beginning-of-line
ff69721bef4a (cfengine-font-lock-syntactic-keywords): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68773
diff changeset
247 (font-lock-syntactic-keywords
ff69721bef4a (cfengine-font-lock-syntactic-keywords): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68773
diff changeset
248 . cfengine-font-lock-syntactic-keywords)))
52888
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
249 (setq imenu-generic-expression cfengine-imenu-expression)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
250 (set (make-local-variable 'beginning-of-defun-function)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
251 #'cfengine-beginning-of-defun)
54460
82f7cd1ab4eb (cfengine-mode): Set parse-sexp-ignore-comments.
Juanma Barranquero <lekktu@gmail.com>
parents: 52910
diff changeset
252 (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
253 ;; 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
254 ;; `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
255 ;; preceding comment.
82f7cd1ab4eb (cfengine-mode): Set parse-sexp-ignore-comments.
Juanma Barranquero <lekktu@gmail.com>
parents: 52910
diff changeset
256 (set (make-local-variable 'parse-sexp-ignore-comments) t))
52888
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
257
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
258 (provide 'cfengine)
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
259
72799
ff69721bef4a (cfengine-font-lock-syntactic-keywords): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68773
diff changeset
260 ;; arch-tag: 6b931be2-1505-4124-afa6-9675971e26d4
52888
bc07c51257ae *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
261 ;;; cfengine.el ends here