Subject: bug#62749: 28.2; Emacs keeps opening related file from vc-diff buffer

From: Oleksandr Gavenko <[email-masked]>
Date: Sun, 14 May 2023 13:59:49 +0300

After bisecting my long .emacs config I pinpointed the culprit:

(which-func-mode 1)

During the movement through a diff buffer this mode loads corresponding
files:

  if the cursor reaches a new hunk - the corresponding file is opened ((

This is done one by one file while I scroll down with the cursor.

Removing the line significantly improved performance during scromming in VC
diff buffer in Cygwin and no more new files opened!

I think which-function-mode is broken for diff-mode, the workaround for
those who wants this mode is to deal with:

(defcustom which-func-modes t
  ;; '(emacs-lisp-mode c-mode c++-mode objc-mode perl-mode cperl-mode
python-mode
  ;;               makefile-mode sh-mode fortran-mode f90-mode ada-mode
  ;;               diff-mode)
  "List of major modes for which Which Function mode should be used.
For other modes it is disabled.  If this is equal to t,
then Which Function mode is enabled in any major mode that supports it."

What are the next actions?

On Tue, Apr 11, 2023 at 1:23 AM Dmitry Gutov <[email-masked]> wrote:

> Hi! Thanks for the report.
>
> On 10/04/2023 15:11, Oleksandr Gavenko wrote:
> > In GNU Emacs 28.2 (build 1, x86_64-pc-cygwin)
> >   of 2022-09-16 built on fv-az140-985
> > Repository revision: 70134aa8264ded36d80248204b2ba43ae3d8f599
> >
> > Whenever I open vc-diff buffer by "d" (log-view-diff) to read repository
> > history from "C-x v L" (vc-print-root-log) Emacs opens all files
> referenced by
> > diff.
> >
> > The diff might be very big so:
> >
> > * I end with lots of opened files that I need eventually close.
> > * Emacs pollutes recentf history - I don't want robotically opened file
> mixed
> >    with human opened files.
> > * Cygwin is slow (especially under antivirus supervision) file opening
> delays
> >    Emacs for many seconds.
> >
> > Initially I asked for help in Emacs 27.1:
> >
> >
> https://emacs.stackexchange.com/questions/61760/lags-when-navigating-vc-root-diff-buffer/
> >
> > and found workaround with:
> >
> >    (setq diff-font-lock-syntax nil)
>
> This workaround should help, in particular to improve performance under
> Cygwin.
>
> The thing about opened files is quite odd, though:
> diff-syntax-fontify-hunk does not visit any new files. It either uses an
> existing buffer, or fetches file contents using insert-file-contents, or
> calls vc-find-revision-no-save which, again, inserts the previous'
> revision file contents into the provided buffer, without visiting a file.
>
> Perhaps you could edebug diff-syntax-fontify-hunk to find the exact
> place where a file is visited (and added to recentf), if that indeed
> happens.
>