emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master dcad72a779b 1/2: Support displaying function name in the header l


From: Eli Zaretskii
Subject: master dcad72a779b 1/2: Support displaying function name in the header line
Date: Sat, 15 Jul 2023 04:01:42 -0400 (EDT)

branch: master
commit dcad72a779bc4d5d8878c53b4b8bee13e316c9b4
Author: Spencer Baugh <sbaugh@catern.com>
Commit: Eli Zaretskii <eliz@gnu.org>

    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 ++++++++--
 lisp/progmodes/which-func.el | 42 ++++++++++++++++++++++++++++++++++++------
 2 files changed, 44 insertions(+), 8 deletions(-)

diff --git a/doc/emacs/programs.texi b/doc/emacs/programs.texi
index 953de2e4786..40746e03ecc 100644
--- a/doc/emacs/programs.texi
+++ b/doc/emacs/programs.texi
@@ -396,8 +396,8 @@ The Speedbar can also use it (@pxref{Speedbar}).
 @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 @@ changing the value of the variable @code{which-func-modes} 
from
 @code{t} (which means to support all available major modes) to a list
 of major mode names.
 
+@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{mode-and-header} to use the
+header line, mode line, or both, respectively.
+
 @node Program Indent
 @section Indentation for Programs
 @cindex indentation for programs
diff --git a/lisp/progmodes/which-func.el b/lisp/progmodes/which-func.el
index 09937a60988..631d47bb729 100644
--- a/lisp/progmodes/which-func.el
+++ b/lisp/progmodes/which-func.el
@@ -86,6 +86,17 @@ long time to send the information, you can use this option 
to delay
 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.
+
+If 'mode, display in the mode line.  If 'header, display in the
+header line.  If 'mode-and-header, display in both."
+  :type '(choice (const :tag "Display in mode line" mode)
+                 (const :tag "Display in header line" header)
+                 (const :tag "Display in both header and mode line"
+                        mode-and-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 +195,35 @@ and you want to simplify them for the mode line
 ;;;###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 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 " ")))))
+
+(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 +239,10 @@ It creates the Imenu index for the buffer, if necessary."
          (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 +260,7 @@ It creates the Imenu index for the buffer, if necessary."
              (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 +270,8 @@ It creates the Imenu index for the buffer, if necessary."
   (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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]