Disable filtering of commands in M-x completion
This makes the default behavior like it was before: M-x completion doesn't filter out any commands. To have commands filtered based on their relevance to the current buffer's modes, customize the option 'read-extended-command-predicate' to call 'command-completion-default-include-p'. * doc/lispref/commands.texi (Interactive Call): * doc/emacs/m-x.texi (M-x): Update the description of 'read-extended-command-predicate' and improve wording. * etc/NEWS: Update the entry about 'read-extended-command-predicate'. * lisp/simple.el (read-extended-command-predicate): Change default value to nil. Update doc string. Add :group. (read-extended-command): Handle nil as meaning to apply no-filtering.
This commit is contained in:
parent
0324ec1737
commit
927b88571c
4 changed files with 37 additions and 25 deletions
|
@ -46,9 +46,17 @@ from running the command by name.
|
|||
@cindex obsolete command
|
||||
When @kbd{M-x} completes on commands, it ignores the commands that
|
||||
are declared @dfn{obsolete}; for these, you will have to type their
|
||||
full name. Obsolete commands are those for which newer, better
|
||||
full name. (Obsolete commands are those for which newer, better
|
||||
alternatives exist, and which are slated for removal in some future
|
||||
Emacs release.
|
||||
Emacs release.)
|
||||
|
||||
@vindex read-extended-command-predicate
|
||||
In addition, @kbd{M-x} completion can exclude commands that are not
|
||||
relevant to, and generally cannot work with, the current buffer's
|
||||
major mode (@pxref{Major Modes}) and minor modes (@pxref{Minor
|
||||
Modes}). By default, no commands are excluded, but you can customize
|
||||
the option @var{read-extended-command-predicate} to exclude those
|
||||
irrelevant commands from completion results.
|
||||
|
||||
To cancel the @kbd{M-x} and not run a command, type @kbd{C-g} instead
|
||||
of entering the command name. This takes you back to command level.
|
||||
|
@ -94,8 +102,3 @@ the command is followed by arguments.
|
|||
@kbd{M-x} works by running the command
|
||||
@code{execute-extended-command}, which is responsible for reading the
|
||||
name of another command and invoking it.
|
||||
|
||||
@vindex read-extended-command-predicate
|
||||
This command heeds the @code{read-extended-command-predicate}
|
||||
variable, which will (by default) filter out commands that are not
|
||||
applicable to the current major mode (or enabled minor modes).
|
||||
|
|
|
@ -776,12 +776,16 @@ part of the prompt.
|
|||
|
||||
@vindex read-extended-command-predicate
|
||||
This command heeds the @code{read-extended-command-predicate}
|
||||
variable, which will (by default) filter out commands that are not
|
||||
applicable to the current major mode (or enabled minor modes).
|
||||
@code{read-extended-command-predicate} will be called with two
|
||||
parameters: The symbol that is to be included or not, and the current
|
||||
buffer. If should return non-@code{nil} if the command is to be
|
||||
included when completing.
|
||||
variable, which can filter out commands that are not applicable to the
|
||||
current major mode (or enabled minor modes). By default, the value of
|
||||
this variable is @code{nil}, and no commands are filtered out.
|
||||
However, customizing it to invoke the function
|
||||
@code{command-completion-default-include-p} will perform
|
||||
mode-dependent filtering. @code{read-extended-command-predicate} can
|
||||
be any predicate function; it will be called with two parameters: the
|
||||
command's symbol and the current buffer. If should return
|
||||
non-@code{nil} if the command is to be included when completing in
|
||||
that buffer.
|
||||
@end deffn
|
||||
|
||||
@node Distinguish Interactive
|
||||
|
|
8
etc/NEWS
8
etc/NEWS
|
@ -253,9 +253,11 @@ commands. The new keystrokes are 'C-x x g' ('revert-buffer'),
|
|||
|
||||
+++
|
||||
** New user option 'read-extended-command-predicate'.
|
||||
This option controls how 'M-x TAB' performs completions. The default
|
||||
predicate excludes commands that are not applicable to the current
|
||||
major and minor modes, and also respects the command's completion
|
||||
This option controls how 'M-x' performs completion of commands when
|
||||
you type TAB. By default, any command that matches what you have
|
||||
typed is considered a completion candidate, but you can customize this
|
||||
option to exclude commands that are not applicable to the current
|
||||
buffer's major and minor modes, and respect the command's completion
|
||||
predicate (if any).
|
||||
|
||||
---
|
||||
|
|
|
@ -1904,17 +1904,18 @@ to get different commands to edit and resubmit."
|
|||
(defvar extended-command-history nil)
|
||||
(defvar execute-extended-command--last-typed nil)
|
||||
|
||||
(defcustom read-extended-command-predicate
|
||||
#'command-completion-default-include-p
|
||||
(defcustom read-extended-command-predicate nil
|
||||
"Predicate to use to determine which commands to include when completing.
|
||||
The predicate function is called with two parameters: The
|
||||
symbol (i.e., command) in question that should be included or
|
||||
not, and the current buffer. The predicate should return non-nil
|
||||
if the command should be present when doing `M-x TAB'."
|
||||
If it's nil, include all the commands.
|
||||
If it's a functoion, it will be called with two parameters: the
|
||||
symbol of the command and a buffer. The predicate should return
|
||||
non-nil if the command should be present when doing `M-x TAB'
|
||||
in that buffer."
|
||||
:version "28.1"
|
||||
:type `(choice (const :tag "Exclude commands not relevant to the current mode"
|
||||
:group 'completion
|
||||
:type `(choice (const :tag "Don't exclude any commands" nil)
|
||||
(const :tag "Exclude commands irrelevant to current buffer's mode"
|
||||
command-completion-default-include-p)
|
||||
(const :tag "All commands" ,(lambda (_s _b) t))
|
||||
(function :tag "Other function")))
|
||||
|
||||
(defun read-extended-command ()
|
||||
|
@ -1971,7 +1972,9 @@ This function uses the `read-extended-command-predicate' user option."
|
|||
(complete-with-action action obarray string pred)))
|
||||
(lambda (sym)
|
||||
(and (commandp sym)
|
||||
(funcall read-extended-command-predicate sym buffer)))
|
||||
(or (null read-extended-command-predicate)
|
||||
(and (functionp read-extended-command-predicate)
|
||||
(funcall read-extended-command-predicate sym buffer)))))
|
||||
t nil 'extended-command-history))))
|
||||
|
||||
(defun command-completion-default-include-p (symbol buffer)
|
||||
|
|
Loading…
Add table
Reference in a new issue