unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Marcin Borkowski <mbork@mbork.pl>
Cc: help-gnu-emacs@gnu.org
Subject: Re: How to define a (derived) minor mode inaccessible to the user
Date: Fri, 22 Jan 2021 10:38:15 -0500	[thread overview]
Message-ID: <jwvv9bpro14.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <875z3pknav.fsf@mbork.pl> (Marcin Borkowski's message of "Fri, 22 Jan 2021 16:23:52 +0100")

>> The `interactive-form` property is virtually never used.  Instead, the
>> interactive form is traditionally stored within the function.
> So how does `execute-extended-command' know what to list, then?

You can use `commandp` to know if it's got an interactive form or not,
and `interactive-form` (the function) to extract it from a function.

> A cursory look told me that it uses `read-extended-command', which uses
> `commandp'.  So, how does `commandp' know?  (I'm not well versed in C,
> but do I guess correctly that it checks the `interactive-form' property,
> and if nil, it (somehow) looks for `(interactive ...)' in its
> definition?)

Pretty much, yes (with the extra handling for the cases where the
function is not a `(lambda ...)` list but a byte-compiled object, or an
autoloaded function, or a function implemented in C).

>> If you *really* care about hiding the major mode from the user
>> I suggest you use an "obscure" or "scary" name.
> Well, the convention is to use two dashes, but how can the end-user (not
> knowing Elisp and the conventions) know that?

That's indeed the convention for functions.  For commands we don't
really have a convention for "commands that should be hidden from `M-x".
We used to prevent completion from revealing obsolete commands.
It's been reverted recently (to my disappointment), but we could add
a similar feature for "commands not to be used via M-x" (could be used
for those commands that only work when bound to a mouse event, for
example).

Maybe `smex` offers something like that.  When I rewrote
`execute-extended-command' into Elisp, I hoped that it would encourage
people to hack on it and add features to it (like this one), but sadly
it doesn't seem to have had much effect of this kind so far.

We could add some property that holds a predicate function which
`execute-extended-command' could use to filter out commands which can't
be used in the current context (e.g. the predicate could check the
major mode, for those commands which only work in a given major mode).

> So, basically you move the function definition from the function cell to
> the value cell of `my-mode', right?  Clever!  Is it actually used
> anywhere in Emacs?

No, and I don't recommend it.
E.g `C-h m` will then fail to show the proper docstring of the major mode.


        Stefan




  reply	other threads:[~2021-01-22 15:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-22  5:11 How to define a (derived) minor mode inaccessible to the user Marcin Borkowski
2021-01-22  5:34 ` [External] : " Drew Adams
2021-01-22 15:01   ` Marcin Borkowski
2021-01-22 14:19 ` Stefan Monnier
2021-01-22 15:23   ` Marcin Borkowski
2021-01-22 15:38     ` Stefan Monnier [this message]
2021-01-28  7:42       ` Marcin Borkowski
2021-01-28 14:31         ` Stefan Monnier
2021-01-23 13:08 ` Michael Heerdegen
2021-01-28  7:45   ` Marcin Borkowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvv9bpro14.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=help-gnu-emacs@gnu.org \
    --cc=mbork@mbork.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).