emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/corfu-doc 5d08342a82 28/95: Fix #6: do not show the doc


From: ELPA Syncer
Subject: [elpa] externals/corfu-doc 5d08342a82 28/95: Fix #6: do not show the documentation popup immediately
Date: Tue, 19 Jul 2022 15:58:02 -0400 (EDT)

branch: externals/corfu-doc
commit 5d08342a8227e40522b34cc5abe544d0a6debf2c
Author: Yuwei Tian <ibluefocus@outlook.com>
Commit: Yuwei Tian <ibluefocus@outlook.com>

    Fix #6: do not show the documentation popup immediately
    
    Update it with a timer, the delay time can be set by `corfu-doc-delay`.
---
 corfu-doc.el | 86 +++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 47 insertions(+), 39 deletions(-)

diff --git a/corfu-doc.el b/corfu-doc.el
index ec11f6d82c..c06906978f 100644
--- a/corfu-doc.el
+++ b/corfu-doc.el
@@ -289,40 +289,35 @@ If this is nil, do not resize corfu doc frame 
automatically."
              (t (setq y y-on-bottom-side-of-cf-frame)))))))
     (list x y cf-doc-frame-width cf-doc-frame-height)))
 
-(defun corfu-doc--show ()
-  (let ((candidate (and (> corfu--total 0)
-                        (nth corfu--index corfu--candidates)))
-        (cf-frame-edges (frame-edges corfu--frame 'inner)))
-    (if candidate
-        (when (and (and (fboundp 'corfu-mode) corfu-mode)
-                   (frame-visible-p corfu--frame))
-          (unless (and (string= corfu-doc--candidate candidate)
-                       (frame-live-p corfu-doc--frame)
-                       (frame-visible-p corfu-doc--frame)
-                       (equal cf-frame-edges corfu-doc--cf-frame-edges)
-                       (eq (selected-window) corfu-doc--window))
-            ;; show doc frame
-            (if-let* ((res (ignore-errors (corfu-doc-fetch-documentation)))
-                      (doc (unless (string-empty-p (string-trim res)) res)))
-                (progn
-                  (corfu-doc--make-frame doc)
-                  (apply #'corfu-doc--set-frame-position
-                         corfu-doc--frame
-                         (corfu-doc--calculate-doc-frame-position)))
-              (corfu-doc--hide)))
-          (corfu--echo-refresh))
-      (corfu-doc--hide))
-    (setq corfu-doc--candidate candidate)
-    (setq corfu-doc--cf-frame-edges cf-frame-edges)
-    (setq corfu-doc--window (selected-window))))
+(defun corfu-doc--get-candidate ()
+  (and (> corfu--total 0)
+       (nth corfu--index corfu--candidates)))
 
-(defun corfu-doc--hide ()
-  (when (frame-live-p corfu-doc--frame)
-    (make-frame-invisible corfu-doc--frame)
-    (with-current-buffer
-        (window-buffer (frame-root-window corfu-doc--frame))
-      (let ((inhibit-read-only t))
-        (erase-buffer)))))
+(defun corfu-doc--show ()
+  (when (and (and (fboundp 'corfu-mode) corfu-mode)
+             (frame-visible-p corfu--frame))
+    (when-let ((candidate (corfu-doc--get-candidate))
+               (cf-frame-edges (frame-edges corfu--frame 'inner)))
+      (if (and (string= candidate corfu-doc--candidate)
+               (eq (selected-window) corfu-doc--window)
+               (frame-live-p corfu-doc--frame))
+          (progn
+            (make-frame-visible corfu-doc--frame)
+            (unless (equal cf-frame-edges corfu-doc--cf-frame-edges)
+              (apply #'corfu-doc--set-frame-position
+                     corfu-doc--frame
+                     (corfu-doc--calculate-doc-frame-position))))
+        ;; fetch documentation and show
+        (when-let* ((res (ignore-errors (corfu-doc-fetch-documentation)))
+                    (doc (unless (string-empty-p (string-trim res)) res)))
+          (corfu-doc--make-frame doc)
+          (apply #'corfu-doc--set-frame-position
+                 corfu-doc--frame
+                 (corfu-doc--calculate-doc-frame-position))))
+      (corfu--echo-refresh)
+      (setq corfu-doc--candidate candidate)
+      (setq corfu-doc--cf-frame-edges cf-frame-edges)
+      (setq corfu-doc--window (selected-window)))))
 
 (defun corfu-doc-manually ()
   (interactive)
@@ -330,15 +325,17 @@ If this is nil, do not resize corfu doc frame 
automatically."
     (corfu-doc--set-timer)))
 
 (defun corfu-doc--set-timer (&rest _args)
+  ;; hide the doc frame immediately when candidate selection changed
+  (let ((candidate (corfu-doc--get-candidate)))
+    (unless (and (string= candidate corfu-doc--candidate)
+                 (eq (selected-window) corfu-doc--window))
+      (when (and (frame-live-p corfu-doc--frame)
+                 (frame-visible-p corfu-doc--frame))
+        (make-frame-invisible corfu-doc--frame))))
   (when (or (null corfu-doc--timer)
             (eq this-command #'corfu-doc-manually))
     (setq corfu-doc--timer
-          (run-with-timer
-           (if (and (frame-live-p corfu-doc--frame)
-                    (frame-visible-p corfu-doc--frame))
-               0
-             corfu-doc-delay)
-           nil #'corfu-doc-show))))
+          (run-with-timer corfu-doc-delay nil #'corfu-doc-show))))
 
 (defun corfu-doc--cancel-timer ()
   (when (timerp corfu-doc--timer)
@@ -349,6 +346,17 @@ If this is nil, do not resize corfu doc frame 
automatically."
   (corfu-doc--cancel-timer)
   (corfu-doc--show))
 
+(defun corfu-doc--hide ()
+  (when (frame-live-p corfu-doc--frame)
+    (make-frame-invisible corfu-doc--frame)
+    (with-current-buffer
+        (window-buffer (frame-root-window corfu-doc--frame))
+      (let ((inhibit-read-only t))
+        (erase-buffer)))
+    (setq corfu-doc--candidate nil)
+    (setq corfu-doc--cf-frame-edges nil)
+    (setq corfu-doc--window nil)))
+
 (defun corfu-doc-hide ()
   (when corfu-doc-delay
     (corfu-doc--cancel-timer))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]