Subject: Re: bug#63825: 29.0.90; The header line should be hidden when empty

From: Eli Zaretskii <[email-masked]>
Date: Fri, 02 Jun 2023 09:23:19 +0300

> From: Spencer Baugh <[email-masked]>
> Cc: Eshel Yaron <[email-masked]>,  [email-masked]
> Date: Thu, 01 Jun 2023 16:22:14 -0400
> 
> >> So this shows an empty header line:
> >> 
> >> --8<---------------cut here---------------start------------->8---
> >> (setq-default header-line-format '(:eval nil))
> >> --8<---------------cut here---------------end--------------->8---
> >> 
> >> (In Emacs master with -Q.)
> >
> > It shouldn't be hard to make this special case behave as you want.
> > 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?

No, using format-mode-line for displaying the mode line is not a good
idea, for several subtle reason which I won't go into.  If you want to
understand the reasons, look at the code of format-mode-line and how
it affects what display_mode_element does.  In particular, there's no
way to distinguish between the special value of header-line-format we
are discussing and the value that really yields an empty string: the
latter we don't want to change.

Why can't you simply copy some of the code from display_mode_element
that handles the :eval and the cons cell with a symbol cases into
display_mode_line, before it calls display_mode_element, and have the
function return zero in case the result is nil?  Then the callers of
display_mode_line should treat the zero value as an indication that
the mode line was not displayed/produced, and act accordingly.

Alternatively, you could do something special in display_mode_element
when these two forms evaluate to nil and DEPTH is 1, and add some
logic in display_mode_line to handle that.