]> git.eshelyaron.com Git - emacs.git/commitdiff
Add command for teaching Imenu about ERC macros
authorF. Jason Park <jp@neverwas.me>
Tue, 23 Apr 2024 01:11:24 +0000 (18:11 -0700)
committerEshel Yaron <me@eshelyaron.com>
Mon, 23 Dec 2024 15:18:56 +0000 (16:18 +0100)
* lisp/erc/erc-backend.el (define-erc-response-handler): Add
`doc-string' to `declare' specification.
* test/lisp/erc/resources/erc-tests-common.el
(erc-tests-common-add-imenu-expressions): New function for defining and
undefining Imenu patterns useful to ERC developers.

(cherry picked from commit e9591fae5e7ba772b63c6cc548bb5ebe68f583e6)

lisp/erc/erc-backend.el
test/lisp/erc/resources/erc-tests-common.el

index 16e8cae473303769a9419384a49e20817bbe8903..9dd368585ebb255234a804c5043e15c3ffb0e947 100644 (file)
@@ -1662,6 +1662,7 @@ Would expand to:
                                   ([&or integerp symbolp]
                                    &rest [&or integerp symbolp])]
                            &optional sexp sexp def-body))
+           (doc-string 2)
            (indent defun))
   (if (numberp name) (setq name (intern (format "%03i" name))))
   (setq aliases (mapcar (lambda (a)
index db0c5d626c9de8e4184f94bcc02301a910b526ab..be873283f3f55fd0e123ba9fef6b0d2531235d11 100644 (file)
@@ -410,4 +410,41 @@ faces in the reverse order they appear in an inserted message."
 
     (funcall test (lambda (arg) (setq faces arg)))))
 
+;; To use this function, add something like
+;;
+;;   ("lisp/erc"
+;;    (emacs-lisp-mode (eval erc-tests-common-add-imenu-expressions)))
+;;
+;; to your ~/emacs/master/.dir-locals-2.el.  Optionally, add the sexp
+;;
+;;   (erc-tests-common-add-imenu-expressions)
+;;
+;; to the user option `safe-local-eval-forms', and load this file before
+;; hacking, possibly by autoloading this function in your init.el.
+(defun erc-tests-common-add-imenu-expressions (&optional removep)
+  "Tell `imenu' about ERC-defined macros.  With REMOVEP, do the opposite."
+  (interactive "P")
+  ;; This currently produces results like "ERC response FOO BAR", but it
+  ;; would be preferable to end up with "erc-response-FOO" and
+  ;; "erc-response-BAR" instead, possibly as separate items.  Likewise
+  ;; for modules: "erc-foo-mode" instead of "ERC module foo".
+  (dolist (item `(("ERC response"
+                   ,(rx bol (* (syntax whitespace))
+                        "(define-erc-response-handler (" (group (+ nonl)) ")")
+                   1)
+                  ("ERC module"
+                   ,(rx bol (* (syntax whitespace))
+                        ;; No `lisp-mode-symbol' in < Emacs 29.
+                        "(define-erc-module " (group (+ (| (syntax word)
+                                                           (syntax symbol)
+                                                           (: "\\" nonl)))))
+                   1)))
+    ;; This should only run in `emacs-lisp-mode' buffers, which have
+    ;; this variable set locally.
+    (cl-assert (local-variable-p 'imenu-generic-expression))
+    (if removep
+        (setq imenu-generic-expression
+              (remove item imenu-generic-expression))
+      (cl-pushnew item imenu-generic-expression :test #'equal))))
+
 (provide 'erc-tests-common)