GNU bug report logs -
#75993
Special mode-class for diff-mode
Previous Next
Reported by: Juri Linkov <juri <at> linkov.net>
Date: Sat, 1 Feb 2025 17:37:01 UTC
Severity: normal
Tags: patch
Fixed in version 31.0.50
Done: Juri Linkov <juri <at> linkov.net>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 75993 in the body.
You can then email your comments to 75993 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org
:
bug#75993
; Package
emacs
.
(Sat, 01 Feb 2025 17:37:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Juri Linkov <juri <at> linkov.net>
:
New bug report received and forwarded. Copy sent to
monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org
.
(Sat, 01 Feb 2025 17:37:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75993
; Package
emacs
.
(Sun, 02 Feb 2025 23:36:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 75993 <at> debbugs.gnu.org (full text, mbox):
> 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
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75993
; Package
emacs
.
(Mon, 03 Feb 2025 07:59:03 GMT)
Full text and
rfc822 format available.
Message #11 received at 75993 <at> debbugs.gnu.org (full text, mbox):
>> 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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75993
; Package
emacs
.
(Mon, 03 Feb 2025 11:18:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 75993 <at> debbugs.gnu.org (full text, mbox):
>> 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
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75993
; Package
emacs
.
(Mon, 03 Feb 2025 18:07:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 75993 <at> debbugs.gnu.org (full text, mbox):
>>> 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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75993
; Package
emacs
.
(Tue, 04 Feb 2025 19:49:02 GMT)
Full text and
rfc822 format available.
Message #20 received at 75993 <at> debbugs.gnu.org (full text, mbox):
>>>> 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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75993
; Package
emacs
.
(Tue, 04 Feb 2025 20:53:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 75993 <at> debbugs.gnu.org (full text, mbox):
> 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
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75993
; Package
emacs
.
(Thu, 06 Feb 2025 08:35:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 75993 <at> debbugs.gnu.org (full text, mbox):
>> 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'.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75993
; Package
emacs
.
(Thu, 06 Feb 2025 15:41:01 GMT)
Full text and
rfc822 format available.
Message #29 received at 75993 <at> debbugs.gnu.org (full text, mbox):
>>> 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'.
Hmm... when you `(setq diff-default-read-only nil)`, `w` is not bound to
`diff-kill-ring-save` but to `self-insert-command`, so I think we *do*
want `view-read-only` to apply in this case.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75993
; Package
emacs
.
(Thu, 06 Feb 2025 17:20:02 GMT)
Full text and
rfc822 format available.
Message #32 received at 75993 <at> debbugs.gnu.org (full text, mbox):
>>>> 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'.
>
> Hmm... when you `(setq diff-default-read-only nil)`, `w` is not bound to
> `diff-kill-ring-save` but to `self-insert-command`, so I think we *do*
> want `view-read-only` to apply in this case.
`w` is bound to `diff-kill-ring-save` because of
the read-only file and therefore read-only buffer.
There is no place for view-mode keybindings
since there are only 2 states:
- editable where `w` is `self-insert-command`
- read-only where `w` is `diff-kill-ring-save`
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75993
; Package
emacs
.
(Thu, 06 Feb 2025 18:24:02 GMT)
Full text and
rfc822 format available.
Message #35 received at 75993 <at> debbugs.gnu.org (full text, mbox):
>> Hmm... when you `(setq diff-default-read-only nil)`, `w` is not bound to
>> `diff-kill-ring-save` but to `self-insert-command`, so I think we *do*
>> want `view-read-only` to apply in this case.
> `w` is bound to `diff-kill-ring-save` because of
> the read-only file and therefore read-only buffer.
Hmm... looks like you're right.
So why don't we make `diff-mode` inherit from `special-mode`?
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75993
; Package
emacs
.
(Thu, 06 Feb 2025 18:51:02 GMT)
Full text and
rfc822 format available.
Message #38 received at 75993 <at> debbugs.gnu.org (full text, mbox):
> So why don't we make `diff-mode` inherit from `special-mode`?
Because it doesn't allow self-inserting keys in editable mode.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#75993
; Package
emacs
.
(Sun, 09 Feb 2025 07:45:02 GMT)
Full text and
rfc822 format available.
Message #41 received at 75993 <at> debbugs.gnu.org (full text, mbox):
close 75993 31.0.50
thanks
>> So why don't we make `diff-mode` inherit from `special-mode`?
>
> Because it doesn't allow self-inserting keys in editable mode.
Ok, so now pushed. The only problem was dependence of
view-mode activation on the symbol property with unrelated name
that is quite confusing.
bug marked as fixed in version 31.0.50, send any further explanations to
75993 <at> debbugs.gnu.org and Juri Linkov <juri <at> linkov.net>
Request was from
Juri Linkov <juri <at> linkov.net>
to
control <at> debbugs.gnu.org
.
(Sun, 09 Feb 2025 07:46:01 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sun, 09 Mar 2025 11:24:14 GMT)
Full text and
rfc822 format available.
This bug report was last modified 103 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.