From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Spencer Baugh Newsgroups: gmane.emacs.bugs Subject: bug#64533: [PATCH] Support displaying function name in the header line Date: Sat, 08 Jul 2023 13:56:23 -0400 Message-ID: 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="25487"; mail-complaints-to="usenet@ciao.gmane.io" To: 64533@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jul 08 19:57:11 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 1qICBC-0006MZ-Ss for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 08 Jul 2023 19:57:10 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qICB5-0003nL-6t; Sat, 08 Jul 2023 13:57:03 -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 1qICB4-0003mj-Gt for bug-gnu-emacs@gnu.org; Sat, 08 Jul 2023 13:57: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 1qICB4-0005S6-8p for bug-gnu-emacs@gnu.org; Sat, 08 Jul 2023 13:57:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qICB4-0008Us-4k for bug-gnu-emacs@gnu.org; Sat, 08 Jul 2023 13:57:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 08 Jul 2023 17:57:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 64533 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.168883899032583 (code B ref -1); Sat, 08 Jul 2023 17:57:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 8 Jul 2023 17:56:30 +0000 Original-Received: from localhost ([127.0.0.1]:45148 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qICAX-0008TT-Vh for submit@debbugs.gnu.org; Sat, 08 Jul 2023 13:56:30 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:39310) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qICAW-0008TH-2P for submit@debbugs.gnu.org; Sat, 08 Jul 2023 13:56:29 -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 1qICAV-0003i4-S9 for bug-gnu-emacs@gnu.org; Sat, 08 Jul 2023 13:56:27 -0400 Original-Received: from mxout5.mail.janestreet.com ([64.215.233.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qICAS-0005IP-T6 for bug-gnu-emacs@gnu.org; Sat, 08 Jul 2023 13:56:27 -0400 Received-SPF: pass client-ip=64.215.233.18; envelope-from=sbaugh@janestreet.com; helo=mxout5.mail.janestreet.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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:264785 Archived-At: --=-=-= Content-Type: text/plain 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' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Support-displaying-function-name-in-the-header-line.patch >From a3f3e73dfcce1ae92da42e95f57740448327332f Mon Sep 17 00:00:00 2001 From: Spencer Baugh 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 --=-=-=--