all messages for Emacs-related lists mirrored at yhetil.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: Spencer Baugh <sbaugh@janestreet.com>
Cc: Eli Zaretskii <eliz@gnu.org>, 63825@debbugs.gnu.org
Subject: bug#63825: 29.0.90; The header line should be hidden when empty
Date: Fri, 02 Jun 2023 09:19:17 +0300	[thread overview]
Message-ID: <m1ilc64c9m.fsf@eshelyaron.com> (raw)
In-Reply-To: <ierv8g7ylu1.fsf@janestreet.com> (Spencer Baugh's message of "Thu, 01 Jun 2023 16:22:14 -0400")

Spencer Baugh <sbaugh@janestreet.com> writes:

> Eli Zaretskii <eliz@gnu.org> writes:
>> Specifically, if the header-line-format is just a single cons cell,
>> and the car of that cons cell is either :eval or a symbol, and the
>> result of evaluation those yields nil, don't display the header line.
>> (I don't really like the idea of not displaying the mode line under
>> the same conditions.)
>>
>> Patches welcome.
>
> Ok, the easy way to achieve that is to run format-mode-line on the
> header-line-format and if it evaluates to "", don't display the header
> line.  That also ignores the cases where header-line-format is multiple
> cons cells, all of which evaluate to nil, and other such scenarios.  Is
> that an acceptable approach to you?

This might be a bit too coarse IMO, because it would make it a lot
harder to create an empty header line.  Namely, setting
`header-line-format` to an empty string would no longer create an empty
header line.

I'm far from fluent in Emacs's internals, but AFAIU from skimming
src/xdisp.c there's another issue which is that Emacs checks whether a
window should have a header line in many circumstances, as it affects
the window's effective dimensions.  So formatting the entire header line
each time Emacs just wants to know whether there is or isn't a header
line might not be ideal in terms of efficiency.

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):

diff --git a/src/window.c b/src/window.c
index f4e09f49eae..10bccc6df65 100644
--- a/src/window.c
+++ b/src/window.c
@@ -5471,6 +5471,36 @@ window_wants_mode_line (struct window *w)
 }
 
 
+/**
+ * null_header_line_format:
+ *
+ * Return 1 when header line format F indicates that the header line
+ * should not be displayed at all.
+ *
+ * This is when F is nil, or F is a cons cell and either its car is a
+ * symbol whose value as a variable is nil, or its car is the symbol
+ * ':eval' and its cddr evaluates to nil.
+ */
+static bool
+null_header_line_format (Lisp_Object f)
+{
+  Lisp_Object car;
+
+  if (NILP (f))
+    return 1;
+
+  if (CONSP (f)) {
+    car = XCAR (f);
+    return (SYMBOLP (car)
+	    && ((EQ (car, QCeval)
+		 && NILP (Feval (XCAR (XCDR (f)), Qnil)))
+		|| NILP (find_symbol_value (car))));
+  }
+
+  return 0;
+}
+
+
 /**
  * window_wants_header_line:
  *
@@ -5495,8 +5525,8 @@ 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)





  reply	other threads:[~2023-06-02  6:19 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 [this message]
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
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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m1ilc64c9m.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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.