emacs-diffs
[Top][All Lists]
Advanced

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

master 927b885 1/3: Disable filtering of commands in M-x completion


From: Eli Zaretskii
Subject: master 927b885 1/3: Disable filtering of commands in M-x completion
Date: Wed, 17 Feb 2021 11:59:45 -0500 (EST)

branch: master
commit 927b88571cebb4f64aca360fbfa5d15a1f922ad6
Author: Eli Zaretskii <eliz@gnu.org>
Commit: Eli Zaretskii <eliz@gnu.org>

    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.
---
 doc/emacs/m-x.texi        | 17 ++++++++++-------
 doc/lispref/commands.texi | 16 ++++++++++------
 etc/NEWS                  |  8 +++++---
 lisp/simple.el            | 21 ++++++++++++---------
 4 files changed, 37 insertions(+), 25 deletions(-)

diff --git a/doc/emacs/m-x.texi b/doc/emacs/m-x.texi
index 689125e..b877098 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 b3bcdf3..cd30fb1 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 b38865d..3bef739 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 248d044..e54cbed 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)



reply via email to

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