[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to define a (derived) minor mode inaccessible to the user
From: |
Stefan Monnier |
Subject: |
Re: How to define a (derived) minor mode inaccessible to the user |
Date: |
Fri, 22 Jan 2021 09:19:06 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
> I'd like to define a special-purpose major mode, derived from
> `special-mode', in such a way that the user cannot set it using M-x.
Can you explain why?
> (It is to be called via another command.)
That doesn't explain why it would be harmful to also expose the actual
major mode command.
E.g. You can do `M-x comint-mode` even though it likely won't do you
much good since `comint-mode` needs to be used together with a process
and is hence normally enabled by the command that launches the process.
> It seems that `define-derived-mode' always sets the mode as
> `interactive'.
Indeed.
> M-: (symbol-plist 'my--mode)
> expecting an `interactive-form' entry on the plist
The `interactive-form` property is virtually never used. Instead, the
interactive form is traditionally stored within the function.
If you *really* care about hiding the major mode from the user
I suggest you use an "obscure" or "scary" name.
> What's going on? Is it possible to define a (derived) major mode so
> that it can't be called interactively?
Of course it is:
(define-derived-mode my-mode "My" "My doc.")
(defconst my-mode (symbol-function 'my-mode))
(fmakunbound 'my-mode)
and then you can enable the mode with `(funcall my-mode)`.
Stefan
Re: How to define a (derived) minor mode inaccessible to the user, Michael Heerdegen, 2021/01/23