aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Roberts2005-05-06 22:11:35 +0000
committerNick Roberts2005-05-06 22:11:35 +0000
commita93d834478577e77dedb3cf35f22f8eb6c16c95c (patch)
treec2c1c496a6de9dae03e57d26e94508e0e279baab
parentce38ddb8ae8f43a888d4d62695dd62c589dc6b08 (diff)
downloademacs-a93d834478577e77dedb3cf35f22f8eb6c16c95c.tar.gz
emacs-a93d834478577e77dedb3cf35f22f8eb6c16c95c.zip
(require): CL no longer needed to compile case.
(tooltip-mode): Do not toggle functions for GUD tooltips. (tooltip-gud-tips-p): Remove. Replace with minor mode gud-tooltip-mode in gud.el. (tooltip-gud-modes, tooltip-gud-display, tooltip-gud-echo-area) (tooltip-gud-toggle-dereference): Rename in gud.el by replacing tooltip-gud prefix with gud-tooltip and obsolete. (tooltip-change-major-mode, tooltip-activate-mouse-motions-if-enabled) (tooltip-mouse-motions-active, tooltip-activate-mouse-motions) (tooltip-mouse-motion): Mouse movement functions/variable. Rename in gud.el by adding gud prefix. (tooltip-gud-original-filter, tooltip-gud-dereference) (tooltip-gud-event, tooltip-toggle-gud-tips) (tooltip-gud-process-output, tooltip-gud-print-command) (tooltip-gud-tips): GUD tooltip functions/variables. Rename in gud.el by replacing tooltip-gud prefix with gud-tooltip. (gdb-tooltip-print): Move to gdb-ui.el.
-rw-r--r--lisp/tooltip.el211
1 files changed, 9 insertions, 202 deletions
diff --git a/lisp/tooltip.el b/lisp/tooltip.el
index 9bd35f05d11..7a2865b9dfa 100644
--- a/lisp/tooltip.el
+++ b/lisp/tooltip.el
@@ -27,9 +27,6 @@
27 27
28;;; Code: 28;;; Code:
29 29
30(eval-when-compile (require 'cl)) ; for case macro
31
32
33;;; Customizable settings 30;;; Customizable settings
34 31
35(defgroup tooltip nil 32(defgroup tooltip nil
@@ -116,42 +113,6 @@ position to pop up the tooltip."
116 "Face for tooltips." 113 "Face for tooltips."
117 :group 'tooltip) 114 :group 'tooltip)
118 115
119(defcustom tooltip-gud-tips-p nil
120 "*Non-nil means show tooltips in GUD sessions.
121
122This allows you to display a variable's value in a tooltip simply
123by pointing at it with the mouse. In the case of a C program
124controlled by GDB, it shows the associated #define directives
125when program is not executing."
126 :type 'boolean
127 :tag "GUD"
128 :group 'tooltip)
129
130(defcustom tooltip-gud-modes '(gud-mode c-mode c++-mode fortran-mode)
131 "List of modes for which to enable GUD tips."
132 :type 'sexp
133 :tag "GUD modes"
134 :group 'tooltip)
135
136(defcustom tooltip-gud-display
137 '((eq (tooltip-event-buffer tooltip-gud-event)
138 (marker-buffer gud-overlay-arrow-position)))
139 "List of forms determining where GUD tooltips are displayed.
140
141Forms in the list are combined with AND. The default is to display
142only tooltips in the buffer containing the overlay arrow."
143 :type 'sexp
144 :tag "GUD buffers predicate"
145 :group 'tooltip)
146
147(defcustom tooltip-gud-echo-area nil
148 "Use the echo area instead of frames for GUD tooltips."
149 :type 'boolean
150 :tag "Use echo area"
151 :group 'tooltip)
152
153(defvaralias 'tooltip-use-echo-area 'tooltip-gud-echo-area)
154(make-obsolete-variable 'tooltip-use-echo-area 'tooltip-gud-echo-area "22.1")
155 116
156;;; Variables that are not customizable. 117;;; Variables that are not customizable.
157 118
@@ -169,7 +130,6 @@ the last mouse movement event that occurred.")
169(defvar tooltip-hide-time nil 130(defvar tooltip-hide-time nil
170 "Time when the last tooltip was hidden.") 131 "Time when the last tooltip was hidden.")
171 132
172
173;;; Event accessors 133;;; Event accessors
174 134
175(defun tooltip-event-buffer (event) 135(defun tooltip-event-buffer (event)
@@ -178,7 +138,6 @@ This might return nil if the event did not occur over a buffer."
178 (let ((window (posn-window (event-end event)))) 138 (let ((window (posn-window (event-end event))))
179 (and window (window-buffer window)))) 139 (and window (window-buffer window))))
180 140
181
182;;; Switching tooltips on/off 141;;; Switching tooltips on/off
183 142
184;; We don't set track-mouse globally because this is a big redisplay 143;; We don't set track-mouse globally because this is a big redisplay
@@ -202,16 +161,15 @@ With ARG, turn tooltip mode on if and only if ARG is positive."
202 :group 'tooltip 161 :group 'tooltip
203 (unless (or (null tooltip-mode) (fboundp 'x-show-tip)) 162 (unless (or (null tooltip-mode) (fboundp 'x-show-tip))
204 (error "Sorry, tooltips are not yet available on this system")) 163 (error "Sorry, tooltips are not yet available on this system"))
205 (let ((hook-fn (if tooltip-mode 'add-hook 'remove-hook))) 164 (if tooltip-mode
206 (funcall hook-fn 'change-major-mode-hook 'tooltip-change-major-mode) 165 (progn
207 (tooltip-activate-mouse-motions-if-enabled) 166 (add-hook 'pre-command-hook 'tooltip-hide)
208 (funcall hook-fn 'pre-command-hook 'tooltip-hide) 167 (add-hook 'tooltip-hook 'tooltip-help-tips))
209 (funcall hook-fn 'tooltip-hook 'tooltip-gud-tips) 168 (unless (and (boundp 'gud-tooltip-mode) gud-tooltip-mode)
210 (funcall hook-fn 'tooltip-hook 'tooltip-help-tips) 169 (remove-hook 'pre-command-hook 'tooltip-hide))
211 (setq show-help-function (if tooltip-mode 'tooltip-show-help-function nil)) 170 (remove-hook 'tooltip-hook 'tooltip-help-tips))
212 ;; `ignore' is the default binding for mouse movements. 171 (setq show-help-function
213 (define-key global-map [mouse-movement] 172 (if tooltip-mode 'tooltip-show-help-function nil)))
214 (if tooltip-mode 'tooltip-mouse-motion 'ignore))))
215 173
216 174
217;;; Timeout for tooltip display 175;;; Timeout for tooltip display
@@ -242,49 +200,6 @@ With ARG, turn tooltip mode on if and only if ARG is positive."
242 tooltip-last-mouse-motion-event)) 200 tooltip-last-mouse-motion-event))
243 201
244 202
245;;; Reacting on mouse movements
246
247(defun tooltip-change-major-mode ()
248 "Function added to `change-major-mode-hook' when tooltip mode is on."
249 (add-hook 'post-command-hook 'tooltip-activate-mouse-motions-if-enabled))
250
251(defun tooltip-activate-mouse-motions-if-enabled ()
252 "Reconsider for all buffers whether mouse motion events are desired."
253 (remove-hook 'post-command-hook 'tooltip-activate-mouse-motions-if-enabled)
254 (dolist (buffer (buffer-list))
255 (save-excursion
256 (set-buffer buffer)
257 (if (and tooltip-mode
258 tooltip-gud-tips-p
259 (memq major-mode tooltip-gud-modes))
260 (tooltip-activate-mouse-motions t)
261 (tooltip-activate-mouse-motions nil)))))
262
263(defvar tooltip-mouse-motions-active nil
264 "Locally t in a buffer if tooltip processing of mouse motion is enabled.")
265
266(defun tooltip-activate-mouse-motions (activatep)
267 "Activate/deactivate mouse motion events for the current buffer.
268ACTIVATEP non-nil means activate mouse motion events."
269 (if activatep
270 (progn
271 (make-local-variable 'tooltip-mouse-motions-active)
272 (setq tooltip-mouse-motions-active t)
273 (make-local-variable 'track-mouse)
274 (setq track-mouse t))
275 (when tooltip-mouse-motions-active
276 (kill-local-variable 'tooltip-mouse-motions-active)
277 (kill-local-variable 'track-mouse))))
278
279(defun tooltip-mouse-motion (event)
280 "Command handler for mouse movement events in `global-map'."
281 (interactive "e")
282 (tooltip-hide)
283 (when (car (mouse-pixel-position))
284 (setq tooltip-last-mouse-motion-event (copy-sequence event))
285 (tooltip-start-delayed-tip)))
286
287
288;;; Displaying tips 203;;; Displaying tips
289 204
290(defun tooltip-set-param (alist key value) 205(defun tooltip-set-param (alist key value)
@@ -396,114 +311,6 @@ of PROCESS."
396 output)) 311 output))
397 312
398 313
399;;; Tips for `gud'
400
401(defvar tooltip-gud-original-filter nil
402 "Process filter to restore after GUD output has been received.")
403
404(defvar tooltip-gud-dereference nil
405 "Non-nil means print expressions with a `*' in front of them.
406For C this would dereference a pointer expression.")
407
408(defvar tooltip-gud-event nil
409 "The mouse movement event that led to a tooltip display.
410This event can be examined by forms in TOOLTIP-GUD-DISPLAY.")
411
412(defun tooltip-gud-toggle-dereference ()
413 "Toggle whether tooltips should show `* expr' or `expr'."
414 (interactive)
415 (setq tooltip-gud-dereference (not tooltip-gud-dereference))
416 (when (interactive-p)
417 (message "Dereferencing is now %s."
418 (if tooltip-gud-dereference "on" "off"))))
419
420(defun tooltip-toggle-gud-tips ()
421 "Toggle the display of GUD tooltips."
422 (interactive)
423 (setq tooltip-gud-tips-p (not tooltip-gud-tips-p))
424 ;; Reconsider for all buffers whether mouse motion events are desired.
425 (tooltip-change-major-mode)
426 (when (interactive-p)
427 (message (format "GUD tooltips %sabled"
428 (if tooltip-gud-tips-p "en" "dis")))))
429
430; This will only display data that comes in one chunk.
431; Larger arrays (say 400 elements) are displayed in
432; the tootip incompletely and spill over into the gud buffer.
433; Switching the process-filter creates timing problems and
434; it may be difficult to do better. Using annotations as in
435; gdb-ui.el gets round this problem.
436(defun tooltip-gud-process-output (process output)
437 "Process debugger output and show it in a tooltip window."
438 (set-process-filter process tooltip-gud-original-filter)
439 (tooltip-show (tooltip-strip-prompt process output)
440 tooltip-gud-echo-area))
441
442(defun tooltip-gud-print-command (expr)
443 "Return a suitable command to print the expression EXPR.
444If TOOLTIP-GUD-DEREFERENCE is t, also prepend a `*' to EXPR."
445 (when tooltip-gud-dereference
446 (setq expr (concat "*" expr)))
447 (case gud-minor-mode
448 ((gdb gdba) (concat "server print " expr))
449 (dbx (concat "print " expr))
450 (xdb (concat "p " expr))
451 (sdb (concat expr "/"))
452 (perldb expr)))
453
454(defun tooltip-gud-tips (event)
455 "Show tip for identifier or selection under the mouse.
456The mouse must either point at an identifier or inside a selected
457region for the tip window to be shown. If tooltip-gud-dereference is t,
458add a `*' in front of the printed expression. In the case of a C program
459controlled by GDB, show the associated #define directives when program is
460not executing.
461
462This function must return nil if it doesn't handle EVENT."
463 (let (process)
464 (when (and (eventp event)
465 tooltip-gud-tips-p
466 (boundp 'gud-comint-buffer)
467 gud-comint-buffer
468 (buffer-name gud-comint-buffer); gud-comint-buffer might be killed
469 (setq process (get-buffer-process gud-comint-buffer))
470 (posn-point (event-end event))
471 (or (eq gud-minor-mode 'gdba)
472 (progn (setq tooltip-gud-event event)
473 (eval (cons 'and tooltip-gud-display)))))
474 (let ((expr (tooltip-expr-to-print event)))
475 (when expr
476 (if (and (eq gud-minor-mode 'gdba)
477 (not gdb-active-process))
478 (progn
479 (with-current-buffer
480 (window-buffer (let ((mouse (mouse-position)))
481 (window-at (cadr mouse)
482 (cddr mouse))))
483 (let ((define-elt (assoc expr gdb-define-alist)))
484 (unless (null define-elt)
485 (tooltip-show (cdr define-elt))
486 expr))))
487 (let ((cmd (tooltip-gud-print-command expr)))
488 (unless (null cmd) ; CMD can be nil if unknown debugger
489 (case gud-minor-mode
490 (gdba (gdb-enqueue-input
491 (list (concat cmd "\n") 'gdb-tooltip-print)))
492 (t
493 (setq tooltip-gud-original-filter (process-filter process))
494 (set-process-filter process 'tooltip-gud-process-output)
495 (gud-basic-call cmd)))
496 expr))))))))
497
498(defun gdb-tooltip-print ()
499 (tooltip-show
500 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer)
501 (let ((string (buffer-string)))
502 ;; remove newline for tooltip-gud-echo-area
503 (substring string 0 (- (length string) 1))))
504 tooltip-gud-echo-area))
505
506
507;;; Tooltip help. 314;;; Tooltip help.
508 315
509(defvar tooltip-help-message nil 316(defvar tooltip-help-message nil