emacs-devel
[Top][All Lists]
Advanced

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

Smarter M-x that filters on major-mode


From: Stefan Kangas
Subject: Smarter M-x that filters on major-mode
Date: Wed, 10 Feb 2021 20:50:10 -0600

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Matt Armstrong <matt@rfc20.org> writes:
>
>> What if instead help showed all the interactive commands provided by
>> the mode? What if M-x were smarter about highlighting mode specific
>> commands?
>
> It's been discussed before -- somebody just has to implement one of the
> various possibilities here.  The problem is that commands are only tied
> very loosely to modes:
>
> (defun foo-thing ()
>   (interactive)
>   ...)
>
> will make `M-x fTAB' show `foo-thing' even if it's useless outside of
> all other modes than `foo-mode'.  Conversely, `C-h m' in `foo-mode'
> won't, as you mention, list `foo-thing' unless there's a binding for it.
>
> My suggestion is to introduce a new form:
>
> (defun foo-thing ()
>   (command foo-mode)
>   ...)
>
> This would be just like `interactive', but will do the right thing in
> `M-x fTAB' and `C-h m' in modes derived from `foo-mode'.  (It could also
> be a list of mode, of course, but that'd be more rare, is my guess.)

It would indeed be very useful to provide a mechanism to exclude
commands from M-x that are useless outside of their major mode.

I've had a related idea to make `M-X' (a.k.a. `M-S-x') run a version of
`M-x' that *includes* only commands that are specifically relevant to
the current major mode.  This would be used when I specifically want to
do something in my major mode, as opposed to looking at the gazillion
different entry points for things like calendar, gnus, or tetris.

I only just now discovered that my completion framework (ivy) has had
the exact same idea for M-S-x.  It filters all commands according to
some heuristics, seemingly only showing commands beginning with whatever
package prefix your mode is using.  It is not perfect, as it seems to
show commands not relevant to the current major mode, if they share the
prefix.  For example, when replying to emails I'm in
notmuch-message-mode and don't need to see commands used for navigating
my list of emails (notmuch-search-mode).

Anyways, these are just my thoughts.  I would encourage anyone to start
working on this.  The blacklisting for normal M-x discussed by Lars
above seems like a good starting point.



reply via email to

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