summaryrefslogtreecommitdiff
path: root/corfu.el
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2026-01-05 13:05:26 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2026-01-05 13:05:26 +0100
commit037d756a861e138fa622e4dd1a4dd61a815fffd3 (patch)
treee44f2142fdf8356373d0786193e69f70359e3474 /corfu.el
parenta86c73f69275ef31472c3c2e89930e8500e247f8 (diff)
Move auto completion code to corfu-auto.el
Diffstat (limited to 'corfu.el')
-rw-r--r--corfu.el83
1 files changed, 4 insertions, 79 deletions
diff --git a/corfu.el b/corfu.el
index 7e9dd18..00f1ea0 100644
--- a/corfu.el
+++ b/corfu.el
@@ -171,35 +171,6 @@ This function is used even if a completion table specifies its
own sort function."
:type '(choice (const nil) function))
-(defcustom corfu-auto-trigger ""
- "Characters which trigger auto completion.
-If a trigger character is detected `corfu-auto-prefix' is ignored."
- :type 'string)
-
-(defcustom corfu-auto-prefix 3
- "Minimum length of prefix for auto completion.
-The completion backend can override this with :company-prefix-length.
-It is not recommended to use a small prefix length (below 2), since this
-will create high load for Emacs. See also `corfu-auto-delay' and
-`corfu-auto-trigger'."
- :type 'natnum)
-
-(defcustom corfu-auto-delay 0.2
- "Delay for auto completion.
-It is not recommended to use a short delay or even 0, since this will
-create high load for Emacs, in particular if executing the completion
-backend is costly. Instead of reducing the delay too much, try
-`corfu-auto-trigger' to trigger immediate completion after certain
-characters."
- :type 'float)
-
-(defcustom corfu-auto-commands
- '("self-insert-command\\'" "delete-backward-char\\'" "\\`backward-delete-char"
- c-electric-colon c-electric-lt-gt c-electric-slash c-scope-operator)
- "Commands which initiate auto completion.
-The list can contain either command symbols or regular expressions."
- :type '(repeat (choice regexp symbol)))
-
(defcustom corfu-auto nil
"Enable auto completion.
Auto completion is disabled by default for safety and unobtrusiveness.
@@ -277,9 +248,6 @@ settings `corfu-auto-delay', `corfu-auto-prefix' and
"M-h" 'corfu-info-documentation
"M-SPC" #'corfu-insert-separator)
-(defvar corfu--auto-timer (timer-create)
- "Auto completion timer.")
-
(defvar corfu--candidates nil
"List of candidates.")
@@ -1051,51 +1019,6 @@ See `completion-in-region' for the arguments BEG, END, TABLE, PRED."
(define-key map (vector last-command-event) replace)
(funcall replace)))
-(defun corfu--auto-complete-deferred (&optional tick)
- "Initiate auto completion if TICK did not change."
- (corfu--protect
- (lambda ()
- (when (and (not completion-in-region-mode)
- (or (not tick) (equal tick (corfu--auto-tick))))
- (pcase (while-no-input ;; Interruptible Capf query
- (run-hook-wrapped
- 'completion-at-point-functions
- #'corfu--capf-wrapper corfu-auto-prefix corfu-auto-trigger))
- (`(,fun ,beg ,end ,table . ,plist)
- (let ((completion-in-region-mode-predicate
- (lambda ()
- (when-let* ((newbeg (car-safe (funcall fun))))
- (= newbeg beg))))
- (completion-extra-properties plist))
- (corfu--setup beg end table (plist-get plist :predicate))
- (corfu--exhibit 'auto))))))))
-
-(defun corfu--auto-post-command ()
- "Post command hook which initiates auto completion."
- (corfu--protect
- (lambda ()
- (cancel-timer corfu--auto-timer)
- (when (and (not completion-in-region-mode)
- (not defining-kbd-macro)
- (not buffer-read-only)
- (corfu--match-symbol-p corfu-auto-commands this-command)
- (corfu--popup-support-p))
- (if (or (<= corfu-auto-delay 0)
- (seq-contains-p corfu-auto-trigger last-command-event))
- (corfu--auto-complete-deferred)
- ;; Do not use `timer-set-idle-time' since this leads to
- ;; unpredictable pauses, in particular with `flyspell-mode'.
- (timer-set-time corfu--auto-timer
- (timer-relative-time nil corfu-auto-delay))
- (timer-set-function corfu--auto-timer #'corfu--auto-complete-deferred
- (list (corfu--auto-tick)))
- (timer-activate corfu--auto-timer))))))
-
-(defun corfu--auto-tick ()
- "Return the current tick/status of the buffer.
-Auto completion is only performed if the tick did not change."
- (list (selected-window) (current-buffer) (buffer-chars-modified-tick) (point)))
-
(cl-defgeneric corfu--popup-show (pos off width lines &optional curr lo bar)
"Show LINES as popup at POS - OFF.
WIDTH is the width of the popup.
@@ -1455,10 +1378,12 @@ Quit if no candidate is selected."
:group 'corfu :keymap corfu-mode-map
(cond
(corfu-mode
- (and corfu-auto (add-hook 'post-command-hook #'corfu--auto-post-command 100 'local))
+ (when corfu-auto
+ (require 'corfu-auto)
+ (add-hook 'post-command-hook 'corfu-auto--post-command 100 'local))
(setq-local completion-in-region-function #'corfu--in-region))
(t
- (remove-hook 'post-command-hook #'corfu--auto-post-command 'local)
+ (remove-hook 'post-command-hook 'corfu-auto--post-command 'local)
(kill-local-variable 'completion-in-region-function))))
(defcustom global-corfu-minibuffer t