annotate lisp/cedet/pulse.el @ 112291:d10e4c917525

* fileio.c (make_temp_name): Remove unreachable code.
author Paul Eggert <eggert@cs.ucla.edu>
date Sun, 16 Jan 2011 23:07:30 -0800
parents ef719132ddfa
children
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
112218
376148b31b5e Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents: 110531
diff changeset
3 ;;; Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
105241
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>
110531
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
6 ;; Version: 1.0
105241
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
7
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
9
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
10 ;; 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
11 ;; 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
12 ;; the Free Software Foundation, either version 3 of the License, or
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
13 ;; (at your option) any later version.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
14
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
15 ;; 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
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
18 ;; GNU General Public License for more details.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
19
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
20 ;; 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
21 ;; 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
22
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
23 ;;; Commentary:
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
24 ;;
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
25 ;; Manage temporary pulsing of faces and overlays.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
26 ;;
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
27 ;; This is a temporal decoration technique where something is to be
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
28 ;; highlighted briefly. This adds a gentle pulsing style to the text
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
29 ;; decorated this way.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
30 ;;
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
31 ;; The following are useful entry points:
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
32 ;;
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
33 ;; `pulse' - Cause `pulse-highlight-face' to shift toward background color.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
34 ;; Assumes you are using a version of Emacs that supports pulsing.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
35 ;;
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-momentary-highlight-one-line' - Pulse a single line at POINT.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
38 ;; `pulse-momentary-highlight-region' - Pulse a region.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
39 ;; `pulse-momentary-highlight-overlay' - Pulse an overlay
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
40 ;; These three functions will just blink the specified area if
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
41 ;; the version of Emacs you are using doesn't support pulsing.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
42 ;;
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
43 ;; `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
44 ;; hook that will pulse whatever line the cursor is on.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
45 ;;
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
46 ;;; History:
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
47 ;;
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
48 ;; The original pulse code was written for semantic tag highlighting.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
49 ;; It has been extracted, and adapted for general purpose pulsing.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
50 ;;
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
51 ;; Pulse is a part of CEDET. http://cedet.sf.net
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
52
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
53 (defun pulse-available-p ()
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
54 "Return non-nil if pulsing is available on the current frame."
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
55 (condition-case nil
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
56 (let ((v (color-values (face-background 'default))))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
57 (numberp (car-safe v)))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
58 (error nil)))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
59
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
60 (defcustom pulse-flag (pulse-available-p)
110531
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
61 "Whether to use pulsing for momentary highlighting.
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
62 Pulsing involves a bright highlight that slowly shifts to the
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
63 background color.
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
64
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
65 If the value is nil, highlight with an unchanging color until a
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
66 key is pressed.
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
67 If the value is `never', do no coloring at all.
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
68 Any other value means to the default pulsing behavior.
105241
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)
110531
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
186 (if (eq pulse-flag 'never)
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
187 nil
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
188 (if (or (not pulse-flag) (not (pulse-available-p)))
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
189 ;; Provide a face... clear on next command
105241
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
190 (progn
110531
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
191 (overlay-put o 'face (or face 'pulse-highlight-start-face))
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
192 (add-hook 'pre-command-hook
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
193 'pulse-momentary-unhighlight))
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
194 ;; pulse it.
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
195 (unwind-protect
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
196 (progn
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
197 (overlay-put o 'face 'pulse-highlight-face)
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
198 ;; The pulse function puts FACE onto 'pulse-highlight-face.
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
199 ;; Thus above we put our face on the overlay, but pulse
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
200 ;; with a reference face needed for the color.
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
201 (pulse face))
67ff8ad45bd5 Synch SRecode to CEDET 1.0.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
202 (pulse-momentary-unhighlight)))))
105241
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
203
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
204 (defun pulse-momentary-unhighlight ()
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
205 "Unhighlight a line recently highlighted."
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
206 ;; If someone passes in an overlay, then pulse-momentary-overlay
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
207 ;; will still be nil, and won't need modifying.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
208 (when pulse-momentary-overlay
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
209 ;; clear the starting face
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
210 (mapc
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
211 (lambda (ol)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
212 (overlay-put ol 'face (overlay-get ol 'original-face))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
213 (overlay-put ol 'original-face nil)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
214 ;; Clear the overlay if it needs deleting.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
215 (when (overlay-get ol 'pulse-delete) (delete-overlay ol)))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
216 pulse-momentary-overlay)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
217
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
218 ;; Clear the variable.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
219 (setq pulse-momentary-overlay nil))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
220
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
221 ;; Reset the pulsing face.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
222 (pulse-reset-face)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
223
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
224 ;; Remove this hook.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
225 (remove-hook 'pre-command-hook 'pulse-momentary-unhighlight))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
226
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
227 (defun pulse-momentary-highlight-one-line (point &optional face)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
228 "Highlight the line around POINT, unhighlighting before next command.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
229 Optional argument FACE specifies the face to do the highlighting."
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
230 (let ((start (point-at-bol))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
231 (end (save-excursion
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
232 (end-of-line)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
233 (when (not (eobp))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
234 (forward-char 1))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
235 (point))))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
236 (pulse-momentary-highlight-region start end face)))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
237
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
238 (defun pulse-momentary-highlight-region (start end &optional face)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
239 "Highlight between START and END, unhighlighting before next command.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
240 Optional argument FACE specifies the fact to do the highlighting."
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
241 (let ((o (make-overlay start end)))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
242 ;; Mark it for deletion
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
243 (overlay-put o 'pulse-delete t)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
244 (pulse-momentary-highlight-overlay o face)))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
245
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
246 ;;; Random integration with other tools
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
247
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
248 (defvar pulse-command-advice-flag nil)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
249
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
250 (defun pulse-line-hook-function ()
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
251 "Function used in hooks to pulse the current line.
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
252 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
253 (when pulse-command-advice-flag
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
254 (pulse-momentary-highlight-one-line (point))))
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
255
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
256 (provide 'pulse)
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
257
130db1220dfd * cedet/cedet-cscope.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
258 ;;; pulse.el ends here