[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/corfu-doc 8c30a44d67 41/95: Fix #7: change the behavior
From: |
ELPA Syncer |
Subject: |
[elpa] externals/corfu-doc 8c30a44d67 41/95: Fix #7: change the behavior of the corfu-doc-toggle command |
Date: |
Tue, 19 Jul 2022 15:58:03 -0400 (EDT) |
branch: externals/corfu-doc
commit 8c30a44d6738d4093f6caf55737b50191fbae168
Author: Yuwei Tian <ibluefocus@outlook.com>
Commit: Yuwei Tian <ibluefocus@outlook.com>
Fix #7: change the behavior of the corfu-doc-toggle command
The code of `corfu-doc-toggle` is mainly provided by
Karthik Chikmagalur <karthikchikmagalur@gmail.com>.
Add a new setting item `corfu-doc-auto` to choose to display
the doc popup automatically or manually.
---
corfu-doc.el | 133 ++++++++++++++++++++++++++++++++---------------------------
1 file changed, 73 insertions(+), 60 deletions(-)
diff --git a/corfu-doc.el b/corfu-doc.el
index b6e70dfad6..54be989a62 100644
--- a/corfu-doc.el
+++ b/corfu-doc.el
@@ -43,6 +43,11 @@
:group 'corfu
:prefix "corfu-doc-")
+(defcustom corfu-doc-auto t
+ "Display documentation popup automatically."
+ :type 'boolean
+ :group 'corfu-doc)
+
(defcustom corfu-doc-delay 0.2
"The number of seconds to wait before displaying the documentation popup."
:type 'float
@@ -315,6 +320,17 @@ FWIDTH and FHEIGHT."
(let ((inhibit-read-only t))
(erase-buffer))))
+(defun corfu-doc--hide ()
+ (when corfu-doc--timer
+ (cancel-timer corfu-doc--timer)
+ (setq corfu-doc--timer nil))
+ (when (frame-live-p corfu-doc--frame)
+ (make-frame-invisible corfu-doc--frame)
+ (corfu-doc--clear-buffer)
+ (setq corfu-doc--candidate nil)
+ (setq corfu-doc--cf-frame-edges nil)
+ (setq corfu-doc--window nil)))
+
(defun corfu-doc--show ()
(when (and (and (fboundp 'corfu-mode) corfu-mode)
(frame-visible-p corfu--frame))
@@ -342,57 +358,7 @@ FWIDTH and FHEIGHT."
(setq corfu-doc--cf-frame-edges cf-frame-edges)
(corfu--echo-refresh)
(setq corfu-doc--window (selected-window)))
- (corfu-doc-hide))))))
-
-(defun corfu-doc-manually ()
- (interactive)
- (let ((corfu-doc-delay 0))
- (corfu-doc--set-timer)))
-
-(defun corfu-doc--set-timer (&rest _args)
- (when (> corfu-doc-delay 0)
- (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))
- (if (> corfu-doc-delay corfu-doc-hide-threshold)
- (make-frame-invisible corfu-doc--frame)
- ;; clear buffer and reset doc frame position immediately
- (corfu-doc--clear-buffer)
- (let ((cf-frame-edges (frame-edges corfu--frame 'inner)))
- (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
- (frame-pixel-width corfu-doc--frame)
- (frame-pixel-height corfu-doc--frame))))))))))
- (when (or (null corfu-doc--timer)
- (eq this-command #'corfu-doc-manually))
- (setq corfu-doc--timer
- (run-with-timer corfu-doc-delay nil #'corfu-doc-show))))
-
-(defun corfu-doc--cancel-timer ()
- (when (timerp corfu-doc--timer)
- (cancel-timer corfu-doc--timer)
- (setq corfu-doc--timer nil)))
-
-(defun corfu-doc-show ()
- (corfu-doc--cancel-timer)
- (corfu-doc--show))
-
-(defun corfu-doc--hide ()
- (when (frame-live-p corfu-doc--frame)
- (make-frame-invisible corfu-doc--frame)
- (corfu-doc--clear-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))
- (corfu-doc--hide))
+ (corfu-doc--hide))))))
(defun corfu-doc--funcall (function &rest args)
(when-let ((cf-doc-buf (and (frame-live-p corfu-doc--frame)
@@ -420,23 +386,70 @@ FWIDTH and FHEIGHT."
:group 'corfu
(cond
(corfu-doc-mode
- (advice-add 'corfu--popup-show :after #'corfu-doc--set-timer)
- (advice-add 'corfu--popup-hide :after #'corfu-doc-hide))
+ (advice-add 'corfu--popup-show :after #'corfu-doc--auto-show)
+ (advice-add 'corfu--popup-hide :after #'corfu-doc--hide))
(t
- (advice-remove 'corfu--popup-show #'corfu-doc--set-timer)
- (advice-remove 'corfu--popup-hide #'corfu-doc-hide))))
+ (advice-remove 'corfu--popup-show #'corfu-doc--auto-show)
+ (advice-remove 'corfu--popup-hide #'corfu-doc--hide))))
+
+(defun corfu-doc--auto-show (&rest _args)
+ (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))
+ (if (and corfu-doc-mode corfu-doc-auto)
+ (if (> corfu-doc-delay 0)
+ (if (> corfu-doc-delay corfu-doc-hide-threshold)
+ (make-frame-invisible corfu-doc--frame)
+ ;; clear buffer and reset doc frame position immediately
+ (corfu-doc--clear-buffer)
+ (let ((cf-frame-edges (frame-edges corfu--frame 'inner)))
+ (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
+ (frame-pixel-width corfu-doc--frame)
+ (frame-pixel-height corfu-doc--frame)))))))
+ (corfu-doc--hide)))))
+ (when (and corfu-doc-mode corfu-doc-auto)
+ (setq corfu-doc--timer
+ (run-with-timer corfu-doc-delay nil #'corfu-doc--show))))
+
+(defun corfu-doc--cleanup ()
+ (advice-remove 'corfu--popup-hide #'corfu-doc--cleanup)
+ (unless corfu-doc-mode
+ (advice-remove 'corfu--popup-show #'corfu-doc--auto-show))
+ (corfu-doc--hide))
+
+;;;###autoload
+(defun corfu-doc-toggle ()
+ "Toggles the doc popup display or hide.
+
+When using this command to manually hide the doc popup, it will
+not be displayed until this command is called again. Even if the
+corfu doc mode is turned on and `corfu-doc-auto' is set to Non-nil."
+ (interactive)
+ (advice-add 'corfu--popup-hide :after #'corfu-doc--cleanup)
+ (if (and (frame-live-p corfu-doc--frame)
+ (frame-visible-p corfu-doc--frame))
+ (progn
+ (corfu-doc--hide)
+ (advice-remove 'corfu--popup-show #'corfu-doc--auto-show))
+ (corfu-doc--show)
+ (advice-add 'corfu--popup-show :after #'corfu-doc--auto-show)))
;;;###autoload
-(defun corfu-doc-toggle (&optional arg)
- "Toggle corfu doc on or off.
-With optional ARG, turn corfu doc on if and only if ARG is positive."
+(defun toggle-corfu-doc-mode (&optional arg)
+ "Toggles corfu doc mode on or off.
+With optional ARG, turn corfu doc mode on if and only if ARG is positive."
(interactive "P")
(if (null arg)
(setq arg (if corfu-doc-mode -1 1))
(setq arg (prefix-numeric-value arg)))
(if (> arg 0)
- (corfu-doc-manually)
- (corfu-doc-hide))
+ (corfu-doc--show)
+ (corfu-doc--hide))
(corfu-doc-mode arg))
- [elpa] externals/corfu-doc da93136780 95/95: Increase the default max width of the doc frame to 80 characters, (continued)
- [elpa] externals/corfu-doc da93136780 95/95: Increase the default max width of the doc frame to 80 characters, ELPA Syncer, 2022/07/19
- [elpa] externals/corfu-doc 8e463cccad 11/95: Fix #4: add requirement for map library, ELPA Syncer, 2022/07/19
- [elpa] externals/corfu-doc b8b47f79bc 03/95: Make the documentation scrollable, ELPA Syncer, 2022/07/19
- [elpa] externals/corfu-doc d2260b04d7 04/95: Fix doc frame border missing problem, ELPA Syncer, 2022/07/19
- [elpa] externals/corfu-doc fd15093639 05/95: Add left and right margins, ELPA Syncer, 2022/07/19
- [elpa] externals/corfu-doc c6b54c923e 14/95: Add command to quickly toggle documentation popup on or off, ELPA Syncer, 2022/07/19
- [elpa] externals/corfu-doc 98398c61fa 15/95: Fix wrong argument type error when calling frame-visible-p, ELPA Syncer, 2022/07/19
- [elpa] externals/corfu-doc e18aea61e7 10/95: Version 0.0.3, ELPA Syncer, 2022/07/19
- [elpa] externals/corfu-doc 98509cbe29 44/95: Decrease auto delay to 0.1, ELPA Syncer, 2022/07/19
- [elpa] externals/corfu-doc 0741012875 26/95: Fix typo in comment, ELPA Syncer, 2022/07/19
- [elpa] externals/corfu-doc 8c30a44d67 41/95: Fix #7: change the behavior of the corfu-doc-toggle command,
ELPA Syncer <=
- [elpa] externals/corfu-doc f83307a233 09/95: Update doc frame when corfu frame coordinates changed, ELPA Syncer, 2022/07/19
- [elpa] externals/corfu-doc 488da67753 13/95: Revert previous commit, ELPA Syncer, 2022/07/19
- [elpa] externals/corfu-doc ef1edadb4f 29/95: README: Document `corfu-doc-delay`, ELPA Syncer, 2022/07/19
- [elpa] externals/corfu-doc 5d08342a82 28/95: Fix #6: do not show the documentation popup immediately, ELPA Syncer, 2022/07/19
- [elpa] externals/corfu-doc d051b8e0b1 23/95: Place doc frame at top or bottom of the completion popup frame, ELPA Syncer, 2022/07/19
- [elpa] externals/corfu-doc 7926ff406c 47/95: Avoid using map-merge, ELPA Syncer, 2022/07/19
- [elpa] externals/corfu-doc a8835a6540 43/95: Version 0.4.0, ELPA Syncer, 2022/07/19
- [elpa] externals/corfu-doc 75faa58328 21/95: Version 0.0.5, ELPA Syncer, 2022/07/19
- [elpa] externals/corfu-doc d7d7c27703 70/95: Version 0.6.2, ELPA Syncer, 2022/07/19
- [elpa] externals/corfu-doc d5224ad109 30/95: Decrease popup displaying delay to 0.2 seconds, ELPA Syncer, 2022/07/19