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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 66283 in the body.
You can then email your comments to 66283 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#66283; Package emacs. (Sat, 30 Sep 2023 21:09:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Mekeor Melire <mekeor <at> posteo.de>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 30 Sep 2023 21:09:02 GMT) Full text and rfc822 format available.

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

From: Mekeor Melire <mekeor <at> posteo.de>
To: bug-gnu-emacs <at> gnu.org
Cc: Author <sbaugh <at> catern.com>, Committer <eliz <at> gnu.org>
Subject: 30.0.50; which-function-mode: When configured to display in header,
 and toggling off, then does not remove header
Date: Sat, 30 Sep 2023 20:41:05 +0000
Execute: emacs -Q

Configure Which Function Mode to display in header by evaluating 
the following; note that this is a new feature in Emacs 30: 
(customize-set-variable 'which-func-display 'header)

Toggle Which Function Mode on by typing: M-x which-function-mode 
RET

Toggle Which Function Mode off by typing again: M-x 
which-function-mode RET

You can see a dysfunctional header. (It won't be update because 
Which Function Mode is off.) To be precise, the value of variable 
`header-line-format' is '(("" which-func-format " ")). Apparently, 
this variable has not been cleaned up appropriately. This is the 
job of the function `which-func--disable'. [1]

In order to test the `which-func--disable' function, type: M-: (which-func--disable) RET

The header disappeared. The value of variable `header-line-format' is `nil'. This means, that the function does its job well. Apparently, it's not being called when toggling off. [2]

[1]: https://git.sv.gnu.org/cgit/emacs.git/tree/lisp/progmodes/which-func.el?h=35fbf6f15830f576fd1909f4a8d30e7ba1d777bd#n225

[2]: Where is the "Turn it off." comment here? https://git.sv.gnu.org/cgit/emacs.git/tree/lisp/progmodes/which-func.el?h=35fbf6f15830f576fd1909f4a8d30e7ba1d777bd#n289

--
In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 
3.24.37, cairo version 1.16.0)
Windowing system distributor 'The X.Org Foundation', version 
11.0.12101004
System Description: Guix System




Added tag(s) confirmed. Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Sun, 01 Oct 2023 13:30:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#66283; Package emacs. (Wed, 04 Oct 2023 13:58:02 GMT) Full text and rfc822 format available.

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


Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#66283; Package emacs. (Wed, 04 Oct 2023 14:58:02 GMT) Full text and rfc822 format available.

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

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Spencer Baugh <sbaugh <at> janestreet.com>, 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, 4 Oct 2023 14:56:43 +0000
tags 66283 + patch
thanks

Spencer Baugh <sbaugh <at> janestreet.com> writes:

> Thanks for the report.  The attached patch should fix this.

LGTM.  I didn't test it, though.




Added tag(s) patch. Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Wed, 04 Oct 2023 14:58:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#66283; Package emacs. (Wed, 04 Oct 2023 15:14:01 GMT) Full text and rfc822 format available.

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

From: Spencer Baugh <sbaugh <at> janestreet.com>
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: Mekeor Melire <mekeor <at> posteo.de>, 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 11:13:06 -0400
[Message part 1 (text/plain, inline)]
Two fixes to the previous patch:

- There was always a bug with which-function-mode where if you enabled
  it when there were already existing buffers, it would behave
  differently than if you enabled it and then created those buffers.
  Namely it would enable which-func-mode for every buffer, even if the
  buffer didn't support imenu.  This is especially noticeable when
  toggling which-function-mode and using the header line, so I fixed it.

- Also, I accidentally dropped a paren before submitting.  Now that's
  fixed :)

[0001-Remove-the-header-line-after-disabling-which-functio.patch (text/x-patch, inline)]
From 9918722015e52510b12b0eeee093f11e231d14fe 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, previously, when we ran (which-function-mode), we would enable
which-function-mode for all buffers even if they didn't support imenu.
We didn't run the normal logic in which-func-ff-hook to disable
which-func-mode if imenu wasn't present.  Now we do run that logic, by
just calling which-func-ff-hook.  This is especially important when
the header line is enabled, because otherwise there's a very
noticeable header line added to every buffer, including e.g. *Help*
and *Buffer List*.

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-ff-hook and
which-func--header-line-remove. (bug#66283)
---
 lisp/progmodes/which-func.el | 39 ++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/lisp/progmodes/which-func.el b/lisp/progmodes/which-func.el
index 09d0250515f..0e04bab6ea4 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)
+  (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--disable ()
-  (when (and which-func-mode which-func--use-header-line)
+(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)))
+          (delete '("" which-func-format " ") header-line-format))))
+
+(defun which-func--disable ()
+  (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-ff-hook))))
 
 (defvar which-function-imenu-failed nil
   "Locally t in a buffer if `imenu--make-index-alist' found nothing there.")
