diff options
| author | Dmitry Gutov | 2015-05-06 05:54:52 +0300 |
|---|---|---|
| committer | Dmitry Gutov | 2015-05-06 05:58:24 +0300 |
| commit | d804150fb26c5c46cf8c7bc6bac1cbf88c3d5bed (patch) | |
| tree | 5b9d3124021fbf35d28f5d59141f285418d8fcab | |
| parent | 4d3fed0157e96c0f9a8138ad52530d7fa53b1833 (diff) | |
| download | emacs-d804150fb26c5c46cf8c7bc6bac1cbf88c3d5bed.tar.gz emacs-d804150fb26c5c46cf8c7bc6bac1cbf88c3d5bed.zip | |
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.
| -rw-r--r-- | 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 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" | |||
| 121 | :group 'pulse | 121 | :group 'pulse |
| 122 | :type 'number) | 122 | :type 'number) |
| 123 | (defcustom pulse-delay .03 | 123 | (defcustom pulse-delay .03 |
| 124 | "Delay between face lightening iterations, as used by `sit-for'." | 124 | "Delay between face lightening iterations." |
| 125 | :group 'pulse | 125 | :group 'pulse |
| 126 | :type 'number) | 126 | :type 'number) |
| 127 | 127 | ||
| @@ -179,6 +179,9 @@ Be sure to call `pulse-reset-face' after calling pulse." | |||
| 179 | (defvar pulse-momentary-overlay nil | 179 | (defvar pulse-momentary-overlay nil |
| 180 | "The current pulsing overlay.") | 180 | "The current pulsing overlay.") |
| 181 | 181 | ||
| 182 | (defvar pulse-momentary-stop-time nil | ||
| 183 | "The current stop time.") | ||
| 184 | |||
| 182 | (defun pulse-momentary-highlight-overlay (o &optional face) | 185 | (defun pulse-momentary-highlight-overlay (o &optional face) |
| 183 | "Pulse the overlay O, unhighlighting before next command. | 186 | "Pulse the overlay O, unhighlighting before next command. |
| 184 | Optional argument FACE specifies the face to do the highlighting." | 187 | Optional argument FACE specifies the face to do the highlighting." |
| @@ -192,15 +195,25 @@ Optional argument FACE specifies the face to do the highlighting." | |||
| 192 | (overlay-put o 'face (or face 'pulse-highlight-start-face)) | 195 | (overlay-put o 'face (or face 'pulse-highlight-start-face)) |
| 193 | (add-hook 'pre-command-hook | 196 | (add-hook 'pre-command-hook |
| 194 | 'pulse-momentary-unhighlight)) | 197 | 'pulse-momentary-unhighlight)) |
| 195 | ;; pulse it. | 198 | ;; Pulse it. |
| 196 | (unwind-protect | 199 | (overlay-put o 'face 'pulse-highlight-face) |
| 197 | (progn | 200 | ;; The pulse function puts FACE onto 'pulse-highlight-face. |
| 198 | (overlay-put o 'face 'pulse-highlight-face) | 201 | ;; Thus above we put our face on the overlay, but pulse |
| 199 | ;; The pulse function puts FACE onto 'pulse-highlight-face. | 202 | ;; with a reference face needed for the color. |
| 200 | ;; Thus above we put our face on the overlay, but pulse | 203 | (pulse-reset-face face) |
| 201 | ;; with a reference face needed for the color. | 204 | (setq pulse-momentary-stop-time (time-add (current-time) |
| 202 | (pulse face)) | 205 | (* pulse-delay |
| 203 | (pulse-momentary-unhighlight))))) | 206 | pulse-iterations))) |
| 207 | (let ((timer (run-with-timer 0 pulse-delay #'ignore))) | ||
| 208 | (timer-set-function timer #'pulse-tick | ||
| 209 | (list | ||
| 210 | timer)))))) | ||
| 211 | |||
| 212 | (defun pulse-tick (timer) | ||
| 213 | (if (time-less-p (current-time) pulse-momentary-stop-time) | ||
| 214 | (pulse-lighten-highlight) | ||
| 215 | (pulse-momentary-unhighlight) | ||
| 216 | (cancel-timer timer))) | ||
| 204 | 217 | ||
| 205 | (defun pulse-momentary-unhighlight () | 218 | (defun pulse-momentary-unhighlight () |
| 206 | "Unhighlight a line recently highlighted." | 219 | "Unhighlight a line recently highlighted." |
| @@ -222,6 +235,9 @@ Optional argument FACE specifies the face to do the highlighting." | |||
| 222 | ;; Reset the pulsing face. | 235 | ;; Reset the pulsing face. |
| 223 | (pulse-reset-face) | 236 | (pulse-reset-face) |
| 224 | 237 | ||
| 238 | ;; Signal the timer to cancel. | ||
| 239 | (setq pulse-momentary-stop-time (current-time)) | ||
| 240 | |||
| 225 | ;; Remove this hook. | 241 | ;; Remove this hook. |
| 226 | (remove-hook 'pre-command-hook 'pulse-momentary-unhighlight)) | 242 | (remove-hook 'pre-command-hook 'pulse-momentary-unhighlight)) |
| 227 | 243 | ||