]> code.delx.au - gnu-emacs/commitdiff
* lisp/progmodes/cfengine.el (cfengine3-defun-full-re): New var.
authorLeo Liu <sdl.web@gmail.com>
Thu, 23 Oct 2014 08:07:40 +0000 (16:07 +0800)
committerLeo Liu <sdl.web@gmail.com>
Thu, 23 Oct 2014 08:07:40 +0000 (16:07 +0800)
(cfengine3-create-imenu-index): Use it and use ` ' for separation.
(cfengine3-current-defun): New function.
(cfengine3-mode): Set add-log-current-defun-function.

lisp/ChangeLog
lisp/progmodes/cfengine.el

index 715e132c43275c6de3ea4ec26b5511f7c2b737d8..c766b83311873be779eabb2aba57b46aa208c6b3 100644 (file)
@@ -1,3 +1,10 @@
+2014-10-23  Leo Liu  <sdl.web@gmail.com>
+
+       * progmodes/cfengine.el (cfengine3-defun-full-re): New var.
+       (cfengine3-create-imenu-index): Use it and use ` ' for separation.
+       (cfengine3-current-defun): New function.
+       (cfengine3-mode): Set add-log-current-defun-function.
+
 2014-10-23  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        * select.el: Use lexical-binding.
index 8e43c812470eca3f3627fcb6699ac94a4da5ec91..53d5be90cab5dd7cff2de5bbbdf106aa1b3c359f 100644 (file)
@@ -817,6 +817,12 @@ This includes those for cfservd as well as cfagent.")
   (defconst cfengine3-defuns-regex (regexp-opt cfengine3-defuns t)
     "Regex to match the CFEngine 3.x defuns.")
 
+  (defconst cfengine3-defun-full-re (concat "^\\s-*" cfengine3-defuns-regex
+                                            "\\s-+\\(\\(?:\\w\\|\\s_\\)+\\)" ;type
+                                            "\\s-+\\(\\(?:\\w\\|\\s_\\)+\\)" ;id
+                                            )
+    "Regexp matching full defun declaration (excluding argument list).")
+
   (defconst cfengine3-class-selector-regex "\\([[:alnum:]_().&|!:]+\\)::")
 
   (defconst cfengine3-category-regex "\\([[:alnum:]_]+\\):")
@@ -1299,19 +1305,25 @@ Use it by enabling `eldoc-mode'."
     ("::" . ?∷)))
 
 (defun cfengine3-create-imenu-index ()
-  "A function for `imenu-create-index-function'."
+  "A function for `imenu-create-index-function'.
+Note: defun name is separated by space such as `body
+package_method opencsw' and imenu will replace spaces according
+to `imenu-space-replacement' (which see)."
   (goto-char (point-min))
-  (let ((re (concat "^\\s-*" cfengine3-defuns-regex
-                    "\\s-+\\(\\(?:\\w\\|\\s_\\)+\\)" ;type
-                    "\\s-+\\(\\(?:\\w\\|\\s_\\)+\\)" ;id
-                    ))
-        (defuns ()))
-    (while (re-search-forward re nil t)
-      (push (cons (mapconcat #'match-string '(1 2 3) ".")
+  (let ((defuns ()))
+    (while (re-search-forward cfengine3-defun-full-re nil t)
+      (push (cons (mapconcat #'match-string '(1 2 3) " ")
                   (copy-marker (match-beginning 3)))
             defuns))
     (nreverse defuns)))
 
+(defun cfengine3-current-defun ()
+  "A function for `add-log-current-defun-function'."
+  (end-of-line)
+  (beginning-of-defun)
+  (and (looking-at cfengine3-defun-full-re)
+       (mapconcat #'match-string '(1 2 3) " ")))
+
 ;;;###autoload
 (define-derived-mode cfengine3-mode prog-mode "CFE3"
   "Major mode for editing CFEngine3 input.
@@ -1347,7 +1359,8 @@ to the action header."
   (setq-local beginning-of-defun-function #'cfengine3-beginning-of-defun)
   (setq-local end-of-defun-function #'cfengine3-end-of-defun)
 
-  (setq-local imenu-create-index-function #'cfengine3-create-imenu-index))
+  (setq-local imenu-create-index-function #'cfengine3-create-imenu-index)
+  (setq-local add-log-current-defun-function #'cfengine3-current-defun))
 
 ;;;###autoload
 (define-derived-mode cfengine2-mode prog-mode "CFE2"