Subject: Re: bug#73872: 30.0.91; emacs-lisp-mode-syntax-table active when calling `describe-variable' on variable with textually large value.

From: Stefan Monnier <[email-masked]>
Date: Thu, 14 Nov 2024 09:40:48 -0500

>> When you call `describle-variable' on a variable with a value that's
>> large enough that it's moved to the end of the help buffer, the syntax
>> table is changed to `emacs-lisp-mode-syntax-table' but never changed
>> back. There is a very easy fix where you just set it back to
>> `help-mode-syntax-table' at the end of the enclosing
>> `with-current-buffer', but I guess you could also switch to a
>> temporary buffer instead. Below is the relevant code snippet with the
>> first suggested fix applied.

I'm curious: in which context did you notice this?
Does it lead to an undesirable behavior in a specific case?

> Shouldn't the syntax table be left at that value until the buffer is
> reused for another variable/function?  Otherwise, why do we set the
> syntax table to this value?  Stefan, do you know the reason?

FWIW, according to my reading of the Git history, this behavior dates
back at least to 2001 when Miles split `help.el` into several files
(I didn't bother to check the previous history of that code on
`help.el`), so it's far from new.

AFAICT the syntax-table of the *Help* buffer shouldn't matter very much
once the buffer is filled: it affects only navigation by the user, where
the prose part would presumably prefer a syntax-table somewhat like that
of `text-mode` whereas the var's value part would prefer something like
that of `elisp-mode`.

But, AFAICT the `help-mode-syntax-table` happens to be a derivative of
`emacs-lisp-mode-syntax-table` just with extra matching of ‘...’, so
reverting to it would be safe enough in most cases.  This said, I think
The Right Thing™ would be to add a `syntax-table` property on the
printed value (regardless if it stays at the beginning or is moved to
the end of the buffer) so it's not affected by the syntax-table used in
the rest of the buffer.

        Stefan