annotate lisp/cedet/pulse.el @ 105330:7660578a04ee

(cd-absolute): Don't abbreviate-file-name (bug#4599).
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 01 Oct 2009 03:34:04 +0000
parents 130db1220dfd
children 7f4c7f5c0eba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
105241
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1 ;;; pulse.el --- Pulsing Overlays
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
2
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
3 ;;; Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
4
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
5 ;; Author: Eric M. Ludlam <eric@siege-engine.com>
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
6
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
8
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
11 ;; the Free Software Foundation, either version 3 of the License, or
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
12 ;; (at your option) any later version.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
13
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
17 ;; GNU General Public License for more details.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
18
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
21
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
22 ;;; Commentary:
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
23 ;;
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
24 ;; Manage temporary pulsing of faces and overlays.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
25 ;;
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
26 ;; This is a temporal decoration technique where something is to be
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
27 ;; highlighted briefly. This adds a gentle pulsing style to the text
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
28 ;; decorated this way.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
29 ;;
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
30 ;; Useful user functions:
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
31 ;;
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
32 ;; `pulse-enable-integration-advice' - Turn on advice to make various
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
33 ;; Emacs commands pulse, such as `goto-line', or `find-tag'.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
34 ;;
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
35 ;; The following are useful entry points:
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
36 ;;
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
37 ;; `pulse' - Cause `pulse-highlight-face' to shift toward background color.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
38 ;; Assumes you are using a version of Emacs that supports pulsing.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
39 ;;
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
40 ;;
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
41 ;; `pulse-momentary-highlight-one-line' - Pulse a single line at POINT.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
42 ;; `pulse-momentary-highlight-region' - Pulse a region.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
43 ;; `pulse-momentary-highlight-overlay' - Pulse an overlay
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
44 ;; These three functions will just blink the specified area if
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
45 ;; the version of Emacs you are using doesn't support pulsing.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
46 ;;
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
47 ;; `pulse-line-hook-function' - A simple function that can be used in a
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
48 ;; hook that will pulse whatever line the cursor is on.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
49 ;;
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
50 ;;; History:
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
51 ;;
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
52 ;; The original pulse code was written for semantic tag highlighting.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
53 ;; It has been extracted, and adapted for general purpose pulsing.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
54 ;;
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
55 ;; Pulse is a part of CEDET. http://cedet.sf.net
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
56
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
57 (defun pulse-available-p ()
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
58 "Return non-nil if pulsing is available on the current frame."
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
59 (condition-case nil
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
60 (let ((v (color-values (face-background 'default))))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
61 (numberp (car-safe v)))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
62 (error nil)))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
63
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
64 (defcustom pulse-flag (pulse-available-p)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
65 "*Non-nil means to pulse the overlay face for momentary highlighting.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
66 Pulsing involves a bright highlight that slowly shifts to the background
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
67 color. Non-nil just means to highlight with an unchanging color for a short
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
68 time.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
69
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
70 If `pulse-flag' is non-nil, but `pulse-available-p' is nil, then
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
71 this flag is ignored."
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
72 :group 'pulse
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
73 :type 'boolean)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
74
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
75 (defface pulse-highlight-start-face
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
76 '((((class color) (background dark))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
77 (:background "#AAAA33"))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
78 (((class color) (background light))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
79 (:background "#FFFFAA")))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
80 "*Face used at beginning of a highight."
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
81 :group 'pulse)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
82
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
83 (defface pulse-highlight-face
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
84 '((((class color) (background dark))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
85 (:background "#AAAA33"))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
86 (((class color) (background light))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
87 (:background "#FFFFAA")))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
88 "*Face used during a pulse for display. *DO NOT CUSTOMIZE*
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
89 Face used for temporary highlighting of tags for effect."
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
90 :group 'pulse)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
91
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
92 ;;; Code:
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
93 ;;
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
94 (defun pulse-int-to-hex (int &optional nb-digits)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
95 "Convert integer argument INT to a #XXXXXXXXXXXX format hex string.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
96 Each X in the output string is a hexadecimal digit.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
97 NB-DIGITS is the number of hex digits. If INT is too large to be
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
98 represented with NB-DIGITS, then the result is truncated from the
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
99 left. So, for example, INT=256 and NB-DIGITS=2 returns \"00\", since
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
100 the hex equivalent of 256 decimal is 100, which is more than 2 digits.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
101
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
102 This function was blindly copied from hexrgb.el by Drew Adams.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
103 http://www.emacswiki.org/cgi-bin/wiki/hexrgb.el"
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
104 (setq nb-digits (or nb-digits 4))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
105 (substring (format (concat "%0" (int-to-string nb-digits) "X") int) (- nb-digits)))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
106
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
107 (defun pulse-color-values-to-hex (values)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
108 "Convert list of rgb color VALUES to a hex string, #XXXXXXXXXXXX.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
109 Each X in the string is a hexadecimal digit.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
110 Input VALUES is as for the output of `x-color-values'.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
111
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
112 This function was blindly copied from hexrgb.el by Drew Adams.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
113 http://www.emacswiki.org/cgi-bin/wiki/hexrgb.el"
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
114 (concat "#"
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
115 (pulse-int-to-hex (nth 0 values) 4) ; red
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
116 (pulse-int-to-hex (nth 1 values) 4) ; green
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
117 (pulse-int-to-hex (nth 2 values) 4))) ; blue
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
118
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
119 (defcustom pulse-iterations 10
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
120 "Number of iterations in a pulse operation."
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
121 :group 'pulse
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
122 :type 'number)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
123 (defcustom pulse-delay .03
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
124 "Delay between face lightening iterations, as used by `sit-for'."
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
125 :group 'pulse
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
126 :type 'number)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
127
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
128 (defun pulse-lighten-highlight ()
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
129 "Lighten the face by 1/`pulse-iterations' toward the background color.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
130 Return t if there is more drift to do, nil if completed."
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
131 (if (>= (get 'pulse-highlight-face :iteration) pulse-iterations)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
132 nil
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
133 (let* ((frame (color-values (face-background 'default)))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
134 (start (color-values (face-background
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
135 (get 'pulse-highlight-face
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
136 :startface))))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
137 (frac (list (/ (- (nth 0 frame) (nth 0 start)) pulse-iterations)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
138 (/ (- (nth 1 frame) (nth 1 start)) pulse-iterations)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
139 (/ (- (nth 2 frame) (nth 2 start)) pulse-iterations)))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
140 (it (get 'pulse-highlight-face :iteration))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
141 )
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
142 (set-face-background 'pulse-highlight-face
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
143 (pulse-color-values-to-hex
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
144 (list
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
145 (+ (nth 0 start) (* (nth 0 frac) it))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
146 (+ (nth 1 start) (* (nth 1 frac) it))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
147 (+ (nth 2 start) (* (nth 2 frac) it)))))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
148 (put 'pulse-highlight-face :iteration (1+ it))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
149 (if (>= (1+ it) pulse-iterations)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
150 nil
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
151 t))))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
152
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
153 (defun pulse-reset-face (&optional face)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
154 "Reset the pulse highlighting FACE."
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
155 (set-face-background 'pulse-highlight-face
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
156 (if face
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
157 (face-background face)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
158 (face-background 'pulse-highlight-start-face)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
159 ))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
160 (put 'pulse-highlight-face :startface (or face
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
161 'pulse-highlight-start-face))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
162 (put 'pulse-highlight-face :iteration 0))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
163
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
164 (defun pulse (&optional face)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
165 "Pulse the colors on our highlight face.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
166 If optional FACE is provide, reset the face to FACE color,
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
167 instead of `pulse-highlight-start-face'.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
168 Be sure to call `pulse-reset-face' after calling pulse."
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
169 (unwind-protect
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
170 (progn
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
171 (pulse-reset-face face)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
172 (while (and (pulse-lighten-highlight)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
173 (sit-for pulse-delay))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
174 nil))))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
175
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
176 ;;; Convenience Functions
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
177 ;;
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
178 (defvar pulse-momentary-overlay nil
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
179 "The current pulsing overlay.")
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
180
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
181 (defun pulse-momentary-highlight-overlay (o &optional face)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
182 "Pulse the overlay O, unhighlighting before next command.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
183 Optional argument FACE specifies the fact to do the highlighting."
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
184 (overlay-put o 'original-face (overlay-get o 'face))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
185 (add-to-list 'pulse-momentary-overlay o)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
186 (if (or (not pulse-flag) (not (pulse-available-p)))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
187 ;; Provide a face... clear on next command
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
188 (progn
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
189 (overlay-put o 'face (or face 'pulse-highlight-start-face))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
190 (add-hook 'pre-command-hook
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
191 'pulse-momentary-unhighlight)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
192 )
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
193 ;; pulse it.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
194 (unwind-protect
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
195 (progn
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
196 (overlay-put o 'face 'pulse-highlight-face)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
197 ;; The pulse function puts FACE onto 'pulse-highlight-face.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
198 ;; Thus above we put our face on the overlay, but pulse
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
199 ;; with a reference face needed for the color.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
200 (pulse face))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
201 (pulse-momentary-unhighlight))))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
202
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
203 (defun pulse-momentary-unhighlight ()
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
204 "Unhighlight a line recently highlighted."
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
205 ;; If someone passes in an overlay, then pulse-momentary-overlay
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
206 ;; will still be nil, and won't need modifying.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
207 (when pulse-momentary-overlay
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
208 ;; clear the starting face
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
209 (mapc
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
210 (lambda (ol)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
211 (overlay-put ol 'face (overlay-get ol 'original-face))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
212 (overlay-put ol 'original-face nil)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
213 ;; Clear the overlay if it needs deleting.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
214 (when (overlay-get ol 'pulse-delete) (delete-overlay ol)))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
215 pulse-momentary-overlay)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
216
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
217 ;; Clear the variable.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
218 (setq pulse-momentary-overlay nil))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
219
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
220 ;; Reset the pulsing face.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
221 (pulse-reset-face)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
222
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
223 ;; Remove this hook.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
224 (remove-hook 'pre-command-hook 'pulse-momentary-unhighlight))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
225
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
226 (defun pulse-momentary-highlight-one-line (point &optional face)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
227 "Highlight the line around POINT, unhighlighting before next command.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
228 Optional argument FACE specifies the face to do the highlighting."
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
229 (let ((start (point-at-bol))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
230 (end (save-excursion
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
231 (end-of-line)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
232 (when (not (eobp))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
233 (forward-char 1))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
234 (point))))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
235 (pulse-momentary-highlight-region start end face)))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
236
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
237 (defun pulse-momentary-highlight-region (start end &optional face)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
238 "Highlight between START and END, unhighlighting before next command.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
239 Optional argument FACE specifies the fact to do the highlighting."
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
240 (let ((o (make-overlay start end)))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
241 ;; Mark it for deletion
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
242 (overlay-put o 'pulse-delete t)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
243 (pulse-momentary-highlight-overlay o face)))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
244
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
245 ;;; Random integration with other tools
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
246
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
247 (defvar pulse-command-advice-flag nil)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
248
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
249 (defun pulse-line-hook-function ()
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
250 "Function used in hooks to pulse the current line.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
251 Only pulses the line if `pulse-command-advice-flag' is non-nil."
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
252 (when pulse-command-advice-flag
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
253 (pulse-momentary-highlight-one-line (point))))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
254
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
255 (provide 'pulse)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
256
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
257 ;;; pulse.el ends here