summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2024-09-26 20:10:40 +0200
committerDaniel Mendler <mail@daniel-mendler.de>2024-09-26 20:10:40 +0200
commit4c5a584dcbd984b0fb8f1a5650f7ef3d03e4d940 (patch)
treeb7e471b797e3f8dab9e533cf054c885dde1d1633
parent4ccfa33026163d9fadcaf254eae1eba2f0ffaaca (diff)
global-corfu-mode: :predicate is broken on 28 and older
-rw-r--r--corfu.el21
1 files changed, 19 insertions, 2 deletions
diff --git a/corfu.el b/corfu.el
index c810738..feb6495 100644
--- a/corfu.el
+++ b/corfu.el
@@ -1347,6 +1347,16 @@ Quit if no candidate is selected."
(remove-hook 'post-command-hook #'corfu--auto-post-command 'local)
(kill-local-variable 'completion-in-region-function))))
+(defcustom global-corfu-modes t
+ "List of modes where Corfu should be enabled by `global-corfu-mode'.
+The variable can either be t, nil or a list of t, nil, mode
+symbols or elements of the form (not modes). Examples:
+ - Enable everywhere, except in Org: ((not org-mode) t).
+ - Enable in programming modes except Python: ((not python-mode) prog-mode).
+ - Enable only in text modes: (text-mode)."
+ :type '(choice (const t) (repeat sexp)))
+
+;; TODO use `:predicate' on Emacs 29
(defcustom global-corfu-minibuffer t
"Corfu should be enabled in the minibuffer by `global-corfu-mode'.
The variable can either be t, nil or a custom predicate function. If
@@ -1357,7 +1367,6 @@ local `completion-at-point-functions'."
;;;###autoload
(define-globalized-minor-mode global-corfu-mode
corfu-mode corfu--on
- :predicate t
:group 'corfu
(remove-hook 'minibuffer-setup-hook #'corfu--minibuffer-on)
(when (and global-corfu-mode global-corfu-minibuffer)
@@ -1365,7 +1374,15 @@ local `completion-at-point-functions'."
(defun corfu--on ()
"Enable `corfu-mode' in the current buffer respecting `global-corfu-modes'."
- (unless (or noninteractive (eq (aref (buffer-name) 0) ?\s))
+ (when (and (not noninteractive) (not (eq (aref (buffer-name) 0) ?\s))
+ ;; TODO use `:predicate' on Emacs 29
+ (or (eq t global-corfu-modes)
+ (eq t (cl-loop for p in global-corfu-modes thereis
+ (pcase-exhaustive p
+ ('t t)
+ ('nil 0)
+ ((pred symbolp) (and (derived-mode-p p) t))
+ (`(not . ,m) (and (seq-some #'derived-mode-p m) 0)))))))
(corfu-mode 1)))
(defun corfu--minibuffer-on ()