]> code.delx.au - gnu-emacs/blob - lisp/progmodes/cfengine.el
* progmodes/cfengine.el: add CFEngine 3-specific indentation.
[gnu-emacs] / lisp / progmodes / cfengine.el
1 ;;; cfengine.el --- mode for editing Cfengine files
2
3 ;; Copyright (C) 2001-2013 Free Software Foundation, Inc.
4
5 ;; Author: Dave Love <fx@gnu.org>
6 ;; Maintainer: Ted Zlatanov <tzz@lifelogs.com>
7 ;; Keywords: languages
8 ;; Version: 1.2
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24
25 ;;; Commentary:
26
27 ;; Provides support for editing GNU Cfengine files, including
28 ;; font-locking, Imenu and indentation, but with no special keybindings.
29
30 ;; The CFEngine 3.x support doesn't have Imenu support but patches are
31 ;; welcome.
32
33 ;; You can set it up so either `cfengine2-mode' (2.x and earlier) or
34 ;; `cfengine3-mode' (3.x) will be picked, depending on the buffer
35 ;; contents:
36
37 ;; (add-to-list 'auto-mode-alist '("\\.cf\\'" . cfengine-mode))
38
39 ;; OR you can choose to always use a specific version, if you prefer
40 ;; it:
41
42 ;; (add-to-list 'auto-mode-alist '("\\.cf\\'" . cfengine3-mode))
43 ;; (add-to-list 'auto-mode-alist '("^cf\\." . cfengine2-mode))
44 ;; (add-to-list 'auto-mode-alist '("^cfagent.conf\\'" . cfengine2-mode))
45
46 ;; This is not the same as the mode written by Rolf Ebert
47 ;; <ebert@waporo.muc.de>, distributed with cfengine-2.0.5. It does
48 ;; better fontification and indentation, inter alia.
49
50 ;;; Code:
51
52 (defgroup cfengine ()
53 "Editing CFEngine files."
54 :group 'languages)
55
56 (defcustom cfengine-indent 2
57 "Size of a CFEngine indentation step in columns."
58 :group 'cfengine
59 :type 'integer)
60
61 (defcustom cfengine-parameters-indent '(promise pname 0)
62 "*Indentation of CFEngine3 promise parameters (hanging indent).
63
64 For example, say you have this code:
65
66 bundle x y
67 {
68 section:
69 class::
70 promise ...
71 promiseparameter => ...
72 }
73
74 You can choose to indent promiseparameter from the beginning of
75 the line (absolutely) or from the word \"promise\" (relatively).
76
77 You can also choose to indent the start of the word
78 \"promiseparameter\" or the arrow that follows it.
79
80 Finally, you can choose the amount of the indent.
81
82 The default is to anchor at promise, indent parameter name, and offset 0:
83
84 bundle agent rcfiles
85 {
86 files:
87 any::
88 \"/tmp/netrc\"
89 comment => \"my netrc\",
90 perms => mog(\"600\", \"tzz\", \"tzz\");
91 }
92
93 Here we anchor at beginning of line, indent arrow, and offset 10:
94
95 bundle agent rcfiles
96 {
97 files:
98 any::
99 \"/tmp/netrc\"
100 comment => \"my netrc\",
101 perms => mog(\"600\", \"tzz\", \"tzz\");
102 }
103
104 Some, including cfengine_stdlib.cf, like to anchor at promise, indent
105 arrow, and offset 16 or so:
106
107 bundle agent rcfiles
108 {
109 files:
110 any::
111 \"/tmp/netrc\"
112 comment => \"my netrc\",
113 perms => mog(\"600\", \"tzz\", \"tzz\");
114 }
115 "
116
117 :group 'cfengine
118 :type '(list
119 (choice (const :tag "Anchor at beginning of promise" promise)
120 (const :tag "Anchor at beginning of line" bol))
121 (choice (const :tag "Indent parameter name" pname)
122 (const :tag "Indent arrow" arrow))
123 (integer :tag "Indentation amount from anchor")))
124
125 (defvar cfengine-mode-debug nil
126 "Whether `cfengine-mode' should print debugging info.")
127
128 (defcustom cfengine-mode-abbrevs nil
129 "Abbrevs for CFEngine2 mode."
130 :group 'cfengine
131 :type '(repeat (list (string :tag "Name")
132 (string :tag "Expansion")
133 (choice :tag "Hook" (const nil) function))))
134
135 (make-obsolete-variable 'cfengine-mode-abbrevs 'edit-abbrevs "24.1")
136
137 ;; Taken from the doc for pre-release 2.1.
138 (eval-and-compile
139 (defconst cfengine2-actions
140 '("acl" "alerts" "binservers" "broadcast" "control" "classes" "copy"
141 "defaultroute" "disks" "directories" "disable" "editfiles" "files"
142 "filters" "groups" "homeservers" "ignore" "import" "interfaces"
143 "links" "mailserver" "methods" "miscmounts" "mountables"
144 "processes" "packages" "rename" "required" "resolve"
145 "shellcommands" "tidy" "unmount"
146 ;; Keywords for cfservd.
147 "admit" "grant" "deny")
148 "List of the action keywords supported by Cfengine.
149 This includes those for cfservd as well as cfagent.")
150
151 (defconst cfengine3-defuns
152 (mapcar
153 'symbol-name
154 '(bundle body))
155 "List of the CFEngine 3.x defun headings.")
156
157 (defconst cfengine3-defuns-regex
158 (regexp-opt cfengine3-defuns t)
159 "Regex to match the CFEngine 3.x defuns.")
160
161 (defconst cfengine3-class-selector-regex "\\([[:alnum:]_().&|!:]+\\)::")
162
163 (defconst cfengine3-category-regex "\\([[:alnum:]_]+\\):")
164
165 (defconst cfengine3-vartypes
166 (mapcar
167 'symbol-name
168 '(string int real slist ilist rlist irange rrange counter))
169 "List of the CFEngine 3.x variable types."))
170
171 (defvar cfengine2-font-lock-keywords
172 `(;; Actions.
173 ;; List the allowed actions explicitly, so that errors are more obvious.
174 (,(concat "^[ \t]*" (eval-when-compile
175 (regexp-opt cfengine2-actions t))
176 ":")
177 1 font-lock-keyword-face)
178 ;; Classes.
179 ("^[ \t]*\\([[:alnum:]_().|!]+\\)::" 1 font-lock-function-name-face)
180 ;; Variables.
181 ("$(\\([[:alnum:]_]+\\))" 1 font-lock-variable-name-face)
182 ("${\\([[:alnum:]_]+\\)}" 1 font-lock-variable-name-face)
183 ;; Variable definitions.
184 ("\\<\\([[:alnum:]_]+\\)[ \t]*=[ \t]*(" 1 font-lock-variable-name-face)
185 ;; File, acl &c in group: { token ... }
186 ("{[ \t]*\\([^ \t\n]+\\)" 1 font-lock-constant-face)))
187
188 (defvar cfengine3-font-lock-keywords
189 `(
190 ;; Defuns. This happens early so they don't get caught by looser
191 ;; patterns.
192 (,(concat "\\<" cfengine3-defuns-regex "\\>"
193 "[ \t]+\\<\\([[:alnum:]_.:]+\\)\\>"
194 "[ \t]+\\<\\([[:alnum:]_.:]+\\)"
195 ;; Optional parentheses with variable names inside.
196 "\\(?:(\\([^)]*\\))\\)?")
197 (1 font-lock-builtin-face)
198 (2 font-lock-constant-face)
199 (3 font-lock-function-name-face)
200 (4 font-lock-variable-name-face nil t))
201
202 ;; Class selectors.
203 (,(concat "^[ \t]*" cfengine3-class-selector-regex)
204 1 font-lock-keyword-face)
205
206 ;; Categories.
207 (,(concat "^[ \t]*" cfengine3-category-regex)
208 1 font-lock-builtin-face)
209
210 ;; Variables, including scope, e.g. module.var
211 ("[@$](\\([[:alnum:]_.:]+\\))" 1 font-lock-variable-name-face)
212 ("[@$]{\\([[:alnum:]_.:]+\\)}" 1 font-lock-variable-name-face)
213
214 ;; Variable definitions.
215 ("\\<\\([[:alnum:]_]+\\)[ \t]*=[ \t]*(" 1 font-lock-variable-name-face)
216
217 ;; Variable types.
218 (,(concat "\\<" (eval-when-compile (regexp-opt cfengine3-vartypes t)) "\\>")
219 1 font-lock-type-face)))
220
221 (defvar cfengine2-imenu-expression
222 `((nil ,(concat "^[ \t]*" (eval-when-compile
223 (regexp-opt cfengine2-actions t))
224 ":[^:]")
225 1)
226 ("Variables/classes" "\\<\\([[:alnum:]_]+\\)[ \t]*=[ \t]*(" 1)
227 ("Variables/classes" "\\<define=\\([[:alnum:]_]+\\)" 1)
228 ("Variables/classes" "\\<DefineClass\\>[ \t]+\\([[:alnum:]_]+\\)" 1))
229 "`imenu-generic-expression' for CFEngine mode.")
230
231 (defun cfengine2-outline-level ()
232 "`outline-level' function for CFEngine mode."
233 (if (looking-at "[^:]+\\(?:[:]+\\)$")
234 (length (match-string 1))))
235
236 (defun cfengine2-beginning-of-defun ()
237 "`beginning-of-defun' function for CFEngine mode.
238 Treats actions as defuns."
239 (unless (<= (current-column) (current-indentation))
240 (end-of-line))
241 (if (re-search-backward "^[[:alpha:]]+: *$" nil t)
242 (beginning-of-line)
243 (goto-char (point-min)))
244 t)
245
246 (defun cfengine2-end-of-defun ()
247 "`end-of-defun' function for CFEngine mode.
248 Treats actions as defuns."
249 (end-of-line)
250 (if (re-search-forward "^[[:alpha:]]+: *$" nil t)
251 (beginning-of-line)
252 (goto-char (point-max)))
253 t)
254
255 ;; Fixme: Should get an extra indent step in editfiles BeginGroup...s.
256
257 (defun cfengine2-indent-line ()
258 "Indent a line in Cfengine mode.
259 Intended as the value of `indent-line-function'."
260 (let ((pos (- (point-max) (point))))
261 (save-restriction
262 (narrow-to-defun)
263 (back-to-indentation)
264 (cond
265 ;; Action selectors aren't indented; class selectors are
266 ;; indented one step.
267 ((looking-at "[[:alnum:]_().|!]+:\\(:\\)?")
268 (if (match-string 1)
269 (indent-line-to cfengine-indent)
270 (indent-line-to 0)))
271 ;; Outdent leading close brackets one step.
272 ((or (eq ?\} (char-after))
273 (eq ?\) (char-after)))
274 (condition-case ()
275 (indent-line-to (save-excursion
276 (forward-char)
277 (backward-sexp)
278 (current-column)))
279 (error nil)))
280 ;; Inside brackets/parens: indent to start column of non-comment
281 ;; token on line following open bracket or by one step from open
282 ;; bracket's column.
283 ((condition-case ()
284 (progn (indent-line-to (save-excursion
285 (backward-up-list)
286 (forward-char)
287 (skip-chars-forward " \t")
288 (if (looking-at "[^\n#]")
289 (current-column)
290 (skip-chars-backward " \t")
291 (+ (current-column) -1
292 cfengine-indent))))
293 t)
294 (error nil)))
295 ;; Indent by two steps after a class selector.
296 ((save-excursion
297 (re-search-backward "^[ \t]*[[:alnum:]_().|!]+::" nil t))
298 (indent-line-to (* 2 cfengine-indent)))
299 ;; Indent by one step if we're after an action header.
300 ((save-excursion
301 (goto-char (point-min))
302 (looking-at "[[:alpha:]]+:[ \t]*$"))
303 (indent-line-to cfengine-indent))
304 ;; Else don't indent.
305 (t
306 (indent-line-to 0))))
307 ;; If initial point was within line's indentation,
308 ;; position after the indentation. Else stay at same point in text.
309 (if (> (- (point-max) pos) (point))
310 (goto-char (- (point-max) pos)))))
311
312 ;; This doesn't work too well in Emacs 21.2. See 22.1 development
313 ;; code.
314 (defun cfengine-fill-paragraph (&optional justify)
315 "Fill `paragraphs' in Cfengine code."
316 (interactive "P")
317 (or (if (fboundp 'fill-comment-paragraph)
318 (fill-comment-paragraph justify) ; post Emacs 21.3
319 ;; else do nothing in a comment
320 (nth 4 (parse-partial-sexp (save-excursion
321 (beginning-of-defun)
322 (point))
323 (point))))
324 (let ((paragraph-start
325 ;; Include start of parenthesized block.
326 "\f\\|[ \t]*$\\|.*\(")
327 (paragraph-separate
328 ;; Include action and class lines, start and end of
329 ;; bracketed blocks and end of parenthesized blocks to
330 ;; avoid including these in fill. This isn't ideal.
331 "[ \t\f]*$\\|.*#\\|.*[\){}]\\|\\s-*[[:alpha:]_().|!]+:")
332 fill-paragraph-function)
333 (fill-paragraph justify))
334 t))
335
336 (defun cfengine3-beginning-of-defun ()
337 "`beginning-of-defun' function for Cfengine 3 mode.
338 Treats body/bundle blocks as defuns."
339 (unless (<= (current-column) (current-indentation))
340 (end-of-line))
341 (if (re-search-backward (concat "^[ \t]*" cfengine3-defuns-regex "\\>") nil t)
342 (beginning-of-line)
343 (goto-char (point-min)))
344 t)
345
346 (defun cfengine3-end-of-defun ()
347 "`end-of-defun' function for Cfengine 3 mode.
348 Treats body/bundle blocks as defuns."
349 (end-of-line)
350 (if (re-search-forward (concat "^[ \t]*" cfengine3-defuns-regex "\\>") nil t)
351 (beginning-of-line)
352 (goto-char (point-max)))
353 t)
354
355 (defun cfengine3-indent-line ()
356 "Indent a line in Cfengine 3 mode.
357 Intended as the value of `indent-line-function'."
358 (let ((pos (- (point-max) (point)))
359 parse)
360 (save-restriction
361 (narrow-to-defun)
362 (back-to-indentation)
363 (setq parse (parse-partial-sexp (point-min) (point)))
364 (when cfengine-mode-debug
365 (message "%S" parse))
366
367 (cond
368 ;; Body/bundle blocks start at 0.
369 ((looking-at (concat cfengine3-defuns-regex "\\>"))
370 (indent-line-to 0))
371 ;; Categories are indented one step.
372 ((looking-at (concat cfengine3-category-regex "[ \t]*\\(#.*\\)*$"))
373 (indent-line-to cfengine-indent))
374 ;; Class selectors are indented two steps.
375 ((looking-at (concat cfengine3-class-selector-regex "[ \t]*\\(#.*\\)*$"))
376 (indent-line-to (* 2 cfengine-indent)))
377 ;; Outdent leading close brackets one step.
378 ((or (eq ?\} (char-after))
379 (eq ?\) (char-after)))
380 (condition-case ()
381 (indent-line-to (save-excursion
382 (forward-char)
383 (backward-sexp)
384 (move-beginning-of-line nil)
385 (skip-chars-forward " \t")
386 (current-column)))
387 (error nil)))
388 ;; Inside a string and it starts before this line.
389 ((and (nth 3 parse)
390 (< (nth 8 parse) (save-excursion (beginning-of-line) (point))))
391 (indent-line-to 0))
392
393 ;; Inside a defun, but not a nested list (depth is 1). This is
394 ;; a promise, usually.
395
396 ;; Indent to cfengine-indent times the nested depth
397 ;; plus 2. That way, promises indent deeper than class
398 ;; selectors, which in turn are one deeper than categories.
399 ((= 1 (nth 0 parse))
400 (let ((p-anchor (nth 0 cfengine-parameters-indent))
401 (p-what (nth 1 cfengine-parameters-indent))
402 (p-indent (nth 2 cfengine-parameters-indent)))
403 ;; Do we have the parameter anchor and location and indent
404 ;; defined, and are we looking at a promise parameter?
405 (if (and p-anchor p-what p-indent
406 (looking-at "\\([[:alnum:]_]+[ \t]*\\)=>"))
407 (let* ((arrow-offset (* -1 (length (match-string 1))))
408 (extra-offset (if (eq p-what 'arrow) arrow-offset 0))
409 (base-offset (if (eq p-anchor 'promise)
410 (* (+ 2 (nth 0 parse)) cfengine-indent)
411 0)))
412 (indent-line-to (max 0 (+ p-indent base-offset extra-offset))))
413 ;; Else, indent to cfengine-indent times the nested depth
414 ;; plus 2. That way, promises indent deeper than class
415 ;; selectors, which in turn are one deeper than categories.
416 (indent-line-to (* (+ 2 (nth 0 parse)) cfengine-indent)))))
417 ;; Inside brackets/parens: indent to start column of non-comment
418 ;; token on line following open bracket or by one step from open
419 ;; bracket's column.
420 ((condition-case ()
421 (progn (indent-line-to (save-excursion
422 (backward-up-list)
423 (forward-char)
424 (skip-chars-forward " \t")
425 (cond
426 ((looking-at "[^\n#]")
427 (current-column))
428 ((looking-at "[^\n#]")
429 (current-column))
430 (t
431 (skip-chars-backward " \t")
432 (+ (current-column) -1
433 cfengine-indent)))))
434 t)
435 (error nil)))
436 ;; Else don't indent.
437 (t (indent-line-to 0))))
438 ;; If initial point was within line's indentation,
439 ;; position after the indentation. Else stay at same point in text.
440 (if (> (- (point-max) pos) (point))
441 (goto-char (- (point-max) pos)))))
442
443 ;; CFEngine 3.x grammar
444
445 ;; specification: blocks
446 ;; blocks: block | blocks block;
447 ;; block: bundle typeid blockid bundlebody
448 ;; | bundle typeid blockid usearglist bundlebody
449 ;; | body typeid blockid bodybody
450 ;; | body typeid blockid usearglist bodybody;
451
452 ;; typeid: id
453 ;; blockid: id
454 ;; usearglist: '(' aitems ')';
455 ;; aitems: aitem | aitem ',' aitems |;
456 ;; aitem: id
457
458 ;; bundlebody: '{' statements '}'
459 ;; statements: statement | statements statement;
460 ;; statement: category | classpromises;
461
462 ;; bodybody: '{' bodyattribs '}'
463 ;; bodyattribs: bodyattrib | bodyattribs bodyattrib;
464 ;; bodyattrib: class | selections;
465 ;; selections: selection | selections selection;
466 ;; selection: id ASSIGN rval ';' ;
467
468 ;; classpromises: classpromise | classpromises classpromise;
469 ;; classpromise: class | promises;
470 ;; promises: promise | promises promise;
471 ;; category: CATEGORY
472 ;; promise: promiser ARROW rval constraints ';' | promiser constraints ';';
473 ;; constraints: constraint | constraints ',' constraint |;
474 ;; constraint: id ASSIGN rval;
475 ;; class: CLASS
476 ;; id: ID
477 ;; rval: ID | QSTRING | NAKEDVAR | list | usefunction
478 ;; list: '{' litems '}' ;
479 ;; litems: litem | litem ',' litems |;
480 ;; litem: ID | QSTRING | NAKEDVAR | list | usefunction
481
482 ;; functionid: ID | NAKEDVAR
483 ;; promiser: QSTRING
484 ;; usefunction: functionid givearglist
485 ;; givearglist: '(' gaitems ')'
486 ;; gaitems: gaitem | gaitems ',' gaitem |;
487 ;; gaitem: ID | QSTRING | NAKEDVAR | list | usefunction
488
489 ;; # from lexer:
490
491 ;; bundle: "bundle"
492 ;; body: "body"
493 ;; COMMENT #[^\n]*
494 ;; NAKEDVAR [$@][(][a-zA-Z0-9_\200-\377.]+[)]|[$@][{][a-zA-Z0-9_\200-\377.]+[}]
495 ;; ID: [a-zA-Z0-9_\200-\377]+
496 ;; ASSIGN: "=>"
497 ;; ARROW: "->"
498 ;; QSTRING: \"((\\\")|[^"])*\"|\'((\\\')|[^'])*\'|`[^`]*`
499 ;; CLASS: [.|&!()a-zA-Z0-9_\200-\377]+::
500 ;; CATEGORY: [a-zA-Z_]+:
501
502 (defun cfengine-common-settings ()
503 (set (make-local-variable 'syntax-propertize-function)
504 ;; In the main syntax-table, \ is marked as a punctuation, because
505 ;; of its use in DOS-style directory separators. Here we try to
506 ;; recognize the cases where \ is used as an escape inside strings.
507 (syntax-propertize-rules ("\\(\\(?:\\\\\\)+\\)\"" (1 "\\"))))
508 (set (make-local-variable 'parens-require-spaces) nil)
509 (set (make-local-variable 'comment-start) "# ")
510 (set (make-local-variable 'comment-start-skip)
511 "\\(\\(?:^\\|[^\\\\\n]\\)\\(?:\\\\\\\\\\)*\\)#+[ \t]*")
512 ;; Like Lisp mode. Without this, we lose with, say,
513 ;; `backward-up-list' when there's an unbalanced quote in a
514 ;; preceding comment.
515 (set (make-local-variable 'parse-sexp-ignore-comments) t))
516
517 (defun cfengine-common-syntax (table)
518 ;; The syntax defaults seem OK to give reasonable word movement.
519 (modify-syntax-entry ?# "<" table)
520 (modify-syntax-entry ?\n ">#" table)
521 (modify-syntax-entry ?\" "\"" table) ; "string"
522 (modify-syntax-entry ?\' "\"" table) ; 'string'
523 ;; Variable substitution.
524 (modify-syntax-entry ?$ "." table)
525 ;; Doze path separators.
526 (modify-syntax-entry ?\\ "." table))
527
528 ;;;###autoload
529 (define-derived-mode cfengine3-mode prog-mode "CFE3"
530 "Major mode for editing CFEngine3 input.
531 There are no special keybindings by default.
532
533 Action blocks are treated as defuns, i.e. \\[beginning-of-defun] moves
534 to the action header."
535 (cfengine-common-settings)
536 (cfengine-common-syntax cfengine3-mode-syntax-table)
537
538 (set (make-local-variable 'indent-line-function) #'cfengine3-indent-line)
539 (setq font-lock-defaults
540 '(cfengine3-font-lock-keywords nil nil nil beginning-of-defun))
541
542 ;; Use defuns as the essential syntax block.
543 (set (make-local-variable 'beginning-of-defun-function)
544 #'cfengine3-beginning-of-defun)
545 (set (make-local-variable 'end-of-defun-function)
546 #'cfengine3-end-of-defun))
547
548 ;;;###autoload
549 (define-derived-mode cfengine2-mode prog-mode "CFE2"
550 "Major mode for editing CFEngine2 input.
551 There are no special keybindings by default.
552
553 Action blocks are treated as defuns, i.e. \\[beginning-of-defun] moves
554 to the action header."
555 (cfengine-common-settings)
556 (cfengine-common-syntax cfengine2-mode-syntax-table)
557
558 ;; Shell commands can be quoted by single, double or back quotes.
559 ;; It's debatable whether we should define string syntax, but it
560 ;; should avoid potential confusion in some cases.
561 (modify-syntax-entry ?\` "\"" cfengine2-mode-syntax-table)
562
563 (set (make-local-variable 'indent-line-function) #'cfengine2-indent-line)
564 (set (make-local-variable 'outline-regexp) "[ \t]*\\(\\sw\\|\\s_\\)+:+")
565 (set (make-local-variable 'outline-level) #'cfengine2-outline-level)
566 (set (make-local-variable 'fill-paragraph-function)
567 #'cfengine-fill-paragraph)
568 (define-abbrev-table 'cfengine2-mode-abbrev-table cfengine-mode-abbrevs)
569 (setq font-lock-defaults
570 '(cfengine2-font-lock-keywords nil nil nil beginning-of-line))
571 ;; Fixme: set the args of functions in evaluated classes to string
572 ;; syntax, and then obey syntax properties.
573 (setq imenu-generic-expression cfengine2-imenu-expression)
574 (set (make-local-variable 'beginning-of-defun-function)
575 #'cfengine2-beginning-of-defun)
576 (set (make-local-variable 'end-of-defun-function) #'cfengine2-end-of-defun))
577
578 ;;;###autoload
579 (defun cfengine-auto-mode ()
580 "Choose between `cfengine2-mode' and `cfengine3-mode' depending
581 on the buffer contents"
582 (let ((v3 nil))
583 (save-restriction
584 (goto-char (point-min))
585 (while (not (or (eobp) v3))
586 (setq v3 (looking-at (concat cfengine3-defuns-regex "\\>")))
587 (forward-line)))
588 (if v3 (cfengine3-mode) (cfengine2-mode))))
589
590 (defalias 'cfengine-mode 'cfengine3-mode)
591
592 (provide 'cfengine3)
593 (provide 'cfengine)
594
595 ;;; cfengine.el ends here