help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: How to make M-x TAB not work on (interactive) declaration?


From: Tassilo Horn
Subject: Re: How to make M-x TAB not work on (interactive) declaration?
Date: Sun, 08 Jan 2023 09:34:28 +0100
User-agent: mu4e 1.9.12; emacs 30.0.50

Jean Louis <bugs@gnu.support> writes:

Hi Jean,

> Reference:
> (describe-function 'interactive)
>
> If MODES is present, it should be a list of mode names (symbols) that
> this command is applicable for.  The main effect of this is that ‘M-x
> TAB’ (by default) won’t list this command if the current buffer’s mode
> doesn’t match the list.  That is, if either the major mode isn’t
> derived from them, or (when it’s a minor mode) the mode isn’t in
> effect.

MODES is a &rest argument and the mode symbols shouldn't be quoted, so
you use it like so:

(defun my-function ()
  (interactive nil text-mode some-other-mode)
  (message "Hello"))

> For this example here I can still see it in M-x TAB expansion in any
> mode.

You also have to set

(setq read-extended-command-predicate
      #'command-completion-default-include-p)

I've added that to my init.el when the feature was built, see the info
docs at (info "(emacs) M-x"):

--8<---------------cut here---------------start------------->8---
   In addition, ‘M-x’ completion can exclude commands that are not
relevant to, and generally cannot work with, the current buffer’s major
mode (*note Major Modes::) and minor modes (*note Minor Modes::).  By
default, no commands are excluded, but you can customize the option
‘read-extended-command-predicate’ to exclude those irrelevant commands
from completion results.
--8<---------------cut here---------------end--------------->8---

You are right that this is feature is probably not documented good
enough.  It seems `command-completion-default-include-p' isn't
documented at all (but customize knows about it) and the `interactive'
docstring is missing references to that and
`read-extended-command-predicate', too.  I'd suggest to write a bug
report.

Bye,
Tassilo



reply via email to

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