(put-image): Remove optional buffer parameter.
[bpt/emacs.git] / lisp / mouse.el
CommitLineData
be010748 1;;; mouse.el --- window system-independent mouse support
84176303 2
2f9e343b 3;; Copyright (C) 1993, 1994, 1995, 1999 Free Software Foundation, Inc.
eea8d4ef 4
84176303 5;; Maintainer: FSF
84176303
ER
6;; Keywords: hardware
7
be010748 8;; This file is part of GNU Emacs.
72ea54a4 9
be010748
RS
10;; GNU Emacs is free software; you can redistribute it and/or modify
11;; it 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.
72ea54a4 14
be010748
RS
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
72ea54a4 19
be010748 20;; You should have received a copy of the GNU General Public License
4c9afcbe
RS
21;; along with GNU Emacs; see the file COPYING. If not, write to the
22;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23;; Boston, MA 02111-1307, USA.
72ea54a4 24
edbd2f74
ER
25;;; Commentary:
26
27;; This package provides various useful commands (including help
28;; system access) through the mouse. All this code assumes that mouse
29;; interpretation has been abstracted into Emacs input events.
30;;
31;; The code is rather X-dependent.
32
aae56ea7
ER
33;;; Code:
34
cc0a8174 35;;; Utility functions.
72ea54a4 36
cc0a8174
JB
37;;; Indent track-mouse like progn.
38(put 'track-mouse 'lisp-indent-function 0)
72ea54a4 39
3b558d41
RS
40(defcustom mouse-yank-at-point nil
41 "*If non-nil, mouse yank commands yank at point instead of at click."
42 :type 'boolean
43 :group 'mouse)
cc0a8174 44\f
95132d1c
RS
45;; Provide a mode-specific menu on a mouse button.
46
6a16c4cb 47(defun mouse-major-mode-menu (event prefix)
b98e5762
DL
48 "Pop up a mode-specific menu of mouse commands.
49Default to the Edit menu if the major mode doesn't define a menu."
95132d1c
RS
50 ;; Switch to the window clicked on, because otherwise
51 ;; the mode's commands may not make sense.
6a16c4cb 52 (interactive "@e\nP")
25f9b4bf
RS
53 ;; Let the mode update its menus first.
54 (run-hooks 'activate-menubar-hook)
b98e5762
DL
55 (let* (;; This is where mouse-major-mode-menu-prefix
56 ;; returns the prefix we should use (after menu-bar).
57 ;; It is either nil or (SOME-SYMBOL).
58 (mouse-major-mode-menu-prefix nil)
59 ;; Keymap from which to inherit; may be null.
60 (ancestor (mouse-major-mode-menu-1
61 (and (current-local-map)
62 (lookup-key (current-local-map) [menu-bar]))))
63 ;; Make a keymap in which our last command leads to a menu or
64 ;; default to the edit menu.
65 (newmap (if ancestor
66 (make-sparse-keymap (concat mode-name " Mode"))
67 menu-bar-edit-menu))
68 result)
69 (if ancestor
70 ;; Make our menu inherit from the desired keymap which we want
71 ;; to display as the menu now.
72 (set-keymap-parent newmap ancestor))
d5c847bb
KH
73 (setq result (x-popup-menu t (list newmap)))
74 (if result
75 (let ((command (key-binding
76 (apply 'vector (append '(menu-bar)
77 mouse-major-mode-menu-prefix
78 result)))))
6a16c4cb
RS
79 ;; Clear out echoing, which perhaps shows a prefix arg.
80 (message "")
d5c847bb 81 (if command
6a16c4cb
RS
82 (progn
83 (setq prefix-arg prefix)
84 (command-execute command)))))))
95132d1c
RS
85
86;; Compute and cache the equivalent keys in MENU and all its submenus.
d5c847bb
KH
87;;;(defun mouse-major-mode-menu-compute-equiv-keys (menu)
88;;; (and (eq (car menu) 'keymap)
89;;; (x-popup-menu nil menu))
90;;; (while menu
91;;; (and (consp (car menu))
92;;; (consp (cdr (car menu)))
93;;; (let ((tail (cdr (car menu))))
94;;; (while (and (consp tail)
95;;; (not (eq (car tail) 'keymap)))
96;;; (setq tail (cdr tail)))
97;;; (if (consp tail)
98;;; (mouse-major-mode-menu-compute-equiv-keys tail))))
99;;; (setq menu (cdr menu))))
95132d1c
RS
100
101;; Given a mode's menu bar keymap,
102;; if it defines exactly one menu bar menu,
103;; return just that menu.
104;; Otherwise return a menu for all of them.
105(defun mouse-major-mode-menu-1 (menubar)
106 (if menubar
107 (let ((tail menubar)
108 submap)
109 (while tail
110 (if (consp (car tail))
111 (if submap
112 (setq submap t)
d5c847bb 113 (setq submap (car tail))))
95132d1c 114 (setq tail (cdr tail)))
d5c847bb 115 (if (eq submap t)
d3e458b0 116 menubar
d5c847bb
KH
117 (setq mouse-major-mode-menu-prefix (list (car submap)))
118 (cdr (cdr submap))))))
95132d1c 119\f
544e7e73
RS
120;; Commands that operate on windows.
121
d65147f6
KH
122(defun mouse-minibuffer-check (event)
123 (let ((w (posn-window (event-start event))))
124 (and (window-minibuffer-p w)
125 (not (minibuffer-window-active-p w))
33c448cd
RS
126 (error "Minibuffer window is not active")))
127 ;; Give temporary modes such as isearch a chance to turn off.
128 (run-hooks 'mouse-leave-buffer-hook))
d65147f6 129
cc0a8174 130(defun mouse-delete-window (click)
947da0c4 131 "Delete the window you click on.
a926a0fa
RS
132If the frame has just one window, bury the current buffer instead.
133This command must be bound to a mouse click."
ec558adc 134 (interactive "e")
a926a0fa
RS
135 (if (one-window-p t)
136 (bury-buffer)
137 (mouse-minibuffer-check click)
138 (delete-window (posn-window (event-start click)))))
cc0a8174 139
3c2dd2c0
RS
140(defun mouse-select-window (click)
141 "Select the window clicked on; don't move point."
142 (interactive "e")
d65147f6 143 (mouse-minibuffer-check click)
3c2dd2c0
RS
144 (let ((oframe (selected-frame))
145 (frame (window-frame (posn-window (event-start click)))))
146 (select-window (posn-window (event-start click)))
147 (raise-frame frame)
148 (select-frame frame)
149 (or (eq frame oframe)
e1877477 150 (set-mouse-position (selected-frame) (1- (frame-width)) 0))))
3c2dd2c0 151
b0f3a26b
JB
152(defun mouse-tear-off-window (click)
153 "Delete the window clicked on, and create a new frame displaying its buffer."
154 (interactive "e")
d65147f6 155 (mouse-minibuffer-check click)
b0f3a26b
JB
156 (let* ((window (posn-window (event-start click)))
157 (buf (window-buffer window))
01a911e3 158 (frame (make-frame)))
b0f3a26b
JB
159 (select-frame frame)
160 (switch-to-buffer buf)
161 (delete-window window)))
162
b5370f03 163(defun mouse-delete-other-windows ()
947da0c4 164 "Delete all window except the one you click on."
b5370f03 165 (interactive "@")
cc0a8174 166 (delete-other-windows))
72ea54a4 167
cc0a8174
JB
168(defun mouse-split-window-vertically (click)
169 "Select Emacs window mouse is on, then split it vertically in half.
170The window is split at the line clicked on.
171This command must be bound to a mouse click."
947da0c4 172 (interactive "@e")
d65147f6 173 (mouse-minibuffer-check click)
b5370f03
JB
174 (let ((start (event-start click)))
175 (select-window (posn-window start))
85d6b80b 176 (let ((new-height (1+ (cdr (posn-col-row (event-end click)))))
5ba2dc3f
JB
177 (first-line window-min-height)
178 (last-line (- (window-height) window-min-height)))
179 (if (< last-line first-line)
0a50b993 180 (error "Window too short to split")
5ba2dc3f
JB
181 (split-window-vertically
182 (min (max new-height first-line) last-line))))))
cc0a8174 183
947da0c4
RS
184(defun mouse-split-window-horizontally (click)
185 "Select Emacs window mouse is on, then split it horizontally in half.
186The window is split at the column clicked on.
187This command must be bound to a mouse click."
188 (interactive "@e")
d65147f6 189 (mouse-minibuffer-check click)
5ba2dc3f
JB
190 (let ((start (event-start click)))
191 (select-window (posn-window start))
192 (let ((new-width (1+ (car (posn-col-row (event-end click)))))
193 (first-col window-min-width)
194 (last-col (- (window-width) window-min-width)))
195 (if (< last-col first-col)
0a50b993 196 (error "Window too narrow to split")
5ba2dc3f
JB
197 (split-window-horizontally
198 (min (max new-width first-col) last-col))))))
947da0c4 199
544e7e73
RS
200(defun mouse-drag-mode-line (start-event)
201 "Change the height of a window by dragging on the mode line."
202 (interactive "e")
33c448cd
RS
203 ;; Give temporary modes such as isearch a chance to turn off.
204 (run-hooks 'mouse-leave-buffer-hook)
544e7e73
RS
205 (let ((done nil)
206 (echo-keystrokes 0)
207 (start-event-frame (window-frame (car (car (cdr start-event)))))
208 (start-event-window (car (car (cdr start-event))))
209 (start-nwindows (count-windows t))
210 (old-selected-window (selected-window))
211 should-enlarge-minibuffer
212 event mouse minibuffer y top bot edges wconfig params growth)
213 (setq params (frame-parameters))
951e0427 214 (setq minibuffer (cdr (assq 'minibuffer params)))
544e7e73
RS
215 (track-mouse
216 (progn
217 ;; enlarge-window only works on the selected window, so
218 ;; we must select the window where the start event originated.
219 ;; unwind-protect will restore the old selected window later.
220 (select-window start-event-window)
221 ;; if this is the bottommost ordinary window, then to
222 ;; move its modeline the minibuffer must be enlarged.
223 (setq should-enlarge-minibuffer
224 (and minibuffer
225 (not (one-window-p t))
226 (= (nth 1 (window-edges minibuffer))
227 (nth 3 (window-edges)))))
228 ;; loop reading events and sampling the position of
229 ;; the mouse.
230 (while (not done)
231 (setq event (read-event)
232 mouse (mouse-position))
233 ;; do nothing if
234 ;; - there is a switch-frame event.
235 ;; - the mouse isn't in the frame that we started in
236 ;; - the mouse isn't in any Emacs frame
237 ;; drag if
238 ;; - there is a mouse-movement event
239 ;; - there is a scroll-bar-movement event
240 ;; (same as mouse movement for our purposes)
241 ;; quit if
242 ;; - there is a keyboard event or some other unknown event
243 ;; unknown event.
244 (cond ((integerp event)
245 (setq done t))
246 ((eq (car event) 'switch-frame)
247 nil)
248 ((not (memq (car event)
249 '(mouse-movement scroll-bar-movement)))
250 (if (consp event)
251 (setq unread-command-events
252 (cons event unread-command-events)))
253 (setq done t))
254 ((not (eq (car mouse) start-event-frame))
255 nil)
256 ((null (car (cdr mouse)))
257 nil)
258 (t
259 (setq y (cdr (cdr mouse))
260 edges (window-edges)
261 top (nth 1 edges)
262 bot (nth 3 edges))
263 ;; scale back a move that would make the
264 ;; window too short.
265 (cond ((< (- y top -1) window-min-height)
266 (setq y (+ top window-min-height -1))))
267 ;; compute size change needed
268 (setq growth (- y bot -1)
269 wconfig (current-window-configuration))
951e0427
RS
270 ;; Check for an error case.
271 (if (and (/= growth 0)
272 (not minibuffer)
273 (one-window-p t))
274 (error "Attempt to resize sole window"))
544e7e73
RS
275 ;; grow/shrink minibuffer?
276 (if should-enlarge-minibuffer
277 (progn
278 ;; yes. briefly select minibuffer so
279 ;; enlarge-window will affect the
280 ;; correct window.
281 (select-window minibuffer)
282 ;; scale back shrinkage if it would
283 ;; make the minibuffer less than 1
284 ;; line tall.
285 (if (and (> growth 0)
286 (< (- (window-height minibuffer)
287 growth)
288 1))
289 (setq growth (1- (window-height minibuffer))))
290 (enlarge-window (- growth))
291 (select-window start-event-window))
292 ;; no. grow/shrink the selected window
293 (enlarge-window growth))
294 ;; if this window's growth caused another
295 ;; window to be deleted because it was too
296 ;; short, rescind the change.
297 ;;
298 ;; if size change caused space to be stolen
299 ;; from a window above this one, rescind the
300 ;; change, but only if we didn't grow/srhink
301 ;; the minibuffer. minibuffer size changes
302 ;; can cause all windows to shrink... no way
303 ;; around it.
304 (if (or (/= start-nwindows (count-windows t))
305 (and (not should-enlarge-minibuffer)
306 (/= top (nth 1 (window-edges)))))
307 (set-window-configuration wconfig)))))))))
308\f
08a1c178
RS
309(defun mouse-drag-vertical-line (start-event)
310 "Change the width of a window by dragging on the vertical line."
311 (interactive "e")
312 ;; Give temporary modes such as isearch a chance to turn off.
313 (run-hooks 'mouse-leave-buffer-hook)
5d6a85e0
RS
314 (let* ((done nil)
315 (echo-keystrokes 0)
316 (start-event-frame (window-frame (car (car (cdr start-event)))))
317 (start-event-window (car (car (cdr start-event))))
318 (start-nwindows (count-windows t))
319 (old-selected-window (selected-window))
320 event mouse x left right edges wconfig growth
321 (which-side
322 (or (cdr (assq 'vertical-scroll-bars (frame-parameters start-event-frame)))
323 'right)))
08a1c178
RS
324 (if (one-window-p t)
325 (error "Attempt to resize sole ordinary window"))
4e363e7e
KH
326 (if (eq which-side 'right)
327 (if (= (nth 2 (window-edges start-event-window))
328 (frame-width start-event-frame))
329 (error "Attempt to drag rightmost scrollbar"))
330 (if (= (nth 0 (window-edges start-event-window)) 0)
331 (error "Attempt to drag leftmost scrollbar")))
08a1c178
RS
332 (track-mouse
333 (progn
334 ;; enlarge-window only works on the selected window, so
335 ;; we must select the window where the start event originated.
336 ;; unwind-protect will restore the old selected window later.
337 (select-window start-event-window)
338 ;; loop reading events and sampling the position of
339 ;; the mouse.
340 (while (not done)
341 (setq event (read-event)
342 mouse (mouse-position))
343 ;; do nothing if
344 ;; - there is a switch-frame event.
345 ;; - the mouse isn't in the frame that we started in
346 ;; - the mouse isn't in any Emacs frame
347 ;; drag if
348 ;; - there is a mouse-movement event
349 ;; - there is a scroll-bar-movement event
350 ;; (same as mouse movement for our purposes)
351 ;; quit if
352 ;; - there is a keyboard event or some other unknown event
353 ;; unknown event.
354 (cond ((integerp event)
355 (setq done t))
356 ((eq (car event) 'switch-frame)
357 nil)
358 ((not (memq (car event)
359 '(mouse-movement scroll-bar-movement)))
360 (if (consp event)
361 (setq unread-command-events
362 (cons event unread-command-events)))
363 (setq done t))
364 ((not (eq (car mouse) start-event-frame))
365 nil)
366 ((null (car (cdr mouse)))
367 nil)
368 (t
b0ea497f
KH
369 (save-selected-window
370 ;; If the scroll bar is on the window's left,
371 ;; adjust the window on the left.
4e363e7e
KH
372 (unless (eq which-side 'right)
373 (select-window (previous-window)))
b0ea497f 374 (setq x (- (car (cdr mouse))
4e363e7e 375 (if (eq which-side 'right) 0 2))
b0ea497f
KH
376 edges (window-edges)
377 left (nth 0 edges)
378 right (nth 2 edges))
379 ;; scale back a move that would make the
380 ;; window too thin.
381 (if (< (- x left -1) window-min-width)
382 (setq x (+ left window-min-width -1)))
383 ;; compute size change needed
384 (setq growth (- x right -1)
385 wconfig (current-window-configuration))
386 (enlarge-window growth t)
387 ;; if this window's growth caused another
388 ;; window to be deleted because it was too
389 ;; thin, rescind the change.
390 ;;
391 ;; if size change caused space to be stolen
392 ;; from a window to the left of this one,
393 ;; rescind the change.
394 (if (or (/= start-nwindows (count-windows t))
395 (/= left (nth 0 (window-edges))))
396 (set-window-configuration wconfig))))))))))
08a1c178 397\f
2a5fa27b 398(defun mouse-set-point (event)
cc0a8174 399 "Move point to the position clicked on with the mouse.
2a5fa27b 400This should be bound to a mouse click event type."
ec558adc 401 (interactive "e")
d65147f6 402 (mouse-minibuffer-check event)
2a5fa27b
RS
403 ;; Use event-end in case called from mouse-drag-region.
404 ;; If EVENT is a click, event-end and event-start give same value.
405 (let ((posn (event-end event)))
0a50b993
RS
406 (if (not (windowp (posn-window posn)))
407 (error "Cursor not in text area of window"))
b5370f03
JB
408 (select-window (posn-window posn))
409 (if (numberp (posn-point posn))
410 (goto-char (posn-point posn)))))
cc0a8174 411
e6c2f5d4
RS
412(defvar mouse-last-region-beg nil)
413(defvar mouse-last-region-end nil)
414(defvar mouse-last-region-tick nil)
415
416(defun mouse-region-match ()
417 "Return non-nil if there's an active region that was set with the mouse."
418 (and (mark t) mark-active
419 (eq mouse-last-region-beg (region-beginning))
420 (eq mouse-last-region-end (region-end))
421 (eq mouse-last-region-tick (buffer-modified-tick))))
422
652ccd35 423(defun mouse-set-region (click)
e37de120 424 "Set the region to the text dragged over, and copy to kill ring.
2a5fa27b 425This should be bound to a mouse drag event."
652ccd35 426 (interactive "e")
d65147f6 427 (mouse-minibuffer-check click)
652ccd35
RS
428 (let ((posn (event-start click))
429 (end (event-end click)))
430 (select-window (posn-window posn))
431 (if (numberp (posn-point posn))
432 (goto-char (posn-point posn)))
fcfc3c63 433 ;; If mark is highlighted, no need to bounce the cursor.
33a35434
KH
434 ;; On X, we highlight while dragging, thus once again no need to bounce.
435 (or transient-mark-mode
b86b9918 436 (memq (framep (selected-frame)) '(x pc w32))
fcfc3c63 437 (sit-for 1))
652ccd35 438 (push-mark)
1cc8a3f4 439 (set-mark (point))
652ccd35 440 (if (numberp (posn-point end))
e37de120
RS
441 (goto-char (posn-point end)))
442 ;; Don't set this-command to kill-region, so that a following
443 ;; C-w will not double the text in the kill ring.
91a6bc10 444 ;; Ignore last-command so we don't append to a preceding kill.
1fa01bcd 445 (let (this-command last-command deactivate-mark)
e6c2f5d4
RS
446 (copy-region-as-kill (mark) (point)))
447 (mouse-set-region-1)))
448
449(defun mouse-set-region-1 ()
450 (setq mouse-last-region-beg (region-beginning))
451 (setq mouse-last-region-end (region-end))
452 (setq mouse-last-region-tick (buffer-modified-tick)))
652ccd35 453
3b558d41 454(defcustom mouse-scroll-delay 0.25
600c6e3a
JB
455 "*The pause between scroll steps caused by mouse drags, in seconds.
456If you drag the mouse beyond the edge of a window, Emacs scrolls the
457window to bring the text beyond that edge into view, with a delay of
458this many seconds between scroll steps. Scrolling stops when you move
459the mouse back into the window, or release the button.
460This variable's value may be non-integral.
3b558d41
RS
461Setting this to zero causes Emacs to scroll as fast as it can."
462 :type 'number
463 :group 'mouse)
600c6e3a 464
3b558d41 465(defcustom mouse-scroll-min-lines 1
a3d6bb97
RS
466 "*The minimum number of lines scrolled by dragging mouse out of window.
467Moving the mouse out the top or bottom edge of the window begins
468scrolling repeatedly. The number of lines scrolled per repetition
469is normally equal to the number of lines beyond the window edge that
470the mouse has moved. However, it always scrolls at least the number
3b558d41
RS
471of lines specified by this variable."
472 :type 'integer
473 :group 'mouse)
08a1c178 474
e919a622
RS
475(defun mouse-scroll-subr (window jump &optional overlay start)
476 "Scroll the window WINDOW, JUMP lines at a time, until new input arrives.
600c6e3a
JB
477If OVERLAY is an overlay, let it stretch from START to the far edge of
478the newly visible text.
479Upon exit, point is at the far edge of the newly visible text."
08a1c178
RS
480 (cond
481 ((and (> jump 0) (< jump mouse-scroll-min-lines))
482 (setq jump mouse-scroll-min-lines))
483 ((and (< jump 0) (< (- jump) mouse-scroll-min-lines))
484 (setq jump (- mouse-scroll-min-lines))))
4e399a53
RS
485 (let ((opoint (point)))
486 (while (progn
487 (goto-char (window-start window))
488 (if (not (zerop (vertical-motion jump window)))
489 (progn
490 (set-window-start window (point))
491 (if (natnump jump)
0320e66f
RS
492 (if (window-end window)
493 (progn
494 (goto-char (window-end window))
495 ;; window-end doesn't reflect the window's new
496 ;; start position until the next redisplay.
497 (vertical-motion (1- jump) window))
498 (vertical-motion (- (window-height window) 2)))
4e399a53
RS
499 (goto-char (window-start window)))
500 (if overlay
501 (move-overlay overlay start (point)))
502 ;; Now that we have scrolled WINDOW properly,
503 ;; put point back where it was for the redisplay
504 ;; so that we don't mess up the selected window.
505 (or (eq window (selected-window))
506 (goto-char opoint))
d2287ded 507 (sit-for mouse-scroll-delay)))))
4e399a53
RS
508 (or (eq window (selected-window))
509 (goto-char opoint))))
fcfc3c63 510
dc269e81 511;; Create an overlay and immediately delete it, to get "overlay in no buffer".
600c6e3a 512(defvar mouse-drag-overlay (make-overlay 1 1))
dc269e81 513(delete-overlay mouse-drag-overlay)
600c6e3a
JB
514(overlay-put mouse-drag-overlay 'face 'region)
515
dd524dbd 516(defvar mouse-selection-click-count 0)
eb6ff46f 517
c8c5bd24
RS
518(defvar mouse-selection-click-count-buffer nil)
519
600c6e3a 520(defun mouse-drag-region (start-event)
bcd5aef1 521 "Set the region to the text that the mouse is dragged over.
78210c95
RS
522Highlight the drag area as you move the mouse.
523This must be bound to a button-down mouse event.
d017deb2
RS
524In Transient Mark mode, the highlighting remains as long as the mark
525remains active. Otherwise, it remains until the next input event."
bcd5aef1 526 (interactive "e")
d65147f6 527 (mouse-minibuffer-check start-event)
4c9afcbe
RS
528 (let* ((echo-keystrokes 0)
529 (start-posn (event-start start-event))
600c6e3a
JB
530 (start-point (posn-point start-posn))
531 (start-window (posn-window start-posn))
b846d039 532 (start-frame (window-frame start-window))
600c6e3a
JB
533 (bounds (window-edges start-window))
534 (top (nth 1 bounds))
535 (bottom (if (window-minibuffer-p start-window)
536 (nth 3 bounds)
537 ;; Don't count the mode line.
e37de120
RS
538 (1- (nth 3 bounds))))
539 (click-count (1- (event-click-count start-event))))
eb6ff46f 540 (setq mouse-selection-click-count click-count)
c8c5bd24 541 (setq mouse-selection-click-count-buffer (current-buffer))
b80f1928 542 (mouse-set-point start-event)
08a1c178
RS
543 ;; In case the down click is in the middle of some intangible text,
544 ;; use the end of that text, and put it in START-POINT.
545 (if (< (point) start-point)
546 (goto-char start-point))
547 (setq start-point (point))
e37de120
RS
548 (let ((range (mouse-start-end start-point start-point click-count)))
549 (move-overlay mouse-drag-overlay (car range) (nth 1 range)
550 (window-buffer start-window)))
f767385c 551 (deactivate-mark)
08a1c178
RS
552 ;; end-of-range is used only in the single-click case.
553 ;; It is the place where the drag has reached so far
554 ;; (but not outside the window where the drag started).
d5c847bb 555 (let (event end end-point last-end-point (end-of-range (point)))
bcd5aef1 556 (track-mouse
600c6e3a 557 (while (progn
b846d039
JB
558 (setq event (read-event))
559 (or (mouse-movement-p event)
560 (eq (car-safe event) 'switch-frame)))
b846d039
JB
561 (if (eq (car-safe event) 'switch-frame)
562 nil
563 (setq end (event-end event)
564 end-point (posn-point end))
3617aa76 565 (if (numberp end-point)
d5c847bb 566 (setq last-end-point end-point))
b846d039
JB
567
568 (cond
b846d039
JB
569 ;; Are we moving within the original window?
570 ((and (eq (posn-window end) start-window)
571 (integer-or-marker-p end-point))
08a1c178
RS
572 ;; Go to START-POINT first, so that when we move to END-POINT,
573 ;; if it's in the middle of intangible text,
574 ;; point jumps in the direction away from START-POINT.
575 (goto-char start-point)
b846d039 576 (goto-char end-point)
08a1c178
RS
577 (if (zerop (% click-count 3))
578 (setq end-of-range (point)))
e37de120
RS
579 (let ((range (mouse-start-end start-point (point) click-count)))
580 (move-overlay mouse-drag-overlay (car range) (nth 1 range))))
b846d039 581
50e527bc
KH
582 (t
583 (let ((mouse-row (cdr (cdr (mouse-position)))))
b846d039 584 (cond
50e527bc 585 ((null mouse-row))
b846d039 586 ((< mouse-row top)
e919a622 587 (mouse-scroll-subr start-window (- mouse-row top)
f9278a75
RS
588 mouse-drag-overlay start-point)
589 ;; Without this, point tends to jump back to the starting
590 ;; position where the mouse button was pressed down.
591 (setq end-of-range (overlay-start mouse-drag-overlay)))
d2287ded 592 ((>= mouse-row bottom)
e919a622 593 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
ce8c2809 594 mouse-drag-overlay start-point)
f9278a75 595 (setq end-of-range (overlay-end mouse-drag-overlay))))))))))
2e3329a5
RS
596 ;; In case we did not get a mouse-motion event
597 ;; for the final move of the mouse before a drag event
598 ;; pretend that we did get one.
599 (when (and (memq 'drag (event-modifiers (car-safe event)))
600 (setq end (event-end event)
601 end-point (posn-point end))
602 (eq (posn-window end) start-window)
603 (integer-or-marker-p end-point))
604
605 ;; Go to START-POINT first, so that when we move to END-POINT,
606 ;; if it's in the middle of intangible text,
607 ;; point jumps in the direction away from START-POINT.
608 (goto-char start-point)
609 (goto-char end-point)
610 (if (zerop (% click-count 3))
611 (setq end-of-range (point)))
612 (let ((range (mouse-start-end start-point (point) click-count)))
613 (move-overlay mouse-drag-overlay (car range) (nth 1 range))))
614
4e399a53 615 (if (consp event)
e37de120 616 (let ((fun (key-binding (vector (car event)))))
bfbcf12e
RS
617 ;; Run the binding of the terminating up-event, if possible.
618 ;; In the case of a multiple click, it gives the wrong results,
619 ;; because it would fail to set up a region.
bb3aa835
RS
620 (if (not (= (overlay-start mouse-drag-overlay)
621 (overlay-end mouse-drag-overlay)))
622 (let* ((stop-point
623 (if (numberp (posn-point (event-end event)))
624 (posn-point (event-end event))
625 last-end-point))
626 ;; The end that comes from where we ended the drag.
627 ;; Point goes here.
628 (region-termination
629 (if (and stop-point (< stop-point start-point))
630 (overlay-start mouse-drag-overlay)
44dc5252 631 (overlay-end mouse-drag-overlay)))
bb3aa835
RS
632 ;; The end that comes from where we started the drag.
633 ;; Mark goes there.
634 (region-commencement
635 (- (+ (overlay-end mouse-drag-overlay)
636 (overlay-start mouse-drag-overlay))
637 region-termination))
638 last-command this-command)
639 (push-mark region-commencement t t)
640 (goto-char region-termination)
1fa01bcd
RS
641 ;; Don't let copy-region-as-kill set deactivate-mark.
642 (let (deactivate-mark)
643 (copy-region-as-kill (point) (mark t)))
bb3aa835
RS
644 (let ((buffer (current-buffer)))
645 (mouse-show-mark)
646 ;; mouse-show-mark can call read-event,
647 ;; and that means the Emacs server could switch buffers
648 ;; under us. If that happened,
649 ;; avoid trying to use the region.
650 (and (mark t) mark-active
651 (eq buffer (current-buffer))
652 (mouse-set-region-1))))
653 (delete-overlay mouse-drag-overlay)
654 ;; Run the binding of the terminating up-event.
655 (if (fboundp fun)
656 (setq unread-command-events
657 (cons event unread-command-events)))))
e6c2f5d4 658 (delete-overlay mouse-drag-overlay)))))
e37de120
RS
659\f
660;; Commands to handle xterm-style multiple clicks.
600c6e3a 661
e37de120
RS
662(defun mouse-skip-word (dir)
663 "Skip over word, over whitespace, or over identical punctuation.
664If DIR is positive skip forward; if negative, skip backward."
665 (let* ((char (following-char))
666 (syntax (char-to-string (char-syntax char))))
258e3295
KH
667 (cond ((string= syntax "w")
668 ;; Here, we can't use skip-syntax-forward/backward because
669 ;; they don't pay attention to word-separating-categories,
670 ;; and thus they will skip over a true word boundary. So,
671 ;; we simularte the original behaviour by using
672 ;; forward-word.
673 (if (< dir 0)
674 (if (not (looking-at "\\<"))
675 (forward-word -1))
676 (if (or (looking-at "\\<") (not (looking-at "\\>")))
677 (forward-word 1))))
678 ((string= syntax " ")
08a1c178
RS
679 (if (< dir 0)
680 (skip-syntax-backward syntax)
681 (skip-syntax-forward syntax)))
682 ((string= syntax "_")
683 (if (< dir 0)
684 (skip-syntax-backward "w_")
685 (skip-syntax-forward "w_")))
686 ((< dir 0)
687 (while (and (not (bobp)) (= (preceding-char) char))
688 (forward-char -1)))
689 (t
690 (while (and (not (eobp)) (= (following-char) char))
691 (forward-char 1))))))
e37de120
RS
692
693;; Return a list of region bounds based on START and END according to MODE.
694;; If MODE is 0 then set point to (min START END), mark to (max START END).
695;; If MODE is 1 then set point to start of word at (min START END),
696;; mark to end of word at (max START END).
697;; If MODE is 2 then do the same for lines.
eb6ff46f 698(defun mouse-start-end (start end mode)
e37de120
RS
699 (if (> start end)
700 (let ((temp start))
701 (setq start end
702 end temp)))
9a974c88 703 (setq mode (mod mode 3))
e37de120
RS
704 (cond ((= mode 0)
705 (list start end))
706 ((and (= mode 1)
707 (= start end)
1ec71583 708 (char-after start)
e37de120 709 (= (char-syntax (char-after start)) ?\())
6f482eec
RS
710 (list start
711 (save-excursion
712 (goto-char start)
713 (forward-sexp 1)
714 (point))))
e37de120
RS
715 ((and (= mode 1)
716 (= start end)
1ec71583 717 (char-after start)
e37de120
RS
718 (= (char-syntax (char-after start)) ?\)))
719 (list (save-excursion
720 (goto-char (1+ start))
d89a4a47
RS
721 (backward-sexp 1)
722 (point))
e37de120 723 (1+ start)))
53770877
RS
724 ((and (= mode 1)
725 (= start end)
726 (char-after start)
727 (= (char-syntax (char-after start)) ?\"))
728 (let ((open (or (eq start (point-min))
729 (save-excursion
730 (goto-char (- start 1))
731 (looking-at "\\s(\\|\\s \\|\\s>")))))
732 (if open
733 (list start
734 (save-excursion
735 (condition-case nil
736 (progn
737 (goto-char start)
738 (forward-sexp 1)
739 (point))
740 (error end))))
f1017d55 741 (list (save-excursion
53770877
RS
742 (condition-case nil
743 (progn
744 (goto-char (1+ start))
745 (backward-sexp 1)
746 (point))
f1017d55
RS
747 (error end)))
748 (1+ start)))))
e37de120
RS
749 ((= mode 1)
750 (list (save-excursion
751 (goto-char start)
752 (mouse-skip-word -1)
753 (point))
754 (save-excursion
755 (goto-char end)
756 (mouse-skip-word 1)
757 (point))))
758 ((= mode 2)
759 (list (save-excursion
760 (goto-char start)
761 (beginning-of-line 1)
762 (point))
763 (save-excursion
764 (goto-char end)
765 (forward-line 1)
766 (point))))))
e66feb07 767\f
3f26b32a
RS
768;; Subroutine: set the mark where CLICK happened,
769;; but don't do anything else.
770(defun mouse-set-mark-fast (click)
d65147f6 771 (mouse-minibuffer-check click)
3f26b32a
RS
772 (let ((posn (event-start click)))
773 (select-window (posn-window posn))
774 (if (numberp (posn-point posn))
775 (push-mark (posn-point posn) t t))))
776
98aac09d
MB
777(defun mouse-undouble-last-event (events)
778 (let* ((index (1- (length events)))
779 (last (nthcdr index events))
780 (event (car last))
781 (basic (event-basic-type event))
397a88f3
RS
782 (old-modifiers (event-modifiers event))
783 (modifiers (delq 'double (delq 'triple (copy-sequence old-modifiers))))
98aac09d
MB
784 (new
785 (if (consp event)
7132500b
RS
786 ;; Use reverse, not nreverse, since event-modifiers
787 ;; does not copy the list it returns.
3bb846b8 788 (cons (event-convert-list (reverse (cons basic modifiers)))
98aac09d
MB
789 (cdr event))
790 event)))
791 (setcar last new)
397a88f3
RS
792 (if (and (not (equal modifiers old-modifiers))
793 (key-binding (apply 'vector events)))
98aac09d
MB
794 t
795 (setcar last event)
796 nil)))
797
3f26b32a 798;; Momentarily show where the mark is, if highlighting doesn't show it.
7aeb7370
RS
799
800(defvar mouse-region-delete-keys '([delete])
801 "List of keys which shall cause the mouse region to be deleted.")
802
3f26b32a 803(defun mouse-show-mark ()
98aac09d 804 (if transient-mark-mode
c8f264ae 805 (if window-system
98aac09d
MB
806 (delete-overlay mouse-drag-overlay))
807 (if window-system
808 (let ((inhibit-quit t)
809 (echo-keystrokes 0)
33d79bad
RS
810 event events key ignore
811 x-lost-selection-hooks)
812 (add-hook 'x-lost-selection-hooks
813 '(lambda (seltype)
814 (if (eq seltype 'PRIMARY)
815 (progn (setq ignore t)
816 (throw 'mouse-show-mark t)))))
98aac09d 817 (move-overlay mouse-drag-overlay (point) (mark t))
33d79bad 818 (catch 'mouse-show-mark
4e2aade1
RS
819 ;; In this loop, execute scroll bar and switch-frame events.
820 ;; Also ignore down-events that are undefined.
33d79bad
RS
821 (while (progn (setq event (read-event))
822 (setq events (append events (list event)))
823 (setq key (apply 'vector events))
397a88f3 824 (or (and (consp event)
4e2aade1
RS
825 (eq (car event) 'switch-frame))
826 (and (consp event)
397a88f3
RS
827 (eq (posn-point (event-end event))
828 'vertical-scroll-bar))
829 (and (memq 'down (event-modifiers event))
830 (not (key-binding key))
831 (not (mouse-undouble-last-event events))
832 (not (member key mouse-region-delete-keys)))))
833 (and (consp event)
4e2aade1
RS
834 (or (eq (car event) 'switch-frame)
835 (eq (posn-point (event-end event))
836 'vertical-scroll-bar))
397a88f3
RS
837 (let ((keys (vector 'vertical-scroll-bar event)))
838 (and (key-binding keys)
839 (progn
840 (call-interactively (key-binding keys)
841 nil keys)
842 (setq events nil)))))))
33d79bad
RS
843 ;; If we lost the selection, just turn off the highlighting.
844 (if ignore
845 nil
846 ;; For certain special keys, delete the region.
847 (if (member key mouse-region-delete-keys)
848 (delete-region (overlay-start mouse-drag-overlay)
849 (overlay-end mouse-drag-overlay))
850 ;; Otherwise, unread the key so it gets executed normally.
851 (setq unread-command-events
852 (nconc events unread-command-events))))
98aac09d
MB
853 (setq quit-flag nil)
854 (delete-overlay mouse-drag-overlay))
855 (save-excursion
856 (goto-char (mark t))
857 (sit-for 1)))))
3f26b32a 858
cc0a8174
JB
859(defun mouse-set-mark (click)
860 "Set mark at the position clicked on with the mouse.
861Display cursor at that position for a second.
862This must be bound to a mouse click."
ec558adc 863 (interactive "e")
f598fb03
RS
864 (mouse-minibuffer-check click)
865 (select-window (posn-window (event-start click)))
866 ;; We don't use save-excursion because that preserves the mark too.
72ea54a4
RS
867 (let ((point-save (point)))
868 (unwind-protect
cc0a8174 869 (progn (mouse-set-point click)
897897e3
RS
870 (push-mark nil t t)
871 (or transient-mark-mode
872 (sit-for 1)))
72ea54a4
RS
873 (goto-char point-save))))
874
cc0a8174
JB
875(defun mouse-kill (click)
876 "Kill the region between point and the mouse click.
877The text is saved in the kill ring, as with \\[kill-region]."
ec558adc 878 (interactive "e")
d65147f6 879 (mouse-minibuffer-check click)
142c7672
KH
880 (let* ((posn (event-start click))
881 (click-posn (posn-point posn)))
882 (select-window (posn-window posn))
bd307392
JB
883 (if (numberp click-posn)
884 (kill-region (min (point) click-posn)
885 (max (point) click-posn)))))
72ea54a4 886
87ef29fd
JB
887(defun mouse-yank-at-click (click arg)
888 "Insert the last stretch of killed text at the position clicked on.
50f58001
RS
889Also move point to one end of the text thus inserted (normally the end).
890Prefix arguments are interpreted as with \\[yank].
891If `mouse-yank-at-point' is non-nil, insert at point
892regardless of where you click."
ec558adc 893 (interactive "e\nP")
33c448cd
RS
894 ;; Give temporary modes such as isearch a chance to turn off.
895 (run-hooks 'mouse-leave-buffer-hook)
50f58001 896 (or mouse-yank-at-point (mouse-set-point click))
d89a4a47 897 (setq this-command 'yank)
a814e9df 898 (setq mouse-selection-click-count 0)
87ef29fd
JB
899 (yank arg))
900
901(defun mouse-kill-ring-save (click)
cc0a8174
JB
902 "Copy the region between point and the mouse click in the kill ring.
903This does not delete the region; it acts like \\[kill-ring-save]."
ec558adc 904 (interactive "e")
3f26b32a 905 (mouse-set-mark-fast click)
6452d8a6
RS
906 (let (this-command last-command)
907 (kill-ring-save (point) (mark t)))
3f26b32a 908 (mouse-show-mark))
72ea54a4 909
dbc4e1c1
JB
910;;; This function used to delete the text between point and the mouse
911;;; whenever it was equal to the front of the kill ring, but some
912;;; people found that confusing.
913
914;;; A list (TEXT START END), describing the text and position of the last
915;;; invocation of mouse-save-then-kill.
916(defvar mouse-save-then-kill-posn nil)
917
26d280b9 918(defun mouse-save-then-kill-delete-region (beg end)
9a974c88
RS
919 ;; We must make our own undo boundaries
920 ;; because they happen automatically only for the current buffer.
921 (undo-boundary)
dd524dbd
RS
922 (if (or (= beg end) (eq buffer-undo-list t))
923 ;; If we have no undo list in this buffer,
924 ;; just delete.
925 (delete-region beg end)
926 ;; Delete, but make the undo-list entry share with the kill ring.
927 ;; First, delete just one char, so in case buffer is being modified
928 ;; for the first time, the undo list records that fact.
2f4b15ef
RS
929 (let (before-change-function after-change-function
930 before-change-functions after-change-functions)
931 (delete-region beg
932 (+ beg (if (> end beg) 1 -1))))
dd524dbd
RS
933 (let ((buffer-undo-list buffer-undo-list))
934 ;; Undo that deletion--but don't change the undo list!
2f4b15ef
RS
935 (let (before-change-function after-change-function
936 before-change-functions after-change-functions)
937 (primitive-undo 1 buffer-undo-list))
dd524dbd
RS
938 ;; Now delete the rest of the specified region,
939 ;; but don't record it.
940 (setq buffer-undo-list t)
9a974c88
RS
941 (if (/= (length (car kill-ring)) (- (max end beg) (min end beg)))
942 (error "Lossage in mouse-save-then-kill-delete-region"))
dd524dbd
RS
943 (delete-region beg end))
944 (let ((tail buffer-undo-list))
945 ;; Search back in buffer-undo-list for the string
946 ;; that came from deleting one character.
947 (while (and tail (not (stringp (car (car tail)))))
948 (setq tail (cdr tail)))
949 ;; Replace it with an entry for the entire deleted text.
950 (and tail
9a974c88
RS
951 (setcar tail (cons (car kill-ring) (min beg end))))))
952 (undo-boundary))
eb6ff46f 953
947da0c4 954(defun mouse-save-then-kill (click)
40a45a9f
RS
955 "Save text to point in kill ring; the second time, kill the text.
956If the text between point and the mouse is the same as what's
957at the front of the kill ring, this deletes the text.
958Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
eb6ff46f
RS
959which prepares for a second click to delete the text.
960
961If you have selected words or lines, this command extends the
962selection through the word or line clicked on. If you do this
963again in a different position, it extends the selection again.
964If you do this twice in the same position, the selection is killed."
947da0c4 965 (interactive "e")
53016bea
RS
966 (let ((before-scroll
967 (with-current-buffer (window-buffer (posn-window (event-start click)))
968 point-before-scroll)))
b64548c7
RS
969 (mouse-minibuffer-check click)
970 (let ((click-posn (posn-point (event-start click)))
971 ;; Don't let a subsequent kill command append to this one:
972 ;; prevent setting this-command to kill-region.
973 (this-command this-command))
c8c5bd24
RS
974 (if (and (save-excursion
975 (set-buffer (window-buffer (posn-window (event-start click))))
976 (and (mark t) (> (mod mouse-selection-click-count 3) 0)
977 ;; Don't be fooled by a recent click in some other buffer.
978 (eq mouse-selection-click-count-buffer
979 (current-buffer)))))
b64548c7
RS
980 (if (not (and (eq last-command 'mouse-save-then-kill)
981 (equal click-posn
982 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
983 ;; Find both ends of the object selected by this click.
984 (let* ((range
985 (mouse-start-end click-posn click-posn
986 mouse-selection-click-count)))
987 ;; Move whichever end is closer to the click.
988 ;; That's what xterm does, and it seems reasonable.
989 (if (< (abs (- click-posn (mark t)))
990 (abs (- click-posn (point))))
991 (set-mark (car range))
992 (goto-char (nth 1 range)))
993 ;; We have already put the old region in the kill ring.
994 ;; Replace it with the extended region.
995 ;; (It would be annoying to make a separate entry.)
996 (kill-new (buffer-substring (point) (mark t)) t)
e6c2f5d4 997 (mouse-set-region-1)
b64548c7
RS
998 ;; Arrange for a repeated mouse-3 to kill this region.
999 (setq mouse-save-then-kill-posn
1000 (list (car kill-ring) (point) click-posn))
1001 (mouse-show-mark))
1002 ;; If we click this button again without moving it,
1003 ;; that time kill.
bcde3748 1004 (mouse-save-then-kill-delete-region (mark) (point))
b64548c7 1005 (setq mouse-selection-click-count 0)
dd524dbd 1006 (setq mouse-save-then-kill-posn nil))
b64548c7
RS
1007 (if (and (eq last-command 'mouse-save-then-kill)
1008 mouse-save-then-kill-posn
1009 (eq (car mouse-save-then-kill-posn) (car kill-ring))
1010 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
1011 ;; If this is the second time we've called
1012 ;; mouse-save-then-kill, delete the text from the buffer.
1013 (progn
1014 (mouse-save-then-kill-delete-region (point) (mark))
1015 ;; After we kill, another click counts as "the first time".
1016 (setq mouse-save-then-kill-posn nil))
c8f264ae
RS
1017 ;; This is not a repetition.
1018 ;; We are adjusting an old selection or creating a new one.
b64548c7
RS
1019 (if (or (and (eq last-command 'mouse-save-then-kill)
1020 mouse-save-then-kill-posn)
1021 (and mark-active transient-mark-mode)
1022 (and (memq last-command
1023 '(mouse-drag-region mouse-set-region))
1024 (or mark-even-if-inactive
1025 (not transient-mark-mode))))
1026 ;; We have a selection or suitable region, so adjust it.
1027 (let* ((posn (event-start click))
1028 (new (posn-point posn)))
1029 (select-window (posn-window posn))
1030 (if (numberp new)
1031 (progn
1032 ;; Move whichever end of the region is closer to the click.
1033 ;; That is what xterm does, and it seems reasonable.
1034 (if (< (abs (- new (point))) (abs (- new (mark t))))
1035 (goto-char new)
1036 (set-mark new))
1037 (setq deactivate-mark nil)))
bcde3748
RS
1038 (kill-new (buffer-substring (point) (mark t)) t)
1039 (mouse-show-mark))
b64548c7
RS
1040 ;; Set the mark where point is, then move where clicked.
1041 (mouse-set-mark-fast click)
1042 (if before-scroll
1043 (goto-char before-scroll))
1044 (exchange-point-and-mark)
c8f264ae
RS
1045 (kill-new (buffer-substring (point) (mark t)))
1046 (if window-system
1047 (mouse-show-mark)))
e6c2f5d4 1048 (mouse-set-region-1)
b64548c7
RS
1049 (setq mouse-save-then-kill-posn
1050 (list (car kill-ring) (point) click-posn)))))))
e66feb07
RS
1051\f
1052(global-set-key [M-mouse-1] 'mouse-start-secondary)
1053(global-set-key [M-drag-mouse-1] 'mouse-set-secondary)
1054(global-set-key [M-down-mouse-1] 'mouse-drag-secondary)
1055(global-set-key [M-mouse-3] 'mouse-secondary-save-then-kill)
9a974c88 1056(global-set-key [M-mouse-2] 'mouse-yank-secondary)
e66feb07
RS
1057
1058;; An overlay which records the current secondary selection
1059;; or else is deleted when there is no secondary selection.
1060;; May be nil.
1061(defvar mouse-secondary-overlay nil)
1062
a94c7fcc
RS
1063(defvar mouse-secondary-click-count 0)
1064
e66feb07
RS
1065;; A marker which records the specified first end for a secondary selection.
1066;; May be nil.
1067(defvar mouse-secondary-start nil)
1068
1069(defun mouse-start-secondary (click)
1070 "Set one end of the secondary selection to the position clicked on.
1071Use \\[mouse-secondary-save-then-kill] to set the other end
1072and complete the secondary selection."
1073 (interactive "e")
d65147f6 1074 (mouse-minibuffer-check click)
e66feb07 1075 (let ((posn (event-start click)))
230aaa73
RS
1076 (save-excursion
1077 (set-buffer (window-buffer (posn-window posn)))
1078 ;; Cancel any preexisting secondary selection.
1079 (if mouse-secondary-overlay
1080 (delete-overlay mouse-secondary-overlay))
1081 (if (numberp (posn-point posn))
1082 (progn
1083 (or mouse-secondary-start
1084 (setq mouse-secondary-start (make-marker)))
1085 (move-marker mouse-secondary-start (posn-point posn)))))))
e66feb07
RS
1086
1087(defun mouse-set-secondary (click)
1088 "Set the secondary selection to the text that the mouse is dragged over.
1089This must be bound to a mouse drag event."
1090 (interactive "e")
d65147f6 1091 (mouse-minibuffer-check click)
e66feb07
RS
1092 (let ((posn (event-start click))
1093 beg
1094 (end (event-end click)))
230aaa73
RS
1095 (save-excursion
1096 (set-buffer (window-buffer (posn-window posn)))
1097 (if (numberp (posn-point posn))
1098 (setq beg (posn-point posn)))
1099 (if mouse-secondary-overlay
1100 (move-overlay mouse-secondary-overlay beg (posn-point end))
1101 (setq mouse-secondary-overlay (make-overlay beg (posn-point end))))
1102 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))))
947da0c4 1103
d89a4a47 1104(defun mouse-drag-secondary (start-event)
e66feb07 1105 "Set the secondary selection to the text that the mouse is dragged over.
d89a4a47 1106Highlight the drag area as you move the mouse.
efc10c97
RS
1107This must be bound to a button-down mouse event.
1108The function returns a non-nil value if it creates a secondary selection."
e66feb07 1109 (interactive "e")
d65147f6 1110 (mouse-minibuffer-check start-event)
4c9afcbe
RS
1111 (let* ((echo-keystrokes 0)
1112 (start-posn (event-start start-event))
d89a4a47
RS
1113 (start-point (posn-point start-posn))
1114 (start-window (posn-window start-posn))
1115 (start-frame (window-frame start-window))
1116 (bounds (window-edges start-window))
1117 (top (nth 1 bounds))
1118 (bottom (if (window-minibuffer-p start-window)
1119 (nth 3 bounds)
1120 ;; Don't count the mode line.
1121 (1- (nth 3 bounds))))
1122 (click-count (1- (event-click-count start-event))))
1123 (save-excursion
1124 (set-buffer (window-buffer start-window))
a94c7fcc 1125 (setq mouse-secondary-click-count click-count)
d89a4a47
RS
1126 (or mouse-secondary-overlay
1127 (setq mouse-secondary-overlay
1128 (make-overlay (point) (point))))
26d280b9 1129 (overlay-put mouse-secondary-overlay 'face 'secondary-selection)
9a974c88 1130 (if (> (mod click-count 3) 0)
26d280b9
RS
1131 ;; Double or triple press: make an initial selection
1132 ;; of one word or line.
d89a4a47
RS
1133 (let ((range (mouse-start-end start-point start-point click-count)))
1134 (set-marker mouse-secondary-start nil)
1135 (move-overlay mouse-secondary-overlay 1 1
1136 (window-buffer start-window))
1137 (move-overlay mouse-secondary-overlay (car range) (nth 1 range)
1138 (window-buffer start-window)))
26d280b9 1139 ;; Single-press: cancel any preexisting secondary selection.
d89a4a47
RS
1140 (or mouse-secondary-start
1141 (setq mouse-secondary-start (make-marker)))
1142 (set-marker mouse-secondary-start start-point)
1143 (delete-overlay mouse-secondary-overlay))
1144 (let (event end end-point)
1145 (track-mouse
1146 (while (progn
1147 (setq event (read-event))
1148 (or (mouse-movement-p event)
1149 (eq (car-safe event) 'switch-frame)))
1150
1151 (if (eq (car-safe event) 'switch-frame)
1152 nil
1153 (setq end (event-end event)
1154 end-point (posn-point end))
1155 (cond
d89a4a47
RS
1156 ;; Are we moving within the original window?
1157 ((and (eq (posn-window end) start-window)
1158 (integer-or-marker-p end-point))
d89a4a47
RS
1159 (let ((range (mouse-start-end start-point end-point
1160 click-count)))
0136e1e3
RS
1161 (if (or (/= start-point end-point)
1162 (null (marker-position mouse-secondary-start)))
1163 (progn
1164 (set-marker mouse-secondary-start nil)
1165 (move-overlay mouse-secondary-overlay
1166 (car range) (nth 1 range))))))
3b0aebe9
RS
1167 (t
1168 (let ((mouse-row (cdr (cdr (mouse-position)))))
1169 (cond
1170 ((null mouse-row))
1171 ((< mouse-row top)
e919a622
RS
1172 (mouse-scroll-subr start-window (- mouse-row top)
1173 mouse-secondary-overlay start-point))
d2287ded 1174 ((>= mouse-row bottom)
e919a622 1175 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
3b0aebe9 1176 mouse-secondary-overlay start-point)))))))))
d89a4a47 1177
4e399a53 1178 (if (consp event)
d89a4a47
RS
1179 (if (marker-position mouse-secondary-start)
1180 (save-window-excursion
1181 (delete-overlay mouse-secondary-overlay)
9a974c88 1182 (x-set-selection 'SECONDARY nil)
d89a4a47
RS
1183 (select-window start-window)
1184 (save-excursion
1185 (goto-char mouse-secondary-start)
efc10c97
RS
1186 (sit-for 1)
1187 nil))
9a974c88
RS
1188 (x-set-selection
1189 'SECONDARY
1190 (buffer-substring (overlay-start mouse-secondary-overlay)
1191 (overlay-end mouse-secondary-overlay)))))))))
e66feb07 1192
9a974c88 1193(defun mouse-yank-secondary (click)
50f58001
RS
1194 "Insert the secondary selection at the position clicked on.
1195Move point to the end of the inserted text.
1196If `mouse-yank-at-point' is non-nil, insert at point
1197regardless of where you click."
9a974c88 1198 (interactive "e")
33c448cd
RS
1199 ;; Give temporary modes such as isearch a chance to turn off.
1200 (run-hooks 'mouse-leave-buffer-hook)
50f58001
RS
1201 (or mouse-yank-at-point (mouse-set-point click))
1202 (insert (x-get-selection 'SECONDARY)))
9a974c88 1203
7e6404f6 1204(defun mouse-kill-secondary ()
9a974c88
RS
1205 "Kill the text in the secondary selection.
1206This is intended more as a keyboard command than as a mouse command
1207but it can work as either one.
1208
1209The current buffer (in case of keyboard use), or the buffer clicked on,
1210must be the one that the secondary selection is in. This requirement
1211is to prevent accidents."
7e6404f6
RS
1212 (interactive)
1213 (let* ((keys (this-command-keys))
1214 (click (elt keys (1- (length keys)))))
1215 (or (eq (overlay-buffer mouse-secondary-overlay)
1216 (if (listp click)
1217 (window-buffer (posn-window (event-start click)))
1218 (current-buffer)))
1219 (error "Select or click on the buffer where the secondary selection is")))
9dfab550
RS
1220 (let (this-command)
1221 (save-excursion
1222 (set-buffer (overlay-buffer mouse-secondary-overlay))
1223 (kill-region (overlay-start mouse-secondary-overlay)
1224 (overlay-end mouse-secondary-overlay))))
e66feb07 1225 (delete-overlay mouse-secondary-overlay)
9dfab550 1226;;; (x-set-selection 'SECONDARY nil)
e66feb07
RS
1227 (setq mouse-secondary-overlay nil))
1228
1229(defun mouse-secondary-save-then-kill (click)
d89a4a47 1230 "Save text to point in kill ring; the second time, kill the text.
7bbe2cc7
RS
1231You must use this in a buffer where you have recently done \\[mouse-start-secondary].
1232If the text between where you did \\[mouse-start-secondary] and where
1233you use this command matches the text at the front of the kill ring,
1234this command deletes the text.
e66feb07 1235Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
7bbe2cc7 1236which prepares for a second click with this command to delete the text.
d89a4a47 1237
7bbe2cc7
RS
1238If you have already made a secondary selection in that buffer,
1239this command extends or retracts the selection to where you click.
1240If you do this again in a different position, it extends or retracts
1241again. If you do this twice in the same position, it kills the selection."
e66feb07 1242 (interactive "e")
d65147f6 1243 (mouse-minibuffer-check click)
d89a4a47
RS
1244 (let ((posn (event-start click))
1245 (click-posn (posn-point (event-start click)))
e66feb07
RS
1246 ;; Don't let a subsequent kill command append to this one:
1247 ;; prevent setting this-command to kill-region.
1248 (this-command this-command))
9a974c88
RS
1249 (or (eq (window-buffer (posn-window posn))
1250 (or (and mouse-secondary-overlay
1251 (overlay-buffer mouse-secondary-overlay))
1252 (if mouse-secondary-start
1253 (marker-buffer mouse-secondary-start))))
1254 (error "Wrong buffer"))
1255 (save-excursion
1256 (set-buffer (window-buffer (posn-window posn)))
a94c7fcc 1257 (if (> (mod mouse-secondary-click-count 3) 0)
9a974c88
RS
1258 (if (not (and (eq last-command 'mouse-secondary-save-then-kill)
1259 (equal click-posn
1260 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
1261 ;; Find both ends of the object selected by this click.
1262 (let* ((range
1263 (mouse-start-end click-posn click-posn
a94c7fcc 1264 mouse-secondary-click-count)))
9a974c88
RS
1265 ;; Move whichever end is closer to the click.
1266 ;; That's what xterm does, and it seems reasonable.
1267 (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay)))
1268 (abs (- click-posn (overlay-end mouse-secondary-overlay))))
1269 (move-overlay mouse-secondary-overlay (car range)
1270 (overlay-end mouse-secondary-overlay))
d89a4a47
RS
1271 (move-overlay mouse-secondary-overlay
1272 (overlay-start mouse-secondary-overlay)
1273 (nth 1 range)))
9a974c88
RS
1274 ;; We have already put the old region in the kill ring.
1275 ;; Replace it with the extended region.
1276 ;; (It would be annoying to make a separate entry.)
f69140fd
KH
1277 (kill-new (buffer-substring
1278 (overlay-start mouse-secondary-overlay)
1279 (overlay-end mouse-secondary-overlay)) t)
9a974c88
RS
1280 ;; Arrange for a repeated mouse-3 to kill this region.
1281 (setq mouse-save-then-kill-posn
1282 (list (car kill-ring) (point) click-posn)))
1283 ;; If we click this button again without moving it,
1284 ;; that time kill.
d89a4a47 1285 (progn
9a974c88
RS
1286 (mouse-save-then-kill-delete-region
1287 (overlay-start mouse-secondary-overlay)
1288 (overlay-end mouse-secondary-overlay))
1289 (setq mouse-save-then-kill-posn nil)
a94c7fcc 1290 (setq mouse-secondary-click-count 0)
9a974c88
RS
1291 (delete-overlay mouse-secondary-overlay)))
1292 (if (and (eq last-command 'mouse-secondary-save-then-kill)
1293 mouse-save-then-kill-posn
1294 (eq (car mouse-save-then-kill-posn) (car kill-ring))
1295 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
1296 ;; If this is the second time we've called
1297 ;; mouse-secondary-save-then-kill, delete the text from the buffer.
1298 (progn
1299 (mouse-save-then-kill-delete-region
1300 (overlay-start mouse-secondary-overlay)
1301 (overlay-end mouse-secondary-overlay))
1302 (setq mouse-save-then-kill-posn nil)
1303 (delete-overlay mouse-secondary-overlay))
1304 (if (overlay-start mouse-secondary-overlay)
1305 ;; We have a selection, so adjust it.
1306 (progn
1307 (if (numberp click-posn)
1308 (progn
1309 ;; Move whichever end of the region is closer to the click.
1310 ;; That is what xterm does, and it seems reasonable.
1311 (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay)))
1312 (abs (- click-posn (overlay-end mouse-secondary-overlay))))
1313 (move-overlay mouse-secondary-overlay click-posn
1314 (overlay-end mouse-secondary-overlay))
d89a4a47
RS
1315 (move-overlay mouse-secondary-overlay
1316 (overlay-start mouse-secondary-overlay)
1317 click-posn))
9a974c88 1318 (setq deactivate-mark nil)))
0136e1e3 1319 (if (eq last-command 'mouse-secondary-save-then-kill)
f69140fd
KH
1320 ;; If the front of the kill ring comes from
1321 ;; an immediately previous use of this command,
1322 ;; replace it with the extended region.
1323 ;; (It would be annoying to make a separate entry.)
1324 (kill-new (buffer-substring
0136e1e3 1325 (overlay-start mouse-secondary-overlay)
f69140fd 1326 (overlay-end mouse-secondary-overlay)) t)
1fa01bcd
RS
1327 (let (deactivate-mark)
1328 (copy-region-as-kill (overlay-start mouse-secondary-overlay)
1329 (overlay-end mouse-secondary-overlay)))))
9a974c88
RS
1330 (if mouse-secondary-start
1331 ;; All we have is one end of a selection,
1332 ;; so put the other end here.
1333 (let ((start (+ 0 mouse-secondary-start)))
1334 (kill-ring-save start click-posn)
1335 (if mouse-secondary-overlay
1336 (move-overlay mouse-secondary-overlay start click-posn)
1337 (setq mouse-secondary-overlay (make-overlay start click-posn)))
1338 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))))
1339 (setq mouse-save-then-kill-posn
1340 (list (car kill-ring) (point) click-posn))))
fb28fd5b
RS
1341 (if (overlay-buffer mouse-secondary-overlay)
1342 (x-set-selection 'SECONDARY
9a974c88
RS
1343 (buffer-substring
1344 (overlay-start mouse-secondary-overlay)
1345 (overlay-end mouse-secondary-overlay)))))))
e66feb07 1346\f
0d9be91c 1347(defcustom mouse-buffer-menu-maxlen 20
f1107960
RS
1348 "*Number of buffers in one pane (submenu) of the buffer menu.
1349If we have lots of buffers, divide them into groups of
0d9be91c 1350`mouse-buffer-menu-maxlen' and make a pane (or submenu) for each one."
3b558d41
RS
1351 :type 'integer
1352 :group 'mouse)
f1107960 1353
3ca87c7b
RS
1354(defcustom mouse-buffer-menu-mode-mult 4
1355 "*Group the buffers by the major mode groups on \\[mouse-buffer-menu]?
1356This number which determines (in a hairy way) whether \\[mouse-buffer-menu]
1357will split the buffer menu by the major modes (see
1358`mouse-buffer-menu-mode-groups') or just by menu length.
1359Set to 1 (or even 0!) if you want to group by major mode always, and to
1360a large number if you prefer a mixed multitude. The default is 4."
1361 :type 'integer
1362 :group 'mouse
1363 :version "20.3")
1364
284a88a3
RS
1365(defvar mouse-buffer-menu-mode-groups
1366 '(("Info\\|Help\\|Apropos\\|Man" . "Help")
1367 ("\\bVM\\b\\|\\bMH\\b\\|Message\\|Mail\\|Group\\|Score\\|Summary\\|Article"
1368 . "Mail/News")
1369 ("\\<C\\>" . "C")
1370 ("ObjC" . "C")
1371 ("Text" . "Text")
1372 ("Outline" . "Text")
1373 ("Lisp" . "Lisp"))
1374 "How to group various major modes together in \\[mouse-buffer-menu].
1375Each element has the form (REGEXP . GROUPNAME).
1376If the major mode's name string matches REGEXP, use GROUPNAME instead.")
1377
8b34e79d 1378(defun mouse-buffer-menu (event)
2d82f7b9
RS
1379 "Pop up a menu of buffers for selection with the mouse.
1380This switches buffers in the window that you clicked on,
1381and selects that window."
ec558adc 1382 (interactive "e")
d65147f6 1383 (mouse-minibuffer-check event)
3ca87c7b 1384 (let ((buffers (buffer-list)) alist menu split-by-major-mode sum-of-squares)
284a88a3
RS
1385 ;; Make an alist of elements that look like (MENU-ITEM . BUFFER).
1386 (let ((tail buffers))
1387 (while tail
1388 ;; Divide all buffers into buckets for various major modes.
1389 ;; Each bucket looks like (MODE NAMESTRING BUFFERS...).
1390 (with-current-buffer (car tail)
1391 (let* ((adjusted-major-mode major-mode) elt)
1392 (let ((tail mouse-buffer-menu-mode-groups))
1393 (while tail
1394 (if (string-match (car (car tail)) mode-name)
1395 (setq adjusted-major-mode (cdr (car tail))))
1396 (setq tail (cdr tail))))
1397 (setq elt (assoc adjusted-major-mode split-by-major-mode))
1398 (if (null elt)
1399 (setq elt (list adjusted-major-mode
1400 (if (stringp adjusted-major-mode)
1401 adjusted-major-mode
1402 mode-name))
1403 split-by-major-mode (cons elt split-by-major-mode)))
1404 (or (memq (car tail) (cdr (cdr elt)))
1405 (setcdr (cdr elt) (cons (car tail) (cdr (cdr elt)))))))
1406 (setq tail (cdr tail))))
1407 ;; Compute the sum of squares of sizes of the major-mode buckets.
1408 (let ((tail split-by-major-mode))
1409 (setq sum-of-squares 0)
1410 (while tail
1411 (setq sum-of-squares
1412 (+ sum-of-squares
3ca87c7b 1413 (let ((len (length (cdr (cdr (car tail)))))) (* len len))))
284a88a3 1414 (setq tail (cdr tail))))
3ca87c7b
RS
1415 (if (< (* sum-of-squares mouse-buffer-menu-mode-mult)
1416 (* (length buffers) (length buffers)))
284a88a3
RS
1417 ;; Subdividing by major modes really helps, so let's do it.
1418 (let (subdivided-menus (buffers-left (length buffers)))
1419 ;; Sort the list to put the most popular major modes first.
1420 (setq split-by-major-mode
1421 (sort split-by-major-mode
1422 (function (lambda (elt1 elt2)
1423 (> (length elt1) (length elt2))))))
1424 ;; Make a separate submenu for each major mode
1425 ;; that has more than one buffer,
1426 ;; unless all the remaining buffers are less than 1/10 of them.
1427 (while (and split-by-major-mode
1428 (and (> (length (car split-by-major-mode)) 3)
1429 (> (* buffers-left 10) (length buffers))))
1430 (setq subdivided-menus
1431 (cons (cons
1432 (nth 1 (car split-by-major-mode))
1433 (mouse-buffer-menu-alist
1434 (cdr (cdr (car split-by-major-mode)))))
1435 subdivided-menus))
1436 (setq buffers-left
1437 (- buffers-left (length (cdr (car split-by-major-mode)))))
1438 (setq split-by-major-mode (cdr split-by-major-mode)))
1439 ;; If any major modes are left over,
1440 ;; make a single submenu for them.
1441 (if split-by-major-mode
1442 (setq subdivided-menus
1443 (cons (cons
1444 "Others"
1445 (mouse-buffer-menu-alist
3ca87c7b
RS
1446 ;; we don't need split-by-major-mode any
1447 ;; more, so we can ditch it with nconc.
1448 (apply 'nconc (mapcar 'cddr split-by-major-mode))))
284a88a3 1449 subdivided-menus)))
3ca87c7b 1450 (setq menu (cons "Buffer Menu" (nreverse subdivided-menus))))
284a88a3
RS
1451 (progn
1452 (setq alist (mouse-buffer-menu-alist buffers))
1453 (setq menu (cons "Buffer Menu"
1454 (mouse-buffer-menu-split "Select Buffer" alist)))))
2d82f7b9
RS
1455 (let ((buf (x-popup-menu event menu))
1456 (window (posn-window (event-start event))))
3ca87c7b 1457 (when buf
c0bb9f3b 1458 (or (framep window) (select-window window))
3ca87c7b 1459 (switch-to-buffer buf)))))
284a88a3
RS
1460
1461(defun mouse-buffer-menu-alist (buffers)
1462 (let (tail
1463 (maxlen 0)
1464 head)
1465 (setq buffers
1466 (sort buffers
1467 (function (lambda (elt1 elt2)
1468 (string< (buffer-name elt1) (buffer-name elt2))))))
1469 (setq tail buffers)
1470 (while tail
1471 (or (eq ?\ (aref (buffer-name (car tail)) 0))
1472 (setq maxlen
1473 (max maxlen
1474 (length (buffer-name (car tail))))))
1475 (setq tail (cdr tail)))
1476 (setq tail buffers)
1477 (while tail
1478 (let ((elt (car tail)))
1479 (if (/= (aref (buffer-name elt) 0) ?\ )
1480 (setq head
1481 (cons
1482 (cons
1483 (format
1484 (format "%%%ds %%s%%s %%s" maxlen)
1485 (buffer-name elt)
1486 (if (buffer-modified-p elt) "*" " ")
1487 (save-excursion
1488 (set-buffer elt)
1489 (if buffer-read-only "%" " "))
1490 (or (buffer-file-name elt)
1491 (save-excursion
1492 (set-buffer elt)
1493 (if list-buffers-directory
1494 (expand-file-name
1495 list-buffers-directory)))
1496 ""))
1497 elt)
1498 head))))
1499 (setq tail (cdr tail)))
1500 ;; Compensate for the reversal that the above loop does.
1501 (nreverse head)))
1502
1503(defun mouse-buffer-menu-split (title alist)
1504 ;; If we have lots of buffers, divide them into groups of 20
1505 ;; and make a pane (or submenu) for each one.
0d9be91c 1506 (if (> (length alist) (/ (* mouse-buffer-menu-maxlen 3) 2))
284a88a3
RS
1507 (let ((alist alist) sublists next
1508 (i 1))
1509 (while alist
0d9be91c 1510 ;; Pull off the next mouse-buffer-menu-maxlen buffers
284a88a3 1511 ;; and make them the next element of sublist.
0d9be91c 1512 (setq next (nthcdr mouse-buffer-menu-maxlen alist))
284a88a3 1513 (if next
0d9be91c 1514 (setcdr (nthcdr (1- mouse-buffer-menu-maxlen) alist)
284a88a3
RS
1515 nil))
1516 (setq sublists (cons (cons (format "Buffers %d" i) alist)
1517 sublists))
1518 (setq i (1+ i))
1519 (setq alist next))
1520 (nreverse sublists))
1521 ;; Few buffers--put them all in one pane.
1522 (list (cons title alist))))
72ea54a4 1523\f
5ba2dc3f 1524;;; These need to be rewritten for the new scroll bar implementation.
dbc4e1c1
JB
1525
1526;;;!! ;; Commands for the scroll bar.
1527;;;!!
1528;;;!! (defun mouse-scroll-down (click)
1529;;;!! (interactive "@e")
1530;;;!! (scroll-down (1+ (cdr (mouse-coords click)))))
1531;;;!!
1532;;;!! (defun mouse-scroll-up (click)
1533;;;!! (interactive "@e")
1534;;;!! (scroll-up (1+ (cdr (mouse-coords click)))))
1535;;;!!
1536;;;!! (defun mouse-scroll-down-full ()
1537;;;!! (interactive "@")
1538;;;!! (scroll-down nil))
1539;;;!!
1540;;;!! (defun mouse-scroll-up-full ()
1541;;;!! (interactive "@")
1542;;;!! (scroll-up nil))
1543;;;!!
1544;;;!! (defun mouse-scroll-move-cursor (click)
1545;;;!! (interactive "@e")
1546;;;!! (move-to-window-line (1+ (cdr (mouse-coords click)))))
1547;;;!!
1548;;;!! (defun mouse-scroll-absolute (event)
1549;;;!! (interactive "@e")
1550;;;!! (let* ((pos (car event))
1551;;;!! (position (car pos))
1552;;;!! (length (car (cdr pos))))
1553;;;!! (if (<= length 0) (setq length 1))
1554;;;!! (let* ((scale-factor (max 1 (/ length (/ 8000000 (buffer-size)))))
1555;;;!! (newpos (* (/ (* (/ (buffer-size) scale-factor)
1556;;;!! position)
1557;;;!! length)
1558;;;!! scale-factor)))
1559;;;!! (goto-char newpos)
1560;;;!! (recenter '(4)))))
1561;;;!!
1562;;;!! (defun mouse-scroll-left (click)
1563;;;!! (interactive "@e")
1564;;;!! (scroll-left (1+ (car (mouse-coords click)))))
1565;;;!!
1566;;;!! (defun mouse-scroll-right (click)
1567;;;!! (interactive "@e")
1568;;;!! (scroll-right (1+ (car (mouse-coords click)))))
1569;;;!!
1570;;;!! (defun mouse-scroll-left-full ()
1571;;;!! (interactive "@")
1572;;;!! (scroll-left nil))
1573;;;!!
1574;;;!! (defun mouse-scroll-right-full ()
1575;;;!! (interactive "@")
1576;;;!! (scroll-right nil))
1577;;;!!
1578;;;!! (defun mouse-scroll-move-cursor-horizontally (click)
1579;;;!! (interactive "@e")
1580;;;!! (move-to-column (1+ (car (mouse-coords click)))))
1581;;;!!
1582;;;!! (defun mouse-scroll-absolute-horizontally (event)
1583;;;!! (interactive "@e")
1584;;;!! (let* ((pos (car event))
1585;;;!! (position (car pos))
1586;;;!! (length (car (cdr pos))))
1587;;;!! (set-window-hscroll (selected-window) 33)))
1588;;;!!
1589;;;!! (global-set-key [scroll-bar mouse-1] 'mouse-scroll-up)
1590;;;!! (global-set-key [scroll-bar mouse-2] 'mouse-scroll-absolute)
1591;;;!! (global-set-key [scroll-bar mouse-3] 'mouse-scroll-down)
1592;;;!!
1593;;;!! (global-set-key [vertical-slider mouse-1] 'mouse-scroll-move-cursor)
1594;;;!! (global-set-key [vertical-slider mouse-2] 'mouse-scroll-move-cursor)
1595;;;!! (global-set-key [vertical-slider mouse-3] 'mouse-scroll-move-cursor)
1596;;;!!
1597;;;!! (global-set-key [thumbup mouse-1] 'mouse-scroll-up-full)
1598;;;!! (global-set-key [thumbup mouse-2] 'mouse-scroll-up-full)
1599;;;!! (global-set-key [thumbup mouse-3] 'mouse-scroll-up-full)
1600;;;!!
1601;;;!! (global-set-key [thumbdown mouse-1] 'mouse-scroll-down-full)
1602;;;!! (global-set-key [thumbdown mouse-2] 'mouse-scroll-down-full)
1603;;;!! (global-set-key [thumbdown mouse-3] 'mouse-scroll-down-full)
1604;;;!!
1605;;;!! (global-set-key [horizontal-scroll-bar mouse-1] 'mouse-scroll-left)
1606;;;!! (global-set-key [horizontal-scroll-bar mouse-2]
1607;;;!! 'mouse-scroll-absolute-horizontally)
1608;;;!! (global-set-key [horizontal-scroll-bar mouse-3] 'mouse-scroll-right)
1609;;;!!
1610;;;!! (global-set-key [horizontal-slider mouse-1]
1611;;;!! 'mouse-scroll-move-cursor-horizontally)
1612;;;!! (global-set-key [horizontal-slider mouse-2]
1613;;;!! 'mouse-scroll-move-cursor-horizontally)
1614;;;!! (global-set-key [horizontal-slider mouse-3]
1615;;;!! 'mouse-scroll-move-cursor-horizontally)
1616;;;!!
1617;;;!! (global-set-key [thumbleft mouse-1] 'mouse-scroll-left-full)
1618;;;!! (global-set-key [thumbleft mouse-2] 'mouse-scroll-left-full)
1619;;;!! (global-set-key [thumbleft mouse-3] 'mouse-scroll-left-full)
1620;;;!!
1621;;;!! (global-set-key [thumbright mouse-1] 'mouse-scroll-right-full)
1622;;;!! (global-set-key [thumbright mouse-2] 'mouse-scroll-right-full)
1623;;;!! (global-set-key [thumbright mouse-3] 'mouse-scroll-right-full)
1624;;;!!
1625;;;!! (global-set-key [horizontal-scroll-bar S-mouse-2]
1626;;;!! 'mouse-split-window-horizontally)
1627;;;!! (global-set-key [mode-line S-mouse-2]
1628;;;!! 'mouse-split-window-horizontally)
1629;;;!! (global-set-key [vertical-scroll-bar S-mouse-2]
1630;;;!! 'mouse-split-window)
6b2154de 1631\f
dbc4e1c1
JB
1632;;;!! ;;;;
1633;;;!! ;;;; Here are experimental things being tested. Mouse events
1634;;;!! ;;;; are of the form:
1635;;;!! ;;;; ((x y) window screen-part key-sequence timestamp)
1636;;;!! ;;
1637;;;!! ;;;;
1638;;;!! ;;;; Dynamically track mouse coordinates
1639;;;!! ;;;;
1640;;;!! ;;
1641;;;!! ;;(defun track-mouse (event)
1642;;;!! ;; "Track the coordinates, absolute and relative, of the mouse."
1643;;;!! ;; (interactive "@e")
1644;;;!! ;; (while mouse-grabbed
1645;;;!! ;; (let* ((pos (read-mouse-position (selected-screen)))
1646;;;!! ;; (abs-x (car pos))
1647;;;!! ;; (abs-y (cdr pos))
1648;;;!! ;; (relative-coordinate (coordinates-in-window-p
1649;;;!! ;; (list (car pos) (cdr pos))
1650;;;!! ;; (selected-window))))
1651;;;!! ;; (if (consp relative-coordinate)
1652;;;!! ;; (message "mouse: [%d %d], (%d %d)" abs-x abs-y
1653;;;!! ;; (car relative-coordinate)
1654;;;!! ;; (car (cdr relative-coordinate)))
1655;;;!! ;; (message "mouse: [%d %d]" abs-x abs-y)))))
1656;;;!!
1657;;;!! ;;
1658;;;!! ;; Dynamically put a box around the line indicated by point
1659;;;!! ;;
1660;;;!! ;;
1661;;;!! ;;(require 'backquote)
1662;;;!! ;;
1663;;;!! ;;(defun mouse-select-buffer-line (event)
1664;;;!! ;; (interactive "@e")
1665;;;!! ;; (let ((relative-coordinate
1666;;;!! ;; (coordinates-in-window-p (car event) (selected-window)))
1667;;;!! ;; (abs-y (car (cdr (car event)))))
1668;;;!! ;; (if (consp relative-coordinate)
1669;;;!! ;; (progn
1670;;;!! ;; (save-excursion
1671;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1672;;;!! ;; (x-draw-rectangle
1673;;;!! ;; (selected-screen)
1674;;;!! ;; abs-y 0
1675;;;!! ;; (save-excursion
1676;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1677;;;!! ;; (end-of-line)
1678;;;!! ;; (push-mark nil t)
1679;;;!! ;; (beginning-of-line)
1680;;;!! ;; (- (region-end) (region-beginning))) 1))
1681;;;!! ;; (sit-for 1)
1682;;;!! ;; (x-erase-rectangle (selected-screen))))))
1683;;;!! ;;
1684;;;!! ;;(defvar last-line-drawn nil)
1685;;;!! ;;(defvar begin-delim "[^ \t]")
1686;;;!! ;;(defvar end-delim "[^ \t]")
1687;;;!! ;;
1688;;;!! ;;(defun mouse-boxing (event)
1689;;;!! ;; (interactive "@e")
1690;;;!! ;; (save-excursion
1691;;;!! ;; (let ((screen (selected-screen)))
1692;;;!! ;; (while (= (x-mouse-events) 0)
1693;;;!! ;; (let* ((pos (read-mouse-position screen))
1694;;;!! ;; (abs-x (car pos))
1695;;;!! ;; (abs-y (cdr pos))
1696;;;!! ;; (relative-coordinate
1697;;;!! ;; (coordinates-in-window-p (` ((, abs-x) (, abs-y)))
1698;;;!! ;; (selected-window)))
1699;;;!! ;; (begin-reg nil)
1700;;;!! ;; (end-reg nil)
1701;;;!! ;; (end-column nil)
1702;;;!! ;; (begin-column nil))
1703;;;!! ;; (if (and (consp relative-coordinate)
1704;;;!! ;; (or (not last-line-drawn)
1705;;;!! ;; (not (= last-line-drawn abs-y))))
1706;;;!! ;; (progn
1707;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1708;;;!! ;; (if (= (following-char) 10)
1709;;;!! ;; ()
1710;;;!! ;; (progn
1711;;;!! ;; (setq begin-reg (1- (re-search-forward end-delim)))
1712;;;!! ;; (setq begin-column (1- (current-column)))
1713;;;!! ;; (end-of-line)
1714;;;!! ;; (setq end-reg (1+ (re-search-backward begin-delim)))
1715;;;!! ;; (setq end-column (1+ (current-column)))
1716;;;!! ;; (message "%s" (buffer-substring begin-reg end-reg))
1717;;;!! ;; (x-draw-rectangle screen
1718;;;!! ;; (setq last-line-drawn abs-y)
1719;;;!! ;; begin-column
1720;;;!! ;; (- end-column begin-column) 1))))))))))
1721;;;!! ;;
1722;;;!! ;;(defun mouse-erase-box ()
1723;;;!! ;; (interactive)
1724;;;!! ;; (if last-line-drawn
1725;;;!! ;; (progn
1726;;;!! ;; (x-erase-rectangle (selected-screen))
1727;;;!! ;; (setq last-line-drawn nil))))
1728;;;!!
1729;;;!! ;;; (defun test-x-rectangle ()
1730;;;!! ;;; (use-local-mouse-map (setq rectangle-test-map (make-sparse-keymap)))
1731;;;!! ;;; (define-key rectangle-test-map mouse-motion-button-left 'mouse-boxing)
1732;;;!! ;;; (define-key rectangle-test-map mouse-button-left-up 'mouse-erase-box))
1733;;;!!
1734;;;!! ;;
1735;;;!! ;; Here is how to do double clicking in lisp. About to change.
1736;;;!! ;;
1737;;;!!
1738;;;!! (defvar double-start nil)
1739;;;!! (defconst double-click-interval 300
1740;;;!! "Max ticks between clicks")
1741;;;!!
1742;;;!! (defun double-down (event)
1743;;;!! (interactive "@e")
1744;;;!! (if double-start
1745;;;!! (let ((interval (- (nth 4 event) double-start)))
1746;;;!! (if (< interval double-click-interval)
1747;;;!! (progn
1748;;;!! (backward-up-list 1)
1749;;;!! ;; (message "Interval %d" interval)
1750;;;!! (sleep-for 1)))
1751;;;!! (setq double-start nil))
1752;;;!! (setq double-start (nth 4 event))))
1753;;;!!
1754;;;!! (defun double-up (event)
1755;;;!! (interactive "@e")
1756;;;!! (and double-start
1757;;;!! (> (- (nth 4 event ) double-start) double-click-interval)
1758;;;!! (setq double-start nil)))
1759;;;!!
1760;;;!! ;;; (defun x-test-doubleclick ()
1761;;;!! ;;; (use-local-mouse-map (setq doubleclick-test-map (make-sparse-keymap)))
1762;;;!! ;;; (define-key doubleclick-test-map mouse-button-left 'double-down)
1763;;;!! ;;; (define-key doubleclick-test-map mouse-button-left-up 'double-up))
1764;;;!!
1765;;;!! ;;
5ba2dc3f 1766;;;!! ;; This scrolls while button is depressed. Use preferable in scroll bar.
dbc4e1c1
JB
1767;;;!! ;;
1768;;;!!
1769;;;!! (defvar scrolled-lines 0)
1770;;;!! (defconst scroll-speed 1)
1771;;;!!
1772;;;!! (defun incr-scroll-down (event)
1773;;;!! (interactive "@e")
1774;;;!! (setq scrolled-lines 0)
1775;;;!! (incremental-scroll scroll-speed))
1776;;;!!
1777;;;!! (defun incr-scroll-up (event)
1778;;;!! (interactive "@e")
1779;;;!! (setq scrolled-lines 0)
1780;;;!! (incremental-scroll (- scroll-speed)))
1781;;;!!
1782;;;!! (defun incremental-scroll (n)
1783;;;!! (while (= (x-mouse-events) 0)
1784;;;!! (setq scrolled-lines (1+ (* scroll-speed scrolled-lines)))
1785;;;!! (scroll-down n)
1786;;;!! (sit-for 300 t)))
1787;;;!!
1788;;;!! (defun incr-scroll-stop (event)
1789;;;!! (interactive "@e")
1790;;;!! (message "Scrolled %d lines" scrolled-lines)
1791;;;!! (setq scrolled-lines 0)
1792;;;!! (sleep-for 1))
1793;;;!!
1794;;;!! ;;; (defun x-testing-scroll ()
1795;;;!! ;;; (let ((scrolling-map (function mouse-vertical-scroll-bar-prefix)))
1796;;;!! ;;; (define-key scrolling-map mouse-button-left 'incr-scroll-down)
1797;;;!! ;;; (define-key scrolling-map mouse-button-right 'incr-scroll-up)
1798;;;!! ;;; (define-key scrolling-map mouse-button-left-up 'incr-scroll-stop)
1799;;;!! ;;; (define-key scrolling-map mouse-button-right-up 'incr-scroll-stop)))
1800;;;!!
1801;;;!! ;;
1802;;;!! ;; Some playthings suitable for picture mode? They need work.
1803;;;!! ;;
1804;;;!!
1805;;;!! (defun mouse-kill-rectangle (event)
1806;;;!! "Kill the rectangle between point and the mouse cursor."
1807;;;!! (interactive "@e")
1808;;;!! (let ((point-save (point)))
1809;;;!! (save-excursion
1810;;;!! (mouse-set-point event)
1811;;;!! (push-mark nil t)
1812;;;!! (if (> point-save (point))
1813;;;!! (kill-rectangle (point) point-save)
1814;;;!! (kill-rectangle point-save (point))))))
1815;;;!!
1816;;;!! (defun mouse-open-rectangle (event)
1817;;;!! "Kill the rectangle between point and the mouse cursor."
1818;;;!! (interactive "@e")
1819;;;!! (let ((point-save (point)))
1820;;;!! (save-excursion
1821;;;!! (mouse-set-point event)
1822;;;!! (push-mark nil t)
1823;;;!! (if (> point-save (point))
1824;;;!! (open-rectangle (point) point-save)
1825;;;!! (open-rectangle point-save (point))))))
1826;;;!!
1827;;;!! ;; Must be a better way to do this.
1828;;;!!
1829;;;!! (defun mouse-multiple-insert (n char)
1830;;;!! (while (> n 0)
1831;;;!! (insert char)
1832;;;!! (setq n (1- n))))
1833;;;!!
1834;;;!! ;; What this could do is not finalize until button was released.
1835;;;!!
1836;;;!! (defun mouse-move-text (event)
1837;;;!! "Move text from point to cursor position, inserting spaces."
1838;;;!! (interactive "@e")
1839;;;!! (let* ((relative-coordinate
1840;;;!! (coordinates-in-window-p (car event) (selected-window))))
1841;;;!! (if (consp relative-coordinate)
1842;;;!! (cond ((> (current-column) (car relative-coordinate))
1843;;;!! (delete-char
1844;;;!! (- (car relative-coordinate) (current-column))))
1845;;;!! ((< (current-column) (car relative-coordinate))
1846;;;!! (mouse-multiple-insert
1847;;;!! (- (car relative-coordinate) (current-column)) " "))
1848;;;!! ((= (current-column) (car relative-coordinate)) (ding))))))
07a78410 1849\f
f936ae06
RS
1850;; Choose a completion with the mouse.
1851
1852(defun mouse-choose-completion (event)
49e61c42 1853 "Click on an alternative in the `*Completions*' buffer to choose it."
f936ae06 1854 (interactive "e")
33c448cd
RS
1855 ;; Give temporary modes such as isearch a chance to turn off.
1856 (run-hooks 'mouse-leave-buffer-hook)
d89a4a47 1857 (let ((buffer (window-buffer))
02680e9b
RS
1858 choice
1859 base-size)
f936ae06
RS
1860 (save-excursion
1861 (set-buffer (window-buffer (posn-window (event-start event))))
f36f4e9e
RS
1862 (if completion-reference-buffer
1863 (setq buffer completion-reference-buffer))
02680e9b 1864 (setq base-size completion-base-size)
f936ae06
RS
1865 (save-excursion
1866 (goto-char (posn-point (event-start event)))
b6be5d95 1867 (let (beg end)
9a43a594
RS
1868 (if (and (not (eobp)) (get-text-property (point) 'mouse-face))
1869 (setq end (point) beg (1+ (point))))
1870 (if (null beg)
1871 (error "No completion here"))
1872 (setq beg (previous-single-property-change beg 'mouse-face))
2f5ed2e8
RS
1873 (setq end (or (next-single-property-change end 'mouse-face)
1874 (point-max)))
b6be5d95 1875 (setq choice (buffer-substring beg end)))))
73e2025f
RS
1876 (let ((owindow (selected-window)))
1877 (select-window (posn-window (event-start event)))
874a2cbd
RS
1878 (if (and (one-window-p t 'selected-frame)
1879 (window-dedicated-p (selected-window)))
1880 ;; This is a special buffer's frame
1881 (iconify-frame (selected-frame))
1882 (or (window-dedicated-p (selected-window))
1883 (bury-buffer)))
73e2025f 1884 (select-window owindow))
02680e9b 1885 (choose-completion-string choice buffer base-size)))
f936ae06 1886\f
07a78410
RS
1887;; Font selection.
1888
0eb9fef3
RS
1889(defun font-menu-add-default ()
1890 (let* ((default (cdr (assq 'font (frame-parameters (selected-frame)))))
1891 (font-alist x-fixed-font-alist)
0d94f5ca 1892 (elt (or (assoc "Misc" font-alist) (nth 1 font-alist))))
0eb9fef3
RS
1893 (if (assoc "Default" elt)
1894 (delete (assoc "Default" elt) elt))
1895 (setcdr elt
6b8e486e 1896 (cons (list "Default" default)
0eb9fef3
RS
1897 (cdr elt)))))
1898
07a78410
RS
1899(defvar x-fixed-font-alist
1900 '("Font menu"
1901 ("Misc"
19d973e8
RS
1902 ;; For these, we specify the pixel height and width.
1903 ("fixed" "fixed")
1904 ("6x10" "-misc-fixed-medium-r-normal--10-*-*-*-c-60-iso8859-1" "6x10")
1905 ("6x12"
1906 "-misc-fixed-medium-r-semicondensed--12-*-*-*-c-60-iso8859-1" "6x12")
1907 ("6x13"
1908 "-misc-fixed-medium-r-semicondensed--13-*-*-*-c-60-iso8859-1" "6x13")
1909 ("7x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-70-iso8859-1" "7x13")
1910 ("7x14" "-misc-fixed-medium-r-normal--14-*-*-*-c-70-iso8859-1" "7x14")
1911 ("8x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-80-iso8859-1" "8x13")
1912 ("9x15" "-misc-fixed-medium-r-normal--15-*-*-*-c-90-iso8859-1" "9x15")
1913 ("10x20" "-misc-fixed-medium-r-normal--20-*-*-*-c-100-iso8859-1" "10x20")
1914 ("11x18" "-misc-fixed-medium-r-normal--18-*-*-*-c-110-iso8859-1" "11x18")
1915 ("12x24" "-misc-fixed-medium-r-normal--24-*-*-*-c-120-iso8859-1" "12x24")
fa21fdec 1916 ("")
f29c3695
RS
1917 ("clean 5x8"
1918 "-schumacher-clean-medium-r-normal--8-*-*-*-c-50-iso8859-1")
1919 ("clean 6x8"
1920 "-schumacher-clean-medium-r-normal--8-*-*-*-c-60-iso8859-1")
19d973e8
RS
1921 ("clean 8x8"
1922 "-schumacher-clean-medium-r-normal--8-*-*-*-c-80-iso8859-1")
1923 ("clean 8x10"
1924 "-schumacher-clean-medium-r-normal--10-*-*-*-c-80-iso8859-1")
1925 ("clean 8x14"
1926 "-schumacher-clean-medium-r-normal--14-*-*-*-c-80-iso8859-1")
1927 ("clean 8x16"
1928 "-schumacher-clean-medium-r-normal--16-*-*-*-c-80-iso8859-1")
fa21fdec 1929 ("")
29a3028d 1930 ("sony 8x16" "-sony-fixed-medium-r-normal--16-*-*-*-c-80-iso8859-1")
07a78410
RS
1931;;; We don't seem to have these; who knows what they are.
1932;;; ("fg-18" "fg-18")
1933;;; ("fg-25" "fg-25")
29a3028d
DL
1934 ("lucidasanstypewriter-12" "-b&h-lucidatypewriter-medium-r-normal-sans-*-120-*-*-*-*-iso8859-1")
1935 ("lucidasanstypewriter-bold-14" "-b&h-lucidatypewriter-bold-r-normal-sans-*-140-*-*-*-*-iso8859-1")
1936 ("lucidasanstypewriter-bold-24"
1937 "-b&h-lucidatypewriter-bold-r-normal-sans-*-240-*-*-*-*-iso8859-1")
07a78410
RS
1938;;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
1939;;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
29a3028d 1940 )
07a78410 1941 ("Courier"
19d973e8 1942 ;; For these, we specify the point height.
82c048a9
RS
1943 ("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1")
1944 ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1")
1945 ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1")
1946 ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1")
1947 ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1")
1948 ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1")
1949 ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1")
1950 ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1")
1951 ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1")
1952 ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1")
1953 ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1")
1954 ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1")
1955 ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1")
1956 ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1")
1957 ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1")
1958 ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1")
1959 ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1")
1960 ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1")
1961 ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1")
1962 ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1")
1963 ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1")
1964 ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1")
1965 ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1")
1966 ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1"))
07a78410
RS
1967 )
1968 "X fonts suitable for use in Emacs.")
1969
1900a92b 1970(defun mouse-set-font (&rest fonts)
51a02226 1971 "Select an emacs font from a list of known good fonts and fontsets."
07a78410 1972 (interactive
51a02226
KH
1973 (x-popup-menu
1974 last-nonmenu-event
1975 ;; Append list of fontsets currently defined.
1976 (append x-fixed-font-alist (list (generate-fontset-menu)))))
df4de8c6
KH
1977 (if fonts
1978 (let (font)
1979 (while fonts
1980 (condition-case nil
1981 (progn
3fadec1a 1982 (set-default-font (car fonts))
df4de8c6
KH
1983 (setq font (car fonts))
1984 (setq fonts nil))
3fadec1a
RS
1985 (error
1986 (setq fonts (cdr fonts)))))
df4de8c6 1987 (if (null font)
3fadec1a 1988 (error "Font not found")))))
cc0a8174
JB
1989\f
1990;;; Bindings for mouse commands.
1991
fcfc3c63 1992(define-key global-map [down-mouse-1] 'mouse-drag-region)
dbc4e1c1 1993(global-set-key [mouse-1] 'mouse-set-point)
dbc4e1c1 1994(global-set-key [drag-mouse-1] 'mouse-set-region)
fcfc3c63 1995
e37de120
RS
1996;; These are tested for in mouse-drag-region.
1997(global-set-key [double-mouse-1] 'mouse-set-point)
1998(global-set-key [triple-mouse-1] 'mouse-set-point)
1999
dbc4e1c1
JB
2000(global-set-key [mouse-2] 'mouse-yank-at-click)
2001(global-set-key [mouse-3] 'mouse-save-then-kill)
8b34e79d 2002
dbc4e1c1
JB
2003;; By binding these to down-going events, we let the user use the up-going
2004;; event to make the selection, saving a click.
08a1c178
RS
2005(global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
2006(if (not (eq system-type 'ms-dos))
2007 (global-set-key [S-down-mouse-1] 'mouse-set-font))
eef805d7 2008;; C-down-mouse-2 is bound in facemenu.el.
95132d1c
RS
2009(global-set-key [C-down-mouse-3] 'mouse-major-mode-menu)
2010
07a78410 2011
8b34e79d
RS
2012;; Replaced with dragging mouse-1
2013;; (global-set-key [S-mouse-1] 'mouse-set-mark)
947da0c4 2014
3c2dd2c0 2015(global-set-key [mode-line mouse-1] 'mouse-select-window)
544e7e73
RS
2016(global-set-key [mode-line drag-mouse-1] 'mouse-select-window)
2017(global-set-key [mode-line down-mouse-1] 'mouse-drag-mode-line)
3c2dd2c0 2018(global-set-key [mode-line mouse-2] 'mouse-delete-other-windows)
dbc4e1c1 2019(global-set-key [mode-line mouse-3] 'mouse-delete-window)
3c2dd2c0 2020(global-set-key [mode-line C-mouse-2] 'mouse-split-window-horizontally)
9926ab64 2021(global-set-key [vertical-scroll-bar C-mouse-2] 'mouse-split-window-vertically)
b6522df6 2022(global-set-key [vertical-line C-mouse-2] 'mouse-split-window-vertically)
08a1c178
RS
2023(global-set-key [vertical-line down-mouse-1] 'mouse-drag-vertical-line)
2024(global-set-key [vertical-line mouse-1] 'mouse-select-window)
49116ac0
JB
2025
2026(provide 'mouse)
2027
2fe85227
DL
2028;; This file contains the functionality of the old mldrag.el.
2029(defalias 'mldrag-drag-mode-line 'mouse-drag-mode-line)
2030(defalias 'mldrag-drag-vertical-line 'mouse-drag-vertical-line)
2031(make-obsolete 'mldrag-drag-mode-line 'mouse-drag-mode-line)
2032(make-obsolete 'mldrag-drag-vertical-line 'mouse-drag-vertical-line)
2033(provide 'mldrag)
2034
6594deb0 2035;;; mouse.el ends here