diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2021-07-21 14:47:05 +0200 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2021-07-21 14:47:05 +0200 |
| commit | 6e4164ff49a85e3d1f55210636d8df3314b11ada (patch) | |
| tree | 54b96e837b65596488dfdada1ac5d910d07f09b5 | |
| parent | cb059a4f858c8fb213e944acb33a47917c8f7365 (diff) | |
Expose corfu-auto-commands and corfu-continue-commands
| -rw-r--r-- | corfu.el | 40 |
1 files changed, 23 insertions, 17 deletions
@@ -59,6 +59,12 @@ "Enable cycling for `corfu-next' and `corfu-previous'." :type 'boolean) +(defcustom corfu-continue-commands + ;; nil is undefined command + '(nil completion-at-point "corfu-.*" "scroll-other-window.*") + "Continue Corfu completion after executing these commands." + :type '(repeat (choice regexp symbol))) + (defcustom corfu-commit-predicate t "Automatically commit the selected candidate if the predicate returns t." :type '(choice (const nil) (const t) 'function)) @@ -93,6 +99,11 @@ filter string with spaces is allowed." "Delay for auto completion." :type 'float) +(defcustom corfu-auto-commands + '(".*self-insert-command") + "Commands which initiate auto completion." + :type '(repeat (choice regexp symbol))) + (defcustom corfu-auto nil "Enable auto completion." :type 'boolean) @@ -185,15 +196,6 @@ filter string with spaces is allowed." (defvar corfu--frame nil "Popup frame.") -(defvar corfu--auto-commands - "\\`\\(.*self-insert-command\\)\\'" - "Commands which initiate auto completion.") - -(defvar corfu--continue-commands - ;; nil is undefined command - "\\`\\(nil\\|completion-at-point\\|corfu-.*\\|scroll-other-window.*\\)\\'" - "Continue Corfu completion after executing commands matching this regexp.") - (defconst corfu--state-vars '(corfu--base corfu--candidates @@ -499,10 +501,14 @@ filter string with spaces is allowed." corfu--total total corfu--highlight hl)))) -(defun corfu--continue-p () - "Return t if the Corfu popup should stay alive." - (and (symbolp this-command) - (string-match-p corfu--continue-commands (symbol-name this-command)))) +(defun corfu--match-symbol-p (pattern sym) + "Return non-nil if SYM is matching an element of the PATTERN list." + (and (symbolp sym) + (seq-some (lambda (x) + (if (symbolp x) + (eq sym x) + (string-match-p (format "\\`%s\\'" x) (symbol-name sym)))) + pattern))) (defun corfu-quit () "Quit Corfu completion." @@ -589,7 +595,8 @@ filter string with spaces is allowed." nil) ((and corfu--candidates ;; 2) There exist candidates (not (equal corfu--candidates (list str))) ;; & Not a sole exactly matching candidate - (or (/= beg end) (corfu--continue-p))) ;; & Input is non-empty or continue command + (or (/= beg end) ;; & Input is non-empty or continue command + (corfu--match-symbol-p corfu-continue-commands this-command))) (corfu--show-candidates beg end str metadata) ;; => Show candidates popup t) ;; 3) When after `completion-at-point/corfu-complete', no further completion is possible and the @@ -609,7 +616,7 @@ filter string with spaces is allowed." (defun corfu--pre-command () "Insert selected candidate unless command is marked to continue completion." (add-hook 'window-configuration-change-hook #'corfu--popup-hide) - (unless (or (< corfu--index 0) (corfu--continue-p)) + (unless (or (< corfu--index 0) (corfu--match-symbol-p corfu-continue-commands this-command)) (if (if (functionp corfu-commit-predicate) (funcall corfu-commit-predicate) corfu-commit-predicate) @@ -833,8 +840,7 @@ filter string with spaces is allowed." (setq corfu--auto-timer nil)) (when (and (not completion-in-region-mode) (display-graphic-p) - (symbolp this-command) - (string-match-p corfu--auto-commands (symbol-name this-command))) + (corfu--match-symbol-p corfu-auto-commands this-command)) (setq corfu--auto-timer (run-with-idle-timer corfu-auto-delay nil #'corfu--auto-complete (current-buffer))))) |
