unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier 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: me@eshelyaron.com, 63988@debbugs.gnu.org, aaronjensen@gmail.com
Subject: bug#63988: 30.0.50; Recent header line format changes cause spin/seg fault with format-mode-line
Date: Sat, 10 Jun 2023 15:11:46 -0400	[thread overview]
Message-ID: <jwv8rcrxhw3.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <83h6rfz01q.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 10 Jun 2023 20:42:25 +0300")

>> I wonder why `format-mode-line` calls `window_wants_header_line`.
>> Is there a deep technical reason, or just an accident of how we
>> currently implement the feature?
> format-mode-line calls init_iterator (because the formatting is done
> by display code), and init_iterator calls window_wants_header_line
> because it needs to know the general layout of the window up front.

Ah, I see.

> We could introduce some knobs to perhaps avoid this in the particular
> case of format-mode-line, but the :eval form in header-line-format can
> call any Lisp, not necessarily format-mode-line.

There's no doubt that in the most general case the arbitrary ELisp code
run from `header-line-format` can cause enough redisplay work to require
computation of `header-line-format`, indeed.

>> In the past I've wished for a non-nil mode-line that is not displayed
>> because it's equivalent to nil, so I think the feature makes sense, but
>> I agree it's not super important.  Maybe if we want to make it work
>> well, the better solution is to memoize the computation of
>> (format-mode-line header-line-format) so that it's called at most once
>> per redisplay?
>
> That is possible, and I thought about it as well, but it isn't easy.

Agreed.  I can see two benefits:

- try and handle the recursion by marking the header-line as "wanted"
  while we compute it so recursive calls to `window_wants_header_line`
  just return `true` without actually doing the work recursively.
- try and reduce the cost of re-computing it every time.

But obviously, like all memoization/caching schemes, the hard part is to
figure out how/when to flush the obsolete info.  It's definitely not easy.

> Bottom line: this sounds like a minor convenience feature that causes
> major headaches to implement, because once you allow evaluation of
> arbitrary Lisp, all bets are basically off.

I can't remember the details of when I wanted a non-nil
`mode-line-format` to be equivalent to nil, but IIRC I worked around the
problem with ad-hoc hooks at various places to set/reset
`mode-line-format` to nil and back according to whether a mode line
should be displayed.

Still, I can see cases where we may want a header-line that's only
displayed in some specific *windows*, so the buffer's value can't be nil
(for that window) but shouldn't be non-nil (for the other windows
displaying that buffer).  In the absence of the problematic commit we
can't handle such cases.

But we've lived with such a limitation for almost 40 years, so I'm fine
with removing that feature rather than trying to make it work.
We'll want to ad some comments in the code to try and avoid someone else
go through the same process, tho.


        Stefan






  parent reply	other threads:[~2023-06-10 19:11 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-10  1:09 bug#63988: 30.0.50; Recent header line format changes cause spin/seg fault with format-mode-line Aaron Jensen
2023-06-10  6:47 ` Eli Zaretskii
2023-06-10  8:56   ` Eli Zaretskii
2023-06-10  9:07     ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-15  5:59       ` Eli Zaretskii
2023-06-16  2:30         ` Aaron Jensen
2023-06-23 10:53         ` Eli Zaretskii
2023-07-05 15:30         ` Spencer Baugh
2023-07-05 15:40           ` Eli Zaretskii
2023-06-10 16:16     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-10 17:42       ` Eli Zaretskii
2023-06-10 17:51         ` Aaron Jensen
2023-06-10 19:11         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-06-10 11:08   ` Aaron Jensen
2023-06-10 11:22     ` Eli Zaretskii
2023-06-10 11:59       ` Aaron Jensen
2023-06-10 13:04         ` Eli Zaretskii
2023-06-10 15:06           ` Aaron Jensen

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=jwv8rcrxhw3.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=63988@debbugs.gnu.org \
    --cc=aaronjensen@gmail.com \
    --cc=eliz@gnu.org \
    --cc=me@eshelyaron.com \
    --cc=monnier@iro.umontreal.ca \
    /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).