209
|
1 ;;; mouse.el --- window system-independent mouse support.
|
|
2
|
|
3 ;; Copyright (C) 1988, 1992-4, 1997 Free Software Foundation, Inc.
|
|
4 ;; Copyright (C) 1995 Tinker Systems
|
|
5 ;; Copyright (C) 1995, 1996 Ben Wing.
|
|
6
|
|
7 ;; Maintainer: XEmacs Development Team
|
|
8 ;; Keywords: mouse, dumped
|
|
9
|
|
10 ;; This file is part of XEmacs.
|
|
11
|
|
12 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
13 ;; under the terms of the GNU General Public License as published by
|
|
14 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;; any later version.
|
|
16
|
|
17 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
20 ;; General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
|
23 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
24 ;; Free Software Foundation, 59 Temple Place - Suite 330,
|
|
25 ;; Boston, MA 02111-1307, USA.
|
|
26
|
|
27 ;;; Synched up with: Not synched with FSF. Almost completely divergent.
|
|
28
|
|
29 ;;; Commentary:
|
|
30
|
|
31 ;; This file is dumped with XEmacs (when window system support is compiled in).
|
|
32
|
|
33 ;;; Code:
|
|
34
|
|
35 (provide 'mouse)
|
|
36
|
|
37 (global-set-key 'button1 'mouse-track)
|
|
38 (global-set-key '(shift button1) 'mouse-track-adjust)
|
|
39 (global-set-key '(control button1) 'mouse-track-insert)
|
|
40 (global-set-key '(control shift button1) 'mouse-track-delete-and-insert)
|
|
41 (global-set-key '(meta button1) 'mouse-track-do-rectangle)
|
|
42
|
|
43 ;; enable drag regions (ograf@fga.de)
|
|
44 ;; if button2 is dragged from within a region, this becomes a drop
|
249
|
45 (if (featurep '(or offix cde mswindows))
|
209
|
46 (global-set-key 'button2 'mouse-drag-or-yank)
|
|
47 (global-set-key 'button2 'mouse-yank))
|
|
48
|
249
|
49 ;; enable drops from OffiX (ograf@fga.de) or mswindows
|
|
50 ;; accept any button1,2,3 drop with `mouse-offix-drop' or 'mswindows-mouse-drop'
|
209
|
51 (cond ((featurep 'offix)
|
|
52 (global-set-key 'drop1 'mouse-offix-drop)
|
|
53 (global-set-key 'drop2 'mouse-offix-drop)
|
249
|
54 (global-set-key 'drop3 'mouse-offix-drop))
|
|
55 ((featurep 'mswindows)
|
|
56 (global-set-key 'drop0 'mouse-mswindows-drop)
|
|
57 (global-set-key 'drop1 'mouse-mswindows-drop)
|
|
58 (global-set-key 'drop2 'mouse-mswindows-drop)
|
|
59 (global-set-key 'drop3 'mouse-mswindows-drop)))
|
209
|
60
|
227
|
61 (defgroup mouse nil
|
|
62 "Window system-independent mouse support."
|
|
63 :group 'editing)
|
|
64
|
209
|
65 (defcustom mouse-track-rectangle-p nil
|
|
66 "*If true, then dragging out a region with the mouse selects rectangles
|
|
67 instead of simple start/end regions."
|
|
68 :type 'boolean
|
|
69 :group 'mouse)
|
|
70
|
|
71 (defcustom mouse-yank-at-point nil
|
|
72 "*If non-nil, the function `mouse-yank' will yank text at the cursor location.
|
|
73 Otherwise, the cursor will be moved to the location of the pointer click before
|
|
74 text is inserted."
|
|
75 :type 'boolean
|
|
76 :group 'mouse)
|
|
77
|
|
78 (defcustom mouse-highlight-text 'context
|
|
79 "*Choose the default double-click highlighting behaviour.
|
|
80 If set to `context', double-click will highlight words when the mouse
|
|
81 is at a word character, or a symbol if the mouse is at a symbol
|
|
82 character.
|
|
83 If set to `word', double-click will always attempt to highlight a word.
|
|
84 If set to `symbol', double-click will always attempt to highlight a
|
|
85 symbol (the default behaviour in previous XEmacs versions)."
|
|
86 :type '(choice (const context)
|
|
87 (const word)
|
|
88 (const symbol))
|
|
89 :group 'mouse)
|
|
90
|
|
91 (defvar mouse-yank-function 'mouse-consolidated-yank
|
|
92 "Function that is called upon by `mouse-yank' to actually insert text.")
|
|
93
|
|
94 (defun mouse-consolidated-yank ()
|
|
95 (interactive)
|
|
96 (case (device-type)
|
|
97 (x (x-yank-function))
|
|
98 (tty (yank))
|
|
99 (otherwise (yank))))
|
|
100
|
|
101
|
|
102 (defun mouse-select ()
|
|
103 "Select Emacs window the mouse is on."
|
|
104 (interactive "@"))
|
|
105
|
|
106 (defun mouse-delete-window ()
|
|
107 "Delete the Emacs window the mouse is on."
|
|
108 (interactive "@")
|
|
109 (delete-window))
|
|
110
|
|
111 (defun mouse-keep-one-window ()
|
|
112 "Select Emacs window mouse is on, then kill all other Emacs windows."
|
|
113 (interactive "@")
|
|
114 (delete-other-windows))
|
|
115
|
|
116 (defun mouse-select-and-split ()
|
|
117 "Select Emacs window mouse is on, then split it vertically in half."
|
|
118 (interactive "@")
|
|
119 (split-window-vertically nil))
|
|
120
|
|
121 (defun mouse-set-point (event)
|
|
122 "Select Emacs window mouse is on, and move point to mouse position."
|
|
123 (interactive "@e")
|
|
124 (let ((window (event-window event))
|
|
125 (pos (event-point event))
|
|
126 (close-pos (event-closest-point event)))
|
|
127 (or window (error "not in a window"))
|
|
128 (select-window window)
|
|
129 (if (and pos (> pos 0))
|
|
130 ;; If the event was over a text char, it's easy.
|
|
131 (goto-char (max (min pos (point-max)) (point-min)))
|
|
132 (if (and close-pos (> close-pos 0))
|
|
133 (goto-char (max (min close-pos (point-max)) (point-min)))
|
|
134 ;; When the event occurs outside of the frame directly to the
|
|
135 ;; left or right of a modeline, close-point is nil, but
|
|
136 ;; event-over-modeline is also nil. That will drop us to this
|
|
137 ;; point. So instead of erroring, just return nil.
|
|
138 nil))))
|
|
139
|
|
140 (defun mouse-yank (event)
|
|
141 "Paste text with the mouse.
|
|
142 If the variable `mouse-yank-at-point' is nil, then pasting occurs at the
|
|
143 location of the click; otherwise, pasting occurs at the current cursor
|
|
144 location."
|
|
145 (interactive "e")
|
|
146 (and (not mouse-yank-at-point)
|
|
147 (mouse-set-point event))
|
|
148 (funcall mouse-yank-function))
|
|
149
|
|
150 (defun click-inside-extent-p (click extent)
|
|
151 "Returns non-nil if the button event is within the bounds of the primary
|
|
152 selection-extent, nil otherwise."
|
|
153 ;; stig@hackvan.com
|
|
154 (let ((ewin (event-window click))
|
|
155 (epnt (event-point click)))
|
|
156 (and ewin
|
|
157 epnt
|
|
158 extent
|
|
159 (eq (window-buffer ewin)
|
|
160 (extent-object extent))
|
|
161 (extent-start-position extent)
|
|
162 (> epnt (extent-start-position extent))
|
|
163 (> (extent-end-position extent) epnt))))
|
|
164
|
|
165 (defun click-inside-selection-p (click)
|
|
166 (or (click-inside-extent-p click primary-selection-extent)
|
|
167 (click-inside-extent-p click zmacs-region-extent)
|
|
168 ))
|
|
169
|
|
170 (defun point-inside-extent-p (extent)
|
|
171 "Returns non-nil if the point is within or just after the bounds of the
|
|
172 primary selection-extent, nil otherwise."
|
|
173 ;; stig@hackvan.com
|
|
174 (and extent
|
|
175 (eq (current-buffer)
|
|
176 (extent-object extent))
|
|
177 (> (point) (extent-start-position extent))
|
|
178 (>= (extent-end-position extent) (point))))
|
|
179
|
|
180 (defun point-inside-selection-p ()
|
|
181 ;; by Stig@hackvan.com
|
|
182 (or (point-inside-extent-p primary-selection-extent)
|
|
183 (point-inside-extent-p zmacs-region-extent)))
|
|
184
|
|
185 (defun mouse-drag-or-yank (event)
|
|
186 "Either drag or paste the current selection. If the variable
|
|
187 `mouse-yank-at-point' is non-nil, then moves the cursor to the location of
|
|
188 the click before pasting.
|
|
189 This functions has to be improved. Until now it is just a (working) test."
|
|
190 ;; by Oliver Graf <ograf@fga.de>
|
|
191 (interactive "e")
|
|
192 (if (click-inside-extent-p event zmacs-region-extent)
|
|
193 ;; okay, this is a drag
|
|
194 (cond ((featurep 'offix)
|
|
195 (offix-start-drag-region event
|
|
196 (extent-start-position zmacs-region-extent)
|
|
197 (extent-end-position zmacs-region-extent)))
|
|
198 ((featurep 'cde)
|
|
199 ;; should also work with CDE
|
|
200 (cde-start-drag
|
|
201 (extent-start-position zmacs-region-extent)
|
|
202 (extent-end-position zmacs-region-extent)))
|
|
203 (t (error "No offix or CDE support compiled in")))
|
|
204 ;; no drag, call region-funct
|
|
205 (and (not mouse-yank-at-point)
|
|
206 (mouse-set-point event))
|
|
207 (funcall mouse-yank-function))
|
|
208 )
|
|
209
|
|
210 (defun mouse-offix-drop (event)
|
|
211 "Do something with an OffiX drop event. Inserts Text drops and
|
|
212 executes appropriate commands for specific drops.
|
|
213 Text drops follow the `mouse-yank-at-point' variable."
|
|
214 ;; by Oliver Graf <ograf@fga.de>
|
|
215 (interactive "e")
|
|
216 (let ((type (car (event-drag-and-drop-data event)))
|
|
217 (data (cadr (event-drag-and-drop-data event)))
|
|
218 (frame (event-channel event)))
|
|
219 (cond ((= type 2)
|
|
220 (let ((x pop-up-windows))
|
|
221 (setq pop-up-windows nil)
|
|
222 (pop-to-buffer (find-file-noselect data) nil frame)
|
|
223 (make-frame-visible frame)
|
|
224 (setq pop-up-windows x)))
|
|
225 ((= type 3)
|
|
226 (let ((x pop-up-windows))
|
|
227 (setq pop-up-windows nil)
|
|
228 (while (not (eq data ()))
|
|
229 (pop-to-buffer (find-file-noselect (car data)) nil frame)
|
|
230 (setq data (cdr data)))
|
|
231 (make-frame-visible frame)
|
|
232 (setq pop-up-windows x)))
|
|
233 ((= type 4)
|
|
234 (and (not mouse-yank-at-point)
|
|
235 (mouse-set-point event))
|
|
236 (insert data))
|
|
237 ((= type 5) (dired data))
|
|
238 ((or (= type 6) (= type 7)) (dired data)) ;; this is junk
|
|
239 ((= type 8) (funcall browse-url-browser-function data))
|
|
240 ((= type 9)
|
|
241 (let ((buf (generate-new-buffer "DndMIME")))
|
|
242 (set-buffer buf)
|
|
243 (pop-to-buffer buf nil frame)
|
|
244 (insert data)
|
|
245 (make-frame-visible frame)))
|
|
246 (t ;; this is raw data or unknown stuff
|
|
247 (let ((buf (generate-new-buffer "DndRawData")))
|
|
248 (set-buffer buf)
|
|
249 (pop-to-buffer buf nil frame)
|
|
250 (insert data)
|
|
251 (hexlify-buffer)
|
243
|
252 (make-frame-visible frame))))
|
|
253 (undo-boundary)))
|
209
|
254
|
249
|
255 (defun mouse-mswindows-drop (event)
|
|
256 "Do something with a drop event. Inserts Text drops and
|
|
257 executes appropriate commands for specific drops.
|
|
258 Text drops follow the `mouse-yank-at-point' variable."
|
|
259 (interactive "e")
|
|
260 (let* ((type (car (event-drag-and-drop-data event)))
|
|
261 (data (cadr (event-drag-and-drop-data event)))
|
|
262 (frame (event-channel event))
|
|
263 (window (if frame (event-window event) (frame-selected-window))))
|
|
264 (cond ((= type 2) ;; file
|
|
265 (let ((x pop-up-windows))
|
|
266 (setq pop-up-windows nil)
|
|
267 (cond (window
|
|
268 (select-window window)))
|
|
269 (switch-to-buffer (find-file-noselect data))
|
|
270 (make-frame-visible frame)
|
|
271 (setq pop-up-windows x)))
|
|
272 ((= type 3) ;; files
|
|
273 (let ((x pop-up-windows))
|
|
274 (setq pop-up-windows nil)
|
|
275 (while (not (eq data ()))
|
|
276 (pop-to-buffer (find-file-noselect (car data)) nil frame)
|
|
277 (setq data (cdr data)))
|
|
278 (make-frame-visible frame)
|
|
279 (setq pop-up-windows x)))
|
|
280 ((= type 4) ;; text
|
|
281 (and (not mouse-yank-at-point)
|
|
282 (mouse-set-point event))
|
|
283 (insert data))
|
|
284 (t ;; this is raw data or unknown stuff
|
|
285 (let ((buf (generate-new-buffer "DndRawData")))
|
|
286 (set-buffer buf)
|
|
287 (pop-to-buffer buf nil frame)
|
|
288 (insert data)
|
|
289 (hexlify-buffer)
|
|
290 (make-frame-visible frame))))
|
|
291 (undo-boundary)))
|
|
292
|
209
|
293 (defun mouse-eval-sexp (click force-window)
|
|
294 "Evaluate the sexp under the mouse. Usually, this is the last sexp before
|
|
295 the click, but if you click on a left paren, then it is the sexp beginning
|
|
296 with the paren that is evaluated. Also, since strings evaluate to themselves,
|
|
297 they're fed to re-search-forward and the matched region is highlighted until
|
|
298 the mouse button is released.
|
|
299
|
|
300 Perhaps the most useful thing about this function is that the evaluation of
|
|
301 the expression which is clicked upon is relative not to the window where you
|
|
302 click, but to the current window and the current position of point. Thus,
|
|
303 you can use `mouse-eval-sexp' to interactively test code that acts upon a
|
|
304 buffer...something you cannot do with the standard `eval-last-sexp' function.
|
|
305 It's also fantastic for debugging regular expressions."
|
|
306 ;; by Stig@hackvan.com
|
|
307 (interactive "e\nP")
|
|
308 (let (exp val result-str)
|
|
309 (setq exp (save-window-excursion
|
|
310 (save-excursion
|
|
311 (mouse-set-point click)
|
|
312 (save-excursion
|
|
313 (or (looking-at "(") (forward-sexp -1))
|
|
314 (read (point-marker))))))
|
|
315 (cond ((stringp exp)
|
|
316 (if (setq val (re-search-forward exp nil t))
|
|
317 (let* ((oo (make-extent (match-beginning 0) (match-end 0))))
|
|
318 (set-extent-face oo 'highlight)
|
|
319 (set-extent-priority oo 1000)
|
|
320 ;; wait for button release...
|
|
321 (setq unread-command-event (next-command-event))
|
|
322 (delete-extent oo))
|
|
323 (message "Regex \"%s\" not found" exp)
|
|
324 (ding nil 'quiet)))
|
|
325 (t (setq val (if (fboundp 'eval-interactive)
|
|
326 (eval-interactive exp)
|
|
327 (eval exp)))))
|
|
328 (setq result-str (prin1-to-string val))
|
|
329 ;; #### -- need better test
|
|
330 (if (and (not force-window)
|
|
331 (<= (length result-str) (window-width (selected-window))))
|
|
332 (message "%s" result-str)
|
|
333 (with-output-to-temp-buffer "*Mouse-Eval*"
|
|
334 (condition-case nil
|
|
335 (pprint val)
|
|
336 (error (prin1 val))))
|
|
337 )))
|
|
338
|
|
339 (defun mouse-line-length (event)
|
|
340 "Print the length of the line indicated by the pointer."
|
|
341 (interactive "@e")
|
|
342 (save-excursion
|
|
343 (mouse-set-point event)
|
|
344 (message "Line length: %d" (- (point-at-eol) (point-at-bol))))
|
|
345 (sleep-for 1))
|
|
346
|
|
347 (defun mouse-set-mark (event)
|
|
348 "Select Emacs window mouse is on, and set mark at mouse position.
|
|
349 Display cursor at that position for a second."
|
|
350 (interactive "@e")
|
|
351 (let ((point-save (point)))
|
|
352 (unwind-protect
|
|
353 (progn (mouse-set-point event)
|
|
354 (push-mark nil t)
|
|
355 (sit-for 1))
|
|
356 (goto-char point-save))))
|
|
357
|
|
358 (defun mouse-scroll (event)
|
|
359 "Scroll point to the mouse position."
|
|
360 (interactive "@e")
|
|
361 (save-excursion
|
|
362 (mouse-set-point event)
|
|
363 (recenter 0)
|
|
364 (scroll-right (event-x event))))
|
|
365
|
|
366 (defun mouse-del-char (event)
|
|
367 "Delete the char pointed to by the mouse."
|
|
368 (interactive "@e")
|
|
369 (save-excursion
|
|
370 (mouse-set-point event)
|
|
371 (delete-char 1 nil)))
|
|
372
|
|
373 (defun mouse-kill-line (event)
|
|
374 "Kill the line pointed to by the mouse."
|
|
375 (interactive "@e")
|
|
376 (save-excursion
|
|
377 (mouse-set-point event)
|
|
378 (kill-line nil)))
|
|
379
|
|
380 (defun mouse-bury-buffer (event)
|
|
381 "Bury the buffer pointed to by the mouse, thus selecting the next one."
|
|
382 (interactive "e")
|
|
383 (save-selected-window
|
|
384 (select-window (event-window event))
|
|
385 (bury-buffer)))
|
|
386
|
|
387 (defun mouse-unbury-buffer (event)
|
|
388 "Unbury and select the most recently buried buffer."
|
|
389 (interactive "e")
|
|
390 (save-selected-window
|
|
391 (select-window (event-window event))
|
|
392 (let* ((bufs (buffer-list))
|
|
393 (entry (1- (length bufs)))
|
|
394 val)
|
|
395 (while (not (setq val (nth entry bufs)
|
|
396 val (and (/= (aref (buffer-name val) 0)
|
|
397 ? )
|
|
398 val)))
|
|
399 (setq entry (1- entry)))
|
|
400 (switch-to-buffer val))))
|
|
401
|
|
402 (defun narrow-window-to-region (m n)
|
|
403 "Narrow window to region between point and last mark"
|
|
404 (interactive "r")
|
|
405 (save-excursion
|
|
406 (save-restriction
|
|
407 (if (eq (selected-window) (next-window))
|
|
408 (split-window))
|
|
409 (goto-char m)
|
|
410 (recenter 0)
|
|
411 (if (eq (selected-window)
|
|
412 (if (zerop (minibuffer-depth))
|
|
413 (next-window)))
|
|
414 ()
|
|
415 (shrink-window (- (- (window-height) (count-lines m n)) 1))))))
|
|
416
|
|
417 (defun mouse-window-to-region (event)
|
|
418 "Narrow window to region between cursor and mouse pointer."
|
|
419 (interactive "@e")
|
|
420 (let ((point-save (point)))
|
|
421 (unwind-protect
|
|
422 (progn (mouse-set-point event)
|
|
423 (push-mark nil t)
|
|
424 (sit-for 1))
|
|
425 (goto-char point-save)
|
|
426 (narrow-window-to-region (region-beginning) (region-end)))))
|
|
427
|
|
428 (defun mouse-ignore ()
|
|
429 "Don't do anything."
|
|
430 (interactive))
|
|
431
|
|
432
|
|
433 ;;; mouse/selection tracking
|
|
434 ;;; generalized mouse-track
|
|
435
|
|
436 (defvar default-mouse-track-normalize-point-function
|
|
437 'default-mouse-track-normalize-point
|
|
438 "Function called to normalize position of point.
|
|
439 Called with two arguments: TYPE depends on the number of times that the
|
|
440 mouse has been clicked and is a member of `default-mouse-track-type-list',
|
|
441 FORWARDP determines the direction in which the point should be moved.")
|
|
442
|
|
443 (defvar mouse-track-down-hook nil
|
|
444 "Function or functions called when the user presses the mouse.
|
|
445 This hook is invoked by `mouse-track'; thus, it will not be called
|
|
446 for any buttons with a different binding. The functions will be
|
|
447 called with two arguments: the button-press event and a click
|
|
448 count (see `mouse-track-click-hook').
|
|
449
|
|
450 If any function returns non-nil, the remaining functions will not be
|
|
451 called.
|
|
452
|
|
453 Note that most applications should take action when the mouse is
|
|
454 released, not when it is pressed.'")
|
|
455
|
|
456 (defvar mouse-track-drag-hook nil
|
|
457 "Function or functions called when the user drags the mouse.
|
|
458 This hook is invoked by `mouse-track'; thus, it will not be called
|
|
459 for any buttons with a different binding. The functions will be
|
|
460 called with three arguments: the mouse-motion event, a click
|
|
461 count (see `mouse-track-click-hook'), and whether the call to
|
|
462 this hook occurred as a result of a drag timeout (see
|
|
463 `mouse-track-scroll-delay').
|
|
464
|
|
465 If any function returns non-nil, the remaining functions will not be
|
|
466 called.
|
|
467
|
|
468 Note that no calls to this function will be made until the user
|
|
469 initiates a drag (i.e. moves the mouse more than a certain
|
|
470 threshold in either the X or the Y direction, as defined by
|
|
471 `mouse-track-x-threshold' and `mouse-track-y-threshold').
|
|
472
|
|
473 See also `mouse-track-drag-up-hook'.")
|
|
474
|
|
475 (defvar mouse-track-drag-up-hook nil
|
|
476 "Function or functions called when the user finishes a drag.
|
|
477 This hook is invoked by `mouse-track'; thus, it will not be called
|
|
478 for any buttons with a different binding. The functions will be
|
|
479 called with two arguments: the button-press event and a click
|
|
480 count (see `mouse-track-click-hook').
|
|
481
|
|
482 If any function returns non-nil, the remaining functions will not be
|
|
483 called.
|
|
484
|
|
485 Note that this hook will not be invoked unless the user has
|
|
486 initiated a drag, i.e. moved the mouse more than a certain threshold
|
|
487 (see `mouse-track-drag-hook'). When this function is invoked,
|
|
488 `mouse-track-drag-hook' will have been invoked at least once.
|
|
489
|
|
490 See also `mouse-track-click-hook'.")
|
|
491
|
|
492 (defvar mouse-track-click-hook nil
|
|
493 "Function or functions called when the user clicks the mouse.
|
|
494 `Clicking' means pressing and releasing the mouse without having
|
|
495 initiated a drag (i.e. without having moved more than a certain
|
|
496 threshold -- see `mouse-track-drag-hook').
|
|
497
|
|
498 This hook is invoked by `mouse-track'; thus, it will not be called
|
|
499 for any buttons with a different binding. The functions will be
|
|
500 called with two arguments: the button-release event and a click
|
|
501 count, which specifies the number of times that the mouse has been
|
|
502 clicked in a series of clicks, each of which is separated by at most
|
|
503 `mouse-track-multi-click-time'. This can be used to implement actions
|
|
504 that are called on double clicks, triple clicks, etc.
|
|
505
|
|
506 If any function returns non-nil, the remaining functions will not be
|
|
507 called.
|
|
508
|
|
509 See also `mouse-track-drag-up-hook.")
|
|
510
|
|
511 (defvar mouse-track-up-hook nil
|
|
512 "Function or functions called when the user releases the mouse.
|
|
513 This hook is invoked by `mouse-track'; thus, it will not be called
|
|
514 for any buttons with a different binding. The functions will be
|
|
515 called with two arguments: the button-release event and a click
|
|
516 count (see `mouse-track-click-hook').
|
|
517
|
|
518 For many applications, it is more appropriate to use one or both
|
|
519 of `mouse-track-click-hook' and `mouse-track-drag-up-hook'.")
|
|
520
|
|
521 (defvar mouse-track-cleanup-hook nil
|
|
522 "Function or functions called when `mouse-track' terminates.
|
|
523 This hook will be called in all circumstances, even upon a
|
|
524 non-local exit out of `mouse-track', and so is useful for
|
|
525 doing cleanup work such as removing extents that may have
|
|
526 been created during the operation of `mouse-track'.
|
|
527
|
|
528 Unlike all of the other mouse-track hooks, this is a \"normal\"
|
|
529 hook: the hook functions are called with no arguments, and
|
|
530 all hook functions are called regardless of their return
|
|
531 values.")
|
|
532
|
|
533 (defcustom mouse-track-multi-click-time 400
|
|
534 "*Maximum number of milliseconds allowed between clicks for a multi-click.
|
|
535 See `mouse-track-click-hook'."
|
|
536 :type 'integer
|
|
537 :group 'mouse)
|
|
538
|
|
539 (defcustom mouse-track-scroll-delay 100
|
|
540 "Maximum of milliseconds between calls to `mouse-track-drag-hook'.
|
|
541 If the user is dragging the mouse (i.e. the button is held down and
|
|
542 a drag has been initiated) and does not move the mouse for this many
|
|
543 milliseconds, the hook will be called with t as the value of the
|
|
544 WAS-TIMEOUT parameter. This can be used to implement scrolling
|
|
545 in a selection when the user drags the mouse out the window it
|
|
546 was in.
|
|
547
|
|
548 A value of nil disables the timeout feature."
|
|
549 :type '(choice integer (const :tag "Disabled" nil))
|
|
550 :group 'mouse)
|
|
551
|
|
552 (defvar mouse-track-x-threshold '(face-width 'default)
|
|
553 "Minimum number of pixels in the X direction for a drag to be initiated.
|
|
554 If the mouse is moved more than either the X or Y threshold while the
|
|
555 button is held down (see also `mouse-track-y-threshold'), then a drag
|
|
556 is initiated; otherwise the gesture is considered to be a click.
|
|
557 See `mouse-track'.
|
|
558
|
|
559 The value should be either a number of a form to be evaluated to
|
|
560 produce a number.")
|
|
561
|
|
562 (defvar mouse-track-y-threshold '(face-height 'default)
|
|
563 "Minimum number of pixels in the Y direction for a drag to be initiated.
|
|
564 If the mouse is moved more than either the X or Y threshold while the
|
|
565 button is held down (see also `mouse-track-x-threshold'), then a drag
|
|
566 is initiated; otherwise the gesture is considered to be a click.
|
|
567 See `mouse-track'.
|
|
568
|
|
569 The value should be either a number of a form to be evaluated to
|
|
570 produce a number.")
|
|
571
|
|
572 ;; these variables are private to mouse-track.
|
|
573 (defvar mouse-track-up-time nil)
|
|
574 (defvar mouse-track-up-x nil)
|
|
575 (defvar mouse-track-up-y nil)
|
|
576 (defvar mouse-track-timeout-id nil)
|
|
577 (defvar mouse-track-click-count nil)
|
|
578
|
|
579 (defun mouse-track-set-timeout (event)
|
|
580 (if mouse-track-timeout-id
|
|
581 (disable-timeout mouse-track-timeout-id))
|
|
582 (if mouse-track-scroll-delay
|
|
583 (setq mouse-track-timeout-id
|
|
584 (add-timeout (/ mouse-track-scroll-delay 1000.0)
|
|
585 'mouse-track-scroll-undefined
|
|
586 (copy-event event)))))
|
|
587
|
|
588 (defun mouse-track-run-hook (hook event &rest args)
|
223
|
589 ;; ugh, can't use run-hook-with-args-until-success because we have
|
|
590 ;; to get the value using symbol-value-in-buffer. Doing a
|
|
591 ;; save-excursion/set-buffer is wrong because the hook might want to
|
|
592 ;; change the buffer, but just doing a set-buffer is wrong because
|
|
593 ;; the hook might not want to change the buffer.
|
|
594 ;; #### What we need here is a Lisp interface to
|
|
595 ;; run_hook_with_args_in_buffer. Here is a poor man's version.
|
209
|
596 (let ((buffer (event-buffer event)))
|
223
|
597 (and mouse-grabbed-buffer (setq buffer mouse-grabbed-buffer))
|
|
598 (when buffer
|
|
599 (let ((value (symbol-value-in-buffer hook buffer nil)))
|
|
600 (if (and (listp value) (not (eq (car value) 'lambda)))
|
|
601 ;; List of functions.
|
|
602 (let (retval)
|
|
603 (while (and value (null retval))
|
|
604 ;; Found `t': should process default value. We could
|
|
605 ;; splice it into the buffer-local value, but that
|
|
606 ;; would cons, which is not a good thing for
|
|
607 ;; mouse-track hooks.
|
|
608 (if (eq (car value) t)
|
|
609 (let ((global (default-value hook)))
|
|
610 (if (and (listp global) (not (eq (car global) 'lambda)))
|
|
611 ;; List of functions.
|
|
612 (while (and global
|
|
613 (null (setq retval
|
|
614 (apply (car global) event args))))
|
|
615 (pop global))
|
|
616 ;; lambda
|
|
617 (setq retval (apply (car global) event args))))
|
|
618 (setq retval (apply (car value) event args)))
|
|
619 (pop value))
|
|
620 retval)
|
|
621 ;; lambda
|
|
622 (apply value event args))))))
|
209
|
623
|
|
624 (defun mouse-track-scroll-undefined (random)
|
|
625 ;; the old implementation didn't actually define this function,
|
|
626 ;; and in normal use it won't ever be called because the timeout
|
|
627 ;; will either be removed before it fires or will be picked off
|
|
628 ;; with next-event and not dispatched. However, if you're
|
|
629 ;; attempting to debug a click-hook (which is pretty damn
|
|
630 ;; difficult to do), this function may get called.
|
|
631 )
|
|
632
|
|
633 (defun mouse-track (event)
|
|
634 "Make a selection with the mouse. This should be bound to a mouse button.
|
|
635 The behavior of XEmacs during mouse selection is customizable using various
|
|
636 hooks and variables: see `mouse-track-click-hook', `mouse-track-drag-hook',
|
|
637 `mouse-track-drag-up-hook', `mouse-track-down-hook', `mouse-track-up-hook',
|
|
638 `mouse-track-cleanup-hook', `mouse-track-multi-click-time',
|
|
639 `mouse-track-scroll-delay', `mouse-track-x-threshold', and
|
|
640 `mouse-track-y-threshold'.
|
|
641
|
|
642 Default handlers are provided to implement standard selecting/positioning
|
|
643 behavior. You can explicitly request this default behavior, and override
|
|
644 any custom-supplied handlers, by using the function `mouse-track-default'
|
|
645 instead of `mouse-track'.
|
|
646
|
|
647 Default behavior is as follows:
|
|
648
|
|
649 If you click-and-drag, the selection will be set to the region between the
|
|
650 point of the initial click and the point at which you release the button.
|
|
651 These positions need not be ordered.
|
|
652
|
|
653 If you click-and-release without moving the mouse, then the point is moved
|
|
654 and the selection is disowned (there will be no selection owner). The mark
|
|
655 will be set to the previous position of point.
|
|
656
|
|
657 If you double-click, the selection will extend by symbols instead of by
|
|
658 characters. If you triple-click, the selection will extend by lines.
|
|
659
|
|
660 If you drag the mouse off the top or bottom of the window, you can select
|
|
661 pieces of text which are larger than the visible part of the buffer; the
|
|
662 buffer will scroll as necessary.
|
|
663
|
|
664 The selected text becomes the current X Selection. The point will be left
|
|
665 at the position at which you released the button, and the mark will be left
|
|
666 at the initial click position."
|
|
667 (interactive "e")
|
|
668 (let ((mouse-down t)
|
|
669 (xthresh (eval mouse-track-x-threshold))
|
|
670 (ythresh (eval mouse-track-y-threshold))
|
|
671 (orig-x (event-x-pixel event))
|
|
672 (orig-y (event-y-pixel event))
|
|
673 (buffer (event-buffer event))
|
|
674 (mouse-grabbed-buffer (event-buffer event))
|
|
675 mouse-moved)
|
|
676 (if (or (not mouse-track-up-x)
|
|
677 (not mouse-track-up-y)
|
|
678 (not mouse-track-up-time)
|
|
679 (> (- (event-timestamp event) mouse-track-up-time)
|
|
680 mouse-track-multi-click-time)
|
|
681 (> (abs (- mouse-track-up-x orig-x)) xthresh)
|
|
682 (> (abs (- mouse-track-up-y orig-y)) ythresh))
|
|
683 (setq mouse-track-click-count 1)
|
|
684 (setq mouse-track-click-count (1+ mouse-track-click-count)))
|
|
685 (if (not (event-window event))
|
|
686 (error "Not over a window."))
|
|
687 (mouse-track-run-hook 'mouse-track-down-hook
|
|
688 event mouse-track-click-count)
|
|
689 (unwind-protect
|
|
690 (while mouse-down
|
|
691 (setq event (next-event event))
|
|
692 (cond ((motion-event-p event)
|
|
693 (if (and (not mouse-moved)
|
|
694 (or (> (abs (- (event-x-pixel event) orig-x))
|
|
695 xthresh)
|
|
696 (> (abs (- (event-y-pixel event) orig-y))
|
|
697 ythresh)))
|
|
698 (setq mouse-moved t))
|
|
699 (if mouse-moved
|
|
700 (mouse-track-run-hook 'mouse-track-drag-hook
|
|
701 event mouse-track-click-count nil))
|
|
702 (mouse-track-set-timeout event))
|
|
703 ((and (timeout-event-p event)
|
|
704 (eq (event-function event)
|
|
705 'mouse-track-scroll-undefined))
|
|
706 (if mouse-moved
|
|
707 (mouse-track-run-hook 'mouse-track-drag-hook
|
|
708 (event-object event) mouse-track-click-count t))
|
|
709 (mouse-track-set-timeout (event-object event)))
|
|
710 ((button-release-event-p event)
|
|
711 (setq mouse-track-up-time (event-timestamp event))
|
|
712 (setq mouse-track-up-x (event-x-pixel event))
|
|
713 (setq mouse-track-up-y (event-y-pixel event))
|
|
714 (setq mouse-down nil)
|
|
715 (mouse-track-run-hook 'mouse-track-up-hook
|
|
716 event mouse-track-click-count)
|
|
717 (if mouse-moved
|
|
718 (mouse-track-run-hook 'mouse-track-drag-up-hook
|
|
719 event mouse-track-click-count)
|
|
720 (mouse-track-run-hook 'mouse-track-click-hook
|
|
721 event mouse-track-click-count)))
|
|
722 ((key-press-event-p event)
|
|
723 (error "Selection aborted"))
|
|
724 (t
|
|
725 (dispatch-event event))))
|
|
726 ;; protected
|
|
727 (if mouse-track-timeout-id
|
|
728 (disable-timeout mouse-track-timeout-id))
|
|
729 (setq mouse-track-timeout-id nil)
|
|
730 (and buffer
|
|
731 (save-excursion
|
|
732 (set-buffer buffer)
|
|
733 (run-hooks 'mouse-track-cleanup-hook))))))
|
|
734
|
|
735
|
|
736 ;;;;;;;;;;;; default handlers: new version of mouse-track
|
|
737
|
|
738 (defvar default-mouse-track-type nil)
|
|
739 (defvar default-mouse-track-type-list '(char word line))
|
|
740 (defvar default-mouse-track-window nil)
|
|
741 (defvar default-mouse-track-extent nil)
|
|
742 (defvar default-mouse-track-adjust nil)
|
|
743 (defvar default-mouse-track-min-anchor nil)
|
|
744 (defvar default-mouse-track-max-anchor nil)
|
|
745 (defvar default-mouse-track-result nil)
|
|
746 (defvar default-mouse-track-down-event nil)
|
|
747
|
255
|
748 ;; D. Verna Feb. 17 1998
|
|
749 ;; This function used to assume that when (event-window event) differs from
|
|
750 ;; window, we have to scroll. This is WRONG, for instance when there are
|
|
751 ;; toolbars on the side, in which case window-event returns nil.
|
209
|
752 (defun default-mouse-track-set-point-in-window (event window)
|
255
|
753 (if (event-over-modeline-p event)
|
|
754 nil ;; Scroll
|
|
755 ;; Not over a modeline
|
|
756 (if (eq (event-window event) window)
|
|
757 (let ((p (event-closest-point event)))
|
|
758 (if (or (not p) (not (pos-visible-in-window-p p window)))
|
|
759 nil ;; Scroll
|
|
760 (mouse-set-point event)
|
|
761 t))
|
|
762 ;; Not over a modeline, not the same window. Check if the Y position
|
|
763 ;; is still overlapping the original window.
|
|
764 (let* ((edges (window-pixel-edges window))
|
|
765 (row (event-y-pixel event))
|
|
766 (text-start (nth 1 edges))
|
|
767 (text-end (+ (nth 3 edges))))
|
|
768 (if (or (< row text-start)
|
|
769 (> row text-end))
|
|
770 nil ;; Scroll
|
|
771 ;; The Y pos in overlapping the original window. Check however if
|
|
772 ;; the position is really visible, because there could be a
|
|
773 ;; scrollbar or a modeline at this place.
|
|
774 ;; Find the mean line height (height / lines nb), and approximate
|
|
775 ;; the line number for Y pos.
|
|
776 (select-window window)
|
|
777 (let ((line (/ (* (- row text-start) (window-height))
|
|
778 (- text-end text-start))))
|
|
779 (if (not (save-excursion
|
|
780 (goto-char (window-start))
|
|
781 (pos-visible-in-window-p
|
|
782 (point-at-bol (+ 1 line)))))
|
|
783 nil ;; Scroll
|
|
784 ;; OK, we can go to that position
|
|
785 (goto-char (window-start))
|
|
786 (forward-line line)
|
|
787 ;; On the right side: go to end-of-line.
|
|
788 (when (>= (event-x-pixel event) (nth 2 edges))
|
|
789 (goto-char (point-at-eol)))
|
|
790 t))))
|
|
791 )))
|
|
792
|
209
|
793
|
|
794 (defun default-mouse-track-scroll-and-set-point (event window)
|
|
795 (select-window window)
|
|
796 (let ((edges (window-pixel-edges window))
|
|
797 (row (event-y-pixel event))
|
|
798 (height (face-height 'default)))
|
|
799 (cond ((< (abs (- row (nth 1 edges))) (abs (- row (nth 3 edges))))
|
|
800 ;; closer to window's top than to bottom, so move up
|
|
801 (let ((delta (max 1 (/ (- (nth 1 edges) row) height))))
|
|
802 (condition-case () (scroll-down delta) (error))
|
|
803 (goto-char (window-start))))
|
|
804 ((>= (point) (point-max)))
|
|
805 (t
|
|
806 ;; scroll by one line if over the modeline or a clipped line
|
|
807 (let ((delta (if (or (event-over-modeline-p event)
|
|
808 (< row (nth 3 edges)))
|
|
809 1
|
|
810 (+ (/ (- row (nth 3 edges)) height) 1)))
|
|
811 (close-pos (event-closest-point event)))
|
|
812 (condition-case () (scroll-up delta) (error))
|
|
813 (if (and close-pos (pos-visible-in-window-p close-pos))
|
|
814 (goto-char close-pos)
|
|
815 (goto-char (window-end))
|
|
816 (vertical-motion delta)
|
|
817 ;; window-end reports the end of the clipped line, even if
|
|
818 ;; scroll-on-clipped-lines is t. compensate.
|
|
819 ;; (If window-end gets fixed this can be removed.)
|
|
820 (if (not (pos-visible-in-window-p (max (1- (point))
|
|
821 (point-min))))
|
|
822 (vertical-motion -1))
|
|
823 (condition-case () (backward-char 1)
|
|
824 (error (end-of-line)))))))))
|
|
825
|
|
826
|
|
827 ;; This remembers the last position at which the user clicked, for the
|
|
828 ;; benefit of mouse-track-adjust (for example, button1; scroll until the
|
|
829 ;; position of the click is off the frame; then Sh-button1 to select the
|
|
830 ;; new region.
|
|
831 (defvar default-mouse-track-previous-point nil)
|
|
832
|
|
833 (defun default-mouse-track-set-point (event window)
|
|
834 (if (default-mouse-track-set-point-in-window event window)
|
|
835 nil
|
|
836 (default-mouse-track-scroll-and-set-point event window)))
|
|
837
|
|
838 (defsubst default-mouse-track-beginning-of-word (symbolp)
|
|
839 (let ((word-constituent (cond ((eq symbolp t) "\\w\\|\\s_\\|\\s'")
|
|
840 ((null symbolp) "\\w")
|
|
841 (t "[^ \t\n]")))
|
|
842 (white-space "[ \t]"))
|
|
843 (cond ((bobp) nil)
|
|
844 ((looking-at word-constituent)
|
|
845 (backward-char)
|
|
846 (while (and (not (bobp)) (looking-at word-constituent))
|
|
847 (backward-char))
|
|
848 (if (or (not (bobp)) (not (looking-at word-constituent)))
|
|
849 (forward-char)))
|
|
850 ((looking-at white-space)
|
|
851 (backward-char)
|
|
852 (while (looking-at white-space)
|
|
853 (backward-char))
|
|
854 (forward-char)))))
|
|
855
|
|
856 (defun default-mouse-track-end-of-word (symbolp)
|
|
857 (let ((word-constituent (cond ((eq symbolp t) "\\w\\|\\s_\\|\\s'")
|
|
858 ((null symbolp) "\\w")
|
|
859 (t "[^ \t\n]")))
|
|
860 (white-space "[ \t]"))
|
|
861 (cond ((looking-at word-constituent) ; word or symbol constituent
|
|
862 (while (looking-at word-constituent)
|
|
863 (forward-char)))
|
|
864 ((looking-at white-space) ; word or symbol constituent
|
|
865 (while (looking-at white-space)
|
|
866 (forward-char))))))
|
|
867
|
|
868 ;; Decide what will be the SYMBOLP argument to
|
|
869 ;; default-mouse-track-{beginning,end}-of-word, according to the
|
|
870 ;; syntax of the current character and value of mouse-highlight-text.
|
|
871 (defsubst default-mouse-symbolp (syntax)
|
|
872 (cond ((eq mouse-highlight-text 'context)
|
|
873 (eq syntax ?_))
|
|
874 ((eq mouse-highlight-text 'symbol)
|
|
875 t)
|
|
876 (t
|
|
877 nil)))
|
|
878
|
|
879 (defun default-mouse-track-normalize-point (type forwardp)
|
|
880 (cond ((eq type 'word)
|
|
881 ;; trap the beginning and end of buffer errors
|
|
882 (ignore-errors
|
|
883 (setq type (char-syntax (char-after (point))))
|
|
884 (if forwardp
|
|
885 (if (= type ?\()
|
|
886 (goto-char (scan-sexps (point) 1))
|
|
887 (if (= type ?\))
|
|
888 (forward-char 1)
|
|
889 (default-mouse-track-end-of-word
|
|
890 (default-mouse-symbolp type))))
|
|
891 (if (= type ?\))
|
|
892 (goto-char (scan-sexps (1+ (point)) -1))
|
|
893 (default-mouse-track-beginning-of-word
|
|
894 (default-mouse-symbolp type))))))
|
|
895 ((eq type 'line)
|
|
896 (if forwardp (end-of-line) (beginning-of-line)))
|
|
897 ((eq type 'buffer)
|
|
898 (if forwardp (end-of-buffer) (beginning-of-buffer)))))
|
|
899
|
|
900 (defun default-mouse-track-next-move (min-anchor max-anchor extent)
|
|
901 (let ((anchor (if (<= (point) min-anchor) max-anchor min-anchor)))
|
|
902 (funcall default-mouse-track-normalize-point-function
|
|
903 default-mouse-track-type (> (point) anchor))
|
|
904 (if (consp extent)
|
|
905 (default-mouse-track-next-move-rect anchor (point) extent)
|
|
906 (if extent
|
|
907 (if (<= anchor (point))
|
|
908 (set-extent-endpoints extent anchor (point))
|
|
909 (set-extent-endpoints extent (point) anchor))))))
|
|
910
|
|
911 (defun default-mouse-track-next-move-rect (start end extents &optional pad-p)
|
|
912 (if (< end start)
|
|
913 (let ((tmp start)) (setq start end end tmp)))
|
|
914 (cond
|
|
915 ((= start end) ; never delete the last remaining extent
|
|
916 (mapcar 'delete-extent (cdr extents))
|
|
917 (setcdr extents nil)
|
|
918 (set-extent-endpoints (car extents) start start))
|
|
919 (t
|
|
920 (let ((indent-tabs-mode nil) ; if pad-p, don't use tabs
|
|
921 (rest extents)
|
|
922 left right last p)
|
|
923 (save-excursion
|
|
924 (save-restriction
|
|
925 (goto-char end)
|
|
926 (setq right (current-column))
|
|
927 (goto-char start)
|
|
928 (setq left (current-column))
|
|
929 (if (< right left)
|
|
930 (let ((tmp left))
|
|
931 (setq left right right tmp)
|
|
932 (setq start (- start (- right left))
|
|
933 end (+ end (- right left)))))
|
|
934 ;; End may have been set to a value greater than point-max if drag
|
|
935 ;; or movement extends to end of buffer, so reset it.
|
|
936 (setq end (min end (point-max)))
|
|
937 (beginning-of-line)
|
|
938 (narrow-to-region (point) end)
|
|
939 (goto-char start)
|
|
940 (while (and rest (not (eobp)))
|
|
941 (setq p (point))
|
|
942 (move-to-column right pad-p)
|
|
943 (set-extent-endpoints (car rest) p (point))
|
|
944 ;; this code used to look at the return value
|
|
945 ;; of forward-line, but that doesn't work because
|
|
946 ;; forward-line has bogus behavior: If you're on
|
|
947 ;; the last line of a buffer but not at the very
|
|
948 ;; end, forward-line will move you to the very
|
|
949 ;; end and return 0 instead of 1, like it should.
|
|
950 ;; the result was frequent infinite loops here,
|
|
951 ;; creating very large numbers of extents at
|
|
952 ;; the same position. There was an N^2 sorting
|
|
953 ;; algorithm in extents.c for extents at a
|
|
954 ;; particular position, and the result was very
|
|
955 ;; bad news.
|
|
956 (forward-line 1)
|
|
957 (if (not (eobp))
|
|
958 (move-to-column left pad-p))
|
|
959 (setq last rest
|
|
960 rest (cdr rest)))
|
|
961 (cond (rest
|
|
962 (mapcar 'delete-extent rest)
|
|
963 (setcdr last nil))
|
|
964 ((not (eobp))
|
|
965 (while (not (eobp))
|
|
966 (setq p (point))
|
|
967 (move-to-column right pad-p)
|
|
968 (let ((e (make-extent p (point))))
|
|
969 (set-extent-face e (extent-face (car extents)))
|
|
970 (set-extent-priority e (extent-priority (car extents)))
|
|
971 (setcdr last (cons e nil))
|
|
972 (setq last (cdr last)))
|
|
973 (forward-line 1)
|
|
974 (if (not (eobp))
|
|
975 (move-to-column left pad-p))
|
|
976 )))))
|
|
977 ))))
|
|
978
|
|
979 (defun default-mouse-track-has-selection-p (buffer)
|
|
980 (and (or (not (eq 'x (console-type)))
|
|
981 (x-selection-owner-p))
|
|
982 (extent-live-p primary-selection-extent)
|
|
983 (not (extent-detached-p primary-selection-extent))
|
|
984 (eq buffer (extent-object primary-selection-extent))))
|
|
985
|
|
986 (defun default-mouse-track-anchor (adjust previous-point)
|
|
987 (if adjust
|
|
988 (if (default-mouse-track-has-selection-p (current-buffer))
|
|
989 (let ((start (extent-start-position primary-selection-extent))
|
|
990 (end (extent-end-position primary-selection-extent)))
|
|
991 (cond ((< (point) start) end)
|
|
992 ((> (point) end) start)
|
|
993 ((> (- (point) start) (- end (point))) start)
|
|
994 (t end)))
|
|
995 previous-point)
|
|
996 (point)))
|
|
997
|
|
998 (defun default-mouse-track-maybe-own-selection (pair type)
|
|
999 (let ((start (car pair))
|
|
1000 (end (cdr pair)))
|
|
1001 (or (= start end) (push-mark (if (= (point) start) end start)))
|
|
1002 (cond (zmacs-regions
|
|
1003 (if (= start end)
|
|
1004 nil
|
|
1005 ;; #### UTTER KLUDGE.
|
|
1006 ;; If we don't have this sit-for here, then triple-clicking
|
|
1007 ;; will result in the line not being highlighted as it
|
|
1008 ;; should. What appears to be happening is this:
|
|
1009 ;;
|
|
1010 ;; -- each time the button goes down, the selection is
|
|
1011 ;; disowned (see comment "remove the existing selection
|
|
1012 ;; to unclutter the display", below).
|
|
1013 ;; -- this causes a SelectionClear event to be sent to
|
|
1014 ;; XEmacs.
|
|
1015 ;; -- each time the button goes up except the first, the
|
|
1016 ;; selection is owned again.
|
|
1017 ;; -- later, XEmacs processes the SelectionClear event.
|
|
1018 ;; The selection code attempts to keep track of the
|
|
1019 ;; time that it last asserted the selection, and
|
|
1020 ;; compare it to the time of the SelectionClear event,
|
|
1021 ;; to see if it's a bogus notification or not (as
|
|
1022 ;; is the case here). However, for some unknown
|
|
1023 ;; reason this doesn't work in the triple-clicking
|
|
1024 ;; case, and the selection code bogusly thinks this
|
|
1025 ;; SelectionClear event is the real thing.
|
|
1026 ;; -- putting the sit-for in causes the pending
|
|
1027 ;; SelectionClear events to get processed before
|
|
1028 ;; the selection is reasserted, so everything works
|
|
1029 ;; out OK.
|
|
1030 ;;
|
|
1031 ;; Presumably(?) this means there is a weird timing bug
|
|
1032 ;; in the selection code, but there's not a chance in hell
|
|
1033 ;; that I have the patience to track it down. Blame the
|
|
1034 ;; designers of X for fucking everything up so badly.
|
|
1035 ;;
|
|
1036 ;; This was originally a sit-for 0 but that wasn't
|
|
1037 ;; sufficient to make things work. Even this isn't
|
|
1038 ;; always sufficient but it seems to give something
|
|
1039 ;; approaching a 99% success rate. Making it higher yet
|
|
1040 ;; would help guarantee success with the price that the
|
|
1041 ;; delay would start to become noticable.
|
|
1042 ;;
|
|
1043 (sit-for 0.15 t)
|
|
1044 (zmacs-activate-region)))
|
|
1045 ((eq 'x (console-type))
|
|
1046 (if (= start end)
|
|
1047 (x-disown-selection type)
|
|
1048 (if (consp default-mouse-track-extent)
|
|
1049 ;; own the rectangular region
|
|
1050 ;; this is a hack
|
|
1051 (let ((r default-mouse-track-extent))
|
|
1052 (save-excursion
|
|
1053 (set-buffer (get-buffer-create " *rect yank temp buf*"))
|
|
1054 (while r
|
|
1055 (insert (extent-string (car r)) "\n")
|
|
1056 (setq r (cdr r)))
|
|
1057 (x-own-selection (buffer-substring (point-min) (point-max)))
|
|
1058 (kill-buffer (current-buffer))))
|
|
1059 (x-own-selection (cons (set-marker (make-marker) start)
|
|
1060 (set-marker (make-marker) end))
|
|
1061 type)))))
|
|
1062 (if (and (eq 'x (console-type))
|
|
1063 (not (= start end)))
|
|
1064 ;; I guess cutbuffers should do something with rectangles too.
|
|
1065 ;; does anybody use them?
|
|
1066 (x-store-cutbuffer (buffer-substring start end)))))
|
|
1067
|
|
1068 (defun default-mouse-track-deal-with-down-event (click-count)
|
|
1069 (let ((event default-mouse-track-down-event))
|
|
1070 (if (null event) nil
|
|
1071 (select-frame (event-frame event))
|
|
1072 (let ((adjust default-mouse-track-adjust)
|
|
1073 ;; ####When you click on the splash-screen,
|
|
1074 ;; event-{closest-,}point can be out of bounds. Should
|
|
1075 ;; event-closest-point really be allowed to return a bad
|
|
1076 ;; position like that? Maybe pixel_to_glyph_translation
|
|
1077 ;; needs to invalidate its cache when the buffer changes.
|
|
1078 ;; -dkindred@cs.cmu.edu
|
|
1079 (close-pos (save-excursion
|
|
1080 (set-buffer (event-buffer event))
|
|
1081 (let ((p (event-closest-point event)))
|
|
1082 (and p (min (max p (point-min)) (point-max))))))
|
|
1083 extent previous-point)
|
|
1084
|
|
1085 (if (not (event-window event))
|
|
1086 (error "not over window?"))
|
|
1087 (setq default-mouse-track-type
|
|
1088 (nth (mod (1- click-count)
|
|
1089 (length default-mouse-track-type-list))
|
|
1090 default-mouse-track-type-list))
|
|
1091 (setq default-mouse-track-window (event-window event))
|
|
1092 ;; Note that the extent used here is NOT the extent which
|
|
1093 ;; ends up as the value of zmacs-region-extent - this one is used
|
|
1094 ;; just during mouse-dragging.
|
|
1095 (setq default-mouse-track-extent
|
|
1096 (make-extent close-pos close-pos (event-buffer event)))
|
|
1097 (setq extent default-mouse-track-extent)
|
|
1098 (set-extent-face extent 'zmacs-region)
|
|
1099 ;; While the selection is being dragged out, give the selection extent
|
|
1100 ;; slightly higher priority than any mouse-highlighted extent, so that
|
|
1101 ;; the exact endpoints of the selection will be visible while the mouse
|
|
1102 ;; is down. Normally, the selection and mouse highlighting have the
|
|
1103 ;; same priority, so that conflicts between the two of them are
|
|
1104 ;; resolved by the usual size-and-endpoint-comparison method.
|
|
1105 (set-extent-priority extent (1+ mouse-highlight-priority))
|
|
1106 (if mouse-track-rectangle-p
|
|
1107 (setq default-mouse-track-extent
|
|
1108 (list default-mouse-track-extent)))
|
|
1109
|
|
1110 (setq previous-point
|
|
1111 (if (and adjust
|
|
1112 (markerp default-mouse-track-previous-point)
|
|
1113 (eq (current-buffer)
|
|
1114 (marker-buffer default-mouse-track-previous-point)))
|
|
1115 (marker-position default-mouse-track-previous-point)
|
|
1116 (point)))
|
|
1117 (default-mouse-track-set-point event default-mouse-track-window)
|
|
1118 (if (not adjust)
|
|
1119 (if (markerp default-mouse-track-previous-point)
|
|
1120 (set-marker default-mouse-track-previous-point (point))
|
|
1121 (setq default-mouse-track-previous-point (point-marker))))
|
|
1122 ;;
|
|
1123 ;; adjust point to a word or line boundary if appropriate
|
|
1124 (let ((anchor (default-mouse-track-anchor adjust previous-point)))
|
|
1125 (setq default-mouse-track-min-anchor
|
|
1126 (save-excursion (goto-char anchor)
|
|
1127 (funcall
|
|
1128 default-mouse-track-normalize-point-function
|
|
1129 default-mouse-track-type nil)
|
|
1130 (point)))
|
|
1131 (setq default-mouse-track-max-anchor
|
|
1132 (save-excursion (goto-char anchor)
|
|
1133 (funcall
|
|
1134 default-mouse-track-normalize-point-function
|
|
1135 default-mouse-track-type t)
|
|
1136 (point))))
|
|
1137 ;;
|
|
1138 ;; remove the existing selection to unclutter the display
|
|
1139 (if (not adjust)
|
|
1140 (cond (zmacs-regions
|
|
1141 (zmacs-deactivate-region))
|
|
1142 ((eq 'x (console-type))
|
|
1143 (x-disown-selection)))))
|
|
1144 (setq default-mouse-track-down-event nil))))
|
|
1145
|
|
1146 (defun default-mouse-track-down-hook (event click-count)
|
|
1147 (setq default-mouse-track-down-event (copy-event event))
|
|
1148 nil)
|
|
1149
|
|
1150 (defun default-mouse-track-cleanup-extents-hook ()
|
|
1151 (remove-hook 'pre-command-hook 'default-mouse-track-cleanup-extents-hook)
|
|
1152 (let ((extent default-mouse-track-extent))
|
|
1153 (if (consp extent) ; rectangle-p
|
|
1154 (mapcar 'delete-extent extent)
|
|
1155 (if extent
|
|
1156 (delete-extent extent)))))
|
|
1157
|
|
1158 (defun default-mouse-track-cleanup-hook ()
|
|
1159 (if zmacs-regions
|
|
1160 (funcall 'default-mouse-track-cleanup-extents-hook)
|
|
1161 (let ((extent default-mouse-track-extent)
|
|
1162 (func #'(lambda (e)
|
|
1163 (and (extent-live-p e)
|
|
1164 (set-extent-face e 'primary-selection)))))
|
|
1165 (add-hook 'pre-command-hook 'default-mouse-track-cleanup-extents-hook)
|
|
1166 (if (consp extent) ; rectangle-p
|
|
1167 (mapcar func extent)
|
|
1168 (if extent
|
|
1169 (funcall func extent))))))
|
|
1170
|
|
1171 (defun default-mouse-track-cleanup-extent ()
|
|
1172 (let ((dead-func
|
|
1173 (function (lambda (x)
|
|
1174 (or (not (extent-live-p x))
|
|
1175 (extent-detached-p x)))))
|
|
1176 (extent default-mouse-track-extent))
|
|
1177 (if (consp extent)
|
|
1178 (if (funcall dead-func extent)
|
|
1179 (let (newval)
|
|
1180 (mapcar (function (lambda (x)
|
|
1181 (if (not (funcall dead-func x))
|
|
1182 (setq newval (cons x newval)))))
|
|
1183 extent)
|
|
1184 (setq default-mouse-track-extent (nreverse newval))))
|
|
1185 (if (funcall dead-func extent)
|
|
1186 (setq default-mouse-track-extent nil)))))
|
|
1187
|
|
1188 (defun default-mouse-track-drag-hook (event click-count was-timeout)
|
|
1189 (default-mouse-track-deal-with-down-event click-count)
|
|
1190 (default-mouse-track-set-point event default-mouse-track-window)
|
|
1191 (default-mouse-track-cleanup-extent)
|
|
1192 (default-mouse-track-next-move default-mouse-track-min-anchor
|
|
1193 default-mouse-track-max-anchor
|
|
1194 default-mouse-track-extent)
|
|
1195 t)
|
|
1196
|
|
1197 (defun default-mouse-track-return-dragged-selection (event)
|
|
1198 (default-mouse-track-cleanup-extent)
|
|
1199 (let ((extent default-mouse-track-extent)
|
|
1200 result)
|
|
1201 (default-mouse-track-set-point-in-window event default-mouse-track-window)
|
|
1202 (default-mouse-track-next-move default-mouse-track-min-anchor
|
|
1203 default-mouse-track-max-anchor
|
|
1204 extent)
|
|
1205 (cond ((consp extent) ; rectangle-p
|
|
1206 (let ((first (car extent))
|
|
1207 (last (car (setq extent (nreverse extent)))))
|
|
1208 ;; nreverse is destructive so we need to reset this
|
|
1209 (setq default-mouse-track-extent extent)
|
|
1210 (setq result (cons (extent-start-position first)
|
|
1211 (extent-end-position last)))
|
|
1212 ;; kludge to fix up region when dragging backwards...
|
|
1213 (if (and (/= (point) (extent-start-position first))
|
|
1214 (/= (point) (extent-end-position last))
|
|
1215 (= (point) (extent-end-position first)))
|
|
1216 (goto-char (car result)))))
|
|
1217 (extent
|
|
1218 (setq result (cons (extent-start-position extent)
|
|
1219 (extent-end-position extent)))))
|
|
1220 ;; Minor kludge: if we're selecting in line-mode, include the
|
|
1221 ;; final newline. It's hard to do this in *-normalize-point.
|
|
1222 (if (and result (eq default-mouse-track-type 'line))
|
|
1223 (let ((end-p (= (point) (cdr result))))
|
|
1224 (goto-char (cdr result))
|
|
1225 (if (not (eobp))
|
|
1226 (setcdr result (1+ (cdr result))))
|
|
1227 (goto-char (if end-p (cdr result) (car result)))))
|
|
1228 ;;; ;; Minor kludge sub 2. If in char mode, and we drag the
|
|
1229 ;;; ;; mouse past EOL, include the newline.
|
|
1230 ;;; ;;
|
|
1231 ;;; ;; Major problem: can't easily distinguish between being
|
|
1232 ;;; ;; just past the last char on a line, and well past it,
|
|
1233 ;;; ;; to determine whether or not to include it in the region
|
|
1234 ;;; ;;
|
|
1235 ;;; (if nil ; (eq default-mouse-track-type 'char)
|
|
1236 ;;; (let ((after-end-p (and (not (eobp))
|
|
1237 ;;; (eolp)
|
|
1238 ;;; (> (point) (car result)))))
|
|
1239 ;;; (if after-end-p
|
|
1240 ;;; (progn
|
|
1241 ;;; (setcdr result (1+ (cdr result)))
|
|
1242 ;;; (goto-char (cdr result))))))
|
|
1243 result))
|
|
1244
|
|
1245 (defun default-mouse-track-drag-up-hook (event click-count)
|
|
1246 (let ((result (default-mouse-track-return-dragged-selection event)))
|
|
1247 (if result
|
|
1248 (default-mouse-track-maybe-own-selection result 'PRIMARY)))
|
|
1249 t)
|
|
1250
|
|
1251 (defun default-mouse-track-click-hook (event click-count)
|
|
1252 (default-mouse-track-drag-hook event click-count nil)
|
|
1253 (default-mouse-track-drag-up-hook event click-count)
|
|
1254 t)
|
|
1255
|
|
1256 (add-hook 'mouse-track-down-hook 'default-mouse-track-down-hook)
|
|
1257 (add-hook 'mouse-track-drag-hook 'default-mouse-track-drag-hook)
|
|
1258 (add-hook 'mouse-track-drag-up-hook 'default-mouse-track-drag-up-hook)
|
|
1259 (add-hook 'mouse-track-click-hook 'default-mouse-track-click-hook)
|
|
1260 (add-hook 'mouse-track-cleanup-hook 'default-mouse-track-cleanup-hook)
|
|
1261
|
|
1262
|
|
1263 ;;;;;;;;;;;; other mouse-track stuff (mostly associated with the
|
|
1264 ;;;;;;;;;;;; default handlers)
|
|
1265
|
|
1266 (defun mouse-track-default (event)
|
|
1267 "Invoke `mouse-track' with only the default handlers active."
|
|
1268 (interactive "e")
|
|
1269 (let ((mouse-track-down-hook 'default-mouse-track-down-hook)
|
|
1270 (mouse-track-drag-hook 'default-mouse-track-drag-hook)
|
|
1271 (mouse-track-drag-up-hook 'default-mouse-track-drag-up-hook)
|
|
1272 (mouse-track-click-hook 'default-mouse-track-click-hook)
|
|
1273 (mouse-track-cleanup-hook 'default-mouse-track-cleanup-hook))
|
|
1274 (mouse-track event)))
|
|
1275
|
|
1276 (defun mouse-track-do-rectangle (event)
|
|
1277 "Like `mouse-track' but selects rectangles instead of regions."
|
|
1278 (interactive "e")
|
|
1279 (let ((mouse-track-rectangle-p t))
|
|
1280 (mouse-track event)))
|
|
1281
|
|
1282 (defun mouse-track-adjust (event)
|
|
1283 "Extend the existing selection. This should be bound to a mouse button.
|
|
1284 The selection will be enlarged or shrunk so that the point of the mouse
|
|
1285 click is one of its endpoints. This function in fact behaves fairly
|
|
1286 similarly to `mouse-track', but begins by extending the existing selection
|
|
1287 (or creating a new selection from the previous text cursor position to
|
|
1288 the current mouse position) instead of creating a new, empty selection.
|
|
1289
|
|
1290 The mouse-track handlers are run from this command just like from
|
|
1291 `mouse-track'. Therefore, do not call this command from a mouse-track
|
|
1292 handler!"
|
|
1293 (interactive "e")
|
|
1294 (let ((default-mouse-track-adjust t))
|
|
1295 (mouse-track event)))
|
|
1296
|
|
1297 (defun mouse-track-adjust-default (event)
|
|
1298 "Extend the existing selection, using only the default handlers.
|
|
1299 This is just like `mouse-track-adjust' but will override any
|
|
1300 custom mouse-track handlers that the user may have installed."
|
|
1301 (interactive "e")
|
|
1302 (let ((default-mouse-track-adjust t))
|
|
1303 (mouse-track-default event)))
|
|
1304
|
|
1305 (defvar mouse-track-insert-selected-region nil)
|
|
1306
|
|
1307 (defun mouse-track-insert-drag-up-hook (event click-count)
|
|
1308 (setq mouse-track-insert-selected-region
|
|
1309 (default-mouse-track-return-dragged-selection event)))
|
|
1310
|
|
1311 (defun mouse-track-insert (event &optional delete)
|
|
1312 "Make a selection with the mouse and insert it at point.
|
|
1313 This is exactly the same as the `mouse-track' command on \\[mouse-track],
|
|
1314 except that point is not moved; the selected text is immediately inserted
|
|
1315 after being selected\; and the selection is immediately disowned afterwards."
|
|
1316 (interactive "*e")
|
|
1317 (setq mouse-track-insert-selected-region nil)
|
|
1318 (let ((mouse-track-drag-up-hook 'mouse-track-insert-drag-up-hook)
|
|
1319 (mouse-track-click-hook 'mouse-track-insert-click-hook)
|
|
1320 s)
|
|
1321 (save-excursion
|
|
1322 (save-window-excursion
|
|
1323 (mouse-track event)
|
|
1324 (if (consp mouse-track-insert-selected-region)
|
|
1325 (let ((pair mouse-track-insert-selected-region))
|
|
1326 (setq s (prog1
|
|
1327 (buffer-substring (car pair) (cdr pair))
|
|
1328 (if delete
|
|
1329 (kill-region (car pair) (cdr pair)))))))))
|
|
1330 (or (null s) (equal s "") (insert s))))
|
|
1331
|
|
1332 (defun mouse-track-insert-click-hook (event click-count)
|
|
1333 (default-mouse-track-drag-hook event click-count nil)
|
|
1334 (mouse-track-insert-drag-up-hook event click-count)
|
|
1335 t)
|
|
1336
|
|
1337 (defun mouse-track-delete-and-insert (event)
|
|
1338 "Make a selection with the mouse and insert it at point.
|
|
1339 This is exactly the same as the `mouse-track' command on \\[mouse-track],
|
|
1340 except that point is not moved; the selected text is immediately inserted
|
|
1341 after being selected\; and the text of the selection is deleted."
|
|
1342 (interactive "*e")
|
|
1343 (mouse-track-insert event t))
|
|
1344
|
|
1345 ;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1346
|
|
1347
|
|
1348 (defvar inhibit-help-echo nil
|
|
1349 "Inhibits display of `help-echo' extent properties in the minibuffer.")
|
|
1350 (defvar last-help-echo-object nil)
|
|
1351 (defvar help-echo-owns-message nil)
|
|
1352
|
|
1353 (defun clear-help-echo (&optional ignored-frame)
|
|
1354 (if help-echo-owns-message
|
|
1355 (progn
|
|
1356 (setq help-echo-owns-message nil
|
|
1357 last-help-echo-object nil)
|
|
1358 (clear-message 'help-echo))))
|
|
1359
|
|
1360 (defun show-help-echo (mess)
|
|
1361 ;; (clear-help-echo)
|
|
1362 (setq help-echo-owns-message t)
|
|
1363 (display-message 'help-echo mess))
|
|
1364
|
|
1365 (add-hook 'mouse-leave-frame-hook 'clear-help-echo)
|
|
1366
|
|
1367 ;; It may be a good idea to move this to C, for better performance of
|
|
1368 ;; extent highlighting and pointer changes.
|
|
1369 (defun default-mouse-motion-handler (event)
|
|
1370 "For use as the value of `mouse-motion-handler'.
|
|
1371 This implements the various pointer-shape variables,
|
|
1372 as well as extent highlighting, help-echo, toolbar up/down,
|
|
1373 and `mode-motion-hook'."
|
|
1374 (let* ((frame (or (event-frame event) (selected-frame)))
|
|
1375 (window (event-window event))
|
|
1376 (buffer (event-buffer event))
|
|
1377 (modeline-point (and buffer (event-modeline-position event)))
|
|
1378 (modeline-string (and modeline-point
|
|
1379 (symbol-value-in-buffer
|
|
1380 'generated-modeline-string buffer)))
|
|
1381 ;; point must be invalidated by modeline-point.
|
|
1382 (point (and buffer (not modeline-point)
|
|
1383 (event-point event)))
|
|
1384 (extent (or (and point
|
|
1385 (extent-at point buffer 'mouse-face))
|
|
1386 (and modeline-point
|
|
1387 (extent-at modeline-point modeline-string
|
|
1388 ;; Modeline extents don't have a
|
|
1389 ;; mouse-face property set.
|
|
1390 'help-echo))))
|
|
1391 (glyph-extent1 (event-glyph-extent event))
|
|
1392 (glyph-extent (and glyph-extent1
|
|
1393 (extent-live-p glyph-extent1)
|
|
1394 glyph-extent1))
|
|
1395 ;; This is an extent:
|
|
1396 (user-pointer1 (or (and glyph-extent
|
|
1397 (extent-property glyph-extent 'pointer)
|
|
1398 glyph-extent)
|
|
1399 (and point (extent-at point buffer 'pointer))
|
|
1400 (and modeline-point
|
|
1401 (extent-at modeline-point modeline-string
|
|
1402 'pointer))))
|
|
1403 ;; And this should be a glyph:
|
|
1404 (user-pointer (and user-pointer1 (extent-live-p user-pointer1)
|
|
1405 (extent-property user-pointer1 'pointer)))
|
|
1406 (button (event-toolbar-button event))
|
|
1407 (help (or (and glyph-extent (extent-property glyph-extent 'help-echo)
|
|
1408 glyph-extent)
|
|
1409 (and button (not (null (toolbar-button-help-string button)))
|
|
1410 button)
|
|
1411 (and point
|
|
1412 (extent-at point buffer 'help-echo))
|
|
1413 (and modeline-point
|
|
1414 (extent-at modeline-point modeline-string
|
|
1415 'help-echo))))
|
|
1416 ;; vars is a list of glyph variables to check for a pointer
|
|
1417 ;; value.
|
|
1418 (vars (cond
|
|
1419 ;; Checking if button is non-nil is not sufficent
|
|
1420 ;; since the pointer could be over a blank portion
|
|
1421 ;; of the toolbar.
|
|
1422 ((event-over-toolbar-p event)
|
|
1423 '(toolbar-pointer-glyph nontext-pointer-glyph
|
|
1424 text-pointer-glyph))
|
|
1425 ((or extent glyph-extent)
|
|
1426 '(selection-pointer-glyph text-pointer-glyph))
|
|
1427 ((event-over-modeline-p event)
|
|
1428 '(modeline-pointer-glyph nontext-pointer-glyph
|
|
1429 text-pointer-glyph))
|
|
1430 (point '(text-pointer-glyph))
|
|
1431 (buffer '(nontext-pointer-glyph text-pointer-glyph))
|
|
1432 (t '(nontext-pointer-glyph text-pointer-glyph))))
|
|
1433 pointer)
|
|
1434 (and user-pointer (glyphp user-pointer)
|
|
1435 (push 'user-pointer vars))
|
|
1436 (while (and vars (not (pointer-image-instance-p pointer)))
|
|
1437 (setq pointer (glyph-image-instance (symbol-value (car vars))
|
|
1438 (or window frame))
|
|
1439 vars (cdr vars)))
|
|
1440
|
|
1441 (if (pointer-image-instance-p pointer)
|
|
1442 (set-frame-pointer frame pointer))
|
|
1443
|
|
1444 ;; If last-pressed-toolbar-button is not nil, then check and see
|
|
1445 ;; if we have moved to a new button and adjust the down flags
|
|
1446 ;; accordingly.
|
|
1447 (when (and (featurep 'toolbar) toolbar-active)
|
|
1448 (unless (eq last-pressed-toolbar-button button)
|
|
1449 (release-previous-toolbar-button event)
|
|
1450 (and button (press-toolbar-button event))))
|
|
1451
|
|
1452 (cond (extent (highlight-extent extent t))
|
|
1453 (glyph-extent (highlight-extent glyph-extent t))
|
|
1454 (t (highlight-extent nil nil)))
|
|
1455 (cond ((extentp help)
|
|
1456 (or inhibit-help-echo
|
|
1457 (eq help last-help-echo-object) ;save some time
|
|
1458 (let ((hprop (extent-property help 'help-echo)))
|
|
1459 (setq last-help-echo-object help)
|
|
1460 (or (stringp hprop)
|
|
1461 (setq hprop (funcall hprop help)))
|
|
1462 (and hprop (show-help-echo hprop)))))
|
|
1463 ((and (featurep 'toolbar)
|
|
1464 (toolbar-button-p help)
|
|
1465 (toolbar-button-enabled-p help))
|
|
1466 (or (not toolbar-help-enabled)
|
|
1467 (eq help last-help-echo-object) ;save some time
|
|
1468 (let ((hstring (toolbar-button-help-string button)))
|
|
1469 (setq last-help-echo-object help)
|
|
1470 (or (stringp hstring)
|
|
1471 (setq hstring (funcall hstring help)))
|
|
1472 (show-help-echo hstring))))
|
|
1473 (last-help-echo-object
|
|
1474 (clear-help-echo)))
|
|
1475 (if mouse-grabbed-buffer (setq buffer mouse-grabbed-buffer))
|
|
1476 (if (and buffer (symbol-value-in-buffer 'mode-motion-hook buffer nil))
|
|
1477 (with-current-buffer buffer
|
|
1478 (run-hook-with-args 'mode-motion-hook event)
|
|
1479
|
|
1480 ;; If the mode-motion-hook created a highlightable extent around
|
|
1481 ;; the mouse-point, highlight it right away. Otherwise it wouldn't
|
|
1482 ;; be highlighted until the *next* motion event came in.
|
|
1483 (if (and point
|
|
1484 (null extent)
|
|
1485 (setq extent (extent-at point
|
|
1486 (event-buffer event) ; not buffer
|
|
1487 'mouse-face)))
|
|
1488 (highlight-extent extent t)))))
|
|
1489 nil)
|
|
1490
|
|
1491 (setq mouse-motion-handler 'default-mouse-motion-handler)
|
|
1492
|
|
1493 ;;; mouse.el ends here
|