summaryrefslogtreecommitdiff
path: root/lisp/cedet/pulse.el
diff options
context:
space:
mode:
authorDmitry Gutov <dgutov@yandex.ru>2015-05-06 05:54:52 +0300
committerDmitry Gutov <dgutov@yandex.ru>2015-05-06 05:58:24 +0300
commitd804150fb26c5c46cf8c7bc6bac1cbf88c3d5bed (patch)
tree5b9d3124021fbf35d28f5d59141f285418d8fcab /lisp/cedet/pulse.el
parent4d3fed0157e96c0f9a8138ad52530d7fa53b1833 (diff)
downloademacs-d804150fb26c5c46cf8c7bc6bac1cbf88c3d5bed.tar.gz
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.
Diffstat (limited to 'lisp/cedet/pulse.el')
-rw-r--r--lisp/cedet/pulse.el36
1 files changed, 26 insertions, 10 deletions
diff --git a/lisp/cedet/pulse.el b/lisp/cedet/pulse.el
index 07882efd632..fcc47b989b7 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))