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

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

[nongnu] elpa/evil-goggles 636b263361 215/225: Make async overlay cleanu


From: ELPA Syncer
Subject: [nongnu] elpa/evil-goggles 636b263361 215/225: Make async overlay cleanup more robust, without using pre-command-hook
Date: Wed, 12 Jan 2022 08:59:10 -0500 (EST)

branch: elpa/evil-goggles
commit 636b263361d872bdd1e03ab0612de5313d90e85a
Author: Evgeni Kolev <evgenysw@gmail.com>
Commit: Evgeni Kolev <evgenysw@gmail.com>

    Make async overlay cleanup more robust, without using pre-command-hook
    
    The overlay is cleaned-up correctly even if evil-goggles--vanish is
    interrupted mid-flight, for example by the user pressing C-g.
---
 README.md       |  1 +
 evil-goggles.el | 22 +++++++++++++---------
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/README.md b/README.md
index 31b4e90865..e4421e9f78 100644
--- a/README.md
+++ b/README.md
@@ -178,6 +178,7 @@ evil-goggles-record-macro-face
 
 ## NEWS - Recent Significant Changes
 
+- [Jul 01, 2018] Make async hint cleanup more robust
 - [Jun 01, 2018] Refactor code to not use :around advice-s, which was a source 
of edge-case-issues
 - [Feb 05, 2018] Show hint on start/stop macro recording
 - [Dec 02, 2017] Pulsing hints is no longer experimental
diff --git a/evil-goggles.el b/evil-goggles.el
index 6d05c180d2..c60f802daf 100644
--- a/evil-goggles.el
+++ b/evil-goggles.el
@@ -321,13 +321,17 @@ which take BEG and END as their first and second 
arguments."
 (defvar evil-goggles--async-ov nil)
 
 (defun evil-goggles--vanish (&rest _)
-  "Remove the async overlay and cancel the timer."
-  (when (timerp evil-goggles--timer)
-    (cancel-timer evil-goggles--timer)
-    (setq evil-goggles--timer nil))
-  (when evil-goggles--async-ov
-    (delete-overlay evil-goggles--async-ov)
-    (setq evil-goggles--async-ov nil)))
+  "Remove the async overlay, cancel the timer, unregister from 
‘pre-command-hook’."
+  ;; user's C-g during this function execution should not result in
+  ;; this function getting removed from pre-command-hook/run-at-time
+  (with-local-quit
+    (when (overlayp evil-goggles--async-ov)
+      (delete-overlay evil-goggles--async-ov)
+      (setq evil-goggles--async-ov nil)
+    (when (timerp evil-goggles--timer)
+      (cancel-timer evil-goggles--timer)
+      (setq evil-goggles--timer nil)
+    (remove-hook 'pre-command-hook 'evil-goggles--vanish)))))
 
 (defun evil-goggles--show-async-hint (beg end)
   "Show blocking hint from BEG to END."
@@ -337,6 +341,8 @@ which take BEG and END as their first and second arguments."
     (unwind-protect
         ;; show the overlay
         (evil-goggles--show-or-pulse-overlay ov face dur)
+      ;; any command by the user should prematurely cleanup the overlay
+      (add-hook 'pre-command-hook #'evil-goggles--vanish)
       ;; remove the overlay with a timer
       (setq
        evil-goggles--async-ov ov
@@ -575,7 +581,6 @@ Argument YANK-HANDLER is the yank hanler."
   :require 'evil-goggles
   (if evil-goggles-mode
       (progn
-        (add-hook 'pre-command-hook #'evil-goggles--vanish)
         ;; add advice
         (dolist (command-cfg evil-goggles--commands)
           (let ((cmd (car command-cfg))
@@ -585,7 +590,6 @@ Argument YANK-HANDLER is the yank hanler."
             (when (symbol-value switch)
               (advice-add cmd (if after :after :before) advice)))))
     ;; remove advice
-    (remove-hook   'pre-command-hook        'evil-goggles--vanish)
     (dolist (command-cfg evil-goggles--commands)
       (let ((cmd (car command-cfg))
              (advice (plist-get (cdr command-cfg) :advice)))



reply via email to

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