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