From: Eli Zaretskii Date: Wed, 17 Feb 2021 16:53:54 +0000 (+0200) Subject: Disable filtering of commands in M-x completion X-Git-Tag: emacs-28.0.90~3684 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=927b88571cebb4f64aca360fbfa5d15a1f922ad6;p=emacs.git 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. --- diff --git a/doc/emacs/m-x.texi b/doc/emacs/m-x.texi index 689125e7b4a..b8770982c5e 100644 --- a/doc/emacs/m-x.texi +++ b/doc/emacs/m-x.texi @@ -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). diff --git a/doc/lispref/commands.texi b/doc/lispref/commands.texi index b3bcdf35c9f..cd30fb19ee2 100644 --- a/doc/lispref/commands.texi +++ b/doc/lispref/commands.texi @@ -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 diff --git a/etc/NEWS b/etc/NEWS index b38865dd271..3bef7399fa8 100644 --- a/etc/NEWS +++ b/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). --- diff --git a/lisp/simple.el b/lisp/simple.el index 248d044b19c..e54cbed7a76 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -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)