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