[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 6ea920c: Allow overriding declared predicates, too
From: |
Lars Ingebrigtsen |
Subject: |
master 6ea920c: Allow overriding declared predicates, too |
Date: |
Mon, 15 Feb 2021 08:44:05 -0500 (EST) |
branch: master
commit 6ea920c88d7705e7b09571819d3948efd2e53109
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Allow overriding declared predicates, too
* lisp/simple.el (completion-default-include-p): Rename and move
the checking for an explicit predicate down here...
(read-extended-command): ... from here.
(read-extended-command-predicate): Adjust default value.
---
lisp/simple.el | 60 ++++++++++++++++++++++++++++++----------------------------
1 file changed, 31 insertions(+), 29 deletions(-)
diff --git a/lisp/simple.el b/lisp/simple.el
index aafbb3e..8a9f46c 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1904,15 +1904,15 @@ 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 #'completion-in-mode-p
+(defcustom read-extended-command-predicate #'completion-default-include-p
"Predicate to use to determine which commands to include when completing.
The predicate function is called with two parameter: 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'."
:version "28.1"
- :type '(choice (const :tag "Exclude commands not relevant to this mode"
- #'completion-in-mode-p)
+ :type '(choice (const :tag "Exclude commands not relevant to the current
mode"
+ #'completion-default-include-p)
(const :tag "All commands" (lambda (_ _) t))
(function :tag "Other function")))
@@ -1970,35 +1970,37 @@ This function uses the
`read-extended-command-predicate' user option."
(complete-with-action action obarray string pred)))
(lambda (sym)
(and (commandp sym)
- ;;; FIXME: This should also be possible to disable by
- ;;; the user, but I'm not quite sure what the right
- ;;; design for that would look like.
- (if (get sym 'completion-predicate)
- (funcall (get sym 'completion-predicate) sym buffer)
- (funcall read-extended-command-predicate sym buffer))))
+ (funcall read-extended-command-predicate sym buffer)))
t nil 'extended-command-history))))
-(defun completion-in-mode-p (symbol buffer)
+(defun completion-default-include-p (symbol buffer)
"Say whether SYMBOL should be offered as a completion.
-This is true if the command is applicable to the major mode in
-BUFFER, or any of the active minor modes in BUFFER."
- (let ((modes (command-modes symbol)))
- (or (null modes)
- ;; Common case: Just a single mode.
- (if (null (cdr modes))
- (or (provided-mode-derived-p
- (buffer-local-value 'major-mode buffer) (car modes))
- (memq (car modes)
- (buffer-local-value 'local-minor-modes buffer))
- (memq (car modes) global-minor-modes))
- ;; Uncommon case: Multiple modes.
- (apply #'provided-mode-derived-p
- (buffer-local-value 'major-mode buffer)
- modes)
- (seq-intersection modes
- (buffer-local-value 'local-minor-modes buffer)
- #'eq)
- (seq-intersection modes global-minor-modes #'eq)))))
+If there's a `completion-predicate' for SYMBOL, the result from
+calling that predicate is called. If there isn't one, this
+predicate is true if the command SYMBOL is applicable to the
+major mode in BUFFER, or any of the active minor modes in
+BUFFER."
+ (if (get symbol 'completion-predicate)
+ ;; An explicit completion predicate takes precedence.
+ (funcall (get symbol 'completion-predicate) symbol buffer)
+ ;; Check the modes.
+ (let ((modes (command-modes symbol)))
+ (or (null modes)
+ ;; Common case: Just a single mode.
+ (if (null (cdr modes))
+ (or (provided-mode-derived-p
+ (buffer-local-value 'major-mode buffer) (car modes))
+ (memq (car modes)
+ (buffer-local-value 'local-minor-modes buffer))
+ (memq (car modes) global-minor-modes))
+ ;; Uncommon case: Multiple modes.
+ (apply #'provided-mode-derived-p
+ (buffer-local-value 'major-mode buffer)
+ modes)
+ (seq-intersection modes
+ (buffer-local-value 'local-minor-modes buffer)
+ #'eq)
+ (seq-intersection modes global-minor-modes #'eq))))))
(defun completion-with-modes-p (modes buffer)
"Say whether MODES are in action in BUFFER.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 6ea920c: Allow overriding declared predicates, too,
Lars Ingebrigtsen <=