Subject: bug#76745: 31.0.50; ?d action in save-some-buffers-action-alist to view diff does not work

From: StrawberryTea <[email-masked]>
Date: Sat, 15 Mar 2025 20:14:08 -0400

Juri Linkov <[email-masked]> writes:

Well, let's do this then. Patch something in so that save-some-buffers
"d" key lets us do "q" to exit the diff buffer. I still disagree because
view-mode is supported by Evil etc but if we do like a local-set-key or
something, it will probably break other packages that don't handle this
very special case of save-some-buffers.

>> Well, I agree that for save-some-buffers we should enter view-mode. But
>> I don't see why view-mode should be disabled for diff-mode in general.
>
> Because view-mode overrides diff-mode single letter keybindings:
>
>   "n" #'diff-hunk-next
>   "N" #'diff-file-next
>   "p" #'diff-hunk-prev
>   "P" #'diff-file-prev
>   "k" #'diff-hunk-kill
>   "K" #'diff-file-kill
>   "}" #'diff-file-next
>   "{" #'diff-file-prev
>   "RET" #'diff-goto-source
>   "W" #'widen
>   "w" #'diff-kill-ring-save
>   "o" #'diff-goto-source
>   "A" #'diff-ediff-patch
>   "r" #'diff-restrict-view
>   "R" #'diff-reverse-direction
>
>> The key issue here is that diff-mode serves multiple purposes:
>>
>> 1. Sometimes diff buffers are purely for viewing (like in
>>    save-some-buffers), where the primary user need is quick navigation
>>    and an easy way to exit
>
> I think save-some-buffers is a special case that can be handled specially
> in save-some-buffers to enable view-mode explicitly.
>
>> 2. Other times, users need to actively work with diff content -
>>    navigating by sections, copying hunks, applying patches, etc.
>
> Such actions as navigating by sections and copying hunks
> often needed also while viewing diffs.
>
>> Disabling view-mode entirely for diff-mode (as in #75993) prioritizes
>> the second use case at the expense of the first. But I believe a better
>> approach is to maintain both capabilities and let users or calling
>> functions decide which mode is appropriate for their context.
>
> Users can decide whether to enable view-mode by e.g.
>
>   (add-hook 'diff-mode 'view-mode-enter)
>
> And the caller in 'save-some-buffers' can enable it too.
>
>> For viewing-only situations like save-some-buffers, view-mode provides
>> valuable functionality - particularly the quick navigation keys and the
>> critical ability to exit with 'q' which triggers exit-recursive-edit in
>> this context.
>
> The required functionality from view-mode in this case is only 'q'
> to trigger exit-recursive-edit.
>
>> Rather than disabling view-mode completely for diff-mode, we should
>> investigate why view-mode is being activated when you do not intend it
>> to be. If there are specific situations where view-mode interferes with
>> diff-mode functionality, we should consider either disabling view-mode
>> in those specific contexts or exiting view-mode in those situations,
>> rather than making a global change that affects all diff-mode usage.
>
> view-mode does more harm than good to diff-mode.  So I think
> it should be opt-in, not opt-out.
>
> Even with 'view-read-only' customized to t, no one asked to enable view-mode
> for the most frequent use case of showing diffs from vc-diff where
> view-mode was never activated, because it's activated only for files.