From 76eab2b23f46c885051f2bcb985ab15c3e851033 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Tue, 17 Dec 2024 17:53:34 -0800 Subject: [PATCH 1/2] [5.6.1] Disable which-func-mode in erc-imenu buffers * lisp/erc/erc-imenu.el (erc-imenu-setup): Move after module definition so the variable `erc-imenu-mode' is defined. Run teardown code when module is deactivated. Set `which-func-mode' to nil locally. (erc-imenu-mode, erc-imenu-enable, erc-imenu-disable): Manage membership of `erc-imenu--disable-which-func' in `which-function-mode-hook'. (erc-imenu--disable-which-func): New function. (Bug#74934) --- lisp/erc/erc-imenu.el | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/lisp/erc/erc-imenu.el b/lisp/erc/erc-imenu.el index 4c9cbfc1580..68c7895e2dd 100644 --- a/lisp/erc/erc-imenu.el +++ b/lisp/erc/erc-imenu.el @@ -132,23 +132,36 @@ erc-create-imenu-index (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) + (add-hook 'which-function-mode-hook #'erc-imenu--disable-which-func) (unless erc--updating-modules-p (erc-buffer-do #'erc-imenu-setup))) ((remove-hook 'erc-mode-hook #'erc-imenu-setup) - (erc-with-all-buffers-of-server nil 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))))) + (remove-hook 'which-function-mode-hook #'erc-imenu--disable-which-func) + (erc-buffer-do #'erc-imenu-setup))) + +(defun erc-imenu-setup () + "Set up or tear down Imenu integration." + (if erc-imenu-mode + (progn + (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) + (when (boundp 'which-func-mode) + (setq which-func-mode 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) + (kill-local-variable 'which-func-mode))) + +(defun erc-imenu--disable-which-func () + "Silence `which-function-mode' in ERC buffers." + (defvar which-func-mode) + (erc-with-all-buffers-of-server nil nil + (setq which-func-mode nil))) (provide 'erc-imenu) -- 2.47.1