Subject: Re: bug#72759: 31.0.50; Emacs hangs with open-paren-in-column-0-is-defun-start set to nil

From: Eshel Yaron <[email-masked]>
Date: Thu, 22 Aug 2024 14:37:01 +0200

Eli Zaretskii <[email-masked]> writes:

>> From: Eshel Yaron <[email-masked]>
>> Cc: [email-masked]
>> Date: Thu, 22 Aug 2024 13:31:16 +0200
>> 
>> Eli Zaretskii <[email-masked]> writes:
>> 
>> >> Date: Thu, 22 Aug 2024 12:07:38 +0200
>> >> From:  Eshel Yaron via "Bug reports for GNU Emacs,
>> >>  the Swiss army knife of text editors" <[email-masked]>
>> >> 
>> >> 
>> >> 1. emacs -Q
>> >> 2. (setq open-paren-in-column-0-is-defun-start nil)
>> >> 3. Insert " (foo"
>> >> 4. M-x flymake-mode
>> >> 5. Emacs hangs
>> >> 
>> >> I can reproduce this with Emacs 29 and later.
>> >
>> > Thanks.  Could you show the Lisp backtrace from the hang (assuming it
>> > hangs in Lisp code)?
>> 
>> Sure, see the backtrace below.  It appears that the hang is in
>> checkdoc-next-docstring, namely this loop...
>> 
>> --8<---------------cut here---------------start------------->8---
>> (while (and (not (setq found (checkdoc--next-docstring)))
>>                 (beginning-of-defun -1)))
>> --8<---------------cut here---------------end--------------->8---
>> 
>> ...never terminates, because beginning-of-defun behaves differently with
>> open-paren-in-column-0-is-defun-start set to nil.
>
> Would it make sense to have checkdoc-next-docstring bind
> open-paren-in-column-0-is-defun-start to a non-nil value?

Not entirely: the difference in behavior of beginning-of-defun is
unexpected, and may prove problematic in other cases as well, so it
would be best to fix the root cause IMO.  Namely, in
beginning-of-defun-raw, the fallback cond clause fails to move forward
over an sexp that does starts after the beginning of the line.

You should also be able to see this in effect with C-- C-M-a at the
beginning of a line whose contents is " (foo)".  The results vary
depending on the value of open-paren-in-column-0-is-defun-start.

Eshel