diff options
| author | Dmitry Gutov | 2015-05-06 15:21:32 +0300 |
|---|---|---|
| committer | Dmitry Gutov | 2015-05-06 15:21:32 +0300 |
| commit | a5847f9081585a15c10e2e28fa4d3aa6ffb9c092 (patch) | |
| tree | 0fb9d0617f59051fed11195531e22b5220dfdf3e /lisp | |
| parent | ada5e6b7a7193404c5baa559b4fc01e2f9d79cbd (diff) | |
| download | emacs-a5847f9081585a15c10e2e28fa4d3aa6ffb9c092.tar.gz emacs-a5847f9081585a15c10e2e28fa4d3aa6ffb9c092.zip | |
Clean up pulse.el a little
* lisp/cedet/pulse.el (pulse): Remove.
(pulse-momentary-timer): Save instead of the stop time.
(pulse-momentary-highlight-overlay): Call
pulse-momentary-unhighlight first thing. Treat
pulse-momentary-overlay as a single value, not a list. Save the
created timer. Only pass the stop time to the timer.
(pulse-tick): Update accordingly.
(pulse-momentary-unhighlight): Treat pulse-momentary-overlay as a
single value. Cancel the timer.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/cedet/pulse.el | 64 |
1 files changed, 23 insertions, 41 deletions
diff --git a/lisp/cedet/pulse.el b/lisp/cedet/pulse.el index fcc47b989b7..67ad31a01c9 100644 --- a/lisp/cedet/pulse.el +++ b/lisp/cedet/pulse.el | |||
| @@ -162,31 +162,21 @@ Return t if there is more drift to do, nil if completed." | |||
| 162 | 'pulse-highlight-start-face)) | 162 | 'pulse-highlight-start-face)) |
| 163 | (put 'pulse-highlight-face :iteration 0)) | 163 | (put 'pulse-highlight-face :iteration 0)) |
| 164 | 164 | ||
| 165 | (defun pulse (&optional face) | ||
| 166 | "Pulse the colors on our highlight face. | ||
| 167 | If optional FACE is provided, reset the face to FACE color, | ||
| 168 | instead of `pulse-highlight-start-face'. | ||
| 169 | Be sure to call `pulse-reset-face' after calling pulse." | ||
| 170 | (unwind-protect | ||
| 171 | (progn | ||
| 172 | (pulse-reset-face face) | ||
| 173 | (while (and (pulse-lighten-highlight) | ||
| 174 | (sit-for pulse-delay)) | ||
| 175 | nil)))) | ||
| 176 | |||
| 177 | ;;; Convenience Functions | 165 | ;;; Convenience Functions |
| 178 | ;; | 166 | ;; |
| 179 | (defvar pulse-momentary-overlay nil | 167 | (defvar pulse-momentary-overlay nil |
| 180 | "The current pulsing overlay.") | 168 | "The current pulsing overlay.") |
| 181 | 169 | ||
| 182 | (defvar pulse-momentary-stop-time nil | 170 | (defvar pulse-momentary-timer nil |
| 183 | "The current stop time.") | 171 | "The current pulsing timer.") |
| 184 | 172 | ||
| 185 | (defun pulse-momentary-highlight-overlay (o &optional face) | 173 | (defun pulse-momentary-highlight-overlay (o &optional face) |
| 186 | "Pulse the overlay O, unhighlighting before next command. | 174 | "Pulse the overlay O, unhighlighting before next command. |
| 187 | Optional argument FACE specifies the face to do the highlighting." | 175 | Optional argument FACE specifies the face to do the highlighting." |
| 176 | ;; We don't support simultaneous highlightings. | ||
| 177 | (pulse-momentary-unhighlight) | ||
| 188 | (overlay-put o 'original-face (overlay-get o 'face)) | 178 | (overlay-put o 'original-face (overlay-get o 'face)) |
| 189 | (add-to-list 'pulse-momentary-overlay o) | 179 | (setq pulse-momentary-overlay o) |
| 190 | (if (eq pulse-flag 'never) | 180 | (if (eq pulse-flag 'never) |
| 191 | nil | 181 | nil |
| 192 | (if (or (not pulse-flag) (not (pulse-available-p))) | 182 | (if (or (not pulse-flag) (not (pulse-available-p))) |
| @@ -201,42 +191,34 @@ Optional argument FACE specifies the face to do the highlighting." | |||
| 201 | ;; Thus above we put our face on the overlay, but pulse | 191 | ;; Thus above we put our face on the overlay, but pulse |
| 202 | ;; with a reference face needed for the color. | 192 | ;; with a reference face needed for the color. |
| 203 | (pulse-reset-face face) | 193 | (pulse-reset-face face) |
| 204 | (setq pulse-momentary-stop-time (time-add (current-time) | 194 | (setq pulse-momentary-timer |
| 205 | (* pulse-delay | 195 | (run-with-timer 0 pulse-delay #'pulse-tick |
| 206 | pulse-iterations))) | 196 | (time-add (current-time) |
| 207 | (let ((timer (run-with-timer 0 pulse-delay #'ignore))) | 197 | (* pulse-delay pulse-iterations))))))) |
| 208 | (timer-set-function timer #'pulse-tick | 198 | |
| 209 | (list | 199 | (defun pulse-tick (stop-time) |
| 210 | timer)))))) | 200 | (if (time-less-p (current-time) stop-time) |
| 211 | |||
| 212 | (defun pulse-tick (timer) | ||
| 213 | (if (time-less-p (current-time) pulse-momentary-stop-time) | ||
| 214 | (pulse-lighten-highlight) | 201 | (pulse-lighten-highlight) |
| 215 | (pulse-momentary-unhighlight) | 202 | (pulse-momentary-unhighlight))) |
| 216 | (cancel-timer timer))) | ||
| 217 | 203 | ||
| 218 | (defun pulse-momentary-unhighlight () | 204 | (defun pulse-momentary-unhighlight () |
| 219 | "Unhighlight a line recently highlighted." | 205 | "Unhighlight a line recently highlighted." |
| 220 | ;; If someone passes in an overlay, then pulse-momentary-overlay | ||
| 221 | ;; will still be nil, and won't need modifying. | ||
| 222 | (when pulse-momentary-overlay | 206 | (when pulse-momentary-overlay |
| 223 | ;; clear the starting face | 207 | ;; clear the starting face |
| 224 | (mapc | 208 | (let ((ol pulse-momentary-overlay)) |
| 225 | (lambda (ol) | 209 | (overlay-put ol 'face (overlay-get ol 'original-face)) |
| 226 | (overlay-put ol 'face (overlay-get ol 'original-face)) | 210 | (overlay-put ol 'original-face nil) |
| 227 | (overlay-put ol 'original-face nil) | 211 | ;; Clear the overlay if it needs deleting. |
| 228 | ;; Clear the overlay if it needs deleting. | 212 | (when (overlay-get ol 'pulse-delete) (delete-overlay ol))) |
| 229 | (when (overlay-get ol 'pulse-delete) (delete-overlay ol))) | ||
| 230 | pulse-momentary-overlay) | ||
| 231 | 213 | ||
| 232 | ;; Clear the variable. | 214 | ;; Clear the variable. |
| 233 | (setq pulse-momentary-overlay nil)) | 215 | (setq pulse-momentary-overlay nil) |
| 234 | 216 | ||
| 235 | ;; Reset the pulsing face. | 217 | ;; Reset the pulsing face. |
| 236 | (pulse-reset-face) | 218 | (pulse-reset-face) |
| 237 | 219 | ||
| 238 | ;; Signal the timer to cancel. | 220 | ;; Cancel the timer. |
| 239 | (setq pulse-momentary-stop-time (current-time)) | 221 | (cancel-timer pulse-momentary-timer)) |
| 240 | 222 | ||
| 241 | ;; Remove this hook. | 223 | ;; Remove this hook. |
| 242 | (remove-hook 'pre-command-hook 'pulse-momentary-unhighlight)) | 224 | (remove-hook 'pre-command-hook 'pulse-momentary-unhighlight)) |