GNU bug report logs - #66283
30.0.50; which-function-mode: When configured to display in header, and toggling off, then does not remove header

Previous Next

Package: emacs;

Reported by: Mekeor Melire <mekeor <at> posteo.de>

Date: Sat, 30 Sep 2023 21:09:01 UTC

Severity: minor

Tags: confirmed, patch

Found in version 30.0.50

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


Message #10 received at 66283 <at> debbugs.gnu.org (full text, mbox):

From: Spencer Baugh <sbaugh <at> janestreet.com>
To: Mekeor Melire <mekeor <at> posteo.de>
Cc: Author <sbaugh <at> catern.com>, 66283 <at> debbugs.gnu.org, Committer <eliz <at> gnu.org>
Subject: Re: bug#66283: 30.0.50; which-function-mode: When configured to
 display in header, and toggling off, then does not remove header
Date: Wed, 04 Oct 2023 09:57:15 -0400
[Message part 1 (text/plain, inline)]
Thanks for the report.  The attached patch should fix this.

[0001-Remove-the-header-line-after-disabling-which-functio.patch (text/x-patch, inline)]
From a6cc873b67a0cc420abfb3d5ec08426cbfe733a8 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh <at> janestreet.com>
Date: Wed, 4 Oct 2023 09:53:47 -0400
Subject: [PATCH] Remove the header line after disabling which-function-mode

Previously, the header line would stay around even when after
disabling which-function-mode, although it may be empty.  Now the
which-function-mode element is properly removed from
header-line-format, so the header line will disappear if there's
nothing else in header-line-format.

Also, we now check that header-line-format is a list before trying to
add to it; this makes us work properly when enabling and disabling
which-function-mode for modes which set header-line-format to a string
or symbol, such as eww.

* lisp/progmodes/which-func.el (which-func-try-to-enable): Re-add
which-func-format to the header line.
(which-func--header-line-remove): Add.
(which-func--disable): Call which-func--header-line-remove.
(which-function-mode): Call which-func--header-line-remove.
---
 lisp/progmodes/which-func.el | 41 ++++++++++++++++++++++--------------
 1 file changed, 25 insertions(+), 16 deletions(-)

diff --git a/lisp/progmodes/which-func.el b/lisp/progmodes/which-func.el
index 09d0250515f..77b84615fdc 100644
--- a/lisp/progmodes/which-func.el
+++ b/lisp/progmodes/which-func.el
@@ -208,21 +208,28 @@ which-func--use-mode-line
 (add-hook 'after-change-major-mode-hook #'which-func-ff-hook t)
 
 (defun which-func-try-to-enable ()
-  (unless (or (not which-function-mode)
-              (local-variable-p 'which-func-mode))
-    (setq which-func-mode (or (eq which-func-modes t)
-                              (member major-mode which-func-modes)))
-    (setq which-func--use-mode-line
-          (member which-func-display '(mode mode-and-header)))
-    (setq which-func--use-header-line
-          (member which-func-display '(header mode-and-header)))
-    (when (and which-func-mode which-func--use-header-line)
-      (add-to-list 'header-line-format '("" which-func-format " ")))))
+  (when which-function-mode
+    (unless (local-variable-p 'which-func-mode)
+      (setq which-func-mode (or (eq which-func-modes t)
+                                (member major-mode which-func-modes)))
+      (setq which-func--use-mode-line
+            (member which-func-display '(mode mode-and-header)))
+      (setq which-func--use-header-line
+            (member which-func-display '(header mode-and-header))))
+    ;; We might need to re-add which-func-format to the header line,
+    ;; if which-function-mode was toggled off and on.
+    (when (and which-func-mode which-func--use-header-line
+               (listp header-line-format))
+      (add-to-list 'header-line-format '("" which-func-format " "))))
+
+(defun which-func--header-line-remove ()
+  (when (and which-func-mode which-func--use-header-line
+             (listp header-line-format))
+    (setq header-line-format
+          (delete '("" which-func-format " ") header-line-format))))
 
 (defun which-func--disable ()
-  (when (and which-func-mode which-func--use-header-line)
-    (setq header-line-format
-          (delete '("" which-func-format " ") header-line-format)))
+  (which-func--header-line-remove)
   (setq which-func-mode nil))
 
 (defun which-func-ff-hook ()
@@ -288,9 +295,11 @@ which-function-mode
   (when which-function-mode
     ;;Turn it on.
     (setq which-func-update-timer
-          (run-with-idle-timer idle-update-delay t #'which-func-update))
-    (dolist (buf (buffer-list))
-      (with-current-buffer buf (which-func-try-to-enable)))))
+          (run-with-idle-timer idle-update-delay t #'which-func-update)))
+  (dolist (buf (buffer-list))
+    (with-current-buffer buf
+      (which-func--header-line-remove)
+      (which-func-try-to-enable))))
 
 (defvar which-function-imenu-failed nil
   "Locally t in a buffer if `imenu--make-index-alist' found nothing there.")
-- 
2.39.3


This bug report was last modified 1 year and 207 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.