diff options
| -rw-r--r-- | corfu.el | 21 |
1 files changed, 19 insertions, 2 deletions
@@ -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 () |
