[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Possible Feature Request: Interactive and mode-names

From: Stefan Monnier
Subject: Re: Possible Feature Request: Interactive and mode-names
Date: Sat, 03 Jul 2021 00:09:44 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

T.V Raman [2021-07-02 19:36:39] wrote:
> At present (interactive) doesn't provide the ability to specify that
> what is wanted is a mode-name -- one cay declare that what is wanted
> is a functionp, commandp or symbolp. Q: should we have such a letter
> code?

No need for a letter, you can just

    (interactive (list (my-read-group-name "Foo: ")))

You just need to define `my-read-group-name`.  Sadly, there's currently
no official way to reliably get an exhaustive list of major modes and/or
of minor modes.

The best approximation for minor modes (which intends to be exhaustive
and correct) is `minor-mode-list`.

For major modes it's more tricky.  You can try looking at the
symbol-property `derived-mode-parent` as an indication that a symbol is
the name of a major mode, that's also the best approximation, but some
major modes won't have it (because they're not defined via
`define-derived-mode`) and also some of those modes don't really want to
be "outed", so the correct list will also depend on what you want to do.

> More broadly, does elisp deserve to have a  read-mode-name
> function?

Here's some code I used for a particular case (where the intent was to
write a `customize-mode` command, so I didn't care whether the mode was
major or minor and I only cared about those modes for which I could
find a matching customize group):

    (let ((completion-regexp-list '("-mode\\'"))
          (group (custom-group-of-mode major-mode)))
      (if (and group (not current-prefix-arg))
         (completing-read (format-prompt "Mode" (and group major-mode))
                          t nil nil (if group (symbol-name major-mode))))))

-- Stefan

reply via email to

[Prev in Thread] Current Thread [Next in Thread]