From 2d876a4ca94d7c74339eb18ca98528d017cab2a8 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Thu, 19 Jan 2023 21:07:27 -0800 Subject: [PATCH] Convert ERC's Imenu integration into proper module * lisp/erc/erc-goodies.el: Don't add Imenu hooks to `erc-mode-hook' at top level. Remove autoload for `erc-create-imenu-index' because it already exists in the `erc-imenu' library. (erc-imenu-setup): Move to the erc-imenu library. * lisp/erc/erc-imenu.el (erc-unfill-notice): Allow modifications to read-only text. Thanks to Yusef Aslam for reporting this bug. (erc-imenu-setup): Move here from goodies. (erc-imenu--create-index-function): New helper var to hold previous local value of `imenu-create-index-function'. Perhaps advice should be used instead, but a cursory search of the Emacs code base reveals no such usage. (erc-imenu-mode, erc-imenu-enable, erc-imenu-disable): Create "new" ERC module for Imenu integration. * lisp/erc/erc.el (erc-modules): Add `imenu' to default value and create widget menu item. Update package-version. * test/lisp/erc/erc-tests.el (erc-tests--modules): Add `imenu'. (Bug#60954) --- lisp/erc/erc-goodies.el | 6 ------ lisp/erc/erc-imenu.el | 23 ++++++++++++++++++++++- lisp/erc/erc.el | 4 +++- test/lisp/erc/erc-tests.el | 2 +- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/lisp/erc/erc-goodies.el b/lisp/erc/erc-goodies.el index 5ddacb643fd..7ea6c42ec65 100644 --- a/lisp/erc/erc-goodies.el +++ b/lisp/erc/erc-goodies.el @@ -32,12 +32,6 @@ (eval-when-compile (require 'cl-lib)) (require 'erc) -(defun erc-imenu-setup () - "Setup Imenu support in an ERC buffer." - (setq-local imenu-create-index-function #'erc-create-imenu-index)) - -(add-hook 'erc-mode-hook #'erc-imenu-setup) -(autoload 'erc-create-imenu-index "erc-imenu" "Imenu index creation function") ;;; Automatically scroll to bottom (defcustom erc-input-line-position nil diff --git a/lisp/erc/erc-imenu.el b/lisp/erc/erc-imenu.el index 6223cd3d06f..526afd32249 100644 --- a/lisp/erc/erc-imenu.el +++ b/lisp/erc/erc-imenu.el @@ -52,7 +52,8 @@ Don't rely on this function, read it first!" (forward-line 1) (looking-at " ")) (forward-line 1)) - (end-of-line) (point))))) + (end-of-line) (point)))) + (inhibit-read-only t)) (with-temp-buffer (insert str) (goto-char (point-min)) @@ -124,6 +125,26 @@ Don't rely on this function, read it first!" index-alist)) index-alist)) +(defvar-local erc-imenu--create-index-function nil + "Previous local value of `imenu-create-index-function', if any.") + +(defun erc-imenu-setup () + "Wire up support for Imenu in an ERC buffer." + (when (and (local-variable-p 'imenu-create-index-function) + imenu-create-index-function) + (setq erc-imenu--create-index-function imenu-create-index-function)) + (setq imenu-create-index-function #'erc-create-imenu-index)) + +;;;###autoload(autoload 'erc-imenu-mode "erc-imenu" nil t) +(define-erc-module imenu nil + "Simple Imenu integration for ERC." + ((add-hook 'erc-mode-hook #'erc-imenu-setup)) + ((remove-hook 'erc-mode-hook #'erc-imenu-setup) + (erc-with-all-buffers-of-server erc-server-process nil + (when erc-imenu--create-index-function + (setq imenu-create-index-function erc-imenu--create-index-function) + (kill-local-variable 'erc-imenu--create-index-function))))) + (provide 'erc-imenu) ;;; erc-imenu.el ends here diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 60fe0480412..cc5cac87da8 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -1852,7 +1852,7 @@ buffer rather than a server buffer.") ;; each item is in the format '(old . new) (delete-dups (mapcar #'erc--normalize-module-symbol mods))) -(defcustom erc-modules '( autojoin button completion fill irccontrols +(defcustom erc-modules '( autojoin button completion fill imenu irccontrols list match menu move-to-prompt netsplit networks noncommands readonly ring stamp track) "A list of modules which ERC should enable. @@ -1912,6 +1912,7 @@ removed from the list will be disabled." (const :tag "dcc: Provide Direct Client-to-Client support" dcc) (const :tag "fill: Wrap long lines" fill) (const :tag "identd: Launch an identd server on port 8113" identd) + (const :tag "imenu: A simple Imenu integration" imenu) (const :tag "irccontrols: Highlight or remove IRC control characters" irccontrols) (const :tag "keep-place: Leave point above un-viewed text" keep-place) @@ -1949,6 +1950,7 @@ removed from the list will be disabled." (const :tag "unmorse: Translate morse code in messages" unmorse) (const :tag "xdcc: Act as an XDCC file-server" xdcc) (repeat :tag "Others" :inline t symbol)) + :package-version '(ERC . "5.6") ; FIXME sync on release :group 'erc) (defun erc-update-modules () diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index 0c7b06da436..acd470a1e17 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -1270,7 +1270,7 @@ (defconst erc-tests--modules '( autoaway autojoin button capab-identify completion dcc fill identd - irccontrols keep-place list log match menu move-to-prompt netsplit + imenu irccontrols keep-place list log match menu move-to-prompt netsplit networks noncommands notifications notify page readonly replace ring sasl scrolltobottom services smiley sound spelling stamp track truncate unmorse xdcc)) -- 2.39.2