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