From: Lars Ingebrigtsen Date: Mon, 15 Feb 2021 13:43:53 +0000 (+0100) Subject: Allow overriding declared predicates, too X-Git-Tag: emacs-28.0.90~3717 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=6ea920c88d7705e7b09571819d3948efd2e53109;p=emacs.git 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. --- diff --git a/lisp/simple.el b/lisp/simple.el index aafbb3e1f88..8a9f46cef6c 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.