>From 35f6fc539ba753b1742cbe8580c15cc9ade62541 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Thu, 19 Jan 2023 21:07:27 -0800 Subject: [PATCH 6/6] [5.6] Convert ERC's Imenu integration into proper module TODO: add news item once a section for 5.6 has been added. * 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 erc-imenu. * lisp/erc/erc-imenu.el (erc-imenu-setup): Move here from goodies. (erc-imenu-mode, erc-imenu-enable, erc-imenu-disable): Create new ERC module for Imenu. * lisp/erc/erc.el (erc-modules): Add `imenu' to default value and create 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 | 20 ++++++++++++++++++++ lisp/erc/erc.el | 4 +++- test/lisp/erc/erc-tests.el | 2 +- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lisp/erc/erc-goodies.el b/lisp/erc/erc-goodies.el index cb720663ea0..3d018bb11e0 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..3b5dd988c18 100644 --- a/lisp/erc/erc-imenu.el +++ b/lisp/erc/erc-imenu.el @@ -124,6 +124,26 @@ erc-create-imenu-index 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-local 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 796acbc36f7..ec1ea29a6af 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -1832,7 +1832,7 @@ erc-migrate-modules (defcustom erc-modules '(netsplit fill button match track completion readonly networks ring autojoin noncommands irccontrols - move-to-prompt stamp menu list) + move-to-prompt stamp menu list imenu) "A list of modules which ERC should enable. If you set the value of this without using `customize' remember to call \(erc-update-modules) after you change it. When using `customize', modules @@ -1874,6 +1874,7 @@ erc-modules (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) @@ -1911,6 +1912,7 @@ erc-modules (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.5") ; 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 1cd15233a1d..816469d9894 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -1249,7 +1249,7 @@ erc-handle-irc-url (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.1