branch: externals/corfu commit 7f5dacb340f0ec3f069744a76b3021b055ac98ed Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
Simplifications --- corfu.el | 72 ++++++++++++++++++++++++++++------------------------------------ 1 file changed, 31 insertions(+), 41 deletions(-) diff --git a/corfu.el b/corfu.el index 740194886e..e9b759a5e5 100644 --- a/corfu.el +++ b/corfu.el @@ -131,21 +131,15 @@ separator: Only stay alive if there is no match and "Width of the bar in units of the character width." :type 'float) -(defcustom corfu-echo-documentation '(1.0 0.2) +(defcustom corfu-echo-documentation '(1.0 . 0.2) "Show documentation string in the echo area after that number of seconds. -Set to nil to disable docsig, or t to echo immediately on -selecting a new candidate. Can also be a 2-element list of -floats (or t) to specify initial and seubsequent delay." +Set to nil to disable. The value can be a pair of two floats to specify +initial and subsequent delay." :type '(choice (const :tag "Never" nil) - (const :tag "Instant" t) - (number :tag "Delay [sec]") - (list :tag "Two Delays" - (choice :tag "Initial " - (const :tag "Instant" t) - (number :tag "Delay [sec]")) - (choice :tag "Subsequent" - (const :tag "Instant" t) - (number :tag "Delay [sec]"))))) + (number :tag "Delay in seconds") + (cons :tag "Two Delays" + (choice :tag "Initial " number)) + (choice :tag "Subsequent" number))) (defcustom corfu-margin-formatters nil "Registry for margin formatter functions. @@ -254,9 +248,6 @@ The completion backend can override this with (defvar corfu--auto-timer nil "Auto completion timer.") -(defvar-local corfu--initial t - "Whether on the initial update.") - (defvar-local corfu--candidates nil "List of candidates.") @@ -304,7 +295,6 @@ The completion backend can override this with (defconst corfu--state-vars '(corfu--base - corfu--initial corfu--candidates corfu--highlight corfu--index @@ -788,33 +778,34 @@ there hasn't been any input, then quit." (when corfu--echo-timer (cancel-timer corfu--echo-timer) (setq corfu--echo-timer nil)) - (when corfu--echo-message - (corfu--echo-show corfu--echo-message))) + (corfu--echo-show corfu--echo-message)) -(defun corfu--echo-show (msg) +(defun corfu--echo-show (&optional msg) "Show MSG in echo area." - (setq corfu--echo-message msg) - (corfu--message "%s" (if (text-property-not-all 0 (length msg) 'face nil msg) - msg - (propertize msg 'face 'corfu-echo)))) - -(defun corfu--echo-call-show (fun cand) - (corfu--echo-show (funcall fun cand))) + (when (or msg corfu--echo-message) + (setq msg (or msg "") + corfu--echo-message msg) + (corfu--message "%s" (if (text-property-not-all 0 (length msg) 'face nil msg) + msg + (propertize msg 'face 'corfu-echo))))) (defun corfu--echo-documentation () "Show documentation string of current candidate in echo area." - (if-let* ((delay (if (consp corfu-echo-documentation) - (nth (if corfu--initial 0 1) corfu-echo-documentation) - corfu-echo-documentation)) - (fun (plist-get corfu--extra :company-docsig)) - (cand (and (>= corfu--index 0) - (nth corfu--index corfu--candidates)))) - (if (eq delay t) ; immediate - (corfu--echo-show (funcall fun cand)) - (when corfu--echo-timer (cancel-timer corfu--echo-timer)) - (setq corfu--echo-timer - (run-at-time delay nil #'corfu--echo-call-show fun cand)) - (when corfu--echo-message (corfu--echo-show ""))))) + (when-let* ((delay (if (consp corfu-echo-documentation) + (funcall (if corfu--echo-message #'cdr #'car) + corfu-echo-documentation) + corfu-echo-documentation)) + (fun (plist-get corfu--extra :company-docsig)) + (cand (and (>= corfu--index 0) + (nth corfu--index corfu--candidates)))) + (if (<= delay 0) + (corfu--echo-show (funcall fun cand)) + (when corfu--echo-timer (cancel-timer corfu--echo-timer)) + (setq corfu--echo-timer + (run-at-time delay nil + (lambda () + (corfu--echo-show (funcall fun cand))))))) + (corfu--echo-show)) (defun corfu--update () "Refresh Corfu UI." @@ -852,7 +843,6 @@ there hasn't been any input, then quit." (corfu--candidates-popup beg) (corfu--preview-current beg end str) (corfu--echo-documentation) - (setq corfu--initial nil) (redisplay 'force)) ;; XXX HACK Ensure that popup is redisplayed ;; 4) There are no candidates & corfu-quit-no-match => Confirmation popup. ((and (not corfu--candidates) @@ -1091,7 +1081,7 @@ there hasn't been any input, then quit." (remove-hook 'post-command-hook #'corfu--post-command) (when corfu--preview-ov (delete-overlay corfu--preview-ov)) (when corfu--echo-timer (cancel-timer corfu--echo-timer)) - (when corfu--echo-message (corfu--echo-show "")) + (corfu--echo-show) (accept-change-group corfu--change-group) (mapc #'kill-local-variable corfu--state-vars))