unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#74934: 30.0.92; Unexpected behavior by which-function-mode in erc-mode buffers
@ 2024-12-18  0:43 Anush V
  2024-12-18  2:24 ` J.P.
  0 siblings, 1 reply; 2+ messages in thread
From: Anush V @ 2024-12-18  0:43 UTC (permalink / raw)
  To: 74934

Hello Maintainers,

I guess this is probably unexpected behavior by which-function-mode in erc-mode
buffers and so reporting this.


steps to reproduce:
emacs --no-init
M-x erc
;; join some channel.
M-x which-function-mode

Current behavior:
In erc buffers, which-function-mode displays either "[n/a]" or a string based on
the chat history in the mode line.

Expected behavior:
which-function-mode shouldn’t be adding any string to mode line in erc buffers


Thank you for your time!

* * *

In GNU Emacs 30.0.92 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.41, cairo
version 1.18.0)
Windowing system distributor 'The X.Org Foundation', version 11.0.12101014
System Description: Guix System

Configured using:
 'configure
 CONFIG_SHELL=/gnu/store/3jhfhxdf6v5ms10x5zmnl166dh3yhbr1-bash-minimal-5.1.16/bin/bash
 SHELL=/gnu/store/3jhfhxdf6v5ms10x5zmnl166dh3yhbr1-bash-minimal-5.1.16/bin/bash --prefix=/gnu/store/dgpfiflaxb8j33jcbqk29wadcykajl51-emacs-next-30.0.92-0.881d593 --enable-fast-install --with-cairo --with-modules --with-native-compilation=aot --disable-build-details'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG LCMS2
LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NATIVE_COMP NOTIFY INOTIFY
PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS
TREE_SITTER X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB

--
Regards,
Anush V





^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#74934: 30.0.92; Unexpected behavior by which-function-mode in erc-mode buffers
  2024-12-18  0:43 bug#74934: 30.0.92; Unexpected behavior by which-function-mode in erc-mode buffers Anush V
@ 2024-12-18  2:24 ` J.P.
  0 siblings, 0 replies; 2+ messages in thread
From: J.P. @ 2024-12-18  2:24 UTC (permalink / raw)
  To: Anush V; +Cc: emacs-erc, 74934

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

Hi Anush,

Appreciate you reporting this.

Anush V <j@gnu.org> writes:

> steps to reproduce:
> emacs --no-init
> M-x erc
> ;; join some channel.
> M-x which-function-mode
>
> Current behavior:
> In erc buffers, which-function-mode displays either "[n/a]" or a string based on
> the chat history in the mode line.

FTR, I'm able to reproduce it.

> Expected behavior:
> which-function-mode shouldn’t be adding any string to mode line in erc buffers

The first of the attached patches should hopefully address the issue.

Thanks,
J.P.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-5.6.1-Disable-which-func-mode-in-erc-imenu-buffers.patch --]
[-- Type: text/x-patch, Size: 3029 bytes --]

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-5.6.1-Add-lisp-imenu-generic-expression-for-ERC-hack.patch --]
[-- Type: text/x-patch, Size: 2552 bytes --]

From 6b331f127a7c4f1c4085521ea74c68f644f93cce Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
Date: Mon, 22 Apr 2024 18:11:24 -0700
Subject: [PATCH 2/2] [5.6.1] Add lisp-imenu-generic-expression for ERC hacking

* lisp/erc/erc-backend.el (define-erc-response-handler): Add
`doc-string' to `declare' specification.
* lisp/erc/erc-imenu.el (erc-imenu-add-devel-patterns(): Add locally
autoloaded function for defining `imenu' patterns when hacking on ERC.
---
 lisp/erc/erc-backend.el |  1 +
 lisp/erc/erc-imenu.el   | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
index e72fa036f17..311e3a624e6 100644
--- a/lisp/erc/erc-backend.el
+++ b/lisp/erc/erc-backend.el
@@ -1662,6 +1662,7 @@ define-erc-response-handler
                                   ([&or integerp symbolp]
                                    &rest [&or integerp symbolp])]
                            &optional sexp sexp def-body))
+           (doc-string 2)
            (indent defun))
   (if (numberp name) (setq name (intern (format "%03i" name))))
   (setq aliases (mapcar (lambda (a)
diff --git a/lisp/erc/erc-imenu.el b/lisp/erc/erc-imenu.el
index 68c7895e2dd..c6cb5655e2d 100644
--- a/lisp/erc/erc-imenu.el
+++ b/lisp/erc/erc-imenu.el
@@ -163,6 +163,29 @@ erc-imenu--disable-which-func
   (erc-with-all-buffers-of-server nil nil
     (setq which-func-mode nil)))
 
+;;;###autoload
+(defun erc-imenu-add-devel-patterns ()
+  "Tell `imenu' about ERC-defined macros."
+  ;; This currently produces results like "ERC response FOO BAR".  I'd
+  ;; obviously be nicer to end up with "erc-response-FOO" and
+  ;; "erc-response-BAR", possibly as separate items.  Likewise for
+  ;; modules: "erc-foo-mode" instead of "ERC module foo".
+  (cl-pushnew `("ERC response"
+                ,(rx bol (* (syntax whitespace))
+                     "(define-erc-response-handler (" (group (+ nonl)) ")")
+                1)
+              lisp-imenu-generic-expression
+              :test #'equal)
+  (cl-pushnew `("ERC module"
+                ,(rx bol (* (syntax whitespace))
+                     ;; Lisp-mode-symbol.
+                     "(define-erc-module " (group (+ (| (syntax word)
+                                                        (syntax symbol)
+                                                        (: "\\" nonl)))))
+                1)
+              lisp-imenu-generic-expression
+              :test #'equal))
+
 (provide 'erc-imenu)
 
 ;;; erc-imenu.el ends here
-- 
2.47.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-12-18  2:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-18  0:43 bug#74934: 30.0.92; Unexpected behavior by which-function-mode in erc-mode buffers Anush V
2024-12-18  2:24 ` J.P.

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).