emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master d804150 3/3: Pulse using a timer


From: Dmitry Gutov
Subject: [Emacs-diffs] master d804150 3/3: Pulse using a timer
Date: Wed, 06 May 2015 02:58:31 +0000

branch: master
commit d804150fb26c5c46cf8c7bc6bac1cbf88c3d5bed
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    Pulse using a timer
    
    * lisp/cedet/pulse.el (pulse-momentary-stop-time): New variable.
    (pulse-momentary-highlight-overlay): Set up the timer instead of
    calling `pulse'
    (http://lists.gnu.org/archive/html/emacs-devel/2015-05/).
    (pulse-tick): New function.
    (pulse-momentary-unhighlight): Cut off the stop time.
    (pulse-delay): Update the docstring WRT to not using sit-for.
---
 lisp/cedet/pulse.el |   36 ++++++++++++++++++++++++++----------
 1 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/lisp/cedet/pulse.el b/lisp/cedet/pulse.el
index 07882ef..fcc47b9 100644
--- a/lisp/cedet/pulse.el
+++ b/lisp/cedet/pulse.el
@@ -121,7 +121,7 @@ http://www.emacswiki.org/cgi-bin/wiki/hexrgb.el";
   :group 'pulse
   :type 'number)
 (defcustom pulse-delay .03
-  "Delay between face lightening iterations, as used by `sit-for'."
+  "Delay between face lightening iterations."
   :group 'pulse
   :type 'number)
 
@@ -179,6 +179,9 @@ Be sure to call `pulse-reset-face' after calling pulse."
 (defvar pulse-momentary-overlay nil
   "The current pulsing overlay.")
 
+(defvar pulse-momentary-stop-time nil
+  "The current stop time.")
+
 (defun pulse-momentary-highlight-overlay (o &optional face)
   "Pulse the overlay O, unhighlighting before next command.
 Optional argument FACE specifies the face to do the highlighting."
@@ -192,15 +195,25 @@ Optional argument FACE specifies the face to do the 
highlighting."
          (overlay-put o 'face (or face 'pulse-highlight-start-face))
          (add-hook 'pre-command-hook
                    'pulse-momentary-unhighlight))
-      ;; pulse it.
-      (unwind-protect
-         (progn
-           (overlay-put o 'face 'pulse-highlight-face)
-           ;; The pulse function puts FACE onto 'pulse-highlight-face.
-           ;; Thus above we put our face on the overlay, but pulse
-           ;; with a reference face needed for the color.
-           (pulse face))
-       (pulse-momentary-unhighlight)))))
+      ;; Pulse it.
+      (overlay-put o 'face 'pulse-highlight-face)
+      ;; The pulse function puts FACE onto 'pulse-highlight-face.
+      ;; Thus above we put our face on the overlay, but pulse
+      ;; with a reference face needed for the color.
+      (pulse-reset-face face)
+      (setq pulse-momentary-stop-time (time-add (current-time)
+                                                (* pulse-delay
+                                                   pulse-iterations)))
+      (let ((timer (run-with-timer 0 pulse-delay #'ignore)))
+        (timer-set-function timer #'pulse-tick
+                            (list
+                             timer))))))
+
+(defun pulse-tick (timer)
+  (if (time-less-p (current-time) pulse-momentary-stop-time)
+      (pulse-lighten-highlight)
+    (pulse-momentary-unhighlight)
+    (cancel-timer timer)))
 
 (defun pulse-momentary-unhighlight ()
   "Unhighlight a line recently highlighted."
@@ -222,6 +235,9 @@ Optional argument FACE specifies the face to do the 
highlighting."
   ;; Reset the pulsing face.
   (pulse-reset-face)
 
+  ;; Signal the timer to cancel.
+  (setq pulse-momentary-stop-time (current-time))
+
   ;; Remove this hook.
   (remove-hook 'pre-command-hook 'pulse-momentary-unhighlight))
 



reply via email to

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