annotate lisp/tooltip.el @ 25183:16937a774275

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