Re: bug#60954: 29.0.60; ERC 5.4.1: loading ERC clobbers customizations to erc-mode-hook
"J.P." <[email protected]>
| Newsgroups | gmane.emacs.erc.general |
|---|---|
| Message-ID | <[email protected]> |
"J.P." <[email protected]> writes: > I see two basic avenues of attack here. The first is a pretty safe > stopgap and the second a slightly riskier comprehensive approach that > should have been on the books the moment that bug was closed: > > hack: partially revert a tiny hunk from the commit above > > fix: don't require goodies at all and instead update the module > mapping data and add all necessary autoloads and forward > declarations Under "fix," I forgot to mention also couching any top-level `add-hook' calls in module-setup and teardown functions. Of particular concern are those that mutate user options. Attached is an addition to the (5.6 portion of the) patch set that does this for the Imenu integration.
0004-5.6-Convert-ERC-s-Imenu-integration-into-proper-modu.patch
(text/x-patch, 4.2 KB)
From e7507ed0777a1b346e0161399b077bc0904f1c80 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" <[email protected]> Date: Thu, 19 Jan 2023 21:07:27 -0800 Subject: [PATCH 4/4] [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. --- lisp/erc/erc-goodies.el | 8 -------- lisp/erc/erc-imenu.el | 19 +++++++++++++++++++ lisp/erc/erc.el | 4 +++- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lisp/erc/erc-goodies.el b/lisp/erc/erc-goodies.el index 0bf4bb9537c..f6c1376bb58 100644 --- a/lisp/erc/erc-goodies.el +++ b/lisp/erc/erc-goodies.el @@ -29,8 +29,6 @@ ;;; Code: -;;; Imenu support - (eval-when-compile (require 'cl-lib)) (require 'erc-common) @@ -48,12 +46,6 @@ erc-server-process (declare-function erc-extract-command-from-line "erc" (line)) (declare-function erc-beg-of-input-line "erc" nil) -(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..2514ffcc4d3 100644 --- a/lisp/erc/erc-imenu.el +++ b/lisp/erc/erc-imenu.el @@ -124,6 +124,25 @@ 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)) + +(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 007f70b8671..0d6634d38a9 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -1819,7 +1819,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 @@ -1864,6 +1864,7 @@ erc-modules (const :tag "identd: Launch an identd server on port 8113" identd) (const :tag "irccontrols: Highlight or remove IRC control characters" irccontrols) + (const :tag "imenu: A simple Imenu integration" imenu) (const :tag "keep-place: Leave point above un-viewed text" keep-place) (const :tag "list: List channels in a separate buffer" list) (const :tag "log: Save buffers in logs" log) @@ -1899,6 +1900,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 () -- 2.38.1