Subject: bug#64533: closed (Re: bug#64533: [PATCH] Support displaying function name in the header line)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 15 Jul 2023 08:03:02 +0000

Your bug report

#64533: [PATCH] Support displaying function name in the header line

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
64533: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=64533
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#64533: [PATCH] Support displaying function name in the header line
From: Eli Zaretskii <[email-masked]>
To: [email-masked]
Cc: [email-masked], [email-masked], [email-masked]
Date: Sat, 15 Jul 2023 11:02:50 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

> From: [email-masked]
> Date: Sun, 09 Jul 2023 17:26:09 +0000 (UTC)
> Cc: Spencer Baugh <[email-masked]>, [email-masked],
> 	[email-masked]
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> >> +This should be a list of symbols.  If it contains 'mode, display
> >> +in the mode line.  If it contains 'header, display in the header
> >> +line."
> >
> > Which leaves it to the user to deduce that '(mode header) means both:
> > yet another reason not to prefer this kind of values in user options.
> >
> > It also doesn't tell how to disable this display: another riddle left
> > to the user to solve.
> >
> > Let's always remember that Emacs users are not necessarily experienced
> > Lispers.  User options should not be "tricky", especially where such
> > trickery is unjustified.  And the doc strings should not pose riddles,
> > however logical they seem to us.
> >
> > Thanks.
> 
> Fair point.  Back to the single symbol.

Thanks, installed on master, and closing the bug.

Subject: [PATCH] Support displaying function name in the header line
From: Spencer Baugh <[email-masked]>
To: [email-masked]
Date: Sat, 08 Jul 2023 13:56:23 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

Tags: patch

In some languages, the function name as displayed in the mode-line by
which-func-mode can be quite long.  It's useful to be able to display
it in the header-line instead.  Let's support that.

This was my original motivation for Bug#63825, so that the header line
was not displayed when which-func-mode wasn't enabled, but just teaching
which-function-mode to handle this is much easier.

* lisp/progmodes/which-func.el (which-func-use-header-line)
(which-func-use-mode-line): Add.
(which-func-try-to-enable): Support which-func-use-header-line.
(which-func--disable): Add, to support which-func-use-header-line.
(which-func-ff-hook, which-func-update-1): Use which-func--disable.

In GNU Emacs 29.0.92 (build 3, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.15.12, Xaw scroll bars) of 2023-07-05 built on
 igm-qws-u22796a
Repository revision: 4127aa427fc7e2cb5b3dbae9264c2ee628474db4
Repository branch: emacs-29
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: CentOS Linux 7 (Core)

Configured using:
 'configure --config-cache --with-x-toolkit=lucid
 --with-gif=ifavailable'

>From a3f3e73dfcce1ae92da42e95f57740448327332f Mon Sep 17 00:00:00 2001
From: Spencer Baugh <[email-masked]>
Date: Sat, 8 Jul 2023 13:54:01 -0400
Subject: [PATCH] Support displaying function name in the header line

In some languages, the function name as displayed in the mode-line by
which-func-mode can be quite long.  It's useful to be able to display
it in the header-line instead.  Let's support that.

* lisp/progmodes/which-func.el (which-func-use-header-line)
(which-func-use-mode-line): Add.
(which-func-try-to-enable): Support which-func-use-header-line.
(which-func--disable): Add, to support which-func-use-header-line.
(which-func-ff-hook, which-func-update-1): Use which-func--disable.
---
 lisp/progmodes/which-func.el | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)

diff --git a/lisp/progmodes/which-func.el b/lisp/progmodes/which-func.el
index 09937a60988..846f28bddbd 100644
--- a/lisp/progmodes/which-func.el
+++ b/lisp/progmodes/which-func.el
@@ -86,6 +86,16 @@ which-func-non-auto-modes
 activation of Which Function until Imenu is used for the first time."
   :type '(repeat (symbol :tag "Major mode")))
 
+(defcustom which-func-use-header-line nil
+  "If non-nil, display the function name in the header line."
+  :type '(choice (const :tag "Display in header line" t)
+                 (const :tag "Don't display in header line" nil)))
+
+(defcustom which-func-use-mode-line t
+  "If non-nil, display the function name in the mode line."
+  :type '(choice (const :tag "Display in mode line" t)
+                 (const :tag "Don't display in mode line" nil)))
+
 (defcustom which-func-maxout 500000
   "Don't automatically compute the Imenu menu if buffer is this big or bigger.
 Zero means compute the Imenu menu regardless of size.
@@ -184,7 +194,7 @@ which-func-current
 ;;;###autoload (put 'which-func-current 'risky-local-variable t)
 
 (defvar-local which-func-mode nil
-  "Non-nil means display current function name in mode line.
+  "Non-nil means display current function name in mode or header line.
 This makes a difference only if variable `which-function-mode' is
 non-nil.")
 
@@ -194,7 +204,15 @@ 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)))))
+                              (member major-mode which-func-modes)))
+    (when (and which-func-mode which-func-use-header-line)
+      (add-to-list 'header-line-format '("" which-func-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)))
+  (setq which-func-mode nil))
 
 (defun which-func-ff-hook ()
   "`after-change-major-mode-hook' for Which Function mode.
@@ -210,10 +228,10 @@ which-func-ff-hook
 	  (setq imenu--index-alist
                 (save-excursion (funcall imenu-create-index-function))))
     (imenu-unavailable
-     (setq which-func-mode nil))
+     (which-func--disable))
     (error
      (message "which-func-ff-hook error: %S" err)
-     (setq which-func-mode nil))))
+     (which-func--disable))))
 
 (defun which-func-update ()
   "Update the Which-Function mode display in the current window."
@@ -231,7 +249,7 @@ which-func-update-1
 	      (puthash window current which-func-table)
 	      (force-mode-line-update)))
 	(error
-	 (setq which-func-mode nil)
+	 (which-func--disable)
 	 (error "Error in which-func-update: %S" info))))))
 
 (defvar which-func-update-timer nil)
@@ -241,7 +259,8 @@ which-func-update-timer
   (add-to-list 'mode-line-misc-info
                '(which-function-mode    ;Only display if mode is enabled.
                  (which-func-mode       ;Only display if buffer supports it.
-                  ("" which-func-format " ")))))
+                  (which-func-use-mode-line
+                   ("" which-func-format " "))))))
 
 ;; This is the name people would normally expect.
 ;;;###autoload
-- 
2.39.3