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