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
|
793
|
5 ;; Copyright (C) 1995, 1996, 2000, 2002 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
|
442
|
510 (defcustom mouse-track-activate-strokes '(button1-double-click button2-click)
|
|
511 "List of mouse strokes that can cause \"activation\" of the text extent
|
|
512 under the mouse. The exact meaning of \"activation\" is dependent on the
|
|
513 text clicked on and the mode of the buffer, but typically entails actions
|
|
514 such as following a hyperlink or selecting an entry in a completion buffer.
|
|
515
|
|
516 Possible list entries are
|
|
517
|
|
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
|
|
527 As a general rule, you should not use the \"-down\" values, because this
|
|
528 makes it impossible to have other simultaneous actions, such as selection."
|
|
529 :type '(set
|
|
530 button1-click
|
|
531 button1-double-click
|
|
532 button1-triple-click
|
|
533 button1-down
|
|
534 button2-click
|
|
535 button2-double-click
|
|
536 button2-triple-click
|
|
537 button2-down)
|
|
538 :group 'mouse)
|
|
539
|
428
|
540 (defvar mouse-track-x-threshold '(face-width 'default)
|
|
541 "Minimum number of pixels in the X direction for a drag to be initiated.
|
|
542 If the mouse is moved more than either the X or Y threshold while the
|
|
543 button is held down (see also `mouse-track-y-threshold'), then a drag
|
|
544 is initiated; otherwise the gesture is considered to be a click.
|
|
545 See `mouse-track'.
|
|
546
|
539
|
547 The value should be either a number or a form to be evaluated to
|
428
|
548 produce a number.")
|
|
549
|
|
550 (defvar mouse-track-y-threshold '(face-height 'default)
|
|
551 "Minimum number of pixels in the Y direction for a drag to be initiated.
|
|
552 If the mouse is moved more than either the X or Y threshold while the
|
|
553 button is held down (see also `mouse-track-x-threshold'), then a drag
|
|
554 is initiated; otherwise the gesture is considered to be a click.
|
|
555 See `mouse-track'.
|
|
556
|
|
557 The value should be either a number of a form to be evaluated to
|
|
558 produce a number.")
|
|
559
|
|
560 ;; these variables are private to mouse-track.
|
|
561 (defvar mouse-track-up-time nil)
|
|
562 (defvar mouse-track-up-x nil)
|
|
563 (defvar mouse-track-up-y nil)
|
|
564 (defvar mouse-track-timeout-id nil)
|
|
565 (defvar mouse-track-click-count nil)
|
|
566
|
|
567 (defun mouse-track-set-timeout (event)
|
|
568 (if mouse-track-timeout-id
|
|
569 (disable-timeout mouse-track-timeout-id))
|
|
570 (if mouse-track-scroll-delay
|
|
571 (setq mouse-track-timeout-id
|
|
572 (add-timeout (/ mouse-track-scroll-delay 1000.0)
|
|
573 'mouse-track-scroll-undefined
|
|
574 (copy-event event)))))
|
|
575
|
442
|
576 (defun mouse-track-do-activate (event)
|
|
577 "Execute the activate function under EVENT, if any.
|
|
578 Return true if the function was activated."
|
|
579 (let ((ex (extent-at-event event 'activate-function)))
|
|
580 (when ex
|
|
581 (funcall (extent-property ex 'activate-function)
|
|
582 event ex)
|
|
583 t)))
|
|
584
|
546
|
585 (defvar Mouse-track-gensym (gensym))
|
|
586
|
|
587 (defun mouse-track-run-hook (hook override event &rest args)
|
428
|
588 ;; ugh, can't use run-hook-with-args-until-success because we have
|
|
589 ;; to get the value using symbol-value-in-buffer. Doing a
|
|
590 ;; save-excursion/set-buffer is wrong because the hook might want to
|
|
591 ;; change the buffer, but just doing a set-buffer is wrong because
|
|
592 ;; the hook might not want to change the buffer.
|
|
593 ;; #### What we need here is a Lisp interface to
|
|
594 ;; run_hook_with_args_in_buffer. Here is a poor man's version.
|
546
|
595 (let ((overridden (plist-get override hook Mouse-track-gensym)))
|
|
596 (if (not (eq overridden Mouse-track-gensym))
|
|
597 (if (and (listp overridden) (not (eq (car overridden) 'lambda)))
|
|
598 (some #'(lambda (val) (apply val event args)) overridden)
|
|
599 (apply overridden event args))
|
|
600 (let ((buffer (event-buffer event)))
|
|
601 (and mouse-grabbed-buffer (setq buffer mouse-grabbed-buffer))
|
|
602 (when buffer
|
|
603 (let ((value (symbol-value-in-buffer hook buffer nil)))
|
|
604 (if (and (listp value) (not (eq (car value) 'lambda)))
|
|
605 ;; List of functions.
|
|
606 (let (retval)
|
|
607 (while (and value (null retval))
|
|
608 ;; Found `t': should process default value. We could
|
|
609 ;; splice it into the buffer-local value, but that
|
|
610 ;; would cons, which is not a good thing for
|
|
611 ;; mouse-track hooks.
|
|
612 (if (eq (car value) t)
|
|
613 (let ((global (default-value hook)))
|
|
614 (if (and (listp global) (not (eq (car global)
|
|
615 'lambda)))
|
|
616 ;; List of functions.
|
|
617 (while (and global
|
|
618 (null (setq retval
|
|
619 (apply (car global)
|
|
620 event args))))
|
|
621 (pop global))
|
|
622 ;; lambda
|
|
623 (setq retval (apply (car global) event args))))
|
|
624 (setq retval (apply (car value) event args)))
|
|
625 (pop value))
|
|
626 retval)
|
|
627 ;; lambda
|
|
628 (apply value event args))))))))
|
428
|
629
|
|
630 (defun mouse-track-scroll-undefined (random)
|
|
631 ;; the old implementation didn't actually define this function,
|
|
632 ;; and in normal use it won't ever be called because the timeout
|
|
633 ;; will either be removed before it fires or will be picked off
|
|
634 ;; with next-event and not dispatched. However, if you're
|
|
635 ;; attempting to debug a click-hook (which is pretty damn
|
|
636 ;; difficult to do), this function may get called.
|
|
637 )
|
|
638
|
546
|
639 (defun mouse-track (event &optional overriding-hooks)
|
793
|
640 "Generalized mouse-button handler.
|
|
641 This is the function that handles standard mouse behavior -- moving point
|
|
642 when clicked, selecting text when dragged, etc. -- and should be bound to a
|
|
643 mouse button (normally, button1 and button2).
|
|
644
|
|
645 This allows for overloading of different mouse strokes with different
|
|
646 commands. The behavior of this function is customizable using various
|
|
647 hooks and variables: see `mouse-track-click-hook', `mouse-track-drag-hook',
|
428
|
648 `mouse-track-drag-up-hook', `mouse-track-down-hook', `mouse-track-up-hook',
|
|
649 `mouse-track-cleanup-hook', `mouse-track-multi-click-time',
|
|
650 `mouse-track-scroll-delay', `mouse-track-x-threshold', and
|
|
651 `mouse-track-y-threshold'.
|
|
652
|
|
653 Default handlers are provided to implement standard selecting/positioning
|
|
654 behavior. You can explicitly request this default behavior, and override
|
|
655 any custom-supplied handlers, by using the function `mouse-track-default'
|
|
656 instead of `mouse-track'.
|
|
657
|
546
|
658 \(In general, you can override specific hooks by using the argument
|
|
659 OVERRIDING-HOOKS, which should be a plist of alternating hook names
|
|
660 and values.)
|
|
661
|
428
|
662 Default behavior is as follows:
|
|
663
|
|
664 If you click-and-drag, the selection will be set to the region between the
|
|
665 point of the initial click and the point at which you release the button.
|
|
666 These positions need not be ordered.
|
|
667
|
|
668 If you click-and-release without moving the mouse, then the point is moved
|
|
669 and the selection is disowned (there will be no selection owner). The mark
|
|
670 will be set to the previous position of point.
|
|
671
|
|
672 If you double-click, the selection will extend by symbols instead of by
|
|
673 characters. If you triple-click, the selection will extend by lines.
|
|
674
|
|
675 If you drag the mouse off the top or bottom of the window, you can select
|
|
676 pieces of text which are larger than the visible part of the buffer; the
|
|
677 buffer will scroll as necessary.
|
|
678
|
793
|
679 The point will be left at the position at which you released the button,
|
|
680 and the mark will be left at the initial click position.
|
|
681
|
|
682 Under X Windows, the selected text becomes the current X Selection, and can
|
|
683 be immediately inserted elsewhere using button2. Under MS Windows, this
|
|
684 also works, because the behavior is emulated."
|
428
|
685 (interactive "e")
|
|
686 (let ((mouse-down t)
|
|
687 (xthresh (eval mouse-track-x-threshold))
|
|
688 (ythresh (eval mouse-track-y-threshold))
|
|
689 (orig-x (event-x-pixel event))
|
|
690 (orig-y (event-y-pixel event))
|
|
691 (buffer (event-buffer event))
|
|
692 (mouse-grabbed-buffer (event-buffer event))
|
|
693 mouse-moved)
|
|
694 (if (or (not mouse-track-up-x)
|
|
695 (not mouse-track-up-y)
|
|
696 (not mouse-track-up-time)
|
|
697 (> (- (event-timestamp event) mouse-track-up-time)
|
|
698 mouse-track-multi-click-time)
|
|
699 (> (abs (- mouse-track-up-x orig-x)) xthresh)
|
|
700 (> (abs (- mouse-track-up-y orig-y)) ythresh))
|
|
701 (setq mouse-track-click-count 1)
|
|
702 (setq mouse-track-click-count (1+ mouse-track-click-count)))
|
|
703 (if (not (event-window event))
|
|
704 (error "Not over a window."))
|
546
|
705 (mouse-track-run-hook 'mouse-track-down-hook overriding-hooks
|
428
|
706 event mouse-track-click-count)
|
|
707 (unwind-protect
|
|
708 (while mouse-down
|
|
709 (setq event (next-event event))
|
|
710 (cond ((motion-event-p event)
|
|
711 (if (and (not mouse-moved)
|
|
712 (or (> (abs (- (event-x-pixel event) orig-x))
|
|
713 xthresh)
|
|
714 (> (abs (- (event-y-pixel event) orig-y))
|
|
715 ythresh)))
|
|
716 (setq mouse-moved t))
|
|
717 (if mouse-moved
|
|
718 (mouse-track-run-hook 'mouse-track-drag-hook
|
546
|
719 overriding-hooks
|
|
720 event mouse-track-click-count nil))
|
428
|
721 (mouse-track-set-timeout event))
|
|
722 ((and (timeout-event-p event)
|
|
723 (eq (event-function event)
|
|
724 'mouse-track-scroll-undefined))
|
|
725 (if mouse-moved
|
|
726 (mouse-track-run-hook 'mouse-track-drag-hook
|
546
|
727 overriding-hooks
|
|
728 (event-object event)
|
|
729 mouse-track-click-count t))
|
428
|
730 (mouse-track-set-timeout (event-object event)))
|
|
731 ((button-release-event-p event)
|
|
732 (setq mouse-track-up-time (event-timestamp event))
|
|
733 (setq mouse-track-up-x (event-x-pixel event))
|
|
734 (setq mouse-track-up-y (event-y-pixel event))
|
|
735 (setq mouse-down nil)
|
|
736 (mouse-track-run-hook 'mouse-track-up-hook
|
546
|
737 overriding-hooks
|
|
738 event mouse-track-click-count)
|
428
|
739 (if mouse-moved
|
|
740 (mouse-track-run-hook 'mouse-track-drag-up-hook
|
546
|
741 overriding-hooks
|
|
742 event mouse-track-click-count)
|
428
|
743 (mouse-track-run-hook 'mouse-track-click-hook
|
546
|
744 overriding-hooks
|
|
745 event mouse-track-click-count)))
|
428
|
746 ((or (key-press-event-p event)
|
|
747 (and (misc-user-event-p event)
|
|
748 (eq (event-function event) 'cancel-mode-internal)))
|
|
749 (error "Selection aborted"))
|
|
750 (t
|
|
751 (dispatch-event event))))
|
|
752 ;; protected
|
|
753 (if mouse-track-timeout-id
|
|
754 (disable-timeout mouse-track-timeout-id))
|
|
755 (setq mouse-track-timeout-id nil)
|
479
|
756 (and (buffer-live-p buffer)
|
428
|
757 (save-excursion
|
|
758 (set-buffer buffer)
|
546
|
759 (let ((override (plist-get overriding-hooks
|
|
760 'mouse-track-cleanup-hook
|
|
761 Mouse-track-gensym)))
|
|
762 (if (not (eq override Mouse-track-gensym))
|
|
763 (if (and (listp override) (not (eq (car override) 'lambda)))
|
|
764 (mapc #'funcall override)
|
|
765 (funcall override))
|
|
766 (run-hooks 'mouse-track-cleanup-hook))))))))
|
428
|
767
|
|
768
|
|
769 ;;;;;;;;;;;; default handlers: new version of mouse-track
|
|
770
|
|
771 (defvar default-mouse-track-type nil)
|
|
772 (defvar default-mouse-track-type-list '(char word line))
|
|
773 (defvar default-mouse-track-window nil)
|
|
774 (defvar default-mouse-track-extent nil)
|
|
775 (defvar default-mouse-track-adjust nil)
|
|
776 (defvar default-mouse-track-min-anchor nil)
|
|
777 (defvar default-mouse-track-max-anchor nil)
|
|
778 (defvar default-mouse-track-result nil)
|
|
779 (defvar default-mouse-track-down-event nil)
|
|
780
|
|
781 ;; D. Verna Feb. 17 1998
|
|
782 ;; This function used to assume that when (event-window event) differs from
|
|
783 ;; window, we have to scroll. This is WRONG, for instance when there are
|
|
784 ;; toolbars on the side, in which case window-event returns nil.
|
|
785 (defun default-mouse-track-set-point-in-window (event window)
|
|
786 (if (event-over-modeline-p event)
|
|
787 nil ;; Scroll
|
|
788 ;; Not over a modeline
|
|
789 (if (eq (event-window event) window)
|
|
790 (let ((p (event-closest-point event)))
|
|
791 (if (or (not p) (not (pos-visible-in-window-p p window)))
|
|
792 nil ;; Scroll
|
|
793 (mouse-set-point event)
|
|
794 t))
|
|
795 ;; Not over a modeline, not the same window. Check if the Y position
|
|
796 ;; is still overlapping the original window.
|
|
797 (let* ((edges (window-pixel-edges window))
|
|
798 (row (event-y-pixel event))
|
|
799 (text-start (nth 1 edges))
|
446
|
800 (text-end (nth 3 edges)))
|
428
|
801 (if (or (< row text-start)
|
|
802 (> row text-end))
|
|
803 nil ;; Scroll
|
|
804 ;; The Y pos in overlapping the original window. Check however if
|
|
805 ;; the position is really visible, because there could be a
|
|
806 ;; scrollbar or a modeline at this place.
|
|
807 ;; Find the mean line height (height / lines nb), and approximate
|
|
808 ;; the line number for Y pos.
|
|
809 (select-window window)
|
|
810 (let ((line (/ (* (- row text-start) (window-height))
|
|
811 (- text-end text-start))))
|
|
812 (if (not (save-excursion
|
|
813 (goto-char (window-start))
|
|
814 (pos-visible-in-window-p
|
|
815 (point-at-bol (+ 1 line)))))
|
|
816 nil ;; Scroll
|
|
817 ;; OK, we can go to that position
|
|
818 (goto-char (window-start))
|
|
819 (forward-line line)
|
|
820 ;; On the right side: go to end-of-line.
|
|
821 (when (>= (event-x-pixel event) (nth 2 edges))
|
|
822 (goto-char (point-at-eol)))
|
|
823 t))))
|
|
824 )))
|
|
825
|
|
826
|
|
827 (defun default-mouse-track-scroll-and-set-point (event window)
|
|
828 (select-window window)
|
|
829 (let ((edges (window-pixel-edges window))
|
|
830 (row (event-y-pixel event))
|
|
831 (height (face-height 'default)))
|
|
832 (cond ((< (abs (- row (nth 1 edges))) (abs (- row (nth 3 edges))))
|
|
833 ;; closer to window's top than to bottom, so move up
|
|
834 (let ((delta (max 1 (/ (- (nth 1 edges) row) height))))
|
|
835 (condition-case () (scroll-down delta) (error))
|
|
836 (goto-char (window-start))))
|
|
837 ((>= (point) (point-max)))
|
|
838 (t
|
|
839 ;; scroll by one line if over the modeline or a clipped line
|
|
840 (let ((delta (if (or (event-over-modeline-p event)
|
|
841 (< row (nth 3 edges)))
|
|
842 1
|
|
843 (+ (/ (- row (nth 3 edges)) height) 1)))
|
|
844 (close-pos (event-closest-point event)))
|
|
845 (condition-case () (scroll-up delta) (error))
|
|
846 (if (and close-pos (pos-visible-in-window-p close-pos))
|
|
847 (goto-char close-pos)
|
|
848 (goto-char (window-end))
|
|
849 (vertical-motion delta)
|
|
850 ;; window-end reports the end of the clipped line, even if
|
|
851 ;; scroll-on-clipped-lines is t. compensate.
|
|
852 ;; (If window-end gets fixed this can be removed.)
|
|
853 (if (not (pos-visible-in-window-p (max (1- (point))
|
|
854 (point-min))))
|
|
855 (vertical-motion -1))
|
|
856 (condition-case () (backward-char 1)
|
|
857 (error (end-of-line)))))))))
|
|
858
|
|
859
|
|
860 ;; This remembers the last position at which the user clicked, for the
|
|
861 ;; benefit of mouse-track-adjust (for example, button1; scroll until the
|
|
862 ;; position of the click is off the frame; then Sh-button1 to select the
|
793
|
863 ;; new region).
|
428
|
864 (defvar default-mouse-track-previous-point nil)
|
|
865
|
|
866 (defun default-mouse-track-set-point (event window)
|
|
867 (if (default-mouse-track-set-point-in-window event window)
|
|
868 nil
|
|
869 (default-mouse-track-scroll-and-set-point event window)))
|
|
870
|
|
871 (defsubst default-mouse-track-beginning-of-word (symbolp)
|
|
872 (let ((word-constituent (cond ((eq symbolp t) "\\w\\|\\s_\\|\\s'")
|
|
873 ((null symbolp) "\\w")
|
|
874 (t "[^ \t\n]")))
|
|
875 (white-space "[ \t]"))
|
|
876 (cond ((bobp) nil)
|
|
877 ((looking-at word-constituent)
|
|
878 (backward-char)
|
|
879 (while (and (not (bobp)) (looking-at word-constituent))
|
|
880 (backward-char))
|
|
881 (if (or (not (bobp)) (not (looking-at word-constituent)))
|
|
882 (forward-char)))
|
|
883 ((looking-at white-space)
|
|
884 (backward-char)
|
|
885 (while (looking-at white-space)
|
|
886 (backward-char))
|
|
887 (forward-char)))))
|
|
888
|
|
889 (defun default-mouse-track-end-of-word (symbolp)
|
|
890 (let ((word-constituent (cond ((eq symbolp t) "\\w\\|\\s_\\|\\s'")
|
|
891 ((null symbolp) "\\w")
|
|
892 (t "[^ \t\n]")))
|
|
893 (white-space "[ \t]"))
|
|
894 (cond ((looking-at word-constituent) ; word or symbol constituent
|
|
895 (while (looking-at word-constituent)
|
|
896 (forward-char)))
|
|
897 ((looking-at white-space) ; word or symbol constituent
|
|
898 (while (looking-at white-space)
|
|
899 (forward-char))))))
|
|
900
|
|
901 ;; Decide what will be the SYMBOLP argument to
|
|
902 ;; default-mouse-track-{beginning,end}-of-word, according to the
|
|
903 ;; syntax of the current character and value of mouse-highlight-text.
|
|
904 (defsubst default-mouse-track-symbolp (syntax)
|
|
905 (cond ((eq mouse-highlight-text 'context)
|
|
906 (eq syntax ?_))
|
|
907 ((eq mouse-highlight-text 'symbol)
|
|
908 t)
|
|
909 (t
|
|
910 nil)))
|
|
911
|
|
912 ;; Return t if point is at an opening quote character. This is
|
|
913 ;; determined by testing whether the syntax of the following character
|
|
914 ;; is `string', which will always be true for opening quotes and
|
|
915 ;; always false for closing quotes.
|
|
916 (defun default-mouse-track-point-at-opening-quote-p ()
|
|
917 (save-excursion
|
|
918 (forward-char 1)
|
|
919 (eq (buffer-syntactic-context) 'string)))
|
|
920
|
|
921 (defun default-mouse-track-normalize-point (type forwardp)
|
|
922 (cond ((eq type 'word)
|
|
923 ;; trap the beginning and end of buffer errors
|
|
924 (ignore-errors
|
|
925 (setq type (char-syntax (char-after (point))))
|
|
926 (if forwardp
|
|
927 (if (or (= type ?\()
|
|
928 (and (= type ?\")
|
|
929 (default-mouse-track-point-at-opening-quote-p)))
|
|
930 (goto-char (scan-sexps (point) 1))
|
|
931 (default-mouse-track-end-of-word
|
|
932 (default-mouse-track-symbolp type)))
|
|
933 (if (or (= type ?\))
|
|
934 (and (= type ?\")
|
|
935 (not (default-mouse-track-point-at-opening-quote-p))))
|
|
936 (goto-char (scan-sexps (1+ (point)) -1))
|
|
937 (default-mouse-track-beginning-of-word
|
|
938 (default-mouse-track-symbolp type))))))
|
|
939 ((eq type 'line)
|
793
|
940 (if forwardp
|
|
941 ;; Counter-kludge. If we are adjusting a line-oriented
|
|
942 ;; selection, default-mouse-track-return-dragged-selection
|
|
943 ;; fixed it to include the final newline. Unfortunately, that
|
|
944 ;; will cause us to add another line at the end (the wrong
|
|
945 ;; side of the selection) unless we take evasive action.
|
|
946 (unless (and default-mouse-track-adjust
|
|
947 (bolp))
|
|
948 (end-of-line))
|
|
949 (beginning-of-line)))
|
428
|
950 ((eq type 'buffer)
|
|
951 (if forwardp (end-of-buffer) (beginning-of-buffer)))))
|
|
952
|
|
953 (defun default-mouse-track-next-move (min-anchor max-anchor extent)
|
|
954 (let ((anchor (if (<= (point) min-anchor) max-anchor min-anchor)))
|
|
955 (funcall default-mouse-track-normalize-point-function
|
|
956 default-mouse-track-type (> (point) anchor))
|
|
957 (if (consp extent)
|
|
958 (default-mouse-track-next-move-rect anchor (point) extent)
|
|
959 (if extent
|
|
960 (if (<= anchor (point))
|
|
961 (set-extent-endpoints extent anchor (point))
|
|
962 (set-extent-endpoints extent (point) anchor))))))
|
|
963
|
|
964 (defun default-mouse-track-next-move-rect (start end extents &optional pad-p)
|
|
965 (if (< end start)
|
|
966 (let ((tmp start)) (setq start end end tmp)))
|
|
967 (cond
|
|
968 ((= start end) ; never delete the last remaining extent
|
|
969 (mapcar 'delete-extent (cdr extents))
|
|
970 (setcdr extents nil)
|
|
971 (set-extent-endpoints (car extents) start start))
|
|
972 (t
|
|
973 (let ((indent-tabs-mode nil) ; if pad-p, don't use tabs
|
|
974 (rest extents)
|
|
975 left right last p)
|
|
976 (save-excursion
|
|
977 (save-restriction
|
|
978 (goto-char end)
|
|
979 (setq right (current-column))
|
|
980 (goto-char start)
|
|
981 (setq left (current-column))
|
|
982 (if (< right left)
|
|
983 (let ((tmp left))
|
|
984 (setq left right right tmp)
|
|
985 (setq start (- start (- right left))
|
|
986 end (+ end (- right left)))))
|
|
987 ;; End may have been set to a value greater than point-max if drag
|
|
988 ;; or movement extends to end of buffer, so reset it.
|
|
989 (setq end (min end (point-max)))
|
|
990 (beginning-of-line)
|
|
991 (narrow-to-region (point) end)
|
|
992 (goto-char start)
|
|
993 (while (and rest (not (eobp)))
|
|
994 (setq p (point))
|
|
995 (move-to-column right pad-p)
|
|
996 (set-extent-endpoints (car rest) p (point))
|
|
997 ;; this code used to look at the return value
|
|
998 ;; of forward-line, but that doesn't work because
|
|
999 ;; forward-line has bogus behavior: If you're on
|
|
1000 ;; the last line of a buffer but not at the very
|
|
1001 ;; end, forward-line will move you to the very
|
|
1002 ;; end and return 0 instead of 1, like it should.
|
|
1003 ;; the result was frequent infinite loops here,
|
|
1004 ;; creating very large numbers of extents at
|
|
1005 ;; the same position. There was an N^2 sorting
|
|
1006 ;; algorithm in extents.c for extents at a
|
|
1007 ;; particular position, and the result was very
|
|
1008 ;; bad news.
|
|
1009 (forward-line 1)
|
|
1010 (if (not (eobp))
|
|
1011 (move-to-column left pad-p))
|
|
1012 (setq last rest
|
|
1013 rest (cdr rest)))
|
|
1014 (cond (rest
|
|
1015 (mapcar 'delete-extent rest)
|
|
1016 (setcdr last nil))
|
|
1017 ((not (eobp))
|
|
1018 (while (not (eobp))
|
|
1019 (setq p (point))
|
|
1020 (move-to-column right pad-p)
|
|
1021 (let ((e (make-extent p (point))))
|
|
1022 (set-extent-face e (extent-face (car extents)))
|
|
1023 (set-extent-priority e (extent-priority (car extents)))
|
|
1024 (setcdr last (cons e nil))
|
|
1025 (setq last (cdr last)))
|
|
1026 (forward-line 1)
|
|
1027 (if (not (eobp))
|
|
1028 (move-to-column left pad-p))
|
|
1029 )))))
|
|
1030 ))))
|
|
1031
|
|
1032 (defun default-mouse-track-has-selection-p (buffer)
|
|
1033 (and (selection-owner-p)
|
|
1034 (extent-live-p primary-selection-extent)
|
|
1035 (not (extent-detached-p primary-selection-extent))
|
|
1036 (eq buffer (extent-object primary-selection-extent))))
|
|
1037
|
|
1038 (defun default-mouse-track-anchor (adjust previous-point)
|
|
1039 (if adjust
|
|
1040 (if (default-mouse-track-has-selection-p (current-buffer))
|
|
1041 (let ((start (extent-start-position primary-selection-extent))
|
|
1042 (end (extent-end-position primary-selection-extent)))
|
|
1043 (cond ((< (point) start) end)
|
|
1044 ((> (point) end) start)
|
|
1045 ((> (- (point) start) (- end (point))) start)
|
|
1046 (t end)))
|
|
1047 previous-point)
|
|
1048 (point)))
|
|
1049
|
|
1050 (defun default-mouse-track-maybe-own-selection (pair type)
|
|
1051 (let ((start (car pair))
|
|
1052 (end (cdr pair)))
|
|
1053 (or (= start end) (push-mark (if (= (point) start) end start)))
|
|
1054 (cond (zmacs-regions
|
|
1055 (if (= start end)
|
|
1056 nil
|
|
1057 ;; #### UTTER KLUDGE.
|
|
1058 ;; If we don't have this sit-for here, then triple-clicking
|
|
1059 ;; will result in the line not being highlighted as it
|
|
1060 ;; should. What appears to be happening is this:
|
|
1061 ;;
|
|
1062 ;; -- each time the button goes down, the selection is
|
|
1063 ;; disowned (see comment "remove the existing selection
|
|
1064 ;; to unclutter the display", below).
|
|
1065 ;; -- this causes a SelectionClear event to be sent to
|
|
1066 ;; XEmacs.
|
|
1067 ;; -- each time the button goes up except the first, the
|
|
1068 ;; selection is owned again.
|
|
1069 ;; -- later, XEmacs processes the SelectionClear event.
|
|
1070 ;; The selection code attempts to keep track of the
|
|
1071 ;; time that it last asserted the selection, and
|
|
1072 ;; compare it to the time of the SelectionClear event,
|
|
1073 ;; to see if it's a bogus notification or not (as
|
|
1074 ;; is the case here). However, for some unknown
|
|
1075 ;; reason this doesn't work in the triple-clicking
|
|
1076 ;; case, and the selection code bogusly thinks this
|
|
1077 ;; SelectionClear event is the real thing.
|
|
1078 ;; -- putting the sit-for in causes the pending
|
|
1079 ;; SelectionClear events to get processed before
|
|
1080 ;; the selection is reasserted, so everything works
|
|
1081 ;; out OK.
|
|
1082 ;;
|
|
1083 ;; Presumably(?) this means there is a weird timing bug
|
|
1084 ;; in the selection code, but there's not a chance in hell
|
|
1085 ;; that I have the patience to track it down. Blame the
|
|
1086 ;; designers of X for fucking everything up so badly.
|
|
1087 ;;
|
|
1088 ;; This was originally a sit-for 0 but that wasn't
|
|
1089 ;; sufficient to make things work. Even this isn't
|
|
1090 ;; always sufficient but it seems to give something
|
|
1091 ;; approaching a 99% success rate. Making it higher yet
|
|
1092 ;; would help guarantee success with the price that the
|
|
1093 ;; delay would start to become noticeable.
|
|
1094 ;;
|
|
1095 (and (eq (console-type) 'x)
|
|
1096 (sit-for 0.15 t))
|
487
|
1097 ;; zmacs-activate-region -> zmacs-activate-region-hook ->
|
|
1098 ;; activate-region-as-selection -> either own-selection or
|
|
1099 ;; mouse-track-activate-rectangular-selection
|
428
|
1100 (zmacs-activate-region)))
|
|
1101 ((console-on-window-system-p)
|
487
|
1102 ;; #### do we need this? we don't do it when zmacs-regions = t
|
428
|
1103 (if (= start end)
|
|
1104 (disown-selection type)
|
487
|
1105 (activate-region-as-selection))))
|
428
|
1106 (if (and (eq 'x (console-type))
|
|
1107 (not (= start end)))
|
|
1108 ;; I guess cutbuffers should do something with rectangles too.
|
|
1109 ;; does anybody use them?
|
502
|
1110 (declare-fboundp (x-store-cutbuffer (buffer-substring start end))))))
|
428
|
1111
|
487
|
1112 (defun mouse-track-activate-rectangular-selection ()
|
|
1113 (if (consp default-mouse-track-extent)
|
|
1114 ;; own the rectangular region
|
|
1115 ;; this is a hack
|
|
1116 (let ((r default-mouse-track-extent))
|
|
1117 (save-excursion
|
|
1118 (set-buffer (get-buffer-create " *rect yank temp buf*"))
|
|
1119 (erase-buffer)
|
|
1120 (while r
|
|
1121 (insert (extent-string (car r)) "\n")
|
|
1122 (setq r (cdr r)))
|
|
1123 (own-selection (buffer-substring (point-min) (point-max)))))))
|
|
1124
|
428
|
1125 (defun default-mouse-track-deal-with-down-event (click-count)
|
|
1126 (let ((event default-mouse-track-down-event))
|
|
1127 (if (null event) nil
|
|
1128 (select-frame (event-frame event))
|
|
1129 (let ((adjust default-mouse-track-adjust)
|
|
1130 ;; ####When you click on the splash-screen,
|
|
1131 ;; event-{closest-,}point can be out of bounds. Should
|
|
1132 ;; event-closest-point really be allowed to return a bad
|
|
1133 ;; position like that? Maybe pixel_to_glyph_translation
|
|
1134 ;; needs to invalidate its cache when the buffer changes.
|
|
1135 ;; -dkindred@cs.cmu.edu
|
|
1136 (close-pos (save-excursion
|
|
1137 (set-buffer (event-buffer event))
|
|
1138 (let ((p (event-closest-point event)))
|
|
1139 (and p (min (max p (point-min)) (point-max))))))
|
|
1140 extent previous-point)
|
|
1141
|
|
1142 (if (not (event-window event))
|
|
1143 (error "not over window?"))
|
|
1144 (setq default-mouse-track-type
|
|
1145 (nth (mod (1- click-count)
|
|
1146 (length default-mouse-track-type-list))
|
|
1147 default-mouse-track-type-list))
|
|
1148 (setq default-mouse-track-window (event-window event))
|
|
1149 ;; Note that the extent used here is NOT the extent which
|
|
1150 ;; ends up as the value of zmacs-region-extent - this one is used
|
|
1151 ;; just during mouse-dragging.
|
|
1152 (setq default-mouse-track-extent
|
|
1153 (make-extent close-pos close-pos (event-buffer event)))
|
|
1154 (setq extent default-mouse-track-extent)
|
|
1155 (set-extent-face extent 'zmacs-region)
|
|
1156 ;; While the selection is being dragged out, give the selection extent
|
|
1157 ;; slightly higher priority than any mouse-highlighted extent, so that
|
|
1158 ;; the exact endpoints of the selection will be visible while the mouse
|
|
1159 ;; is down. Normally, the selection and mouse highlighting have the
|
|
1160 ;; same priority, so that conflicts between the two of them are
|
|
1161 ;; resolved by the usual size-and-endpoint-comparison method.
|
|
1162 (set-extent-priority extent (1+ mouse-highlight-priority))
|
|
1163 (if mouse-track-rectangle-p
|
|
1164 (setq default-mouse-track-extent
|
|
1165 (list default-mouse-track-extent)))
|
|
1166
|
|
1167 (setq previous-point
|
|
1168 (if (and adjust
|
|
1169 (markerp default-mouse-track-previous-point)
|
|
1170 (eq (current-buffer)
|
|
1171 (marker-buffer default-mouse-track-previous-point)))
|
|
1172 (marker-position default-mouse-track-previous-point)
|
|
1173 (point)))
|
|
1174 (default-mouse-track-set-point event default-mouse-track-window)
|
|
1175 (if (not adjust)
|
|
1176 (if (markerp default-mouse-track-previous-point)
|
|
1177 (set-marker default-mouse-track-previous-point (point))
|
|
1178 (setq default-mouse-track-previous-point (point-marker))))
|
|
1179 ;;
|
|
1180 ;; adjust point to a word or line boundary if appropriate
|
|
1181 (let ((anchor (default-mouse-track-anchor adjust previous-point)))
|
|
1182 (setq default-mouse-track-min-anchor
|
|
1183 (save-excursion (goto-char anchor)
|
|
1184 (funcall
|
|
1185 default-mouse-track-normalize-point-function
|
|
1186 default-mouse-track-type nil)
|
|
1187 (point)))
|
|
1188 (setq default-mouse-track-max-anchor
|
|
1189 (save-excursion (goto-char anchor)
|
|
1190 (funcall
|
|
1191 default-mouse-track-normalize-point-function
|
|
1192 default-mouse-track-type t)
|
|
1193 (point))))
|
|
1194 ;;
|
|
1195 ;; remove the existing selection to unclutter the display
|
|
1196 (if (not adjust)
|
|
1197 (cond (zmacs-regions
|
|
1198 (zmacs-deactivate-region))
|
|
1199 ((console-on-window-system-p)
|
|
1200 (disown-selection)))))
|
|
1201 (setq default-mouse-track-down-event nil))))
|
|
1202
|
442
|
1203 ;; return t if the button or motion event involved the specified button.
|
|
1204 (defun default-mouse-track-event-is-with-button (event n)
|
|
1205 (cond ((button-event-p event)
|
|
1206 (= n (event-button event)))
|
|
1207 ((motion-event-p event)
|
|
1208 (memq (cdr
|
|
1209 (assq n '((1 . button1) (2 . button2) (3 . button3)
|
|
1210 (4 . button4) (5 . button5))))
|
|
1211 (event-modifiers event)))))
|
|
1212
|
428
|
1213 (defun default-mouse-track-down-hook (event click-count)
|
442
|
1214 (cond ((default-mouse-track-event-is-with-button event 1)
|
|
1215 (if (and (memq 'button1-down mouse-track-activate-strokes)
|
|
1216 (mouse-track-do-activate event))
|
|
1217 t
|
|
1218 (setq default-mouse-track-down-event (copy-event event))
|
|
1219 nil))
|
|
1220 ((default-mouse-track-event-is-with-button event 2)
|
|
1221 (and (memq 'button2-down mouse-track-activate-strokes)
|
|
1222 (mouse-track-do-activate event)))))
|
428
|
1223
|
|
1224 (defun default-mouse-track-cleanup-extents-hook ()
|
|
1225 (remove-hook 'pre-command-hook 'default-mouse-track-cleanup-extents-hook)
|
|
1226 (let ((extent default-mouse-track-extent))
|
|
1227 (if (consp extent) ; rectangle-p
|
|
1228 (mapcar 'delete-extent extent)
|
|
1229 (if extent
|
|
1230 (delete-extent extent)))))
|
|
1231
|
|
1232 (defun default-mouse-track-cleanup-hook ()
|
|
1233 (if zmacs-regions
|
|
1234 (funcall 'default-mouse-track-cleanup-extents-hook)
|
|
1235 (let ((extent default-mouse-track-extent)
|
|
1236 (func #'(lambda (e)
|
|
1237 (and (extent-live-p e)
|
|
1238 (set-extent-face e 'primary-selection)))))
|
|
1239 (add-hook 'pre-command-hook 'default-mouse-track-cleanup-extents-hook)
|
|
1240 (if (consp extent) ; rectangle-p
|
|
1241 (mapcar func extent)
|
|
1242 (if extent
|
442
|
1243 (funcall func extent)))))
|
|
1244 t)
|
428
|
1245
|
|
1246 (defun default-mouse-track-cleanup-extent ()
|
|
1247 (let ((dead-func
|
|
1248 (function (lambda (x)
|
|
1249 (or (not (extent-live-p x))
|
|
1250 (extent-detached-p x)))))
|
|
1251 (extent default-mouse-track-extent))
|
|
1252 (if (consp extent)
|
|
1253 (if (funcall dead-func extent)
|
|
1254 (let (newval)
|
|
1255 (mapcar (function (lambda (x)
|
|
1256 (if (not (funcall dead-func x))
|
|
1257 (setq newval (cons x newval)))))
|
|
1258 extent)
|
|
1259 (setq default-mouse-track-extent (nreverse newval))))
|
|
1260 (if (funcall dead-func extent)
|
|
1261 (setq default-mouse-track-extent nil)))))
|
|
1262
|
|
1263 (defun default-mouse-track-drag-hook (event click-count was-timeout)
|
442
|
1264 (cond ((default-mouse-track-event-is-with-button event 1)
|
|
1265 (default-mouse-track-deal-with-down-event click-count)
|
|
1266 (default-mouse-track-set-point event default-mouse-track-window)
|
|
1267 (default-mouse-track-cleanup-extent)
|
|
1268 (default-mouse-track-next-move default-mouse-track-min-anchor
|
|
1269 default-mouse-track-max-anchor
|
|
1270 default-mouse-track-extent)
|
|
1271 t)
|
|
1272 ((default-mouse-track-event-is-with-button event 2)
|
|
1273 (mouse-begin-drag-n-drop event))))
|
428
|
1274
|
|
1275 (defun default-mouse-track-return-dragged-selection (event)
|
|
1276 (default-mouse-track-cleanup-extent)
|
|
1277 (let ((extent default-mouse-track-extent)
|
|
1278 result)
|
|
1279 (default-mouse-track-set-point-in-window event default-mouse-track-window)
|
|
1280 (default-mouse-track-next-move default-mouse-track-min-anchor
|
|
1281 default-mouse-track-max-anchor
|
|
1282 extent)
|
|
1283 (cond ((consp extent) ; rectangle-p
|
|
1284 (let ((first (car extent))
|
|
1285 (last (car (setq extent (nreverse extent)))))
|
|
1286 ;; nreverse is destructive so we need to reset this
|
|
1287 (setq default-mouse-track-extent extent)
|
|
1288 (setq result (cons (extent-start-position first)
|
|
1289 (extent-end-position last)))
|
|
1290 ;; kludge to fix up region when dragging backwards...
|
|
1291 (if (and (/= (point) (extent-start-position first))
|
|
1292 (/= (point) (extent-end-position last))
|
|
1293 (= (point) (extent-end-position first)))
|
|
1294 (goto-char (car result)))))
|
|
1295 (extent
|
|
1296 (setq result (cons (extent-start-position extent)
|
|
1297 (extent-end-position extent)))))
|
793
|
1298 ;; Minor kludge: if we're selecting in line-mode, include the final
|
|
1299 ;; newline. It's hard to do this in *-normalize-point. Unfortunately
|
|
1300 ;; this necessitates a counter-kludge in
|
|
1301 ;; default-mouse-track-normalize-point.
|
428
|
1302 (if (and result (eq default-mouse-track-type 'line))
|
|
1303 (let ((end-p (= (point) (cdr result))))
|
|
1304 (goto-char (cdr result))
|
793
|
1305 (if (and (eolp) (not (eobp)))
|
428
|
1306 (setcdr result (1+ (cdr result))))
|
|
1307 (goto-char (if end-p (cdr result) (car result)))))
|
|
1308 ;;; ;; Minor kludge sub 2. If in char mode, and we drag the
|
|
1309 ;;; ;; mouse past EOL, include the newline.
|
|
1310 ;;; ;;
|
|
1311 ;;; ;; Major problem: can't easily distinguish between being
|
|
1312 ;;; ;; just past the last char on a line, and well past it,
|
|
1313 ;;; ;; to determine whether or not to include it in the region
|
|
1314 ;;; ;;
|
|
1315 ;;; (if nil ; (eq default-mouse-track-type 'char)
|
|
1316 ;;; (let ((after-end-p (and (not (eobp))
|
|
1317 ;;; (eolp)
|
|
1318 ;;; (> (point) (car result)))))
|
|
1319 ;;; (if after-end-p
|
|
1320 ;;; (progn
|
|
1321 ;;; (setcdr result (1+ (cdr result)))
|
|
1322 ;;; (goto-char (cdr result))))))
|
|
1323 result))
|
|
1324
|
|
1325 (defun default-mouse-track-drag-up-hook (event click-count)
|
442
|
1326 (when (default-mouse-track-event-is-with-button event 1)
|
|
1327 (let ((result (default-mouse-track-return-dragged-selection event)))
|
|
1328 (if result
|
|
1329 (default-mouse-track-maybe-own-selection result 'PRIMARY)))
|
|
1330 t))
|
428
|
1331
|
|
1332 (defun default-mouse-track-click-hook (event click-count)
|
442
|
1333 (cond ((default-mouse-track-event-is-with-button event 1)
|
|
1334 (if (and
|
|
1335 (or (and (= click-count 1)
|
|
1336 (memq 'button1-click
|
|
1337 mouse-track-activate-strokes))
|
|
1338 (and (= click-count 2)
|
|
1339 (memq 'button1-double-click
|
|
1340 mouse-track-activate-strokes))
|
|
1341 (and (= click-count 3)
|
|
1342 (memq 'button1-triple-click
|
|
1343 mouse-track-activate-strokes)))
|
|
1344 (mouse-track-do-activate event))
|
|
1345 t
|
|
1346 (default-mouse-track-drag-hook event click-count nil)
|
|
1347 (default-mouse-track-drag-up-hook event click-count)
|
|
1348 t))
|
|
1349 ((default-mouse-track-event-is-with-button event 2)
|
|
1350 (if (and
|
|
1351 (or (and (= click-count 1)
|
|
1352 (memq 'button2-click
|
|
1353 mouse-track-activate-strokes))
|
|
1354 (and (= click-count 2)
|
|
1355 (memq 'button2-double-click
|
|
1356 mouse-track-activate-strokes))
|
|
1357 (and (= click-count 3)
|
|
1358 (memq 'button2-triple-click
|
|
1359 mouse-track-activate-strokes)))
|
|
1360 (mouse-track-do-activate event))
|
|
1361 t
|
|
1362 (mouse-yank event)
|
|
1363 t))))
|
|
1364
|
428
|
1365
|
|
1366 (add-hook 'mouse-track-down-hook 'default-mouse-track-down-hook)
|
|
1367 (add-hook 'mouse-track-drag-hook 'default-mouse-track-drag-hook)
|
|
1368 (add-hook 'mouse-track-drag-up-hook 'default-mouse-track-drag-up-hook)
|
|
1369 (add-hook 'mouse-track-click-hook 'default-mouse-track-click-hook)
|
|
1370 (add-hook 'mouse-track-cleanup-hook 'default-mouse-track-cleanup-hook)
|
|
1371
|
|
1372
|
|
1373 ;;;;;;;;;;;; other mouse-track stuff (mostly associated with the
|
|
1374 ;;;;;;;;;;;; default handlers)
|
|
1375
|
|
1376 (defun mouse-track-default (event)
|
|
1377 "Invoke `mouse-track' with only the default handlers active."
|
|
1378 (interactive "e")
|
546
|
1379 (mouse-track event
|
|
1380 '(mouse-track-down-hook
|
|
1381 default-mouse-track-down-hook
|
|
1382 mouse-track-up-hook nil
|
|
1383 mouse-track-drag-hook default-mouse-track-drag-hook
|
|
1384 mouse-track-drag-up-hook default-mouse-track-drag-up-hook
|
|
1385 mouse-track-click-hook default-mouse-track-click-hook
|
|
1386 mouse-track-cleanup-hook default-mouse-track-cleanup-hook)))
|
428
|
1387
|
|
1388 (defun mouse-track-do-rectangle (event)
|
|
1389 "Like `mouse-track' but selects rectangles instead of regions."
|
|
1390 (interactive "e")
|
|
1391 (let ((mouse-track-rectangle-p t))
|
|
1392 (mouse-track event)))
|
|
1393
|
793
|
1394 (defun mouse-track-by-lines (event)
|
|
1395 "Make a line-by-line selection with the mouse.
|
|
1396 This actually works the same as `mouse-track' (which handles all
|
|
1397 mouse-button behavior) but forces whole lines to be selected."
|
|
1398 (interactive "e")
|
|
1399 (let ((default-mouse-track-type-list '(line)))
|
|
1400 (mouse-track event)))
|
|
1401
|
428
|
1402 (defun mouse-track-adjust (event)
|
|
1403 "Extend the existing selection. This should be bound to a mouse button.
|
|
1404 The selection will be enlarged or shrunk so that the point of the mouse
|
|
1405 click is one of its endpoints. This function in fact behaves fairly
|
|
1406 similarly to `mouse-track', but begins by extending the existing selection
|
|
1407 (or creating a new selection from the previous text cursor position to
|
|
1408 the current mouse position) instead of creating a new, empty selection.
|
|
1409
|
|
1410 The mouse-track handlers are run from this command just like from
|
|
1411 `mouse-track'. Therefore, do not call this command from a mouse-track
|
|
1412 handler!"
|
|
1413 (interactive "e")
|
|
1414 (let ((default-mouse-track-adjust t))
|
|
1415 (mouse-track event)))
|
|
1416
|
|
1417 (defun mouse-track-adjust-default (event)
|
|
1418 "Extend the existing selection, using only the default handlers.
|
|
1419 This is just like `mouse-track-adjust' but will override any
|
|
1420 custom mouse-track handlers that the user may have installed."
|
|
1421 (interactive "e")
|
|
1422 (let ((default-mouse-track-adjust t))
|
|
1423 (mouse-track-default event)))
|
|
1424
|
793
|
1425 (defun mouse-track-adjust-by-lines (event)
|
|
1426 "Extend the existing selection by lines.
|
|
1427 This works the same as `mouse-track-adjust' (bound to \\[mouse-track-adjust])
|
|
1428 but forces whole lines to be selected."
|
|
1429 (interactive "e")
|
|
1430 (let ((default-mouse-track-type-list '(line))
|
|
1431 (default-mouse-track-adjust t))
|
|
1432 (mouse-track event)))
|
|
1433
|
|
1434 (defun mouse-track-insert-1 (event &optional delete line-p)
|
|
1435 "Guts of mouse-track-insert and friends.
|
|
1436 If DELETE, delete the selection as well as inserting it at the new place.
|
|
1437 If LINE-P, select by lines and insert before current line."
|
428
|
1438 (interactive "*e")
|
793
|
1439 (let ((default-mouse-track-type-list
|
|
1440 (if line-p '(line) default-mouse-track-type-list))
|
|
1441 s selreg)
|
546
|
1442 (flet ((Mouse-track-insert-drag-up-hook (event count)
|
|
1443 (setq selreg
|
|
1444 (default-mouse-track-return-dragged-selection event))
|
|
1445 t)
|
|
1446 (Mouse-track-insert-click-hook (event count)
|
|
1447 (default-mouse-track-drag-hook event count nil)
|
|
1448 (setq selreg
|
|
1449 (default-mouse-track-return-dragged-selection event))
|
|
1450 t))
|
|
1451 (save-excursion
|
|
1452 (save-window-excursion
|
|
1453 (mouse-track
|
|
1454 event
|
|
1455 '(mouse-track-drag-up-hook
|
|
1456 Mouse-track-insert-drag-up-hook
|
|
1457 mouse-track-click-hook
|
|
1458 Mouse-track-insert-click-hook))
|
|
1459 (if (consp selreg)
|
|
1460 (let ((pair selreg))
|
|
1461 (setq s (prog1
|
|
1462 (buffer-substring (car pair) (cdr pair))
|
|
1463 (if delete
|
|
1464 (kill-region (car pair) (cdr pair))))))))))
|
793
|
1465 (or (null s) (equal s "")
|
|
1466 (progn
|
|
1467 (if line-p (beginning-of-line))
|
|
1468 (insert s)))))
|
|
1469
|
|
1470 (defun mouse-track-insert (event)
|
|
1471 "Make a selection with the mouse and insert it at point.
|
|
1472 This works the same as just selecting text using the mouse (the
|
|
1473 `mouse-track' command), except that point is not moved; the selected text
|
|
1474 is immediately inserted after being selected\; and the selection is
|
|
1475 immediately disowned afterwards."
|
|
1476 (interactive "*e")
|
|
1477 (mouse-track-insert-1 event))
|
428
|
1478
|
|
1479 (defun mouse-track-delete-and-insert (event)
|
793
|
1480 "Make a selection with the mouse and move it to point.
|
|
1481 This works the same as just selecting text using the mouse (the
|
|
1482 `mouse-track' command), except that point is not moved; the selected text
|
|
1483 is immediately inserted after being selected\; and the text of the
|
|
1484 selection is deleted."
|
428
|
1485 (interactive "*e")
|
793
|
1486 (mouse-track-insert-1 event t))
|
|
1487
|
|
1488 (defun mouse-track-insert-by-lines (event)
|
|
1489 "Make a line-oriented selection with the mouse and insert it at line start.
|
|
1490 This is similar to `mouse-track-insert' except that it always selects
|
|
1491 entire lines and inserts the lines before the current line rather than at
|
|
1492 point."
|
|
1493 (interactive "*e")
|
|
1494 (mouse-track-insert-1 event nil t))
|
|
1495
|
|
1496 (defun mouse-track-delete-and-insert-by-lines (event)
|
|
1497 "Make a line-oriented selection with the mouse and move it to line start.
|
|
1498 This is similar to `mouse-track-insert' except that it always selects
|
|
1499 entire lines and inserts the lines before the current line rather than at
|
|
1500 point."
|
|
1501 (interactive "*e")
|
|
1502 (mouse-track-insert-1 event nil t))
|
428
|
1503
|
|
1504 ;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1505
|
|
1506
|
|
1507 (defvar inhibit-help-echo nil
|
|
1508 "Inhibits display of `help-echo' extent properties in the minibuffer.")
|
|
1509 (defvar last-help-echo-object nil)
|
|
1510 (defvar help-echo-owns-message nil)
|
|
1511
|
|
1512 (defun clear-help-echo (&optional ignored-frame)
|
|
1513 (if help-echo-owns-message
|
|
1514 (progn
|
|
1515 (setq help-echo-owns-message nil
|
|
1516 last-help-echo-object nil)
|
|
1517 (clear-message 'help-echo))))
|
|
1518
|
|
1519 (defun show-help-echo (mess)
|
|
1520 ;; (clear-help-echo)
|
|
1521 (setq help-echo-owns-message t)
|
|
1522 (display-message 'help-echo mess))
|
|
1523
|
|
1524 (add-hook 'mouse-leave-frame-hook 'clear-help-echo)
|
|
1525
|
|
1526 ;; It may be a good idea to move this to C, for better performance of
|
|
1527 ;; extent highlighting and pointer changes.
|
|
1528 (defun default-mouse-motion-handler (event)
|
|
1529 "For use as the value of `mouse-motion-handler'.
|
|
1530 This implements the various pointer-shape variables,
|
|
1531 as well as extent highlighting, help-echo, toolbar up/down,
|
|
1532 and `mode-motion-hook'."
|
|
1533 (let* ((frame (or (event-frame event) (selected-frame)))
|
|
1534 (window (event-window event))
|
|
1535 (buffer (event-buffer event))
|
|
1536 (modeline-point (and buffer (event-modeline-position event)))
|
|
1537 (modeline-string (and modeline-point
|
|
1538 (symbol-value-in-buffer
|
|
1539 'generated-modeline-string buffer)))
|
|
1540 ;; point must be invalidated by modeline-point.
|
|
1541 (point (and buffer (not modeline-point)
|
|
1542 (event-point event)))
|
|
1543 (extent (or (and point
|
|
1544 (extent-at point buffer 'mouse-face))
|
|
1545 (and modeline-point
|
|
1546 (extent-at modeline-point modeline-string
|
|
1547 ;; Modeline extents don't have a
|
|
1548 ;; mouse-face property set.
|
|
1549 'help-echo))))
|
|
1550 (glyph-extent1 (event-glyph-extent event))
|
|
1551 (glyph-extent (and glyph-extent1
|
|
1552 (extent-live-p glyph-extent1)
|
|
1553 glyph-extent1))
|
|
1554 ;; This is an extent:
|
|
1555 (user-pointer1 (or (and glyph-extent
|
|
1556 (extent-property glyph-extent 'pointer)
|
|
1557 glyph-extent)
|
|
1558 (and point (extent-at point buffer 'pointer))
|
|
1559 (and modeline-point
|
|
1560 (extent-at modeline-point modeline-string
|
|
1561 'pointer))))
|
|
1562 ;; And this should be a glyph:
|
|
1563 (user-pointer (and user-pointer1 (extent-live-p user-pointer1)
|
|
1564 (extent-property user-pointer1 'pointer)))
|
|
1565 (button (event-toolbar-button event))
|
|
1566 (help (or (and glyph-extent (extent-property glyph-extent 'help-echo)
|
|
1567 glyph-extent)
|
|
1568 (and button (not (null (toolbar-button-help-string button)))
|
|
1569 button)
|
|
1570 (and point
|
|
1571 (extent-at point buffer 'help-echo))
|
|
1572 (and modeline-point
|
|
1573 (extent-at modeline-point modeline-string
|
|
1574 'help-echo))))
|
|
1575 ;; vars is a list of glyph variables to check for a pointer
|
|
1576 ;; value.
|
|
1577 (vars (cond
|
440
|
1578 ;; Checking if button is non-nil is not sufficient
|
428
|
1579 ;; since the pointer could be over a blank portion
|
|
1580 ;; of the toolbar.
|
|
1581 ((event-over-toolbar-p event)
|
|
1582 '(toolbar-pointer-glyph nontext-pointer-glyph
|
|
1583 text-pointer-glyph))
|
|
1584 ((or extent glyph-extent)
|
|
1585 '(selection-pointer-glyph text-pointer-glyph))
|
|
1586 ((event-over-modeline-p event)
|
|
1587 '(modeline-pointer-glyph nontext-pointer-glyph
|
|
1588 text-pointer-glyph))
|
|
1589 ((and (event-over-vertical-divider-p event)
|
|
1590 ;; #### I disagree with the check below.
|
|
1591 ;; Discuss it with Kirill for 21.1. --hniksic
|
|
1592 (specifier-instance vertical-divider-always-visible-p
|
|
1593 (event-window event)))
|
|
1594 '(divider-pointer-glyph nontext-pointer-glyph
|
|
1595 text-pointer-glyph))
|
|
1596 (point '(text-pointer-glyph))
|
|
1597 (buffer '(nontext-pointer-glyph text-pointer-glyph))
|
|
1598 (t '(nontext-pointer-glyph text-pointer-glyph))))
|
|
1599 pointer)
|
|
1600 (and user-pointer (glyphp user-pointer)
|
|
1601 (push 'user-pointer vars))
|
|
1602 (while (and vars (not (pointer-image-instance-p pointer)))
|
|
1603 (setq pointer (glyph-image-instance (symbol-value (car vars))
|
|
1604 (or window frame))
|
|
1605 vars (cdr vars)))
|
|
1606
|
|
1607 (if (pointer-image-instance-p pointer)
|
|
1608 (set-frame-pointer frame pointer))
|
|
1609
|
|
1610 ;; If last-pressed-toolbar-button is not nil, then check and see
|
|
1611 ;; if we have moved to a new button and adjust the down flags
|
|
1612 ;; accordingly.
|
|
1613 (when (and (featurep 'toolbar) toolbar-active)
|
|
1614 (unless (eq last-pressed-toolbar-button button)
|
|
1615 (release-previous-toolbar-button event)
|
|
1616 (and button (press-toolbar-button event))))
|
|
1617
|
|
1618 (cond (extent (highlight-extent extent t))
|
|
1619 (glyph-extent (highlight-extent glyph-extent t))
|
|
1620 (t (highlight-extent nil nil)))
|
|
1621 (cond ((extentp help)
|
|
1622 (or inhibit-help-echo
|
|
1623 (eq help last-help-echo-object) ;save some time
|
|
1624 (eq (selected-window) (minibuffer-window))
|
|
1625 (let ((hprop (extent-property help 'help-echo)))
|
|
1626 (setq last-help-echo-object help)
|
|
1627 (or (stringp hprop)
|
|
1628 (setq hprop (funcall hprop help)))
|
|
1629 (and hprop (show-help-echo hprop)))))
|
|
1630 ((and (featurep 'toolbar)
|
|
1631 (toolbar-button-p help)
|
|
1632 (toolbar-button-enabled-p help))
|
|
1633 (or (not toolbar-help-enabled)
|
|
1634 (eq help last-help-echo-object) ;save some time
|
|
1635 (eq (selected-window) (minibuffer-window))
|
|
1636 (let ((hstring (toolbar-button-help-string button)))
|
|
1637 (setq last-help-echo-object help)
|
|
1638 (or (stringp hstring)
|
|
1639 (setq hstring (funcall hstring help)))
|
|
1640 (and hstring (show-help-echo hstring)))))
|
|
1641 (last-help-echo-object
|
|
1642 (clear-help-echo)))
|
|
1643 (if mouse-grabbed-buffer (setq buffer mouse-grabbed-buffer))
|
|
1644 (if (and buffer (symbol-value-in-buffer 'mode-motion-hook buffer nil))
|
|
1645 (with-current-buffer buffer
|
|
1646 (run-hook-with-args 'mode-motion-hook event)
|
|
1647
|
|
1648 ;; If the mode-motion-hook created a highlightable extent around
|
|
1649 ;; the mouse-point, highlight it right away. Otherwise it wouldn't
|
|
1650 ;; be highlighted until the *next* motion event came in.
|
|
1651 (if (and point
|
|
1652 (null extent)
|
|
1653 (setq extent (extent-at point
|
|
1654 (event-buffer event) ; not buffer
|
|
1655 'mouse-face)))
|
|
1656 (highlight-extent extent t)))))
|
|
1657 nil)
|
|
1658
|
|
1659 (setq mouse-motion-handler 'default-mouse-motion-handler)
|
|
1660
|
|
1661 ;;
|
|
1662 ;; Vertical divider dragging
|
|
1663 ;;
|
|
1664 (defun drag-window-divider (event)
|
|
1665 "Handle resizing windows by dragging window dividers.
|
442
|
1666 This is an internal function, normally bound to button1 event in
|
428
|
1667 window-divider-map. You would not call it, but you may bind it to
|
|
1668 other mouse buttons."
|
|
1669 (interactive "e")
|
|
1670 ;; #### I disagree with the check below.
|
|
1671 ;; Discuss it with Kirill for 21.1. --hniksic
|
|
1672 (if (not (specifier-instance vertical-divider-always-visible-p
|
|
1673 (event-window event)))
|
|
1674 (error "Not over a window"))
|
|
1675 (let-specifier ((vertical-divider-shadow-thickness
|
|
1676 (- (specifier-instance vertical-divider-shadow-thickness
|
|
1677 (event-window event)))
|
|
1678 (event-window event)))
|
|
1679 (let* ((window (event-window event))
|
|
1680 (frame (event-channel event))
|
|
1681 (last-timestamp (event-timestamp event))
|
|
1682 done)
|
|
1683 (while (not done)
|
|
1684 (let* ((edges (window-pixel-edges window))
|
|
1685 (old-right (caddr edges))
|
|
1686 (old-left (car edges))
|
|
1687 (backup-conf (current-window-configuration frame))
|
|
1688 (old-edges-all-windows (mapcar 'window-pixel-edges
|
|
1689 (window-list))))
|
|
1690
|
|
1691 ;; This is borrowed from modeline.el:
|
|
1692 ;; requeue event and quit if this is a misc-user, eval or
|
|
1693 ;; keypress event.
|
|
1694 ;; quit if this is a button press or release event, or if the event
|
|
1695 ;; occurred in some other frame.
|
|
1696 ;; drag if this is a mouse motion event and the time
|
|
1697 ;; between this event and the last event is greater than
|
|
1698 ;; drag-divider-event-lag.
|
|
1699 ;; do nothing if this is any other kind of event.
|
|
1700 (setq event (next-event event))
|
|
1701 (cond ((or (misc-user-event-p event)
|
|
1702 (key-press-event-p event))
|
|
1703 (setq unread-command-events (nconc unread-command-events
|
|
1704 (list event))
|
|
1705 done t))
|
|
1706 ((button-release-event-p event)
|
|
1707 (setq done t))
|
|
1708 ((button-event-p event)
|
|
1709 (setq done t))
|
|
1710 ((not (motion-event-p event))
|
|
1711 (dispatch-event event))
|
|
1712 ((not (eq frame (event-frame event)))
|
|
1713 (setq done t))
|
|
1714 ((< (abs (- (event-timestamp event) last-timestamp))
|
|
1715 drag-divider-event-lag))
|
|
1716 (t
|
|
1717 (setq last-timestamp (event-timestamp event))
|
|
1718 ;; Enlarge the window, calculating change in characters
|
|
1719 ;; of default font. Do not let the window to become
|
440
|
1720 ;; less than allowed minimum (not because that's critical
|
428
|
1721 ;; for the code performance, just the visual effect is
|
|
1722 ;; better: when cursor goes to the left of the next left
|
440
|
1723 ;; divider, the window being resized shrinks to minimal
|
428
|
1724 ;; size.
|
|
1725 (enlarge-window (max (- window-min-width (window-width window))
|
|
1726 (/ (- (event-x-pixel event) old-right)
|
|
1727 (face-width 'default window)))
|
|
1728 t window)
|
|
1729 ;; Backout the change if some windows got deleted, or
|
|
1730 ;; if the change caused more than two windows to resize
|
|
1731 ;; (shifting the whole stack right is ugly), or if the
|
|
1732 ;; left window side has slipped (right side cannot be
|
440
|
1733 ;; moved any further to the right, so enlarge-window
|
428
|
1734 ;; plays bad games with the left edge.
|
|
1735 (if (or (/= (count-windows) (length old-edges-all-windows))
|
|
1736 (/= old-left (car (window-pixel-edges window)))
|
|
1737 ;; This check is very hairy. We allow any number
|
|
1738 ;; of left edges to change, but only to the same
|
|
1739 ;; new value. Similar procedure is for the right edges.
|
|
1740 (let ((all-that-bad nil)
|
|
1741 (new-left-ok nil)
|
|
1742 (new-right-ok nil))
|
|
1743 (mapcar* (lambda (window old-edges)
|
|
1744 (let ((new (car (window-pixel-edges window))))
|
|
1745 (if (/= new (car old-edges))
|
|
1746 (if (and new-left-ok
|
|
1747 (/= new-left-ok new))
|
|
1748 (setq all-that-bad t)
|
|
1749 (setq new-left-ok new)))))
|
|
1750 (window-list) old-edges-all-windows)
|
|
1751 (mapcar* (lambda (window old-edges)
|
|
1752 (let ((new (caddr (window-pixel-edges window))))
|
|
1753 (if (/= new (caddr old-edges))
|
|
1754 (if (and new-right-ok
|
|
1755 (/= new-right-ok new))
|
|
1756 (setq all-that-bad t)
|
|
1757 (setq new-right-ok new)))))
|
|
1758 (window-list) old-edges-all-windows)
|
|
1759 all-that-bad))
|
|
1760 (set-window-configuration backup-conf)))))))))
|
|
1761
|
|
1762 (setq vertical-divider-map (make-keymap))
|
|
1763 (define-key vertical-divider-map 'button1 'drag-window-divider)
|
|
1764
|
|
1765 ;;; mouse.el ends here
|