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