unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "J.P." <jp@neverwas.me>
To: 60954@debbugs.gnu.org
Cc: emacs-erc@gnu.org
Subject: bug#60954: 29.0.60; ERC 5.4.1: loading ERC clobbers customizations to erc-mode-hook
Date: Fri, 20 Jan 2023 06:15:29 -0800	[thread overview]
Message-ID: <874jsluwam.fsf__36790.1456587546$1674224182$gmane$org@neverwas.me> (raw)
In-Reply-To: <87pmb9wyz6.fsf@neverwas.me> (J. P.'s message of "Thu, 19 Jan 2023 21:34:37 -0800")

[-- Attachment #1: Type: text/plain, Size: 744 bytes --]

"J.P." <jp@neverwas.me> 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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0004-5.6-Convert-ERC-s-Imenu-integration-into-proper-modu.patch --]
[-- Type: text/x-patch, Size: 4344 bytes --]

From e7507ed0777a1b346e0161399b077bc0904f1c80 Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
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


  parent reply	other threads:[~2023-01-20 14:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87pmb9wyz6.fsf@neverwas.me>
2023-01-20  7:16 ` bug#60954: 29.0.60; ERC 5.4.1: loading ERC clobbers customizations to erc-mode-hook Eli Zaretskii
     [not found] ` <83cz79oeu7.fsf@gnu.org>
2023-01-20 14:14   ` J.P.
2023-01-20 14:15 ` J.P. [this message]
2023-01-21 15:03 ` bug#60954: 30.0.50; ERC >5.5: Stop requiring erc-goodies in erc.el J.P.
2023-01-31 15:27 ` J.P.
2023-02-07 15:22 ` J.P.
2023-02-19 15:07 ` J.P.
2023-03-09 14:43 ` J.P.
2023-03-14 13:32 ` J.P.
2023-03-15 14:04 ` J.P.
2023-01-20  5:34 bug#60954: 29.0.60; ERC 5.4.1: loading ERC clobbers customizations to erc-mode-hook J.P.

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='874jsluwam.fsf__36790.1456587546$1674224182$gmane$org@neverwas.me' \
    --to=jp@neverwas.me \
    --cc=60954@debbugs.gnu.org \
    --cc=emacs-erc@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).