summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Zlatanov <tzz@lifelogs.com>2011-09-25 07:52:53 -0400
committerTed Zlatanov <tzz@lifelogs.com>2011-09-25 07:52:53 -0400
commitf3f9834230b2cf021984c639072ce5cb377643f0 (patch)
treebc277326997ce6a44741879ba4cedfa701afb29f
parentbb72ce91987bea078a4aa72b198759975c126399 (diff)
downloademacs-f3f9834230b2cf021984c639072ce5cb377643f0.tar.gz
* lisp/progmodes/cfengine.el (cfengine-auto-mode): Add convenience function.
* lisp/progmodes/cfengine.el (cfengine-auto-mode): Add convenience function that picks between cfengine 2 and 3 support automatically. Update docs accordingly.
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/progmodes/cfengine.el33
2 files changed, 31 insertions, 8 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 662dd7a7f99..086b6c5b230 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
+2011-09-25 Teodor Zlatanov <tzz@lifelogs.com>
+
+ * progmodes/cfengine.el (cfengine-auto-mode): Add convenience
+ function that picks between cfengine 2 and 3 support
+ automatically. Update docs accordingly.
+
2011-09-22 Ken Manheimer <ken.manheimer@gmail.com>
* allout.el (allout-this-command-hid-stuff): Buffer-local variable
diff --git a/lisp/progmodes/cfengine.el b/lisp/progmodes/cfengine.el
index 7989c60f80c..eea822328f1 100644
--- a/lisp/progmodes/cfengine.el
+++ b/lisp/progmodes/cfengine.el
@@ -26,16 +26,21 @@
;; Provides support for editing GNU Cfengine files, including
;; font-locking, Imenu and indention, but with no special keybindings.
-;; Possible customization for auto-mode selection:
-;; (push '(("^cfagent.conf\\'" . cfengine-mode)) auto-mode-alist)
-;; (push '(("^cf\\." . cfengine-mode)) auto-mode-alist)
-;; (push '(("\\.cf\\'" . cfengine-mode)) auto-mode-alist)
+;; The CFEngine 3.x support doesn't have Imenu support but patches are
+;; welcome.
-;; Or, if you want to use the CFEngine 3.x support:
+;; You can set it up so either cfengine-mode (2.x and earlier) or
+;; cfengine3-mode (3.x) will be picked, depending on the buffer
+;; contents:
-;; (push '(("^cfagent.conf\\'" . cfengine3-mode)) auto-mode-alist)
-;; (push '(("^cf\\." . cfengine3-mode)) auto-mode-alist)
-;; (push '(("\\.cf\\'" . cfengine3-mode)) auto-mode-alist)
+;; (add-to-list 'auto-mode-alist '("\\.cf\\'" . cfengine-auto-mode))
+
+;; OR you can choose to always use a specific version, if you prefer
+;; it
+
+;; (add-to-list 'auto-mode-alist '("\\.cf\\'" . cfengine3-mode))
+;; (add-to-list 'auto-mode-alist '("^cf\\." . cfengine-mode))
+;; (add-to-list 'auto-mode-alist '("^cfagent.conf\\'" . cfengine-mode))
;; This is not the same as the mode written by Rolf Ebert
;; <ebert@waporo.muc.de>, distributed with cfengine-2.0.5. It does
@@ -466,6 +471,18 @@ to the action header."
#'cfengine-beginning-of-defun)
(set (make-local-variable 'end-of-defun-function) #'cfengine-end-of-defun))
+;;;###autoload
+(defun cfengine-auto-mode ()
+ "Choose between `cfengine-mode' and `cfengine3-mode' depending
+on the buffer contents"
+ (let ((v3 nil))
+ (save-restriction
+ (goto-char (point-min))
+ (while (not (or (eobp) v3))
+ (setq v3 (looking-at (concat cfengine3-defuns-regex "\\>")))
+ (forward-line)))
+ (if v3 (cfengine3-mode) (cfengine-mode))))
+
(provide 'cfengine3)
(provide 'cfengine)