From: Spencer Baugh <sbaugh@janestreet.com>
To: Andreas Schwab <schwab@linux-m68k.org>
Cc: Eli Zaretskii <eliz@gnu.org>, 64533@debbugs.gnu.org
Subject: bug#64533: [PATCH] Support displaying function name in the header line
Date: Sat, 08 Jul 2023 16:56:29 -0400 [thread overview]
Message-ID: <ierpm52ruki.fsf@janestreet.com> (raw)
In-Reply-To: <87fs5yi12n.fsf@igel.home> (Andreas Schwab's message of "Sat, 08 Jul 2023 22:46:08 +0200")
[-- Attachment #1: Type: text/plain, Size: 396 bytes --]
Andreas Schwab <schwab@linux-m68k.org> writes:
> On Jul 08 2023, Spencer Baugh wrote:
>
>> +@vindex which-func-display
>> + By default, Which Function mode displays the current function name
>> +using the mode line. Customize @code{which-func-display} to
>> +@code{header}, @code{mode}, or @code{both} to use the header line,
>
> Or a list of 'header and/or 'mode.
Oh much better idea, done:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Support-displaying-function-name-in-the-header-line.patch --]
[-- Type: text/x-patch, Size: 6289 bytes --]
From 8c5acd79f67535703b8c669b25502c6edf141d24 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh@janestreet.com>
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-display)
(which-func--use-header-line, which-func--use-mode-line):
Add. (Bug#64533)
(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.
---
doc/emacs/programs.texi | 10 +++++++--
etc/NEWS | 8 ++++++++
lisp/progmodes/which-func.el | 39 ++++++++++++++++++++++++++++++------
3 files changed, 49 insertions(+), 8 deletions(-)
diff --git a/doc/emacs/programs.texi b/doc/emacs/programs.texi
index 953de2e4786..705e3dd358e 100644
--- a/doc/emacs/programs.texi
+++ b/doc/emacs/programs.texi
@@ -396,8 +396,8 @@ Which Function
@cindex current function name in mode line
Which Function mode is a global minor mode (@pxref{Minor Modes})
-which displays the current function name in the mode line, updating it
-as you move around in a buffer.
+which displays the current function name in the mode line or header
+line, updating it as you move around in a buffer.
@findex which-function-mode
@vindex which-func-modes
@@ -410,6 +410,12 @@ Which Function
@code{t} (which means to support all available major modes) to a list
of major mode names.
+@vindex which-func-display
+ @code{which-func-display} is a list of symbols; if it contains
+@code{mode}, the function name is displayed in the mode line. If it
+contains @code{header}, the function name is displayed in the header
+line. By default it contains only @code{mode}.
+
@node Program Indent
@section Indentation for Programs
@cindex indentation for programs
diff --git a/etc/NEWS b/etc/NEWS
index 0556e8be585..f5de6974a46 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -243,6 +243,14 @@ docstring, or a comment, or (re)indents the surrounding defun if
point is not in a comment or a string. It is by default bound to
'M-q' in 'prog-mode' and all its descendants.
+** Which Function Mode
+
++++
+*** Displaying the function name in the header line is now supported.
+The new user option 'which-func-display' is a list of places to
+display the function name. Add 'header' to that list to display in
+the header line.
+
** Tramp
+++
diff --git a/lisp/progmodes/which-func.el b/lisp/progmodes/which-func.el
index 09937a60988..4c32002e991 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-display '(mode)
+ "Where to display the function name.
+
+This should be a list of symbols
+If 'mode, display in the mode line. If 'header, display in the
+header line. If 'both, display in both."
+ :type '(set (const :tag "Display in mode line" mode)
+ (const :tag "Display in header line" header))
+ :version "30.1")
+
(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,17 +194,33 @@ 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.")
+(defvar-local which-func--use-header-line nil
+ "If non-nil, display the function name in the header line.")
+
+(defvar-local which-func--use-mode-line nil
+ "If non-nil, display the function name in the 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)))))
+ (member major-mode which-func-modes)))
+ (setq which-func--use-mode-line (member 'mode which-func-display))
+ (setq which-func--use-header-line (member 'header which-func-display))
+ (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 +236,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 +257,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 +267,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
next prev parent reply other threads:[~2023-07-08 20:56 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-08 17:56 bug#64533: [PATCH] Support displaying function name in the header line Spencer Baugh
2023-07-08 18:04 ` Eli Zaretskii
2023-07-08 18:14 ` Spencer Baugh
2023-07-08 18:33 ` Eli Zaretskii
2023-07-08 19:26 ` Spencer Baugh
2023-07-08 20:46 ` Andreas Schwab
2023-07-08 20:56 ` Spencer Baugh [this message]
2023-07-08 20:58 ` Spencer Baugh
2023-07-09 5:36 ` Eli Zaretskii
2023-07-09 17:26 ` sbaugh
2023-07-15 8:02 ` Eli Zaretskii
2023-07-09 5:29 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ierpm52ruki.fsf@janestreet.com \
--to=sbaugh@janestreet.com \
--cc=64533@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=schwab@linux-m68k.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).