From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: sbaugh@catern.com Newsgroups: gmane.emacs.bugs Subject: bug#64533: [PATCH] Support displaying function name in the header line Date: Sun, 09 Jul 2023 17:26:09 +0000 (UTC) Message-ID: <87r0phkndb.fsf@catern.com> References: <83y1jqb7pt.fsf@gnu.org> <83wmzab6d5.fsf@gnu.org> <87fs5yi12n.fsf@igel.home> <83o7klbq8q.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7898"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Spencer Baugh , schwab@linux-m68k.org, 64533@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jul 09 19:27:22 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qIYBt-0001q0-IR for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 09 Jul 2023 19:27:22 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qIYBd-0005tT-2N; Sun, 09 Jul 2023 13:27:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qIYBa-0005tI-II for bug-gnu-emacs@gnu.org; Sun, 09 Jul 2023 13:27:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qIYBa-0007Xp-A9 for bug-gnu-emacs@gnu.org; Sun, 09 Jul 2023 13:27:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qIYBa-0005sG-62 for bug-gnu-emacs@gnu.org; Sun, 09 Jul 2023 13:27:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: sbaugh@catern.com Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 09 Jul 2023 17:27:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64533 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 64533-submit@debbugs.gnu.org id=B64533.168892357822523 (code B ref 64533); Sun, 09 Jul 2023 17:27:02 +0000 Original-Received: (at 64533) by debbugs.gnu.org; 9 Jul 2023 17:26:18 +0000 Original-Received: from localhost ([127.0.0.1]:47117 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qIYAr-0005rD-Pw for submit@debbugs.gnu.org; Sun, 09 Jul 2023 13:26:18 -0400 Original-Received: from s.wrqvtzvf.outbound-mail.sendgrid.net ([149.72.126.143]:46796) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qIYAp-0005qz-R1 for 64533@debbugs.gnu.org; Sun, 09 Jul 2023 13:26:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=catern.com; h=from:subject:in-reply-to:references:mime-version:to:cc:content-type: cc:content-type:from:subject:to; s=s1; bh=kuavA96FjUGv8Oxgo7aPAVIbKgifTLcFBJ4Ru87VmEs=; b=whsgmhrElQnxMYxeGW79eTNQMQAs5LF/rO7Q8qG8cZASQuPszkuvhCgJzlII4a38knVK 6daf05lioYd84jx5lptihbYdk5IzczfO/oaMD+ca9j7CZCTv7tEWoE71sujuP3HEVocW2Z H+ixAu7Rcuc6jAz0rR2lNfxMryFS193cbMc3ijLHGXtwJzb/+NkGvQ+9YG/ZyPc6cPi4BV 4BhD8N/PbrR1SjYLakwFLi7XzRWdmtWTbJvyFDYwC53gTpur/xg804ndrKO/Ip1iuLjsdS fHPSQtZDRk8wbfp2t8cBpQxFPB48Mt4f2s5AzgqNuyMrQ3Sf2RQ0JfJzXWfarfIQ== Original-Received: by filterdrecv-84b96456cb-hrvlt with SMTP id filterdrecv-84b96456cb-hrvlt-1-64AAEDB1-12 2023-07-09 17:26:09.408126761 +0000 UTC m=+5161654.404226784 Original-Received: from earth.catern.com (unknown) by geopod-ismtpd-27 (SG) with ESMTP id bn2RCH5wRv-_xxMb5YW4zg Sun, 09 Jul 2023 17:26:09.291 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=::1; helo=localhost; envelope-from=sbaugh@catern.com; receiver=gnu.org Original-Received: from localhost (localhost [IPv6:::1]) by earth.catern.com (Postfix) with ESMTPSA id D6E3762568; Sun, 9 Jul 2023 13:26:08 -0400 (EDT) In-Reply-To: <83o7klbq8q.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 09 Jul 2023 08:36:37 +0300") X-SG-EID: ZgbRq7gjGrt0q/Pjvxk7wM0yQFRdOkTJAtEbkjCkHbJsTf59cN620Cy4HmbjnBASF/DaT/4Kq3zy5B8X3UoirwihzPM9nndvkKW9KHSWAy8nktTidEKCEFtRN/1q4+qSjutZR7cFKPXSRKVR0yezbsbOI945q1jxVbUSjNawkCCQm6r5j5UeehZlB39BG18PE2qHO9mOHwr7bFyXDdcz7g== X-Entity-ID: d/0VcHixlS0t7iB1YKCv4Q== X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:264848 Archived-At: --=-=-= Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Eli Zaretskii writes: >> From: Spencer Baugh >> Cc: Eli Zaretskii , 64533@debbugs.gnu.org >> Date: Sat, 08 Jul 2023 16:58:50 -0400 >> >> +** Which Function Mode >> + >> ++++ >> +*** Displaying the function name in the header line is now supported. > > Passive voice alert! Here's a better wording (also for reasons other > than passive voice);; > > Which Function Mode can now display function names on the header line. Fixed. >> +(defcustom which-func-display '(mode) >> + "Where to display the function name. >> + >> +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. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Support-displaying-function-name-in-the-header-line.patch >From 3f23e559cae5ce864aef2c15e990f6beb5484eb7 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Sun, 9 Jul 2023 12:16:28 -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 | 9 ++++++++ lisp/progmodes/which-func.el | 42 ++++++++++++++++++++++++++++++------ 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/doc/emacs/programs.texi b/doc/emacs/programs.texi index a0e0fc06385..41780a95489 100644 --- a/doc/emacs/programs.texi +++ b/doc/emacs/programs.texi @@ -335,8 +335,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 @@ -349,6 +349,12 @@ Which Function @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/etc/NEWS b/etc/NEWS index 9c99cf6c725..efd323cb1da 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2989,6 +2989,15 @@ The newly created buffer will be displayed via 'display-buffer', which can be customized through the usual mechanism of 'display-buffer-alist' and friends. +** Which Function Mode + ++++ +*** Which Function Mode can now display function names on the header line. +The new user option 'which-func-display' allows choosing where the +function name is displayed. The default is 'mode' to display in the +mode line. 'header' will display in the header line. +'mode-and-header' displays in both the header line and mode line. + ** Tramp +++ 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 @@ 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. + +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 @@ 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 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 @@ 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 +260,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 +270,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.41.0 --=-=-=--