Mercurial > emacs
annotate lisp/tooltip.el @ 34719:329b64b6b71e
*** empty log message ***
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Tue, 19 Dec 2000 14:41:17 +0000 |
parents | e045e0e60223 |
children | f7ca93e40e16 |
rev | line source |
---|---|
25003 | 1 ;;; tooltip.el --- Show tooltip windows |
2 | |
33140
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
3 ;; Copyright (C) 1997, 1999, 2000 Free Software Foundation, Inc. |
25003 | 4 |
5 ;; Author: Gerd Moellmann <gerd@acm.org> | |
6 ;; Keywords: help c mouse tools | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;; Put into your `.emacs' | |
28 | |
29 ;; (require 'tooltip) | |
30 ;; (tooltip-mode 1) | |
31 | |
32 | |
33 | |
34 ;;; Code: | |
35 | |
36 (eval-when-compile | |
37 (require 'cl) | |
38 (require 'comint) | |
39 (require 'gud)) | |
40 | |
41 (provide 'tooltip) | |
42 | |
43 | |
44 ;;; Customizable settings | |
45 | |
46 (defgroup tooltip nil | |
47 "Customization group for the `tooltip' package." | |
48 :group 'help | |
49 :group 'c | |
50 :group 'mouse | |
51 :group 'tools | |
25332
c09e05be2f4b
(tooltip-mode): Customize this, per convention.
Dave Love <fx@gnu.org>
parents:
25003
diff
changeset
|
52 :version "21.1" |
25003 | 53 :tag "Tool Tips") |
54 | |
25332
c09e05be2f4b
(tooltip-mode): Customize this, per convention.
Dave Love <fx@gnu.org>
parents:
25003
diff
changeset
|
55 (defvar tooltip-mode) |
25003 | 56 |
57 (defcustom tooltip-delay 1.0 | |
58 "Seconds to wait before displaying a tooltip the first time." | |
59 :tag "Delay" | |
60 :type 'number | |
61 :group 'tooltip) | |
62 | |
63 | |
64 (defcustom tooltip-short-delay 0.1 | |
65 "Seconds to wait between subsequent tooltips on different items." | |
66 :tag "Short delay" | |
67 :type 'number | |
68 :group 'tooltip) | |
69 | |
70 | |
71 (defcustom tooltip-recent-seconds 1 | |
25332
c09e05be2f4b
(tooltip-mode): Customize this, per convention.
Dave Love <fx@gnu.org>
parents:
25003
diff
changeset
|
72 "Display tooltips if changing tip items within this many seconds. |
c09e05be2f4b
(tooltip-mode): Customize this, per convention.
Dave Love <fx@gnu.org>
parents:
25003
diff
changeset
|
73 Do so after `tooltip-short-delay'." |
25003 | 74 :tag "Recent seconds" |
75 :type 'number | |
76 :group 'tooltip) | |
77 | |
78 | |
33587
7d4c3fcd3421
(tooltip-x-offset, tooltip-y-offset): New user-options.
Gerd Moellmann <gerd@gnu.org>
parents:
33356
diff
changeset
|
79 (defcustom tooltip-x-offset nil |
7d4c3fcd3421
(tooltip-x-offset, tooltip-y-offset): New user-options.
Gerd Moellmann <gerd@gnu.org>
parents:
33356
diff
changeset
|
80 "Specify an X offset for the display of tooltips. |
7d4c3fcd3421
(tooltip-x-offset, tooltip-y-offset): New user-options.
Gerd Moellmann <gerd@gnu.org>
parents:
33356
diff
changeset
|
81 The offset is relative to the position of the mouse. It must |
7d4c3fcd3421
(tooltip-x-offset, tooltip-y-offset): New user-options.
Gerd Moellmann <gerd@gnu.org>
parents:
33356
diff
changeset
|
82 be chosen so that the tooltip window doesn't contain the mouse |
7d4c3fcd3421
(tooltip-x-offset, tooltip-y-offset): New user-options.
Gerd Moellmann <gerd@gnu.org>
parents:
33356
diff
changeset
|
83 when it pops up." |
7d4c3fcd3421
(tooltip-x-offset, tooltip-y-offset): New user-options.
Gerd Moellmann <gerd@gnu.org>
parents:
33356
diff
changeset
|
84 :tag "X offset" |
7d4c3fcd3421
(tooltip-x-offset, tooltip-y-offset): New user-options.
Gerd Moellmann <gerd@gnu.org>
parents:
33356
diff
changeset
|
85 :type '(choice (const :tag "Default" nil) |
7d4c3fcd3421
(tooltip-x-offset, tooltip-y-offset): New user-options.
Gerd Moellmann <gerd@gnu.org>
parents:
33356
diff
changeset
|
86 (integer :tag "Offset" :value 1)) |
7d4c3fcd3421
(tooltip-x-offset, tooltip-y-offset): New user-options.
Gerd Moellmann <gerd@gnu.org>
parents:
33356
diff
changeset
|
87 :group 'tooltip) |
7d4c3fcd3421
(tooltip-x-offset, tooltip-y-offset): New user-options.
Gerd Moellmann <gerd@gnu.org>
parents:
33356
diff
changeset
|
88 |
7d4c3fcd3421
(tooltip-x-offset, tooltip-y-offset): New user-options.
Gerd Moellmann <gerd@gnu.org>
parents:
33356
diff
changeset
|
89 |
7d4c3fcd3421
(tooltip-x-offset, tooltip-y-offset): New user-options.
Gerd Moellmann <gerd@gnu.org>
parents:
33356
diff
changeset
|
90 (defcustom tooltip-y-offset nil |
7d4c3fcd3421
(tooltip-x-offset, tooltip-y-offset): New user-options.
Gerd Moellmann <gerd@gnu.org>
parents:
33356
diff
changeset
|
91 "Specify an Y offset for the display of tooltips. |
7d4c3fcd3421
(tooltip-x-offset, tooltip-y-offset): New user-options.
Gerd Moellmann <gerd@gnu.org>
parents:
33356
diff
changeset
|
92 The offset is relative to the position of the mouse. It must |
7d4c3fcd3421
(tooltip-x-offset, tooltip-y-offset): New user-options.
Gerd Moellmann <gerd@gnu.org>
parents:
33356
diff
changeset
|
93 be chosen so that the tooltip window doesn't contain the mouse |
7d4c3fcd3421
(tooltip-x-offset, tooltip-y-offset): New user-options.
Gerd Moellmann <gerd@gnu.org>
parents:
33356
diff
changeset
|
94 when it pops up." |
7d4c3fcd3421
(tooltip-x-offset, tooltip-y-offset): New user-options.
Gerd Moellmann <gerd@gnu.org>
parents:
33356
diff
changeset
|
95 :tag "Y offset" |
7d4c3fcd3421
(tooltip-x-offset, tooltip-y-offset): New user-options.
Gerd Moellmann <gerd@gnu.org>
parents:
33356
diff
changeset
|
96 :type '(choice (const :tag "Default" nil) |
7d4c3fcd3421
(tooltip-x-offset, tooltip-y-offset): New user-options.
Gerd Moellmann <gerd@gnu.org>
parents:
33356
diff
changeset
|
97 (integer :tag "Offset" :value 1)) |
7d4c3fcd3421
(tooltip-x-offset, tooltip-y-offset): New user-options.
Gerd Moellmann <gerd@gnu.org>
parents:
33356
diff
changeset
|
98 :group 'tooltip) |
7d4c3fcd3421
(tooltip-x-offset, tooltip-y-offset): New user-options.
Gerd Moellmann <gerd@gnu.org>
parents:
33356
diff
changeset
|
99 |
7d4c3fcd3421
(tooltip-x-offset, tooltip-y-offset): New user-options.
Gerd Moellmann <gerd@gnu.org>
parents:
33356
diff
changeset
|
100 |
25003 | 101 (defcustom tooltip-frame-parameters |
102 '((name . "tooltip") | |
103 (foreground-color . "black") | |
104 (background-color . "lightyellow") | |
105 (internal-border-width . 5) | |
106 (border-color . "lightyellow") | |
107 (border-width . 1)) | |
108 "Frame parameters used for tooltips." | |
109 :type 'sexp | |
110 :tag "Frame Parameters" | |
111 :group 'tooltip) | |
112 | |
113 | |
114 (defcustom tooltip-gud-tips-p nil | |
27582
42b52d8b6703
(tooltip-gud-tips-p, tooltip-gud-toggle-dereference):
Dave Love <fx@gnu.org>
parents:
25332
diff
changeset
|
115 "*Non-nil means show tooltips in GUD sessions." |
25003 | 116 :type 'boolean |
117 :tag "GUD" | |
33140
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
118 :set #'(lambda (symbol on) |
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
119 (setq tooltip-gud-tips-p on) |
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
120 (if on (tooltip-gud-tips-setup))) |
25003 | 121 :group 'tooltip) |
122 | |
123 | |
124 (defcustom tooltip-gud-modes '(gud-mode c-mode c++-mode) | |
125 "List of modes for which to enable GUD tips." | |
126 :type 'sexp | |
127 :tag "GUD modes" | |
128 :group 'tooltip) | |
129 | |
30481 | 130 |
25003 | 131 (defcustom tooltip-gud-display |
132 '((eq (tooltip-event-buffer tooltip-gud-event) | |
133 (marker-buffer overlay-arrow-position))) | |
134 "List of forms determining where GUD tooltips are displayed. | |
135 | |
136 Forms in the list are combined with AND. The default is to display | |
137 only tooltips in the buffer containing the overlay arrow." | |
138 :type 'sexp | |
139 :tag "GUD buffers predicate" | |
140 :group 'tooltip) | |
141 | |
142 | |
32431
a35cc9700ff7
* tooltip.el (tooltip-use-echo-area): New user variable.
Sam Steingold <sds@gnu.org>
parents:
30481
diff
changeset
|
143 (defcustom tooltip-use-echo-area nil |
33923 | 144 "Use the echo area instead of tooltip frames. |
145 This is only relevant GUD display, since otherwise it is equivalent to | |
146 turning off Tooltip mode." | |
32431
a35cc9700ff7
* tooltip.el (tooltip-use-echo-area): New user variable.
Sam Steingold <sds@gnu.org>
parents:
30481
diff
changeset
|
147 :type 'boolean |
33925 | 148 :tag "Use echo area" |
32431
a35cc9700ff7
* tooltip.el (tooltip-use-echo-area): New user variable.
Sam Steingold <sds@gnu.org>
parents:
30481
diff
changeset
|
149 :group 'tooltip) |
a35cc9700ff7
* tooltip.el (tooltip-use-echo-area): New user variable.
Sam Steingold <sds@gnu.org>
parents:
30481
diff
changeset
|
150 |
25003 | 151 |
152 ;;; Variables that are not customizable. | |
153 | |
154 (defvar tooltip-hook nil | |
155 "Functions to call to display tooltips. | |
156 Each function is called with one argument EVENT which is a copy of | |
157 the last mouse movement event that occurred.") | |
158 | |
159 | |
160 (defvar tooltip-timeout-id nil | |
161 "The id of the timeout started when Emacs becomes idle.") | |
162 | |
163 | |
164 (defvar tooltip-last-mouse-motion-event nil | |
165 "A copy of the last mouse motion event seen.") | |
166 | |
167 | |
168 (defvar tooltip-hide-time nil | |
169 "Time when the last tooltip was hidden.") | |
170 | |
171 | |
172 (defvar tooltip-gud-debugger nil | |
173 "The debugger for which we show tooltips.") | |
174 | |
175 | |
176 | |
177 ;;; Event accessors | |
178 | |
179 (defun tooltip-event-buffer (event) | |
180 "Return the buffer over which event EVENT occurred. | |
181 This might return nil if the event did not occur over a buffer." | |
182 (let ((window (posn-window (event-end event)))) | |
183 (and window (window-buffer window)))) | |
184 | |
185 | |
186 | |
187 ;;; Switching tooltips on/off | |
188 | |
189 ;; We don't set track-mouse globally because this is a big redisplay | |
190 ;; problem in buffers having a pre-command-hook or such installed, | |
191 ;; which does a set-buffer, like the summary buffer of Gnus. Calling | |
192 ;; set-buffer prevents redisplay optimizations, so every mouse motion | |
193 ;; would be accompanied by a full redisplay. | |
194 | |
195 ;;;###autoload | |
196 (defun tooltip-mode (&optional arg) | |
197 "Mode for tooltip display. | |
198 With ARG, turn tooltip mode on if and only if ARG is positive." | |
199 (interactive "P") | |
34689
e045e0e60223
(tooltip-mode): Signal an error if x-show-tip
Gerd Moellmann <gerd@gnu.org>
parents:
34540
diff
changeset
|
200 (unless (fboundp 'x-show-tip) |
e045e0e60223
(tooltip-mode): Signal an error if x-show-tip
Gerd Moellmann <gerd@gnu.org>
parents:
34540
diff
changeset
|
201 (error "Sorry, tooltips are not yet available on this system")) |
25003 | 202 (let* ((on (if arg |
203 (> (prefix-numeric-value arg) 0) | |
204 (not tooltip-mode))) | |
205 (hook-fn (if on 'add-hook 'remove-hook))) | |
206 (setq tooltip-mode on) | |
207 (funcall hook-fn 'change-major-mode-hook 'tooltip-change-major-mode) | |
208 (tooltip-activate-mouse-motions-if-enabled) | |
209 (funcall hook-fn 'pre-command-hook 'tooltip-hide) | |
210 (funcall hook-fn 'tooltip-hook 'tooltip-gud-tips) | |
211 (funcall hook-fn 'tooltip-hook 'tooltip-help-tips) | |
212 (setq show-help-function (if on 'tooltip-show-help-function nil)) | |
213 ;; `ignore' is the default binding for mouse movements. | |
214 (define-key global-map [mouse-movement] | |
215 (if on 'tooltip-mouse-motion 'ignore)) | |
33140
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
216 (tooltip-gud-tips-setup))) |
25003 | 217 |
33140
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
218 (defun tooltip-gud-tips-setup () |
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
219 "Setup debugger mode-hooks for tooltips." |
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
220 (when (and tooltip-mode tooltip-gud-tips-p) |
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
221 (global-set-key [S-mouse-3] 'tooltip-gud-toggle-dereference) |
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
222 (add-hook 'gdb-mode-hook |
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
223 #'(lambda () (setq tooltip-gud-debugger 'gdb))) |
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
224 (add-hook 'sdb-mode-hook |
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
225 #'(lambda () (setq tooltip-gud-debugger 'sdb))) |
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
226 (add-hook 'dbx-mode-hook |
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
227 #'(lambda () (setq tooltip-gud-debugger 'dbx))) |
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
228 (add-hook 'xdb-mode-hook |
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
229 #'(lambda () (setq tooltip-gud-debugger 'xdb))) |
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
230 (add-hook 'perldb-mode-hook |
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
231 #'(lambda () (setq tooltip-gud-debugger 'perldb))))) |
25003 | 232 |
233 ;;; Timeout for tooltip display | |
234 | |
235 (defun tooltip-delay () | |
236 "Return the delay in seconds for the next tooltip." | |
237 (let ((delay tooltip-delay) | |
30481 | 238 (now (float-time))) |
25003 | 239 (when (and tooltip-hide-time |
240 (< (- now tooltip-hide-time) tooltip-recent-seconds)) | |
241 (setq delay tooltip-short-delay)) | |
242 delay)) | |
243 | |
244 | |
245 (defun tooltip-disable-timeout () | |
246 "Disable the tooltip timeout." | |
247 (when tooltip-timeout-id | |
248 (disable-timeout tooltip-timeout-id) | |
249 (setq tooltip-timeout-id nil))) | |
250 | |
251 | |
252 (defun tooltip-add-timeout () | |
253 "Add a one-shot timeout to call function tooltip-timeout." | |
254 (setq tooltip-timeout-id | |
255 (add-timeout (tooltip-delay) 'tooltip-timeout nil))) | |
256 | |
257 | |
258 (defun tooltip-timeout (object) | |
259 "Function called when timer with id tooltip-timeout-id fires." | |
260 (run-hook-with-args-until-success 'tooltip-hook | |
261 tooltip-last-mouse-motion-event)) | |
262 | |
263 | |
264 | |
265 ;;; Reacting on mouse movements | |
266 | |
267 (defun tooltip-change-major-mode () | |
268 "Function added to `change-major-mode-hook' when tooltip mode is on." | |
269 (add-hook 'post-command-hook 'tooltip-activate-mouse-motions-if-enabled)) | |
270 | |
271 | |
272 (defun tooltip-activate-mouse-motions-if-enabled () | |
273 "Reconsider for all buffers whether mouse motion events are desired." | |
274 (remove-hook 'post-command-hook 'tooltip-activate-mouse-motions-if-enabled) | |
275 (let ((buffers (buffer-list))) | |
276 (save-excursion | |
277 (while buffers | |
278 (set-buffer (car buffers)) | |
279 (if (and tooltip-mode | |
280 tooltip-gud-tips-p | |
281 (memq major-mode tooltip-gud-modes)) | |
282 (tooltip-activate-mouse-motions t) | |
283 (tooltip-activate-mouse-motions nil)) | |
284 (setq buffers (cdr buffers)))))) | |
285 | |
286 | |
287 (defun tooltip-activate-mouse-motions (activatep) | |
288 "Activate/deactivate mouse motion events for the current buffer. | |
289 ACTIVATEP non-nil means activate mouse motion events." | |
290 (if activatep | |
291 (progn | |
292 (make-local-variable 'track-mouse) | |
293 (setq track-mouse t)) | |
294 (kill-local-variable 'track-mouse))) | |
295 | |
296 | |
297 (defun tooltip-mouse-motion (event) | |
298 "Command handler for mouse movement events in `global-map'." | |
299 (interactive "e") | |
300 (tooltip-hide) | |
301 (when (car (mouse-pixel-position)) | |
302 (setq tooltip-last-mouse-motion-event (copy-sequence event)) | |
303 (tooltip-add-timeout))) | |
304 | |
305 | |
306 | |
307 ;;; Displaying tips | |
308 | |
309 (defun tooltip-show (text) | |
310 "Show a tooltip window at the current mouse position displaying TEXT." | |
32431
a35cc9700ff7
* tooltip.el (tooltip-use-echo-area): New user variable.
Sam Steingold <sds@gnu.org>
parents:
30481
diff
changeset
|
311 (if tooltip-use-echo-area |
a35cc9700ff7
* tooltip.el (tooltip-use-echo-area): New user variable.
Sam Steingold <sds@gnu.org>
parents:
30481
diff
changeset
|
312 (message "%s" text) |
34540
e1e4704de6ed
(tooltip-show): If an error is signaled in
Gerd Moellmann <gerd@gnu.org>
parents:
33925
diff
changeset
|
313 (condition-case error |
e1e4704de6ed
(tooltip-show): If an error is signaled in
Gerd Moellmann <gerd@gnu.org>
parents:
33925
diff
changeset
|
314 (x-show-tip text |
e1e4704de6ed
(tooltip-show): If an error is signaled in
Gerd Moellmann <gerd@gnu.org>
parents:
33925
diff
changeset
|
315 (selected-frame) |
e1e4704de6ed
(tooltip-show): If an error is signaled in
Gerd Moellmann <gerd@gnu.org>
parents:
33925
diff
changeset
|
316 tooltip-frame-parameters |
e1e4704de6ed
(tooltip-show): If an error is signaled in
Gerd Moellmann <gerd@gnu.org>
parents:
33925
diff
changeset
|
317 nil |
e1e4704de6ed
(tooltip-show): If an error is signaled in
Gerd Moellmann <gerd@gnu.org>
parents:
33925
diff
changeset
|
318 tooltip-x-offset |
e1e4704de6ed
(tooltip-show): If an error is signaled in
Gerd Moellmann <gerd@gnu.org>
parents:
33925
diff
changeset
|
319 tooltip-y-offset) |
e1e4704de6ed
(tooltip-show): If an error is signaled in
Gerd Moellmann <gerd@gnu.org>
parents:
33925
diff
changeset
|
320 (error |
e1e4704de6ed
(tooltip-show): If an error is signaled in
Gerd Moellmann <gerd@gnu.org>
parents:
33925
diff
changeset
|
321 (message "Error while displaying tooltip: %s" error) |
e1e4704de6ed
(tooltip-show): If an error is signaled in
Gerd Moellmann <gerd@gnu.org>
parents:
33925
diff
changeset
|
322 (sit-for 1) |
e1e4704de6ed
(tooltip-show): If an error is signaled in
Gerd Moellmann <gerd@gnu.org>
parents:
33925
diff
changeset
|
323 (message "%s" text))))) |
e1e4704de6ed
(tooltip-show): If an error is signaled in
Gerd Moellmann <gerd@gnu.org>
parents:
33925
diff
changeset
|
324 |
25003 | 325 |
326 (defun tooltip-hide (&optional ignored-arg) | |
327 "Hide a tooltip, if one is displayed. | |
328 Value is non-nil if tooltip was open." | |
329 (tooltip-disable-timeout) | |
330 (when (x-hide-tip) | |
30481 | 331 (setq tooltip-hide-time (float-time)))) |
25003 | 332 |
333 | |
334 | |
335 ;;; Debugger-related functions | |
336 | |
337 (defun tooltip-identifier-from-point (point) | |
338 "Extract the identifier at POINT, if any. | |
339 Value is nil if no identifier exists at point. Identifier extraction | |
340 is based on the current syntax table." | |
341 (save-excursion | |
342 (goto-char point) | |
343 (let ((start (progn (skip-syntax-backward "w_") (point)))) | |
344 (unless (looking-at "[0-9]") | |
345 (skip-syntax-forward "w_") | |
346 (when (> (point) start) | |
347 (buffer-substring start (point))))))) | |
348 | |
349 | |
350 (defmacro tooltip-region-active-p () | |
351 "Value is non-nil if the region is currently active." | |
352 (if (string-match "^GNU" (emacs-version)) | |
353 `(and transient-mark-mode mark-active) | |
354 `(region-active-p))) | |
355 | |
356 | |
357 (defun tooltip-expr-to-print (event) | |
358 "Return an expression that should be printed for EVENT. | |
359 If a region is active and the mouse is inside the region, print | |
360 the region. Otherwise, figure out the identifier around the point | |
361 where the mouse is." | |
362 (save-excursion | |
363 (set-buffer (tooltip-event-buffer event)) | |
364 (let ((point (posn-point (event-end event)))) | |
365 (if (tooltip-region-active-p) | |
366 (when (and (<= (region-beginning) point) (<= point (region-end))) | |
367 (buffer-substring (region-beginning) (region-end))) | |
368 (tooltip-identifier-from-point point))))) | |
369 | |
370 | |
371 (defun tooltip-process-prompt-regexp (process) | |
372 "Return regexp matching the prompt of PROCESS at the end of a string. | |
373 The prompt is taken from the value of COMINT-PROMPT-REGEXP in the buffer | |
374 of PROCESS." | |
375 (let ((prompt-regexp (save-excursion | |
376 (set-buffer (process-buffer process)) | |
377 comint-prompt-regexp))) | |
378 ;; Most start with `^' but the one for `sdb' cannot be easily | |
379 ;; stripped. Code the prompt for `sdb' fixed here. | |
380 (if (= (aref prompt-regexp 0) ?^) | |
381 (setq prompt-regexp (substring prompt-regexp 1)) | |
382 (setq prompt-regexp "\\*")) | |
383 (concat "\n*" prompt-regexp "$"))) | |
384 | |
385 | |
386 (defun tooltip-strip-prompt (process output) | |
387 "Return OUTPUT with any prompt of PROCESS stripped from its end." | |
388 (let ((prompt-regexp (tooltip-process-prompt-regexp process))) | |
389 (save-match-data | |
390 (when (string-match prompt-regexp output) | |
391 (setq output (substring output 0 (match-beginning 0))))) | |
392 output)) | |
393 | |
394 | |
395 | |
396 ;;; Tips for `gud' | |
397 | |
398 (defvar tooltip-gud-original-filter nil | |
399 "Process filter to restore after GUD output has been received.") | |
400 | |
401 | |
402 (defvar tooltip-gud-dereference nil | |
403 "Non-nil means print expressions with a `*' in front of them. | |
404 For C this would dereference a pointer expression.") | |
405 | |
406 | |
407 (defvar tooltip-gud-event nil | |
408 "The mouse movement event that led to a tooltip display. | |
409 This event can be examined by forms in TOOLTIP-GUD-DISPLAY.") | |
410 | |
411 | |
412 (defvar tooltip-gud-debugger nil | |
413 "A symbol describing the debugger running under GUD.") | |
414 | |
415 | |
416 (defun tooltip-gud-toggle-dereference () | |
27582
42b52d8b6703
(tooltip-gud-tips-p, tooltip-gud-toggle-dereference):
Dave Love <fx@gnu.org>
parents:
25332
diff
changeset
|
417 "Toggle whether tooltips should show `* expr' or `expr'." |
25003 | 418 (interactive) |
419 (setq tooltip-gud-dereference (not tooltip-gud-dereference)) | |
420 (when (interactive-p) | |
421 (message "Dereferencing is now %s." | |
422 (if tooltip-gud-dereference "on" "off")))) | |
423 | |
424 | |
425 (defun tooltip-gud-process-output (process output) | |
426 "Process debugger output and show it in a tooltip window." | |
427 (set-process-filter process tooltip-gud-original-filter) | |
428 (tooltip-show (tooltip-strip-prompt process output))) | |
429 | |
430 | |
431 (defun tooltip-gud-print-command (expr) | |
432 "Return a suitable command to print the expression EXPR. | |
433 If TOOLTIP-GUD-DEREFERENCE is t, also prepend a `*' to EXPR." | |
434 (when tooltip-gud-dereference | |
435 (setq expr (concat "*" expr))) | |
436 (case tooltip-gud-debugger | |
437 ((gdb dbx) (concat "print " expr)) | |
438 (xdb (concat "p " expr)) | |
439 (sdb (concat expr "/")) | |
440 (perldb expr))) | |
30481 | 441 |
25003 | 442 |
443 (defun tooltip-gud-tips (event) | |
25332
c09e05be2f4b
(tooltip-mode): Customize this, per convention.
Dave Love <fx@gnu.org>
parents:
25003
diff
changeset
|
444 "Show tip for identifier or selection under the mouse. |
c09e05be2f4b
(tooltip-mode): Customize this, per convention.
Dave Love <fx@gnu.org>
parents:
25003
diff
changeset
|
445 The mouse must either point at an identifier or inside a selected |
c09e05be2f4b
(tooltip-mode): Customize this, per convention.
Dave Love <fx@gnu.org>
parents:
25003
diff
changeset
|
446 region for the tip window to be shown. If tooltip-gud-dereference is t, |
c09e05be2f4b
(tooltip-mode): Customize this, per convention.
Dave Love <fx@gnu.org>
parents:
25003
diff
changeset
|
447 add a `*' in front of the printed expression. |
25003 | 448 |
449 This function must return nil if it doesn't handle EVENT." | |
450 (let (gud-buffer process) | |
451 (when (and (eventp event) | |
452 tooltip-gud-tips-p | |
453 (boundp 'gud-comint-buffer) | |
454 (setq gud-buffer gud-comint-buffer) | |
455 (setq process (get-buffer-process gud-buffer)) | |
456 (posn-point (event-end event)) | |
457 (progn (setq tooltip-gud-event event) | |
458 (eval (cons 'and tooltip-gud-display)))) | |
459 (let ((expr (tooltip-expr-to-print event))) | |
460 (when expr | |
33140
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
461 (let ((cmd (tooltip-gud-print-command expr))) |
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
462 (unless (null cmd) ; CMD can be nil if unknown debugger |
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
463 (setq tooltip-gud-original-filter (process-filter process)) |
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
464 (set-process-filter process 'tooltip-gud-process-output) |
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
465 (gud-basic-call cmd) |
61f4c87b845c
(tooltip-gud-tips-setup): New function.
Miles Bader <miles@gnu.org>
parents:
32431
diff
changeset
|
466 expr))))))) |
25003 | 467 |
468 | |
469 ;;; Tooltip help. | |
470 | |
471 (defvar tooltip-help-message nil | |
472 "The last help message received via `tooltip-show-help-function'.") | |
473 | |
474 | |
475 (defun tooltip-show-help-function (msg) | |
476 "Function installed as `show-help-function'. | |
477 MSG is either a help string to display, or nil to cancel the display." | |
478 (let ((previous-help tooltip-help-message)) | |
479 (setq tooltip-help-message msg) | |
480 (cond ((null msg) | |
481 (tooltip-hide)) | |
482 ((or (not (stringp previous-help)) | |
483 (not (string= msg previous-help))) | |
484 (tooltip-hide) | |
485 (tooltip-add-timeout)) | |
486 (t | |
487 (tooltip-disable-timeout) | |
488 (tooltip-add-timeout))))) | |
489 | |
490 | |
491 (defun tooltip-help-tips (event) | |
492 "Hook function to display a help tooltip. | |
493 Value is non-nil if this function handled the tip." | |
494 (when (stringp tooltip-help-message) | |
495 (tooltip-show tooltip-help-message) | |
496 (setq tooltip-help-message nil) | |
497 t)) | |
498 | |
499 | |
500 | |
33356
73a360d50e18
(tooltip-mode): Add a comment about startup.el
Gerd Moellmann <gerd@gnu.org>
parents:
33140
diff
changeset
|
501 ;;; Do this after all functions have been defined that are called from |
73a360d50e18
(tooltip-mode): Add a comment about startup.el
Gerd Moellmann <gerd@gnu.org>
parents:
33140
diff
changeset
|
502 ;;; `tooltip-mode'. The actual default value of `tooltip-mode' is set |
73a360d50e18
(tooltip-mode): Add a comment about startup.el
Gerd Moellmann <gerd@gnu.org>
parents:
33140
diff
changeset
|
503 ;;; in startup.el. |
25332
c09e05be2f4b
(tooltip-mode): Customize this, per convention.
Dave Love <fx@gnu.org>
parents:
25003
diff
changeset
|
504 |
c09e05be2f4b
(tooltip-mode): Customize this, per convention.
Dave Love <fx@gnu.org>
parents:
25003
diff
changeset
|
505 ;;;###autoload |
c09e05be2f4b
(tooltip-mode): Customize this, per convention.
Dave Love <fx@gnu.org>
parents:
25003
diff
changeset
|
506 (defcustom tooltip-mode nil |
c09e05be2f4b
(tooltip-mode): Customize this, per convention.
Dave Love <fx@gnu.org>
parents:
25003
diff
changeset
|
507 "Toggle tooltip-mode. |
c09e05be2f4b
(tooltip-mode): Customize this, per convention.
Dave Love <fx@gnu.org>
parents:
25003
diff
changeset
|
508 Setting this variable directly does not take effect; |
c09e05be2f4b
(tooltip-mode): Customize this, per convention.
Dave Love <fx@gnu.org>
parents:
25003
diff
changeset
|
509 use either \\[customize] or the function `tooltip-mode'." |
c09e05be2f4b
(tooltip-mode): Customize this, per convention.
Dave Love <fx@gnu.org>
parents:
25003
diff
changeset
|
510 :set (lambda (symbol value) |
c09e05be2f4b
(tooltip-mode): Customize this, per convention.
Dave Love <fx@gnu.org>
parents:
25003
diff
changeset
|
511 (tooltip-mode (or value 0))) |
c09e05be2f4b
(tooltip-mode): Customize this, per convention.
Dave Love <fx@gnu.org>
parents:
25003
diff
changeset
|
512 :initialize 'custom-initialize-default |
25003 | 513 :type 'boolean |
514 :require 'tooltip | |
515 :group 'tooltip) | |
516 | |
517 | |
518 ;;; tooltip.el ends here |