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