* bug#75993: Special mode-class for diff-mode
@ 2025-02-01 17:33 Juri Linkov
2025-02-02 23:35 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 8+ messages in thread
From: Juri Linkov @ 2025-02-01 17:33 UTC (permalink / raw)
To: 75993; +Cc: Stefan Monnier
Tags: patch
Visiting a diff file and trying to copy lines with 'w' (diff-kill-ring-save)
does something unexpected since view-mode overrides 'w' with
'View-scroll-page-backward-set-page-size' for non-nil 'view-read-only'.
Here is the fix like for all modes that use single-letter keys:
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index 77807fc4f35..b88dd4bf736 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -1550,6 +1550,7 @@ diff-mode-read-only
(defvar whitespace-style)
(defvar whitespace-trailing-regexp)
+(put 'diff-mode 'mode-class 'special)
;;;###autoload
(define-derived-mode diff-mode fundamental-mode "Diff"
"Major mode for viewing/editing context diffs.
^ permalink raw reply related [flat|nested] 8+ messages in thread
* bug#75993: Special mode-class for diff-mode
2025-02-01 17:33 bug#75993: Special mode-class for diff-mode Juri Linkov
@ 2025-02-02 23:35 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-02-03 7:56 ` Juri Linkov
0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2025-02-02 23:35 UTC (permalink / raw)
To: Juri Linkov; +Cc: 75993
> Visiting a diff file and trying to copy lines with 'w' (diff-kill-ring-save)
> does something unexpected since view-mode overrides 'w' with
> 'View-scroll-page-backward-set-page-size' for non-nil 'view-read-only'.
>
> Here is the fix like for all modes that use single-letter keys:
[...]
> +(put 'diff-mode 'mode-class 'special)
> ;;;###autoload
> (define-derived-mode diff-mode fundamental-mode "Diff"
> "Major mode for viewing/editing context diffs.
Hmm... this doesn't smell right:
- I hate distinguishing between "mode-class = special" and "derives from
`special-mode`".
- Whether we want to do that depends on `diff-mode-read-only` which is
buffer-local.
Stefan
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#75993: Special mode-class for diff-mode
2025-02-02 23:35 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2025-02-03 7:56 ` Juri Linkov
2025-02-03 11:16 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 8+ messages in thread
From: Juri Linkov @ 2025-02-03 7:56 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 75993
>> Visiting a diff file and trying to copy lines with 'w' (diff-kill-ring-save)
>> does something unexpected since view-mode overrides 'w' with
>> 'View-scroll-page-backward-set-page-size' for non-nil 'view-read-only'.
>>
>> Here is the fix like for all modes that use single-letter keys:
> [...]
>> +(put 'diff-mode 'mode-class 'special)
>> ;;;###autoload
>> (define-derived-mode diff-mode fundamental-mode "Diff"
>> "Major mode for viewing/editing context diffs.
>
> Hmm... this doesn't smell right:
>
> - I hate distinguishing between "mode-class = special" and "derives from
> `special-mode`".
> - Whether we want to do that depends on `diff-mode-read-only` which is
> buffer-local.
AFAICS, the special mode-class is handled only in `read-only-mode`:
((and buffer-read-only view-read-only
(not view-mode)
(not (eq (get major-mode 'mode-class) 'special)))
(view-mode-enter))
This is exactly what is needed in diff-mode when it switches to read-only
it should not enable view-mode.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#75993: Special mode-class for diff-mode
2025-02-03 7:56 ` Juri Linkov
@ 2025-02-03 11:16 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-02-03 17:59 ` Juri Linkov
0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2025-02-03 11:16 UTC (permalink / raw)
To: Juri Linkov; +Cc: 75993
>> Hmm... this doesn't smell right:
>>
>> - I hate distinguishing between "mode-class = special" and "derives from
>> `special-mode`".
>> - Whether we want to do that depends on `diff-mode-read-only` which is
>> buffer-local.
>
> AFAICS, the special mode-class is handled only in `read-only-mode`:
>
> ((and buffer-read-only view-read-only
> (not view-mode)
> (not (eq (get major-mode 'mode-class) 'special)))
> (view-mode-enter))
>
> This is exactly what is needed in diff-mode when it switches to read-only
> it should not enable view-mode.
Maybe, but:
- Nothing in its name or in its doc says so, AFAICT. IOW, it's just an accident.
- As a symbol property, it's not buffer-local.
Stefan
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#75993: Special mode-class for diff-mode
2025-02-03 11:16 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2025-02-03 17:59 ` Juri Linkov
2025-02-04 19:37 ` Juri Linkov
0 siblings, 1 reply; 8+ messages in thread
From: Juri Linkov @ 2025-02-03 17:59 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 75993
>>> Hmm... this doesn't smell right:
>>>
>>> - I hate distinguishing between "mode-class = special" and "derives from
>>> `special-mode`".
>>> - Whether we want to do that depends on `diff-mode-read-only` which is
>>> buffer-local.
>>
>> AFAICS, the special mode-class is handled only in `read-only-mode`:
>>
>> ((and buffer-read-only view-read-only
>> (not view-mode)
>> (not (eq (get major-mode 'mode-class) 'special)))
>> (view-mode-enter))
>>
>> This is exactly what is needed in diff-mode when it switches to read-only
>> it should not enable view-mode.
>
> Maybe, but:
>
> - Nothing in its name or in its doc says so, AFAICT. IOW, it's just an accident.
> - As a symbol property, it's not buffer-local.
This description seems to fit the purpose of diff-mode:
⢠If this mode is appropriate only for specially-prepared text
produced by the mode itself (rather than by the user typing at the
keyboard or by an external file), then the major mode command
symbol should have a property named âmode-classâ with value
âspecialâ, put on as follows:
(put 'funny-mode 'mode-class 'special)
This tells Emacs that new buffers created while the current buffer
is in Funny mode should not be put in Funny mode, even though the
default value of âmajor-modeâ is ânilâ. By default, the value of
ânilâ for âmajor-modeâ means to use the current buffer's major mode
when creating new buffers (*note Auto Major Mode::), but with such
âspecialâ modes, Fundamental mode is used instead. Modes such as
Dired, Rmail, and Buffer List use this feature.
The function âview-bufferâ does not enable View mode in buffers
whose mode-class is special, because such modes usually provide
their own View-like bindings.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#75993: Special mode-class for diff-mode
2025-02-03 17:59 ` Juri Linkov
@ 2025-02-04 19:37 ` Juri Linkov
2025-02-04 20:52 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 8+ messages in thread
From: Juri Linkov @ 2025-02-04 19:37 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 75993
>>>> Hmm... this doesn't smell right:
>>>>
>>>> - I hate distinguishing between "mode-class = special" and "derives from
>>>> `special-mode`".
>>>> - Whether we want to do that depends on `diff-mode-read-only` which is
>>>> buffer-local.
>>>
>>> AFAICS, the special mode-class is handled only in `read-only-mode`:
>>>
>>> ((and buffer-read-only view-read-only
>>> (not view-mode)
>>> (not (eq (get major-mode 'mode-class) 'special)))
>>> (view-mode-enter))
>>>
>>> This is exactly what is needed in diff-mode when it switches to read-only
>>> it should not enable view-mode.
>>
>> Maybe, but:
>>
>> - Nothing in its name or in its doc says so, AFAICT. IOW, it's just an accident.
>> - As a symbol property, it's not buffer-local.
>
> This description seems to fit the purpose of diff-mode:
>
> • If this mode is appropriate only for specially-prepared text
> produced by the mode itself (rather than by the user typing at the
> keyboard or by an external file), then the major mode command
> symbol should have a property named ‘mode-class’ with value
> ‘special’, put on as follows:
>
> (put 'funny-mode 'mode-class 'special)
>
> This tells Emacs that new buffers created while the current buffer
> is in Funny mode should not be put in Funny mode, even though the
> default value of ‘major-mode’ is ‘nil’. By default, the value of
> ‘nil’ for ‘major-mode’ means to use the current buffer's major mode
> when creating new buffers (*note Auto Major Mode::), but with such
> ‘special’ modes, Fundamental mode is used instead. Modes such as
> Dired, Rmail, and Buffer List use this feature.
I still don't understand implications from the above text.
Dired is read-only by default but can be switched to editable mode,
so is Diff mode.
I tested with special mode-class, and see no negative side effect.
> The function ‘view-buffer’ does not enable View mode in buffers
> whose mode-class is special, because such modes usually provide
> their own View-like bindings.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#75993: Special mode-class for diff-mode
2025-02-04 19:37 ` Juri Linkov
@ 2025-02-04 20:52 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-02-06 7:58 ` Juri Linkov
0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2025-02-04 20:52 UTC (permalink / raw)
To: Juri Linkov; +Cc: 75993
> I still don't understand implications from the above text.
> Dired is read-only by default but can be switched to editable mode,
Note that when you make it writable, Dired changes the `major-mode`.
Also, AFAIK you can't open a Dired buffer in writable mode.
> so is Diff mode.
In contrast, `diff-mode` can be used both read-only and writable without
changing `major-mode`.
> I tested with special mode-class, and see no negative side effect.
Have you tried to
(setq diff-default-read-only nil)
(setq view-read-only t)
and then open a read-only `.patch` file?
I think your patch will hinder
the auto-activation of `view-mode` in that case.
Stefan
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#75993: Special mode-class for diff-mode
2025-02-04 20:52 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2025-02-06 7:58 ` Juri Linkov
0 siblings, 0 replies; 8+ messages in thread
From: Juri Linkov @ 2025-02-06 7:58 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 75993
>> I tested with special mode-class, and see no negative side effect.
>
> Have you tried to
>
> (setq diff-default-read-only nil)
> (setq view-read-only t)
>
> and then open a read-only `.patch` file?
> I think your patch will hinder
> the auto-activation of `view-mode` in that case.
Indeed, `view-mode` is not activated in this case,
and this is the right thing to do to allow using
diff-mode single letters like 'w' (diff-kill-ring-save)
instead of overriding it with
'View-scroll-page-backward-set-page-size'.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-02-06 7:58 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-01 17:33 bug#75993: Special mode-class for diff-mode Juri Linkov
2025-02-02 23:35 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-02-03 7:56 ` Juri Linkov
2025-02-03 11:16 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-02-03 17:59 ` Juri Linkov
2025-02-04 19:37 ` Juri Linkov
2025-02-04 20:52 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-02-06 7:58 ` Juri Linkov
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.