unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eshel Yaron via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: sbaugh@janestreet.com, 63825@debbugs.gnu.org
Subject: bug#63825: 29.0.90; The header line should be hidden when empty
Date: Fri, 02 Jun 2023 21:53:45 +0300	[thread overview]
Message-ID: <m1o7lxhf0m.fsf@eshelyaron.com> (raw)
In-Reply-To: <83mt1iayfj.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 02 Jun 2023 14:36:16 +0300")

[-- Attachment #1: Type: text/plain, Size: 911 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

>> The way I read Eli's above message, it boils down to extending the C
>> function `window_wants_mode_line` with a couple of special cases.
>> Something like the following (mildly tested):

> Thanks, this is an elegant solution.  A few minor comments:


Thanks for reviewing, I'm attaching an updated patch below.

Regarding this comment:

>> +/**
>> + * null_header_line_format:
>> + *
>> + * Return 1 when header line format F indicates that the header line
>> + * should not be displayed at all.

> We usually say "Return non-zero", not 1.

I've changed the wording accordingly, note that some other functions
that return `bool` in src/window.c currently say "Return 1",
e.g. `window_wants_header_line`.

> And finally, please accompany the change with a suitable commit log
> message, an entry in NEWS, and a change for the ELisp manual.

Sure, here's the new patch:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Avoid-header-line-with-some-empty-non-nil-formats.patch --]
[-- Type: text/x-patch, Size: 5426 bytes --]

From 5b231a67ef01ec3b0272967ad9eeecc6b689f030 Mon Sep 17 00:00:00 2001
From: Eshel Yaron <me@eshelyaron.com>
Date: Fri, 2 Jun 2023 20:09:43 +0300
Subject: [PATCH] Avoid header line with some empty non-nil formats

Allow the value of 'header-line-format' to indicate that no header
line should be displayed when it trivially yields 'nil', even if it is
not plain 'nil'.  Previously, any non-nil 'header-line-format'
resulted in a (possibly empty) header line.  This change adds some
flexibility by also taking a non-nil value of 'header-line-format' to
mean that no header line should be displayed if it's a list whose
'car' is a symbol and either that symbol is ':eval' and the second
list element evaluates to 'nil', or the symbol's value as a variable
is 'nil' or void.
(Bug#63825)

* src/window.c (null_header_line_format): New function.
(window_wants_header_line): Use it.

* doc/lispref/modes.texi (Header Line): Update to reflect new
conditions for displaying a window's header line.
(Emulating Mode Line): Don't falsely suggest that if
'format-mode-line' yields the empty string then there is no header
line, as there may be an empty header line instead.

* etc/NEWS: Announce updated treatment of 'header-line-format'.
---
 doc/lispref/modes.texi | 18 ++++++++++++-----
 etc/NEWS               |  8 ++++++++
 src/window.c           | 44 ++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 63 insertions(+), 7 deletions(-)

diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index c2698da6d99..c94ad229250 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -2597,6 +2597,15 @@ Header Lines
 line.
 @end defvar
 
+Emacs displays the header line for a window unless
+@code{header-line-format} is either @code{nil}, or it's a list whose
+@sc{car} is a symbol, and either that symbol is @code{:eval} and the
+second list element evaluates to @code{nil} or the symbol's value as a
+variable is @code{nil} or void.  Note that there are other possible
+values @code{header-line-format} that result in an empty header line
+(for example, @code{""}), but all other values tell Emacs to display a
+header line, whether or not it is empty.
+
 If @code{display-line-numbers-mode} is turned on in a buffer
 (@pxref{Display Custom, display-line-numbers-mode,, emacs, The GNU
 Emacs Manual}), the buffer text is indented on display by the amount
@@ -2707,11 +2716,10 @@ Emulating Mode Line
 (Other faces do not cause redisplay.)
 
 For example, @code{(format-mode-line header-line-format)} returns the
-text that would appear in the selected window's header line (@code{""}
-if it has no header line).  @code{(format-mode-line header-line-format
-'header-line)} returns the same text, with each character
-carrying the face that it will have in the header line itself, and also
-redraws the header line.
+text that would appear in the selected window's header line.
+@code{(format-mode-line header-line-format 'header-line)} returns the
+same text, with each character carrying the face that it will have in
+the header line itself, and also redraws the header line.
 @end defun
 
 @node Imenu
diff --git a/etc/NEWS b/etc/NEWS
index 9529282f047..f09e8972bc6 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -451,6 +451,14 @@ hooks named after the feature name, like 'esh-mode-unload-hook'.
 +++
 ** 'copy-tree' now copies records when its optional 2nd argument is non-nil.
 
++++
+** Certain values of 'header-line-format' now inhibit empty header line.
+Emacs now avoids displaying a header line, instead of displaying an
+empty one, when 'header-line-format' is a list whose 'car' is a
+symbol, and either that symbol is ':eval' and the second element of
+the list evaluates to 'nil' or the symbol's value as a variable is
+'nil' or void.
+
 \f
 * Lisp Changes in Emacs 30.1
 
diff --git a/src/window.c b/src/window.c
index f4e09f49eae..bfdf33fc1d6 100644
--- a/src/window.c
+++ b/src/window.c
@@ -5471,6 +5471,45 @@ window_wants_mode_line (struct window *w)
 }
 
 
+/**
+ * null_header_line_format:
+ *
+ * Return non-zero when header line format FMT indicates that the
+ * header line should not be displayed at all.
+ *
+ * This is when FMT is nil, or if FMT is a cons cell and either its
+ * car is a symbol whose value as a variable is nil or void, or its
+ * car is the symbol ':eval' and its cadr evaluates to nil.
+ */
+static bool
+null_header_line_format (Lisp_Object fmt)
+{
+  Lisp_Object car;
+  Lisp_Object val;
+
+  if (NILP (fmt))
+    return true;
+
+  if (CONSP (fmt))
+    {
+      car = XCAR (fmt);
+      if (SYMBOLP (car))
+	{
+	  if (EQ (car, QCeval)
+	      && NILP (Feval (XCAR (XCDR (fmt)), Qnil)))
+	      return true;
+
+	  val = find_symbol_value (car);
+	  return (SYMBOLP (car)
+		  && (EQ (val, Qunbound)
+		      || NILP (val)));
+	}
+    }
+
+  return false;
+}
+
+
 /**
  * window_wants_header_line:
  *
@@ -5495,8 +5534,9 @@ window_wants_header_line (struct window *w)
 	  && !MINI_WINDOW_P (w)
 	  && !WINDOW_PSEUDO_P (w)
 	  && !EQ (window_header_line_format, Qnone)
-	  && (!NILP (window_header_line_format)
-	      || !NILP (BVAR (XBUFFER (WINDOW_BUFFER (w)), header_line_format)))
+	  && (!null_header_line_format (window_header_line_format)
+	      || !null_header_line_format (BVAR (XBUFFER (WINDOW_BUFFER (w)),
+						 header_line_format)))
 	  && (WINDOW_PIXEL_HEIGHT (w)
 	      > (window_wants_mode_line (w)
 		 ? 2 * WINDOW_FRAME_LINE_HEIGHT (w)
-- 
2.40.1


  reply	other threads:[~2023-06-02 18:53 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-01 13:37 bug#63825: 29.0.90; The header line should be hidden when empty Spencer Baugh
2023-06-01 16:14 ` Eli Zaretskii
2023-06-01 16:45   ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-01 17:37     ` Spencer Baugh
2023-06-01 18:46     ` Eli Zaretskii
2023-06-01 20:22       ` Spencer Baugh
2023-06-02  6:19         ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-02 11:36           ` Eli Zaretskii
2023-06-02 18:53             ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-06-03  5:44               ` Eli Zaretskii
2023-06-03  7:28                 ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-04  7:03                   ` Eli Zaretskii
2023-06-04 16:45                     ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-06 12:18                       ` Eli Zaretskii
2023-06-06 12:28                         ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-02  6:23         ` 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=m1o7lxhf0m.fsf@eshelyaron.com \
    --to=bug-gnu-emacs@gnu.org \
    --cc=63825@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=me@eshelyaron.com \
    --cc=sbaugh@janestreet.com \
    /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).