Subject: bug#75993: Special mode-class for diff-mode

From: Juri Linkov <[email-masked]>
Date: Tue, 04 Feb 2025 21:37:32 +0200

>>>> 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.