Subject: bug#62749: 28.2; Disabling minor modes in diff-mode hunk temporary buffers

From: Juri Linkov <[email-masked]>
Date: Tue, 11 Mar 2025 19:19:29 +0200

>> The problem is that 'which-func-mode' is enabled in diff-mode.
>> 'which-function' calls 'add-log-current-defun' that calls
>> 'add-log-current-defun-function' that is 'diff-current-defun'
>> in diff-mode.  Finally, 'diff-find-source-location' visits
>> the source files without killing them afterwards.
>
> In commit 53977213522 Stefan K. fixed a similar sort of problem for
> Paredit users.  Specifically, when trying to use C-c C-w in a Log Edit
> buffer, diff-add-log-current-defuns tries to enable Paredit in its
> *diff-other-text* temporary buffers.
>
> Paredit calls check-parens, which fails because it's just a small
> portion of the file and so the parens aren't balanced.
> This signalled a user-error which interrupts the whole operation.
>
> What is similar in these two cases is that diff-mode code is setting up
> temporary buffers for hunks in which only the major mode matters, but
> there are various possible minor modes that could get in the way because
> they expect to be enabled in buffers visiting whole files.
>
> So I think this your problem here, Juri, might be fixable in a similar
> way to 53977213522, by using delay-mode-hooks ?

This was already fixed long ago: there is '(delay-mode-hooks (set-auto-mode))'
in 'diff-syntax-fontify-props'.

>> I guess this is related to another annoying bug: after every commit need
>> to spend much time killing all buffers created by the commit command.
>
> I'm not sure what you're referring to here, could you expand?

'which-function' uses 'add-log-current-defun' that creates the buffers
for files it visits, but never kills these temporary buffers afterwards.