[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/corfu 09757e8548 2/3: Optimize frame redisplay when com
From: |
ELPA Syncer |
Subject: |
[elpa] externals/corfu 09757e8548 2/3: Optimize frame redisplay when completion is restarted |
Date: |
Sat, 2 Jul 2022 09:57:33 -0400 (EDT) |
branch: externals/corfu
commit 09757e85489592f8bf2f9b1e8087852b528f1c5b
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Optimize frame redisplay when completion is restarted
By deferring the frame hiding we can reuse the frame which is still visible
for
the subsequent completion. Before this change, the frame was made invisible
for
a split second such that one could perceive some flickering.
---
corfu.el | 54 ++++++++++++++++++++++++++++++++----------------------
1 file changed, 32 insertions(+), 22 deletions(-)
diff --git a/corfu.el b/corfu.el
index 499020c507..94fd480774 100644
--- a/corfu.el
+++ b/corfu.el
@@ -294,6 +294,9 @@ The completion backend can override this with
(defvar corfu--frame nil
"Popup frame.")
+(defvar corfu--frame-timer nil
+ "Frame hide timer.")
+
(defconst corfu--state-vars
'(corfu--base
corfu--candidates
@@ -492,21 +495,20 @@ A scroll bar is displayed from LO to LO+BAR."
str))
lines "\n"))))
+(defun corfu--hide-frame-deferred ()
+ "Deferred frame hiding."
+ (setq corfu--frame-timer nil)
+ (when (frame-live-p corfu--frame)
+ (make-frame-invisible corfu--frame)
+ (with-current-buffer (window-buffer (frame-root-window corfu--frame))
+ (let ((inhibit-modification-hooks t)
+ (inhibit-read-only t))
+ (erase-buffer)))))
+
(defun corfu--popup-hide ()
"Hide Corfu popup."
- (when (frame-live-p corfu--frame)
- (run-at-time
- 0 nil
- (lambda ()
- (when (frame-live-p corfu--frame)
- ;; Redisplay such that the input becomes immediately visible before
the popup
- ;; hiding, which is slow (Issue #48). See also corresponding
vertico#89.
- (redisplay)
- (make-frame-invisible corfu--frame)
- (with-current-buffer (window-buffer (frame-root-window corfu--frame))
- (let ((inhibit-modification-hooks t)
- (inhibit-read-only t))
- (erase-buffer))))))))
+ (when (and (frame-live-p corfu--frame) (not corfu--frame-timer))
+ (setq corfu--frame-timer (run-at-time 0 nil
#'corfu--hide-frame-deferred))))
(defun corfu--popup-support-p ()
"Return non-nil if child frames are supported."
@@ -846,6 +848,9 @@ there hasn't been any input, then quit."
(pt (- (point) beg))
(str (buffer-substring-no-properties beg end))
(initializing (not corfu--input)))
+ (when corfu--frame-timer
+ (cancel-timer corfu--frame-timer)
+ (setq corfu--frame-timer nil))
(corfu--echo-refresh)
(cond
;; XXX Guard against errors during candidate generation.
@@ -938,7 +943,8 @@ See `corfu-separator' for more details."
(funcall completion-in-region-mode--predicate))))))
(corfu--update)
t)))
- (corfu-quit)))
+ (corfu-quit))
+ (when corfu-auto (corfu--auto-post-command)))
(defun corfu--goto (index)
"Go to candidate with INDEX."
@@ -1170,10 +1176,11 @@ 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 (tick)
+(defun corfu--auto-complete-deferred (&optional tick)
"Initiate auto completion if TICK did not change."
(setq corfu--auto-timer nil)
- (when (and (not completion-in-region-mode) (equal tick (corfu--auto-tick)))
+ (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))
(`(,fun ,beg ,end ,table . ,plist)
@@ -1193,15 +1200,18 @@ See `completion-in-region' for the arguments BEG, END,
TABLE, PRED."
(when corfu--auto-timer
(cancel-timer corfu--auto-timer)
(setq corfu--auto-timer nil))
- (when (and (not defining-kbd-macro)
+ (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))
- ;; NOTE: Do not use idle timer since this leads to unacceptable slowdowns,
- ;; in particular if flyspell-mode is enabled.
- (setq corfu--auto-timer
- (run-at-time corfu-auto-delay nil
- #'corfu--auto-complete (corfu--auto-tick)))))
+ (if (<= corfu-auto-delay 0)
+ (corfu--auto-complete-deferred)
+ ;; NOTE: Do not use idle timer since this leads to unacceptable
slowdowns,
+ ;; in particular if flyspell-mode is enabled.
+ (setq corfu--auto-timer
+ (run-at-time corfu-auto-delay nil
+ #'corfu--auto-complete-deferred
(corfu--auto-tick))))))
(defun corfu--auto-tick ()
"Return the current tick/status of the buffer.