-- 
2.39.3


Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#66283; Package emacs. (Wed, 04 Oct 2023 19:26:02 GMT) Full text and rfc822 format available.

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

From: Mekeor Melire <mekeor <at> posteo.de>
To: 66283 <at> debbugs.gnu.org
Cc: Author <sbaugh <at> catern.com>, Committer <eliz <at> gnu.org>,
 Stefan Kangas <stefankangas <at> gmail.com>, Spencer Baugh <sbaugh <at> janestreet.com>
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 19:19:41 +0000
2023-10-04 11:13 sbaugh <at> janestreet.com:

> From 9918722015e52510b12b0eeee093f11e231d14fe 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

Thank you! I tested this patch quickly and simply, and it works for me.

By the way, I'd also suggest to make which-function-mode not buffer-local instead of global. But I guess I should submit another bug-report for this.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#66283; Package emacs. (Wed, 04 Oct 2023 20:35:01 GMT) Full text and rfc822 format available.

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

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Mekeor Melire <mekeor <at> posteo.de>, 66283 <at> debbugs.gnu.org
Cc: Author <sbaugh <at> catern.com>, Committer <eliz <at> gnu.org>,
 Spencer Baugh <sbaugh <at> janestreet.com>
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, 4 Oct 2023 20:33:40 +0000
Mekeor Melire <mekeor <at> posteo.de> writes:

> By the way, I'd also suggest to make which-function-mode not
> buffer-local instead of global. But I guess I should submit another
> bug-report for this.

Yes, that's a separate feature request.




Severity set to 'minor' from 'normal' Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Thu, 05 Oct 2023 21:56:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#66283; Package emacs. (Sat, 14 Oct 2023 07:31:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Spencer Baugh <sbaugh <at> janestreet.com>
Cc: mekeor <at> posteo.de, sbaugh <at> catern.com, 66283 <at> debbugs.gnu.org,
 stefankangas <at> gmail.com
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: Sat, 14 Oct 2023 10:29:59 +0300
> From: Spencer Baugh <sbaugh <at> janestreet.com>
> Cc: Mekeor Melire <mekeor <at> posteo.de>,  Author <sbaugh <at> catern.com>,
>    66283 <at> debbugs.gnu.org,  Committer <eliz <at> gnu.org>
> Date: Wed, 04 Oct 2023 11:13:06 -0400
> 
> Two fixes to the previous patch:
> 
> - There was always a bug with which-function-mode where if you enabled
>   it when there were already existing buffers, it would behave
>   differently than if you enabled it and then created those buffers.
>   Namely it would enable which-func-mode for every buffer, even if the
>   buffer didn't support imenu.  This is especially noticeable when
>   toggling which-function-mode and using the header line, so I fixed it.
> 
> - Also, I accidentally dropped a paren before submitting.  Now that's
>   fixed :)

Thanks, but how about some tests for these fixes?  It's high time
which-mode had some test suite, I think.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#66283; Package emacs. (Sat, 21 Oct 2023 14:45:02 GMT) Full text and rfc822 format available.

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

From: sbaugh <at> catern.com
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: mekeor <at> posteo.de, Spencer Baugh <sbaugh <at> janestreet.com>,
 66283 <at> debbugs.gnu.org, stefankangas <at> gmail.com
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: Sat, 21 Oct 2023 14:43:30 +0000 (UTC)
[Message part 1 (text/plain, inline)]
Eli Zaretskii <eliz <at> gnu.org> writes:
>> From: Spencer Baugh <sbaugh <at> janestreet.com>
>> Cc: Mekeor Melire <mekeor <at> posteo.de>,  Author <sbaugh <at> catern.com>,
>>    66283 <at> debbugs.gnu.org,  Committer <eliz <at> gnu.org>
>> Date: Wed, 04 Oct 2023 11:13:06 -0400
>> 
>> Two fixes to the previous patch:
>> 
>> - There was always a bug with which-function-mode where if you enabled
>>   it when there were already existing buffers, it would behave
>>   differently than if you enabled it and then created those buffers.
>>   Namely it would enable which-func-mode for every buffer, even if the
>>   buffer didn't support imenu.  This is especially noticeable when
>>   toggling which-function-mode and using the header line, so I fixed it.
>> 
>> - Also, I accidentally dropped a paren before submitting.  Now that's
>>   fixed :)
>
> Thanks, but how about some tests for these fixes?  It's high time
> which-mode had some test suite, I think.

Sure, here's a patch including a test.

