Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers

From: Juri Linkov <[email-masked]>
Date: Sat, 13 Nov 2021 20:27:36 +0200

>>> +;; - Support outlining files by name (eg to skip automatically
>>> +;;   generated files like package-lock.json in Javascript projects).
>>>…
>>> +(defcustom diff-file-outline-threshold 50
>>> +  "Number of lines of hunks for a file to be outlined.
>>
>> Often the files that need to be hidden contain just one very long line
>> without newlines such as in compiled assets, etc. and eventually make
>> Emacs unresponsive.  This is a big problem.  Would it be possible
>> in your patch to check the size of the hunk counting characters
>> instead of lines?
>
> Good point. I guess counting characters can be achieved by:
>   (- (overlay-end overlay) (overlay-start overlay))
> thus it looks feasible.

It seems this should work.

> Wouldn't it better to add a new choice "Outline hunks with long lines"
> and allow multiple choices in `diff-outline-default-state'
> customization?

Many customizable variables that check the size such as
large-file-warning-threshold etc. count bytes/characters.
But if you think that someone might want to restrict
only the number of lines whereas wanting to see long lines,
then a new option could be added too.

> It would allow to implement one more usefull choice (from my pov),
> "Outline files by name" to hide automatically generated files (like
> package-lock.json in Javascript projects using NPM)...
>
> Does it looks reasonnable to you?

An option to hide by file names (I assume a regexp?) looks useful too.

This is how I configured the xref output buffer to
initially hide only ChangeLog and test files:

#+begin_src emacs-lisp
(add-hook 'xref-after-update-hook
          (lambda ()
            (setq-local outline-regexp (if (eq xref-file-name-display 'abs)
                                           "/" "[^ 0-9]"))
            (outline-minor-mode +1)
            (save-excursion
              (goto-char (point-min))
              (while (and (re-search-forward "ChangeLog\\|test/manual/etags" nil t)
                          (get-text-property (point) 'xref-group))
                (outline-cycle)))))
#+end_src

Something like this could be customizable in diff-mode.