[0001-Remove-the-header-line-after-disabling-which-functio.patch (text/x-patch, inline)]
From b0ae708df7cf81419fbbf6f81fcda31142626a27 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh <at> catern.com>
Date: Sat, 21 Oct 2023 10:41:42 -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, previously, when we ran (which-function-mode), we would enable
which-function-mode for all buffers even if they didn't support imenu.
We didn't run the normal logic in which-func-ff-hook to disable
which-func-mode if imenu wasn't present.  Now we do run that logic, by
just calling which-func-ff-hook.  This is especially important when
the header line is enabled, because otherwise there's a very
noticeable header line added to every buffer, including e.g. *Help*
and *Buffer List*.

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-ff-hook and
which-func--header-line-remove. (bug#66283)
* test/lisp/progmodes/which-func-tests.el: Add.
---
 lisp/progmodes/which-func.el            | 39 ++++++++++-------
 test/lisp/progmodes/which-func-tests.el | 58 +++++++++++++++++++++++++
 2 files changed, 82 insertions(+), 15 deletions(-)
 create mode 100644 test/lisp/progmodes/which-func-tests.el

diff --git a/lisp/progmodes/which-func.el b/lisp/progmodes/which-func.el
index 09d0250515f..0e04bab6ea4 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)
+  (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--disable ()
-  (when (and which-func-mode which-func--use-header-line)
+(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)))
+          (delete '("" which-func-format " ") header-line-format))))
+
+(defun which-func--disable ()
+  (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-ff-hook))))
 
 (defvar which-function-imenu-failed nil
   "Locally t in a buffer if `imenu--make-index-alist' found nothing there.")
diff --git a/test/lisp/progmodes/which-func-tests.el b/test/lisp/progmodes/which-func-tests.el
new file mode 100644
index 00000000000..73709f1c5e5
--- /dev/null
+++ b/test/lisp/progmodes/which-func-tests.el
@@ -0,0 +1,58 @@
+;;; which-func-tests.el --- tests for which-func     -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2023 Free Software Foundation, Inc.
+
+;; Author: Spencer Baugh <sbaugh <at> catern.com>
+
+;; This file is part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+(require 'ert)
+(require 'which-func)
+
+(ert-deftest which-func-tests-toggle ()
+  (let ((which-func-display 'mode-and-header) buf-code buf-not)
+    (setq buf-code (find-file-noselect "which-func-tests.el"))
+    (setq buf-not (get-buffer-create "fundamental"))
+    (with-current-buffer buf-code
+      (should-not which-func-mode) (should-not header-line-format))
+    (with-current-buffer buf-not
+      (should-not which-func-mode) (should-not header-line-format))
+    (which-function-mode 1)
+    (with-current-buffer buf-code
+      (should which-func-mode) (should header-line-format))
+    (with-current-buffer buf-not
+      (should-not which-func-mode) (should-not header-line-format))
+    (which-function-mode -1)
+    ;; which-func-mode stays set even when which-function-mode is off.
+    (with-current-buffer buf-code
+      (should which-func-mode) (should-not header-line-format))
+    (with-current-buffer buf-not
+      (should-not which-func-mode) (should-not header-line-format))
+    (kill-buffer buf-code)
+    (kill-buffer buf-not)
+    (which-function-mode 1)
+    (setq buf-code (find-file-noselect "which-func-tests.el"))
+    (setq buf-not (get-buffer-create "fundamental"))
+    (with-current-buffer buf-code
+      (should which-func-mode) (should header-line-format))
+    (with-current-buffer buf-not
+      (should-not which-func-mode) (should-not header-line-format))))
+
+(provide 'which-func-tests)
+;;; which-func-tests.el ends here
-- 
2.41.0


Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Sun, 29 Oct 2023 11:26:02 GMT) Full text and rfc822 format available.

Notification sent to Mekeor Melire <mekeor <at> posteo.de>:
bug acknowledged by developer. (Sun, 29 Oct 2023 11:26:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: sbaugh <at> catern.com
Cc: mekeor <at> posteo.de, sbaugh <at> janestreet.com, 66283-done <at> debbugs.gnu.org,
 stefankangas <at> gmail.com
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: Sun, 29 Oct 2023 13:24:04 +0200
> From: sbaugh <at> catern.com
> Date: Sat, 21 Oct 2023 14:43:30 +0000 (UTC)
> Cc: Spencer Baugh <sbaugh <at> janestreet.com>, mekeor <at> posteo.de,
> 	66283 <at> debbugs.gnu.org, stefankangas <at> gmail.com
> 
> > Thanks, but how about some tests for these fixes?  It's high time
> > which-mode had some test suite, I think.
> 
> Sure, here's a patch including a test.

Thanks, installed on the master branch, and closing the bug.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 26 Nov 2023 12:24:08 GMT) Full text and rfc822 format available.

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.