HideIfDef mode bug fixes and enhancements. This is #2 of 3 patches based
[bpt/emacs.git] / lisp / mouse.el
CommitLineData
e1894109 1;;; mouse.el --- window system-independent mouse support -*- lexical-binding: t -*-
84176303 2
ba318903 3;; Copyright (C) 1993-1995, 1999-2014 Free Software Foundation, Inc.
eea8d4ef 4
34dc21db 5;; Maintainer: emacs-devel@gnu.org
de420e82 6;; Keywords: hardware, mouse
bd78fa1d 7;; Package: emacs
84176303 8
be010748 9;; This file is part of GNU Emacs.
72ea54a4 10
eb3fa2cf 11;; GNU Emacs is free software: you can redistribute it and/or modify
be010748 12;; it under the terms of the GNU General Public License as published by
eb3fa2cf
GM
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) 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
eb3fa2cf 22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
72ea54a4 23
edbd2f74
ER
24;;; Commentary:
25
26;; This package provides various useful commands (including help
27;; system access) through the mouse. All this code assumes that mouse
28;; interpretation has been abstracted into Emacs input events.
edbd2f74 29
aae56ea7
ER
30;;; Code:
31
cc0a8174 32;;; Utility functions.
72ea54a4 33
ad0d18af 34;; Indent track-mouse like progn.
cc0a8174 35(put 'track-mouse 'lisp-indent-function 0)
72ea54a4 36
3b558d41 37(defcustom mouse-yank-at-point nil
9201cc28 38 "If non-nil, mouse yank commands yank at point instead of at click."
3b558d41
RS
39 :type 'boolean
40 :group 'mouse)
b2dae92a 41
f9d71b42 42(defcustom mouse-drag-copy-region nil
93d68d4f
DDLHG
43 "If non-nil, copy to kill-ring upon mouse adjustments of the region.
44
45This affects `mouse-save-then-kill' (\\[mouse-save-then-kill]) in
46addition to mouse drags."
b2dae92a 47 :type 'boolean
2490cbbc 48 :version "24.1"
b2dae92a
KS
49 :group 'mouse)
50
5dbda518 51(defcustom mouse-1-click-follows-link 450
787e24c3 52 "Non-nil means that clicking Mouse-1 on a link follows the link.
65f76581 53
787e24c3
KS
54With the default setting, an ordinary Mouse-1 click on a link
55performs the same action as Mouse-2 on that link, while a longer
97b1270c 56Mouse-1 click \(hold down the Mouse-1 button for more than 450
787e24c3 57milliseconds) performs the original Mouse-1 binding \(which
65f76581
KS
58typically sets point where you click the mouse).
59
60If value is an integer, the time elapsed between pressing and
61releasing the mouse button determines whether to follow the link
787e24c3 62or perform the normal Mouse-1 action (typically set point).
22bcf204 63The absolute numeric value specifies the maximum duration of a
65f76581
KS
64\"short click\" in milliseconds. A positive value means that a
65short click follows the link, and a longer click performs the
1d68acd3 66normal action. A negative value gives the opposite behavior.
65f76581
KS
67
68If value is `double', a double click follows the link.
69
787e24c3 70Otherwise, a single Mouse-1 click unconditionally follows the link.
65f76581
KS
71
72Note that dragging the mouse never follows the link.
73
74This feature only works in modes that specifically identify
75clickable text as links, so it may not work with some external
76packages. See `mouse-on-link-p' for details."
bf247b6e 77 :version "22.1"
65f76581
KS
78 :type '(choice (const :tag "Disabled" nil)
79 (const :tag "Double click" double)
97b1270c 80 (number :tag "Single click time limit" :value 450)
65f76581
KS
81 (other :tag "Single click" t))
82 :group 'mouse)
83
185a53bb 84(defcustom mouse-1-click-in-non-selected-windows t
9201cc28 85 "If non-nil, a Mouse-1 click also follows links in non-selected windows.
185a53bb
KS
86
87If nil, a Mouse-1 click on a link in a non-selected window performs
88the normal mouse-1 binding, typically selects the window and sets
89point at the click position."
90 :type 'boolean
91 :version "22.1"
92 :group 'mouse)
93
27a98a62
SM
94(defun mouse--down-1-maybe-follows-link (&optional _prompt)
95 "Turn `mouse-1' events into `mouse-2' events if follows-link.
96Expects to be bound to `down-mouse-1' in `key-translation-map'."
97 (if (or (null mouse-1-click-follows-link)
98 (not (eq (if (eq mouse-1-click-follows-link 'double)
99 'double-down-mouse-1 'down-mouse-1)
100 (car-safe last-input-event)))
101 (not (mouse-on-link-p (event-start last-input-event)))
102 (and (not mouse-1-click-in-non-selected-windows)
103 (not (eq (selected-window)
104 (posn-window (event-start last-input-event))))))
105 nil
106 (let ((this-event last-input-event)
107 (timedout
108 (sit-for (if (numberp mouse-1-click-follows-link)
109 (/ (abs mouse-1-click-follows-link) 1000.0)
110 0))))
111 (if (if (and (numberp mouse-1-click-follows-link)
112 (>= mouse-1-click-follows-link 0))
113 timedout (not timedout))
114 nil
115
116 (let ((event (read-event)))
117 (if (eq (car-safe event) (if (eq mouse-1-click-follows-link 'double)
118 'double-mouse-1 'mouse-1))
119 ;; Turn the mouse-1 into a mouse-2 to follow links.
120 (let ((newup (if (eq mouse-1-click-follows-link 'double)
121 'double-mouse-2 'mouse-2))
122 (newdown (if (eq mouse-1-click-follows-link 'double)
123 'double-down-mouse-2 'down-mouse-2)))
124 ;; If mouse-2 has never been done by the user, it doesn't have
125 ;; the necessary property to be interpreted correctly.
126 (put newup 'event-kind (get (car event) 'event-kind))
127 (put newdown 'event-kind (get (car this-event) 'event-kind))
128 (push (cons newup (cdr event)) unread-command-events)
0e6008c5
SM
129 ;; Modify the event in place, so read-key-sequence doesn't
130 ;; generate a second fake prefix key (see fake_prefixed_keys in
131 ;; src/keyboard.c).
132 (setcar this-event newdown)
133 (vector this-event))
27a98a62
SM
134 (push event unread-command-events)
135 nil))))))
136
137(define-key key-translation-map [down-mouse-1]
138 #'mouse--down-1-maybe-follows-link)
139(define-key key-translation-map [double-down-mouse-1]
140 #'mouse--down-1-maybe-follows-link)
185a53bb 141
cc0a8174 142\f
95132d1c
RS
143;; Provide a mode-specific menu on a mouse button.
144
7e4e9c66 145(defun minor-mode-menu-from-indicator (indicator)
fb1a03c9
DN
146 "Show menu for minor mode specified by INDICATOR.
147Interactively, INDICATOR is read using completion.
148If there is no menu defined for the minor mode, then create one with
149items `Turn Off' and `Help'."
150 (interactive
5e38cdab 151 (list (completing-read
fb1a03c9
DN
152 "Minor mode indicator: "
153 (describe-minor-mode-completion-table-for-indicator))))
97b952b7
SM
154 (let* ((minor-mode (lookup-minor-mode-from-indicator indicator))
155 (mm-fun (or (get minor-mode :minor-mode-function) minor-mode)))
fb1a03c9
DN
156 (unless minor-mode (error "Cannot find minor mode for `%s'" indicator))
157 (let* ((map (cdr-safe (assq minor-mode minor-mode-map-alist)))
158 (menu (and (keymapp map) (lookup-key map [menu-bar]))))
ad0d18af
SM
159 (setq menu
160 (if menu
161 (mouse-menu-non-singleton menu)
fb1a03c9 162 `(keymap
ad0d18af 163 ,indicator
97b952b7 164 (turn-off menu-item "Turn Off minor mode" ,mm-fun)
ad0d18af 165 (help menu-item "Help for minor mode"
5e38cdab 166 (lambda () (interactive)
97b952b7 167 (describe-function ',mm-fun))))))
fb1a03c9 168 (popup-menu menu))))
7e4e9c66
GM
169
170(defun mouse-minor-mode-menu (event)
171 "Show minor-mode menu for EVENT on minor modes area of the mode line."
172 (interactive "@e")
173 (let ((indicator (car (nth 4 (car (cdr event))))))
174 (minor-mode-menu-from-indicator indicator)))
175
0b2b62ff 176(defun mouse-menu-major-mode-map ()
d5e6e0b6 177 (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
ad0d18af
SM
178 (let* (;; Keymap from which to inherit; may be null.
179 (ancestor (mouse-menu-non-singleton
b98e5762 180 (and (current-local-map)
25db2767 181 (local-key-binding [menu-bar]))))
b98e5762
DL
182 ;; Make a keymap in which our last command leads to a menu or
183 ;; default to the edit menu.
184 (newmap (if ancestor
48d33090
SM
185 (make-sparse-keymap (concat (format-mode-line mode-name)
186 " Mode"))
4d6769e1 187 menu-bar-edit-menu)))
b98e5762 188 (if ancestor
00f7c5ed 189 (set-keymap-parent newmap ancestor))
0b2b62ff 190 newmap))
95132d1c 191
ad0d18af 192(defun mouse-menu-non-singleton (menubar)
d1f14baa
CY
193 "Return menu keybar MENUBAR, or a lone submenu inside it.
194If MENUBAR defines exactly one submenu, return just that submenu.
195Otherwise, return MENUBAR."
95132d1c 196 (if menubar
ad0d18af
SM
197 (let (submap)
198 (map-keymap
199 (lambda (k v) (setq submap (if submap t (cons k v))))
00f7c5ed 200 (keymap-canonicalize menubar))
ad0d18af
SM
201 (if (eq submap t)
202 menubar
203 (lookup-key menubar (vector (car submap)))))))
de420e82 204
0b2b62ff
SM
205(defun mouse-menu-bar-map ()
206 "Return a keymap equivalent to the menu bar.
de420e82
DL
207The contents are the items that would be in the menu bar whether or
208not it is actually displayed."
d5e6e0b6 209 (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
7636d2a3
EZ
210 (let* ((local-menu (and (current-local-map)
211 (lookup-key (current-local-map) [menu-bar])))
212 (global-menu (lookup-key global-map [menu-bar]))
59836110
EZ
213 ;; If a keymap doesn't have a prompt string (a lazy
214 ;; programmer didn't bother to provide one), create it and
215 ;; insert it into the keymap; each keymap gets its own
216 ;; prompt. This is required for non-toolkit versions to
217 ;; display non-empty menu pane names.
218 (minor-mode-menus
219 (mapcar
00f7c5ed
SM
220 (lambda (menu)
221 (let* ((minor-mode (car menu))
222 (menu (cdr menu))
223 (title-or-map (cadr menu)))
224 (or (stringp title-or-map)
225 (setq menu
226 (cons 'keymap
227 (cons (concat
228 (capitalize (subst-char-in-string
229 ?- ?\s (symbol-name
230 minor-mode)))
231 " Menu")
232 (cdr menu)))))
233 menu))
59836110 234 (minor-mode-key-binding [menu-bar])))
7636d2a3
EZ
235 (local-title-or-map (and local-menu (cadr local-menu)))
236 (global-title-or-map (cadr global-menu)))
7636d2a3
EZ
237 (or (null local-menu)
238 (stringp local-title-or-map)
239 (setq local-menu (cons 'keymap
b38f5e6f 240 (cons (concat (format-mode-line mode-name)
48d33090 241 " Mode Menu")
7636d2a3
EZ
242 (cdr local-menu)))))
243 (or (stringp global-title-or-map)
244 (setq global-menu (cons 'keymap
245 (cons "Global Menu"
246 (cdr global-menu)))))
de420e82 247 ;; Supplying the list is faster than making a new map.
0b2b62ff
SM
248 ;; FIXME: We have a problem here: we have to use the global/local/minor
249 ;; so they're displayed in the expected order, but later on in the command
250 ;; loop, they're actually looked up in the opposite order.
251 (apply 'append
252 global-menu
253 local-menu
254 minor-mode-menus)))
255
256(defun mouse-major-mode-menu (event &optional prefix)
257 "Pop up a mode-specific menu of mouse commands.
258Default to the Edit menu if the major mode doesn't define a menu."
59f7af81 259 (declare (obsolete mouse-menu-major-mode-map "23.1"))
0b2b62ff
SM
260 (interactive "@e\nP")
261 (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
262 (popup-menu (mouse-menu-major-mode-map) event prefix))
0b2b62ff
SM
263
264(defun mouse-popup-menubar (event prefix)
265 "Pop up a menu equivalent to the menu bar for keyboard EVENT with PREFIX.
266The contents are the items that would be in the menu bar whether or
267not it is actually displayed."
59f7af81 268 (declare (obsolete mouse-menu-bar-map "23.1"))
0b2b62ff
SM
269 (interactive "@e \nP")
270 (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
fd6fa53f 271 (popup-menu (mouse-menu-bar-map) (unless (integerp event) event) prefix))
de420e82
DL
272
273(defun mouse-popup-menubar-stuff (event prefix)
274 "Popup a menu like either `mouse-major-mode-menu' or `mouse-popup-menubar'.
275Use the former if the menu bar is showing, otherwise the latter."
59f7af81 276 (declare (obsolete nil "23.1"))
0b2b62ff
SM
277 (interactive "@e\nP")
278 (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
279 (popup-menu
280 (if (zerop (or (frame-parameter nil 'menu-bar-lines) 0))
281 (mouse-menu-bar-map)
282 (mouse-menu-major-mode-map))
283 event prefix))
95132d1c 284\f
544e7e73
RS
285;; Commands that operate on windows.
286
d65147f6
KH
287(defun mouse-minibuffer-check (event)
288 (let ((w (posn-window (event-start event))))
289 (and (window-minibuffer-p w)
290 (not (minibuffer-window-active-p w))
71873e2b 291 (user-error "Minibuffer window is not active")))
33c448cd
RS
292 ;; Give temporary modes such as isearch a chance to turn off.
293 (run-hooks 'mouse-leave-buffer-hook))
d65147f6 294
cc0a8174 295(defun mouse-delete-window (click)
947da0c4 296 "Delete the window you click on.
6b48d742 297Do nothing if the frame has just one window.
a926a0fa 298This command must be bound to a mouse click."
ec558adc 299 (interactive "e")
6b48d742 300 (unless (one-window-p t)
a926a0fa
RS
301 (mouse-minibuffer-check click)
302 (delete-window (posn-window (event-start click)))))
cc0a8174 303
3c2dd2c0
RS
304(defun mouse-select-window (click)
305 "Select the window clicked on; don't move point."
306 (interactive "e")
d65147f6 307 (mouse-minibuffer-check click)
3c2dd2c0
RS
308 (let ((oframe (selected-frame))
309 (frame (window-frame (posn-window (event-start click)))))
310 (select-window (posn-window (event-start click)))
311 (raise-frame frame)
312 (select-frame frame)
313 (or (eq frame oframe)
e1877477 314 (set-mouse-position (selected-frame) (1- (frame-width)) 0))))
3c2dd2c0 315
b0f3a26b
JB
316(defun mouse-tear-off-window (click)
317 "Delete the window clicked on, and create a new frame displaying its buffer."
318 (interactive "e")
d65147f6 319 (mouse-minibuffer-check click)
b0f3a26b
JB
320 (let* ((window (posn-window (event-start click)))
321 (buf (window-buffer window))
01a911e3 322 (frame (make-frame)))
b0f3a26b
JB
323 (select-frame frame)
324 (switch-to-buffer buf)
325 (delete-window window)))
326
b5370f03 327(defun mouse-delete-other-windows ()
5925bb84 328 "Delete all windows except the one you click on."
b5370f03 329 (interactive "@")
cc0a8174 330 (delete-other-windows))
72ea54a4 331
cc0a8174
JB
332(defun mouse-split-window-vertically (click)
333 "Select Emacs window mouse is on, then split it vertically in half.
334The window is split at the line clicked on.
335This command must be bound to a mouse click."
947da0c4 336 (interactive "@e")
d65147f6 337 (mouse-minibuffer-check click)
b5370f03
JB
338 (let ((start (event-start click)))
339 (select-window (posn-window start))
85d6b80b 340 (let ((new-height (1+ (cdr (posn-col-row (event-end click)))))
5ba2dc3f
JB
341 (first-line window-min-height)
342 (last-line (- (window-height) window-min-height)))
343 (if (< last-line first-line)
0a50b993 344 (error "Window too short to split")
5ba2dc3f
JB
345 (split-window-vertically
346 (min (max new-height first-line) last-line))))))
cc0a8174 347
947da0c4
RS
348(defun mouse-split-window-horizontally (click)
349 "Select Emacs window mouse is on, then split it horizontally in half.
350The window is split at the column clicked on.
351This command must be bound to a mouse click."
352 (interactive "@e")
d65147f6 353 (mouse-minibuffer-check click)
5ba2dc3f
JB
354 (let ((start (event-start click)))
355 (select-window (posn-window start))
356 (let ((new-width (1+ (car (posn-col-row (event-end click)))))
357 (first-col window-min-width)
358 (last-col (- (window-width) window-min-width)))
359 (if (< last-col first-col)
0a50b993 360 (error "Window too narrow to split")
5ba2dc3f
JB
361 (split-window-horizontally
362 (min (max new-width first-col) last-col))))))
947da0c4 363
e07b9a6d
MR
364;; `mouse-drag-line' is now the common routine for handling all line
365;; dragging events combining the earlier `mouse-drag-mode-line-1' and
366;; `mouse-drag-vertical-line'. It should improve the behavior of line
367;; dragging wrt Emacs 23 as follows:
368
369;; (1) Gratuitous error messages and restrictions have been (hopefully)
370;; removed. (The help-echo that dragging the mode-line can resize a
371;; one-window-frame's window will still show through via bindings.el.)
372
373;; (2) No gratuitous selection of other windows should happen. (This
374;; has not been completely fixed for mouse-autoselected windows yet.)
375
376;; (3) Mouse clicks below a scroll-bar should pass through via unread
377;; command events.
378
379;; Note that `window-in-direction' replaces `mouse-drag-window-above'
380;; and `mouse-drag-vertical-line-rightward-window' with Emacs 24.1.
01ac65bd 381
e07b9a6d 382(defun mouse-drag-line (start-event line)
01ac65bd 383 "Drag a mode line, header line, or vertical line with the mouse.
e07b9a6d 384START-EVENT is the starting mouse-event of the drag action. LINE
01ac65bd 385must be one of the symbols `header', `mode', or `vertical'."
33c448cd
RS
386 ;; Give temporary modes such as isearch a chance to turn off.
387 (run-hooks 'mouse-leave-buffer-hook)
e07b9a6d 388 (let* ((echo-keystrokes 0)
ee0e2bdd 389 (start (event-start start-event))
e07b9a6d
MR
390 (window (posn-window start))
391 (frame (window-frame window))
392 (minibuffer-window (minibuffer-window frame))
01ac65bd
CY
393 (side (and (eq line 'vertical)
394 (or (cdr (assq 'vertical-scroll-bars
395 (frame-parameters frame)))
396 'right)))
397 (draggable t)
880e6158 398 height finished event position growth dragged)
e07b9a6d
MR
399 (cond
400 ((eq line 'header)
401 ;; Check whether header-line can be dragged at all.
53ebff1f 402 (if (window-at-side-p window 'top)
01ac65bd 403 (setq draggable nil)
880e6158 404 (setq height (/ (window-header-line-height window) 2))
53ebff1f 405 (setq window (window-in-direction 'above window t))))
e07b9a6d
MR
406 ((eq line 'mode)
407 ;; Check whether mode-line can be dragged at all.
880e6158
MR
408 (if (and (window-at-side-p window 'bottom)
409 ;; Allow resizing the minibuffer window if it's on the same
410 ;; frame as and immediately below the clicked window, and
411 ;; it's active or `resize-mini-windows' is nil.
412 (not (and (eq (window-frame minibuffer-window) frame)
413 (= (nth 1 (window-pixel-edges minibuffer-window))
414 (nth 3 (window-pixel-edges window)))
415 (or (not resize-mini-windows)
416 (eq minibuffer-window
417 (active-minibuffer-window))))))
418 (setq draggable nil)
419 (setq height (/ (window-mode-line-height window) 2))))
e07b9a6d 420 ((eq line 'vertical)
880e6158
MR
421 ;; Get the window to adjust for the vertical case. If the scroll
422 ;; bar is on the window's right or we drag a vertical divider,
423 ;; adjust the window where the start-event occurred. If the
424 ;; scroll bar is on the start-event window's left or there are no
425 ;; scrollbars, adjust the window on the left of it.
426 (unless (or (eq side 'right)
427 (not (zerop (window-right-divider-width window))))
01ac65bd 428 (setq window (window-in-direction 'left window t)))))
e07b9a6d
MR
429
430 ;; Start tracking.
544e7e73 431 (track-mouse
880e6158
MR
432 ;; Loop reading events and sampling the position of the mouse.
433 (while (not finished)
434 (setq event (read-event))
435 (setq position (mouse-pixel-position))
c8e5a42c
MR
436 ;; Do nothing if
437 ;; - there is a switch-frame event.
438 ;; - the mouse isn't in the frame that we started in
439 ;; - the mouse isn't in any Emacs frame
880e6158
MR
440 ;; Drag if
441 ;; - there is a mouse-movement event
442 ;; - there is a scroll-bar-movement event (Why? -- cyd)
443 ;; (same as mouse movement for our purposes)
444 ;; Quit if
445 ;; - there is a keyboard event or some other unknown event.
e07b9a6d 446 (cond
880e6158
MR
447 ((not (consp event))
448 (setq finished t))
c8e5a42c
MR
449 ((memq (car event) '(switch-frame select-window))
450 nil)
880e6158
MR
451 ((not (memq (car event) '(mouse-movement scroll-bar-movement)))
452 (when (consp event)
453 ;; Do not unread a drag-mouse-1 event to avoid selecting
454 ;; some other window. For vertical line dragging do not
455 ;; unread mouse-1 events either (but only if we dragged at
456 ;; least once to allow mouse-1 clicks get through).
457 (unless (and dragged
458 (if (eq line 'vertical)
459 (memq (car event) '(drag-mouse-1 mouse-1))
460 (eq (car event) 'drag-mouse-1)))
461 (push event unread-command-events)))
462 (setq finished t))
463 ((not (and (eq (car position) frame)
464 (cadr position)))
e07b9a6d
MR
465 nil)
466 ((eq line 'vertical)
880e6158
MR
467 ;; Drag vertical divider. This must be probably fixed like
468 ;; for the mode-line.
01ac65bd
CY
469 (setq growth (- (cadr position)
470 (if (eq side 'right) 0 2)
880e6158 471 (nth 2 (window-pixel-edges window))
01ac65bd 472 -1))
e07b9a6d 473 (unless (zerop growth)
880e6158 474 (setq dragged t)
a1a04df9 475 (adjust-window-trailing-edge window growth t t)))
01ac65bd
CY
476 (draggable
477 ;; Drag horizontal divider.
e07b9a6d
MR
478 (setq growth
479 (if (eq line 'mode)
880e6158
MR
480 (- (+ (cddr position) height)
481 (nth 3 (window-pixel-edges window)))
e07b9a6d 482 ;; The window's top includes the header line!
880e6158
MR
483 (- (+ (nth 3 (window-pixel-edges window)) height)
484 (cddr position))))
e07b9a6d 485 (unless (zerop growth)
880e6158
MR
486 (setq dragged t)
487 (adjust-window-trailing-edge
f49b4978 488 window (if (eq line 'mode) growth (- growth)) nil t))))))))
e07b9a6d 489
b0d22e20
GM
490(defun mouse-drag-mode-line (start-event)
491 "Change the height of a window by dragging on the mode line."
492 (interactive "e")
e07b9a6d 493 (mouse-drag-line start-event 'mode))
b0d22e20
GM
494
495(defun mouse-drag-header-line (start-event)
e07b9a6d 496 "Change the height of a window by dragging on the header line."
b0d22e20 497 (interactive "e")
e07b9a6d 498 (mouse-drag-line start-event 'header))
73c8f64c 499
08a1c178
RS
500(defun mouse-drag-vertical-line (start-event)
501 "Change the width of a window by dragging on the vertical line."
502 (interactive "e")
e07b9a6d 503 (mouse-drag-line start-event 'vertical))
08a1c178 504\f
2a5fa27b 505(defun mouse-set-point (event)
cc0a8174 506 "Move point to the position clicked on with the mouse.
2a5fa27b 507This should be bound to a mouse click event type."
ec558adc 508 (interactive "e")
d65147f6 509 (mouse-minibuffer-check event)
2a5fa27b
RS
510 ;; Use event-end in case called from mouse-drag-region.
511 ;; If EVENT is a click, event-end and event-start give same value.
541a44d2 512 (posn-set-point (event-end event)))
cc0a8174 513
e6c2f5d4
RS
514(defvar mouse-last-region-beg nil)
515(defvar mouse-last-region-end nil)
516(defvar mouse-last-region-tick nil)
517
518(defun mouse-region-match ()
519 "Return non-nil if there's an active region that was set with the mouse."
520 (and (mark t) mark-active
521 (eq mouse-last-region-beg (region-beginning))
522 (eq mouse-last-region-end (region-end))
523 (eq mouse-last-region-tick (buffer-modified-tick))))
524
652ccd35 525(defun mouse-set-region (click)
e37de120 526 "Set the region to the text dragged over, and copy to kill ring.
43f5740b
LMI
527This should be bound to a mouse drag event.
528See the `mouse-drag-copy-region' variable to control whether this
529command alters the kill ring or not."
652ccd35 530 (interactive "e")
d65147f6 531 (mouse-minibuffer-check click)
f9be2e35
CY
532 (select-window (posn-window (event-start click)))
533 (let ((beg (posn-point (event-start click)))
534 (end (posn-point (event-end click))))
535 (and mouse-drag-copy-region (integerp beg) (integerp end)
536 ;; Don't set this-command to `kill-region', so a following
537 ;; C-w won't double the text in the kill ring. Ignore
538 ;; `last-command' so we don't append to a preceding kill.
539 (let (this-command last-command deactivate-mark)
540 (copy-region-as-kill beg end)))
541 (if (numberp beg) (goto-char beg))
542 ;; On a text terminal, bounce the cursor.
33a35434 543 (or transient-mark-mode
f9be2e35 544 (window-system)
fcfc3c63 545 (sit-for 1))
652ccd35 546 (push-mark)
1cc8a3f4 547 (set-mark (point))
f9be2e35 548 (if (numberp end) (goto-char end))
e6c2f5d4
RS
549 (mouse-set-region-1)))
550
551(defun mouse-set-region-1 ()
a5809dbd 552 ;; Set transient-mark-mode for a little while.
688468a0
CY
553 (unless (eq (car-safe transient-mark-mode) 'only)
554 (setq transient-mark-mode
555 (cons 'only
556 (unless (eq transient-mark-mode 'lambda)
557 transient-mark-mode))))
e6c2f5d4
RS
558 (setq mouse-last-region-beg (region-beginning))
559 (setq mouse-last-region-end (region-end))
560 (setq mouse-last-region-tick (buffer-modified-tick)))
652ccd35 561
3b558d41 562(defcustom mouse-scroll-delay 0.25
9201cc28 563 "The pause between scroll steps caused by mouse drags, in seconds.
600c6e3a
JB
564If you drag the mouse beyond the edge of a window, Emacs scrolls the
565window to bring the text beyond that edge into view, with a delay of
566this many seconds between scroll steps. Scrolling stops when you move
567the mouse back into the window, or release the button.
568This variable's value may be non-integral.
3b558d41
RS
569Setting this to zero causes Emacs to scroll as fast as it can."
570 :type 'number
571 :group 'mouse)
600c6e3a 572
3b558d41 573(defcustom mouse-scroll-min-lines 1
9201cc28 574 "The minimum number of lines scrolled by dragging mouse out of window.
a3d6bb97
RS
575Moving the mouse out the top or bottom edge of the window begins
576scrolling repeatedly. The number of lines scrolled per repetition
577is normally equal to the number of lines beyond the window edge that
578the mouse has moved. However, it always scrolls at least the number
3b558d41
RS
579of lines specified by this variable."
580 :type 'integer
581 :group 'mouse)
08a1c178 582
e919a622
RS
583(defun mouse-scroll-subr (window jump &optional overlay start)
584 "Scroll the window WINDOW, JUMP lines at a time, until new input arrives.
600c6e3a
JB
585If OVERLAY is an overlay, let it stretch from START to the far edge of
586the newly visible text.
587Upon exit, point is at the far edge of the newly visible text."
08a1c178
RS
588 (cond
589 ((and (> jump 0) (< jump mouse-scroll-min-lines))
590 (setq jump mouse-scroll-min-lines))
591 ((and (< jump 0) (< (- jump) mouse-scroll-min-lines))
592 (setq jump (- mouse-scroll-min-lines))))
4e399a53
RS
593 (let ((opoint (point)))
594 (while (progn
595 (goto-char (window-start window))
596 (if (not (zerop (vertical-motion jump window)))
597 (progn
598 (set-window-start window (point))
599 (if (natnump jump)
0320e66f
RS
600 (if (window-end window)
601 (progn
602 (goto-char (window-end window))
603 ;; window-end doesn't reflect the window's new
604 ;; start position until the next redisplay.
605 (vertical-motion (1- jump) window))
606 (vertical-motion (- (window-height window) 2)))
4e399a53
RS
607 (goto-char (window-start window)))
608 (if overlay
609 (move-overlay overlay start (point)))
610 ;; Now that we have scrolled WINDOW properly,
611 ;; put point back where it was for the redisplay
612 ;; so that we don't mess up the selected window.
613 (or (eq window (selected-window))
614 (goto-char opoint))
d2287ded 615 (sit-for mouse-scroll-delay)))))
4e399a53
RS
616 (or (eq window (selected-window))
617 (goto-char opoint))))
fcfc3c63 618
dd524dbd 619(defvar mouse-selection-click-count 0)
eb6ff46f 620
c8c5bd24
RS
621(defvar mouse-selection-click-count-buffer nil)
622
600c6e3a 623(defun mouse-drag-region (start-event)
bcd5aef1 624 "Set the region to the text that the mouse is dragged over.
78210c95
RS
625Highlight the drag area as you move the mouse.
626This must be bound to a button-down mouse event.
d017deb2 627In Transient Mark mode, the highlighting remains as long as the mark
6454615c
RS
628remains active. Otherwise, it remains until the next input event.
629
630If the click is in the echo area, display the `*Messages*' buffer."
bcd5aef1 631 (interactive "e")
fd6fa53f
SM
632 ;; Give temporary modes such as isearch a chance to turn off.
633 (run-hooks 'mouse-leave-buffer-hook)
634 (mouse-drag-track start-event t))
6454615c 635
65f76581 636
91a2acb2 637(defun mouse-posn-property (pos property)
9ed38a84
DK
638 "Look for a property at click position.
639POS may be either a buffer position or a click position like
89bf250e 640those returned from `event-start'. If the click position is on
9ed38a84
DK
641a string, the text property PROPERTY is examined.
642If this is nil or the click is not on a string, then
643the corresponding buffer position is searched for PROPERTY.
644If PROPERTY is encountered in one of those places,
645its value is returned."
91a2acb2
DK
646 (if (consp pos)
647 (let ((w (posn-window pos)) (pt (posn-point pos))
648 (str (posn-string pos)))
649 (or (and str
650 (get-text-property (cdr str) property (car str)))
3a73c34c
SM
651 ;; FIXME: mouse clicks on the mode-line come with a position in
652 ;; (nth 5). Maybe we should change the C code instead so that
653 ;; mouse-clicks don't include a position there!
654 (and pt (not (memq (posn-area pos) '(mode-line header-line)))
91a2acb2
DK
655 (get-char-property pt property w))))
656 (get-char-property pos property)))
657
65f76581
KS
658(defun mouse-on-link-p (pos)
659 "Return non-nil if POS is on a link in the current buffer.
23eb76c4
TTN
660POS must be a buffer position in the current buffer or a mouse
661event location in the selected window (see `event-start').
185a53bb
KS
662However, if `mouse-1-click-in-non-selected-windows' is non-nil,
663POS may be a mouse event location in any window.
65f76581
KS
664
665A clickable link is identified by one of the following methods:
666
b41a4019 667- If the character at POS has a non-nil `follow-link' text or
e5fb57e9 668overlay property, the value of that property determines what to do.
65f76581 669
b41a4019
KS
670- If there is a local key-binding or a keybinding at position POS
671for the `follow-link' event, the binding of that event determines
672what to do.
65f76581 673
b41a4019
KS
674The resulting value determine whether POS is inside a link:
675
676- If the value is `mouse-face', POS is inside a link if there
65f76581
KS
677is a non-nil `mouse-face' property at POS. Return t in this case.
678
b41a4019 679- If the value is a function, FUNC, POS is inside a link if
65f76581 680the call \(FUNC POS) returns non-nil. Return the return value
23eb76c4 681from that call. Arg is \(posn-point POS) if POS is a mouse event.
65f76581 682
b41a4019 683- Otherwise, return the value itself.
65f76581
KS
684
685The return value is interpreted as follows:
686
687- If it is a string, the mouse-1 event is translated into the
688first character of the string, i.e. the action of the mouse-1
689click is the local or global binding of that character.
690
691- If it is a vector, the mouse-1 event is translated into the
692first element of that vector, i.e. the action of the mouse-1
693click is the local or global binding of that event.
694
695- Otherwise, the mouse-1 event is translated into a mouse-2 event
696at the same position."
91a2acb2 697 (let ((action
9a1ff164 698 (and (or (not (consp pos))
91a2acb2
DK
699 mouse-1-click-in-non-selected-windows
700 (eq (selected-window) (posn-window pos)))
701 (or (mouse-posn-property pos 'follow-link)
0e6008c5
SM
702 (let ((area (posn-area pos)))
703 (when area
704 (key-binding (vector area 'follow-link) nil t pos)))
91a2acb2
DK
705 (key-binding [follow-link] nil t pos)))))
706 (cond
707 ((eq action 'mouse-face)
708 (and (mouse-posn-property pos 'mouse-face) t))
709 ((functionp action)
9ed38a84 710 ;; FIXME: This seems questionable if the click is not in a buffer.
e9ae308c 711 ;; Should we instead decide that `action' takes a `posn'?
9ed38a84
DK
712 (if (consp pos)
713 (with-current-buffer (window-buffer (posn-window pos))
624c972d 714 (funcall action (posn-point pos)))
9ed38a84 715 (funcall action pos)))
91a2acb2 716 (t action))))
b0ca1b8a 717
5dbda518
KS
718(defun mouse-fixup-help-message (msg)
719 "Fix help message MSG for `mouse-1-click-follows-link'."
720 (let (mp pos)
721 (if (and mouse-1-click-follows-link
722 (stringp msg)
26ee77a6 723 (string-match-p "\\`mouse-2" msg)
5dbda518
KS
724 (setq mp (mouse-pixel-position))
725 (consp (setq pos (cdr mp)))
726 (car pos) (>= (car pos) 0)
727 (cdr pos) (>= (cdr pos) 0)
728 (setq pos (posn-at-x-y (car pos) (cdr pos) (car mp)))
729 (windowp (posn-window pos)))
730 (with-current-buffer (window-buffer (posn-window pos))
731 (if (mouse-on-link-p pos)
732 (setq msg (concat
733 (cond
734 ((eq mouse-1-click-follows-link 'double) "double-")
735 ((and (integerp mouse-1-click-follows-link)
736 (< mouse-1-click-follows-link 0)) "Long ")
737 (t ""))
738 "mouse-1" (substring msg 7)))))))
739 msg)
65f76581 740
624c972d 741(defun mouse-drag-track (start-event &optional
f1c4f757
S
742 do-mouse-drag-region-post-process)
743 "Track mouse drags by highlighting area between point and cursor.
5592c08f
CY
744The region will be defined with mark and point.
745DO-MOUSE-DRAG-REGION-POST-PROCESS should only be used by
746`mouse-drag-region'."
d65147f6 747 (mouse-minibuffer-check start-event)
aaf15b8b 748 (setq mouse-selection-click-count-buffer (current-buffer))
3f5c9cad 749 (deactivate-mark)
371d6a61 750 (let* ((scroll-margin 0) ; Avoid margin scrolling (Bug#9541).
aaf15b8b
SM
751 ;; We've recorded what we needed from the current buffer and
752 ;; window, now let's jump to the place of the event, where things
753 ;; are happening.
754 (_ (mouse-set-point start-event))
755 (echo-keystrokes 0)
4c9afcbe 756 (start-posn (event-start start-event))
600c6e3a
JB
757 (start-point (posn-point start-posn))
758 (start-window (posn-window start-posn))
02beb936 759 (start-window-start (window-start start-window))
1853aa6b 760 (start-hscroll (window-hscroll start-window))
600c6e3a 761 (bounds (window-edges start-window))
8413d0d2 762 (make-cursor-line-fully-visible nil)
600c6e3a
JB
763 (top (nth 1 bounds))
764 (bottom (if (window-minibuffer-p start-window)
765 (nth 3 bounds)
766 ;; Don't count the mode line.
e37de120 767 (1- (nth 3 bounds))))
81133808 768 (click-count (1- (event-click-count start-event)))
a9d01547
CY
769 ;; Suppress automatic hscrolling, because that is a nuisance
770 ;; when setting point near the right fringe (but see below).
41f03f4d
GM
771 (auto-hscroll-mode-saved auto-hscroll-mode)
772 (auto-hscroll-mode nil)
8cca9703 773 moved-off-start event end end-point)
5592c08f 774
81133808 775 (setq mouse-selection-click-count click-count)
08a1c178
RS
776 ;; In case the down click is in the middle of some intangible text,
777 ;; use the end of that text, and put it in START-POINT.
778 (if (< (point) start-point)
779 (goto-char start-point))
780 (setq start-point (point))
5592c08f 781
81133808
CY
782 ;; Activate the region, using `mouse-start-end' to determine where
783 ;; to put point and mark (e.g., double-click will select a word).
5592c08f
CY
784 (setq transient-mark-mode
785 (if (eq transient-mark-mode 'lambda)
786 '(only)
787 (cons 'only transient-mark-mode)))
9852377f 788 (let ((range (mouse-start-end start-point start-point click-count)))
6d3e82d2 789 (push-mark (nth 0 range) t t)
81133808 790 (goto-char (nth 1 range)))
5592c08f
CY
791
792 ;; Track the mouse until we get a non-movement event.
793 (track-mouse
794 (while (progn
795 (setq event (read-event))
796 (or (mouse-movement-p event)
797 (memq (car-safe event) '(switch-frame select-window))))
798 (unless (memq (car-safe event) '(switch-frame select-window))
799 ;; Automatic hscrolling did not occur during the call to
800 ;; `read-event'; but if the user subsequently drags the
801 ;; mouse, go ahead and hscroll.
41f03f4d 802 (let ((auto-hscroll-mode auto-hscroll-mode-saved))
5592c08f
CY
803 (redisplay))
804 (setq end (event-end event)
805 end-point (posn-point end))
8cca9703
CY
806 ;; Note whether the mouse has left the starting position.
807 (unless (eq end-point start-point)
808 (setq moved-off-start t))
5592c08f 809 (if (and (eq (posn-window end) start-window)
b846d039 810 (integer-or-marker-p end-point))
6d3e82d2
CY
811 (mouse--drag-set-mark-and-point start-point
812 end-point click-count)
5592c08f
CY
813 (let ((mouse-row (cdr (cdr (mouse-position)))))
814 (cond
815 ((null mouse-row))
816 ((< mouse-row top)
817 (mouse-scroll-subr start-window (- mouse-row top)
818 nil start-point))
819 ((>= mouse-row bottom)
820 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
821 nil start-point))))))))
822
823 ;; Handle the terminating event if possible.
824 (when (consp event)
825 ;; Ensure that point is on the end of the last event.
826 (when (and (setq end-point (posn-point (event-end event)))
2e3329a5 827 (eq (posn-window end) start-window)
5592c08f
CY
828 (integer-or-marker-p end-point)
829 (/= start-point end-point))
6d3e82d2
CY
830 (mouse--drag-set-mark-and-point start-point
831 end-point click-count))
832
5592c08f
CY
833 ;; Find its binding.
834 (let* ((fun (key-binding (vector (car event))))
925baaa9
GM
835 ;; FIXME This doesn't make sense, because
836 ;; event-click-count always returns something >= 1.
5592c08f
CY
837 (do-multi-click (and (> (event-click-count event) 0)
838 (functionp fun)
839 (not (memq fun '(mouse-set-point
840 mouse-set-region))))))
841 (if (and (/= (mark) (point))
842 (not do-multi-click))
f479ef6e 843
5592c08f
CY
844 ;; If point has moved, finish the drag.
845 (let* (last-command this-command)
5592c08f
CY
846 (and mouse-drag-copy-region
847 do-mouse-drag-region-post-process
848 (let (deactivate-mark)
9852377f 849 (copy-region-as-kill (mark) (point)))))
f479ef6e 850
8cca9703 851 ;; Otherwise, run binding of terminating up-event.
13841bfc 852 (deactivate-mark)
05e89fea
CY
853 (if do-multi-click
854 (goto-char start-point)
05e89fea
CY
855 (unless moved-off-start
856 (pop-mark)))
857
5592c08f
CY
858 (when (and (functionp fun)
859 (= start-hscroll (window-hscroll start-window))
860 ;; Don't run the up-event handler if the window
861 ;; start changed in a redisplay after the
862 ;; mouse-set-point for the down-mouse event at
863 ;; the beginning of this function. When the
864 ;; window start has changed, the up-mouse event
865 ;; contains a different position due to the new
866 ;; window contents, and point is set again.
867 (or end-point
868 (= (window-start start-window)
869 start-window-start)))
5592c08f
CY
870 (push event unread-command-events)))))))
871
6d3e82d2
CY
872(defun mouse--drag-set-mark-and-point (start click click-count)
873 (let* ((range (mouse-start-end start click click-count))
874 (beg (nth 0 range))
875 (end (nth 1 range)))
876 (cond ((eq (mark) beg)
877 (goto-char end))
878 ((eq (mark) end)
879 (goto-char beg))
880 ((< click (mark))
881 (set-mark end)
882 (goto-char beg))
883 (t
884 (set-mark beg)
885 (goto-char end)))))
886
e37de120 887;; Commands to handle xterm-style multiple clicks.
e37de120
RS
888(defun mouse-skip-word (dir)
889 "Skip over word, over whitespace, or over identical punctuation.
890If DIR is positive skip forward; if negative, skip backward."
891 (let* ((char (following-char))
892 (syntax (char-to-string (char-syntax char))))
258e3295
KH
893 (cond ((string= syntax "w")
894 ;; Here, we can't use skip-syntax-forward/backward because
895 ;; they don't pay attention to word-separating-categories,
896 ;; and thus they will skip over a true word boundary. So,
fffa137c 897 ;; we simulate the original behavior by using forward-word.
258e3295
KH
898 (if (< dir 0)
899 (if (not (looking-at "\\<"))
900 (forward-word -1))
901 (if (or (looking-at "\\<") (not (looking-at "\\>")))
902 (forward-word 1))))
903 ((string= syntax " ")
08a1c178
RS
904 (if (< dir 0)
905 (skip-syntax-backward syntax)
906 (skip-syntax-forward syntax)))
907 ((string= syntax "_")
908 (if (< dir 0)
909 (skip-syntax-backward "w_")
910 (skip-syntax-forward "w_")))
911 ((< dir 0)
912 (while (and (not (bobp)) (= (preceding-char) char))
913 (forward-char -1)))
914 (t
915 (while (and (not (eobp)) (= (following-char) char))
916 (forward-char 1))))))
e37de120 917
eb6ff46f 918(defun mouse-start-end (start end mode)
c3bb6d70 919 "Return a list of region bounds based on START and END according to MODE.
a7df580d
DL
920If MODE is 0 then set point to (min START END), mark to (max START END).
921If MODE is 1 then set point to start of word at (min START END),
922mark to end of word at (max START END).
923If MODE is 2 then do the same for lines."
e37de120
RS
924 (if (> start end)
925 (let ((temp start))
926 (setq start end
927 end temp)))
9a974c88 928 (setq mode (mod mode 3))
e37de120
RS
929 (cond ((= mode 0)
930 (list start end))
931 ((and (= mode 1)
932 (= start end)
1ec71583 933 (char-after start)
e37de120 934 (= (char-syntax (char-after start)) ?\())
6f482eec
RS
935 (list start
936 (save-excursion
937 (goto-char start)
938 (forward-sexp 1)
939 (point))))
e37de120
RS
940 ((and (= mode 1)
941 (= start end)
1ec71583 942 (char-after start)
e37de120 943 (= (char-syntax (char-after start)) ?\)))
7b611de0 944 (list (save-excursion
e37de120 945 (goto-char (1+ start))
d89a4a47
RS
946 (backward-sexp 1)
947 (point))
e37de120 948 (1+ start)))
53770877
RS
949 ((and (= mode 1)
950 (= start end)
951 (char-after start)
952 (= (char-syntax (char-after start)) ?\"))
953 (let ((open (or (eq start (point-min))
954 (save-excursion
955 (goto-char (- start 1))
956 (looking-at "\\s(\\|\\s \\|\\s>")))))
957 (if open
958 (list start
959 (save-excursion
960 (condition-case nil
7b611de0 961 (progn
53770877
RS
962 (goto-char start)
963 (forward-sexp 1)
964 (point))
965 (error end))))
f1017d55 966 (list (save-excursion
53770877
RS
967 (condition-case nil
968 (progn
969 (goto-char (1+ start))
970 (backward-sexp 1)
971 (point))
f1017d55
RS
972 (error end)))
973 (1+ start)))))
e37de120
RS
974 ((= mode 1)
975 (list (save-excursion
976 (goto-char start)
977 (mouse-skip-word -1)
978 (point))
979 (save-excursion
980 (goto-char end)
981 (mouse-skip-word 1)
982 (point))))
983 ((= mode 2)
984 (list (save-excursion
985 (goto-char start)
6d3e82d2 986 (line-beginning-position 1))
e37de120
RS
987 (save-excursion
988 (goto-char end)
989 (forward-line 1)
990 (point))))))
e66feb07 991\f
3f26b32a
RS
992;; Subroutine: set the mark where CLICK happened,
993;; but don't do anything else.
994(defun mouse-set-mark-fast (click)
d65147f6 995 (mouse-minibuffer-check click)
3f26b32a
RS
996 (let ((posn (event-start click)))
997 (select-window (posn-window posn))
998 (if (numberp (posn-point posn))
999 (push-mark (posn-point posn) t t))))
1000
98aac09d
MB
1001(defun mouse-undouble-last-event (events)
1002 (let* ((index (1- (length events)))
1003 (last (nthcdr index events))
1004 (event (car last))
1005 (basic (event-basic-type event))
397a88f3
RS
1006 (old-modifiers (event-modifiers event))
1007 (modifiers (delq 'double (delq 'triple (copy-sequence old-modifiers))))
98aac09d
MB
1008 (new
1009 (if (consp event)
7132500b
RS
1010 ;; Use reverse, not nreverse, since event-modifiers
1011 ;; does not copy the list it returns.
3bb846b8 1012 (cons (event-convert-list (reverse (cons basic modifiers)))
98aac09d
MB
1013 (cdr event))
1014 event)))
1015 (setcar last new)
397a88f3
RS
1016 (if (and (not (equal modifiers old-modifiers))
1017 (key-binding (apply 'vector events)))
98aac09d
MB
1018 t
1019 (setcar last event)
1020 nil)))
1021
7b611de0 1022;; Momentarily show where the mark is, if highlighting doesn't show it.
7aeb7370 1023
cc0a8174
JB
1024(defun mouse-set-mark (click)
1025 "Set mark at the position clicked on with the mouse.
1026Display cursor at that position for a second.
1027This must be bound to a mouse click."
ec558adc 1028 (interactive "e")
f598fb03
RS
1029 (mouse-minibuffer-check click)
1030 (select-window (posn-window (event-start click)))
1031 ;; We don't use save-excursion because that preserves the mark too.
72ea54a4
RS
1032 (let ((point-save (point)))
1033 (unwind-protect
cc0a8174 1034 (progn (mouse-set-point click)
897897e3
RS
1035 (push-mark nil t t)
1036 (or transient-mark-mode
1037 (sit-for 1)))
72ea54a4
RS
1038 (goto-char point-save))))
1039
cc0a8174
JB
1040(defun mouse-kill (click)
1041 "Kill the region between point and the mouse click.
1042The text is saved in the kill ring, as with \\[kill-region]."
ec558adc 1043 (interactive "e")
d65147f6 1044 (mouse-minibuffer-check click)
142c7672
KH
1045 (let* ((posn (event-start click))
1046 (click-posn (posn-point posn)))
1047 (select-window (posn-window posn))
bd307392
JB
1048 (if (numberp click-posn)
1049 (kill-region (min (point) click-posn)
1050 (max (point) click-posn)))))
72ea54a4 1051
87ef29fd
JB
1052(defun mouse-yank-at-click (click arg)
1053 "Insert the last stretch of killed text at the position clicked on.
0e57ab65 1054Also move point to one end of the text thus inserted (normally the end),
231c4d1a 1055and set mark at the beginning.
50f58001
RS
1056Prefix arguments are interpreted as with \\[yank].
1057If `mouse-yank-at-point' is non-nil, insert at point
9852377f 1058regardless of where you click."
a4cabe41 1059 (interactive "e\nP")
33c448cd
RS
1060 ;; Give temporary modes such as isearch a chance to turn off.
1061 (run-hooks 'mouse-leave-buffer-hook)
3f5c9cad
CY
1062 (when select-active-regions
1063 ;; Without this, confusing things happen upon e.g. inserting into
1064 ;; the middle of an active region.
6f3a2682 1065 (deactivate-mark))
50f58001 1066 (or mouse-yank-at-point (mouse-set-point click))
d89a4a47 1067 (setq this-command 'yank)
a814e9df 1068 (setq mouse-selection-click-count 0)
87ef29fd
JB
1069 (yank arg))
1070
63571b5a
RS
1071(defun mouse-yank-primary (click)
1072 "Insert the primary selection at the position clicked on.
e1eb5385
CY
1073Move point to the end of the inserted text, and set mark at
1074beginning. If `mouse-yank-at-point' is non-nil, insert at point
63571b5a
RS
1075regardless of where you click."
1076 (interactive "e")
1077 ;; Give temporary modes such as isearch a chance to turn off.
1078 (run-hooks 'mouse-leave-buffer-hook)
1c409d0b
CY
1079 ;; Without this, confusing things happen upon e.g. inserting into
1080 ;; the middle of an active region.
6c6a75d5 1081 (when select-active-regions
1c409d0b
CY
1082 (let (select-active-regions)
1083 (deactivate-mark)))
63571b5a 1084 (or mouse-yank-at-point (mouse-set-point click))
e7afcf30 1085 (let ((primary
5f30349b
GM
1086 (if (fboundp 'x-get-selection-value)
1087 (if (eq (framep (selected-frame)) 'w32)
1088 ;; MS-Windows emulates PRIMARY in x-get-selection, but not
1089 ;; in x-get-selection-value (the latter only accesses the
1090 ;; clipboard). So try PRIMARY first, in case they selected
1091 ;; something with the mouse in the current Emacs session.
1092 (or (x-get-selection 'PRIMARY)
1093 (x-get-selection-value))
1094 ;; Else MS-DOS or X.
1095 ;; On X, x-get-selection-value supports more formats and
1096 ;; encodings, so use it in preference to x-get-selection.
1097 (or (x-get-selection-value)
1098 (x-get-selection 'PRIMARY)))
1099 ;; FIXME: What about xterm-mouse-mode etc.?
1100 (x-get-selection 'PRIMARY))))
e1eb5385
CY
1101 (unless primary
1102 (error "No selection is available"))
1103 (push-mark (point))
1104 (insert primary)))
63571b5a 1105
87ef29fd 1106(defun mouse-kill-ring-save (click)
cc0a8174
JB
1107 "Copy the region between point and the mouse click in the kill ring.
1108This does not delete the region; it acts like \\[kill-ring-save]."
ec558adc 1109 (interactive "e")
3f26b32a 1110 (mouse-set-mark-fast click)
6452d8a6 1111 (let (this-command last-command)
5592c08f 1112 (kill-ring-save (point) (mark t))))
72ea54a4 1113
ad0d18af
SM
1114;; This function used to delete the text between point and the mouse
1115;; whenever it was equal to the front of the kill ring, but some
1116;; people found that confusing.
dbc4e1c1 1117
d2625c3d 1118;; The position of the last invocation of `mouse-save-then-kill'.
dbc4e1c1
JB
1119(defvar mouse-save-then-kill-posn nil)
1120
26d280b9 1121(defun mouse-save-then-kill-delete-region (beg end)
9a974c88
RS
1122 ;; We must make our own undo boundaries
1123 ;; because they happen automatically only for the current buffer.
1124 (undo-boundary)
dd524dbd
RS
1125 (if (or (= beg end) (eq buffer-undo-list t))
1126 ;; If we have no undo list in this buffer,
1127 ;; just delete.
1128 (delete-region beg end)
1129 ;; Delete, but make the undo-list entry share with the kill ring.
1130 ;; First, delete just one char, so in case buffer is being modified
1131 ;; for the first time, the undo list records that fact.
8faa9707 1132 (let (before-change-functions after-change-functions)
2f4b15ef
RS
1133 (delete-region beg
1134 (+ beg (if (> end beg) 1 -1))))
dd524dbd
RS
1135 (let ((buffer-undo-list buffer-undo-list))
1136 ;; Undo that deletion--but don't change the undo list!
8faa9707 1137 (let (before-change-functions after-change-functions)
2f4b15ef 1138 (primitive-undo 1 buffer-undo-list))
dd524dbd
RS
1139 ;; Now delete the rest of the specified region,
1140 ;; but don't record it.
1141 (setq buffer-undo-list t)
9a974c88
RS
1142 (if (/= (length (car kill-ring)) (- (max end beg) (min end beg)))
1143 (error "Lossage in mouse-save-then-kill-delete-region"))
dd524dbd
RS
1144 (delete-region beg end))
1145 (let ((tail buffer-undo-list))
1146 ;; Search back in buffer-undo-list for the string
1147 ;; that came from deleting one character.
1148 (while (and tail (not (stringp (car (car tail)))))
1149 (setq tail (cdr tail)))
1150 ;; Replace it with an entry for the entire deleted text.
1151 (and tail
9a974c88
RS
1152 (setcar tail (cons (car kill-ring) (min beg end))))))
1153 (undo-boundary))
eb6ff46f 1154
947da0c4 1155(defun mouse-save-then-kill (click)
d2625c3d
CY
1156 "Set the region according to CLICK; the second time, kill it.
1157CLICK should be a mouse click event.
1158
1159If the region is inactive, activate it temporarily. Set mark at
1160the original point, and move point to the position of CLICK.
1161
1162If the region is already active, adjust it. Normally, do this by
1163moving point or mark, whichever is closer, to CLICK. But if you
1164have selected whole words or lines, move point or mark to the
1165word or line boundary closest to CLICK instead.
1166
93d68d4f
DDLHG
1167If `mouse-drag-copy-region' is non-nil, this command also saves the
1168new region to the kill ring (replacing the previous kill if the
1169previous region was just saved to the kill ring).
1170
d2625c3d 1171If this command is called a second consecutive time with the same
93d68d4f
DDLHG
1172CLICK position, kill the region (or delete it
1173if `mouse-drag-copy-region' is non-nil)"
947da0c4 1174 (interactive "e")
d2625c3d
CY
1175 (mouse-minibuffer-check click)
1176 (let* ((posn (event-start click))
1177 (click-pt (posn-point posn))
1178 (window (posn-window posn))
1179 (buf (window-buffer window))
1180 ;; Don't let a subsequent kill command append to this one.
1181 (this-command this-command)
1182 ;; Check if the user has multi-clicked to select words/lines.
1183 (click-count
1184 (if (and (eq mouse-selection-click-count-buffer buf)
1185 (with-current-buffer buf (mark t)))
1186 mouse-selection-click-count
1187 0)))
1188 (cond
1189 ((not (numberp click-pt)) nil)
1190 ;; If the user clicked without moving point, kill the region.
1191 ;; This also resets `mouse-selection-click-count'.
1192 ((and (eq last-command 'mouse-save-then-kill)
1193 (eq click-pt mouse-save-then-kill-posn)
1194 (eq window (selected-window)))
93d68d4f
DDLHG
1195 (if mouse-drag-copy-region
1196 ;; Region already saved in the previous click;
1197 ;; don't make a duplicate entry, just delete.
1198 (delete-region (mark t) (point))
1199 (kill-region (mark t) (point)))
d2625c3d
CY
1200 (setq mouse-selection-click-count 0)
1201 (setq mouse-save-then-kill-posn nil))
1202
1203 ;; Otherwise, if there is a suitable region, adjust it by moving
1204 ;; one end (whichever is closer) to CLICK-PT.
1205 ((or (with-current-buffer buf (region-active-p))
1206 (and (eq window (selected-window))
1207 (mark t)
1208 (or (and (eq last-command 'mouse-save-then-kill)
1209 mouse-save-then-kill-posn)
1210 (and (memq last-command '(mouse-drag-region
1211 mouse-set-region))
1212 (or mark-even-if-inactive
1213 (not transient-mark-mode))))))
1214 (select-window window)
1215 (let* ((range (mouse-start-end click-pt click-pt click-count)))
1216 (if (< (abs (- click-pt (mark t)))
1217 (abs (- click-pt (point))))
1218 (set-mark (car range))
1219 (goto-char (nth 1 range)))
1220 (setq deactivate-mark nil)
1221 (mouse-set-region-1)
93d68d4f
DDLHG
1222 (when mouse-drag-copy-region
1223 ;; Region already copied to kill-ring once, so replace.
1224 (kill-new (filter-buffer-substring (mark t) (point)) t))
d2625c3d
CY
1225 ;; Arrange for a repeated mouse-3 to kill the region.
1226 (setq mouse-save-then-kill-posn click-pt)))
1227
1228 ;; Otherwise, set the mark where point is and move to CLICK-PT.
1229 (t
1230 (select-window window)
1231 (mouse-set-mark-fast click)
1232 (let ((before-scroll (with-current-buffer buf point-before-scroll)))
1233 (if before-scroll (goto-char before-scroll)))
1234 (exchange-point-and-mark)
1235 (mouse-set-region-1)
93d68d4f
DDLHG
1236 (when mouse-drag-copy-region
1237 (kill-new (filter-buffer-substring (mark t) (point))))
d2625c3d
CY
1238 (setq mouse-save-then-kill-posn click-pt)))))
1239
e66feb07
RS
1240\f
1241(global-set-key [M-mouse-1] 'mouse-start-secondary)
1242(global-set-key [M-drag-mouse-1] 'mouse-set-secondary)
1243(global-set-key [M-down-mouse-1] 'mouse-drag-secondary)
1244(global-set-key [M-mouse-3] 'mouse-secondary-save-then-kill)
9a974c88 1245(global-set-key [M-mouse-2] 'mouse-yank-secondary)
e66feb07 1246
aaf15b8b
SM
1247(defconst mouse-secondary-overlay
1248 (let ((ol (make-overlay (point-min) (point-min))))
1249 (delete-overlay ol)
1250 (overlay-put ol 'face 'secondary-selection)
1251 ol)
1252 "An overlay which records the current secondary selection.
1253It is deleted when there is no secondary selection.")
e66feb07 1254
a94c7fcc
RS
1255(defvar mouse-secondary-click-count 0)
1256
e66feb07
RS
1257;; A marker which records the specified first end for a secondary selection.
1258;; May be nil.
1259(defvar mouse-secondary-start nil)
1260
1261(defun mouse-start-secondary (click)
1262 "Set one end of the secondary selection to the position clicked on.
1263Use \\[mouse-secondary-save-then-kill] to set the other end
1264and complete the secondary selection."
1265 (interactive "e")
d65147f6 1266 (mouse-minibuffer-check click)
e66feb07 1267 (let ((posn (event-start click)))
aaf15b8b 1268 (with-current-buffer (window-buffer (posn-window posn))
230aaa73 1269 ;; Cancel any preexisting secondary selection.
aaf15b8b 1270 (delete-overlay mouse-secondary-overlay)
230aaa73
RS
1271 (if (numberp (posn-point posn))
1272 (progn
1273 (or mouse-secondary-start
1274 (setq mouse-secondary-start (make-marker)))
1275 (move-marker mouse-secondary-start (posn-point posn)))))))
e66feb07
RS
1276
1277(defun mouse-set-secondary (click)
1278 "Set the secondary selection to the text that the mouse is dragged over.
1279This must be bound to a mouse drag event."
1280 (interactive "e")
d65147f6 1281 (mouse-minibuffer-check click)
e66feb07
RS
1282 (let ((posn (event-start click))
1283 beg
1284 (end (event-end click)))
aaf15b8b 1285 (with-current-buffer (window-buffer (posn-window posn))
230aaa73
RS
1286 (if (numberp (posn-point posn))
1287 (setq beg (posn-point posn)))
3e4f866b
CY
1288 (move-overlay mouse-secondary-overlay beg (posn-point end))
1289 (x-set-selection
1290 'SECONDARY
1291 (buffer-substring (overlay-start mouse-secondary-overlay)
1292 (overlay-end mouse-secondary-overlay))))))
947da0c4 1293
d89a4a47 1294(defun mouse-drag-secondary (start-event)
e66feb07 1295 "Set the secondary selection to the text that the mouse is dragged over.
d89a4a47 1296Highlight the drag area as you move the mouse.
efc10c97
RS
1297This must be bound to a button-down mouse event.
1298The function returns a non-nil value if it creates a secondary selection."
e66feb07 1299 (interactive "e")
d65147f6 1300 (mouse-minibuffer-check start-event)
4c9afcbe
RS
1301 (let* ((echo-keystrokes 0)
1302 (start-posn (event-start start-event))
d89a4a47
RS
1303 (start-point (posn-point start-posn))
1304 (start-window (posn-window start-posn))
d89a4a47
RS
1305 (bounds (window-edges start-window))
1306 (top (nth 1 bounds))
1307 (bottom (if (window-minibuffer-p start-window)
1308 (nth 3 bounds)
1309 ;; Don't count the mode line.
1310 (1- (nth 3 bounds))))
1311 (click-count (1- (event-click-count start-event))))
aaf15b8b 1312 (with-current-buffer (window-buffer start-window)
a94c7fcc 1313 (setq mouse-secondary-click-count click-count)
9a974c88 1314 (if (> (mod click-count 3) 0)
26d280b9
RS
1315 ;; Double or triple press: make an initial selection
1316 ;; of one word or line.
d89a4a47
RS
1317 (let ((range (mouse-start-end start-point start-point click-count)))
1318 (set-marker mouse-secondary-start nil)
d89a4a47
RS
1319 (move-overlay mouse-secondary-overlay (car range) (nth 1 range)
1320 (window-buffer start-window)))
26d280b9 1321 ;; Single-press: cancel any preexisting secondary selection.
d89a4a47
RS
1322 (or mouse-secondary-start
1323 (setq mouse-secondary-start (make-marker)))
1324 (set-marker mouse-secondary-start start-point)
1325 (delete-overlay mouse-secondary-overlay))
1326 (let (event end end-point)
1327 (track-mouse
1328 (while (progn
1329 (setq event (read-event))
1330 (or (mouse-movement-p event)
fbd8dc8a 1331 (memq (car-safe event) '(switch-frame select-window))))
d89a4a47 1332
fbd8dc8a 1333 (if (memq (car-safe event) '(switch-frame select-window))
d89a4a47
RS
1334 nil
1335 (setq end (event-end event)
1336 end-point (posn-point end))
1337 (cond
d89a4a47
RS
1338 ;; Are we moving within the original window?
1339 ((and (eq (posn-window end) start-window)
1340 (integer-or-marker-p end-point))
d89a4a47
RS
1341 (let ((range (mouse-start-end start-point end-point
1342 click-count)))
0136e1e3
RS
1343 (if (or (/= start-point end-point)
1344 (null (marker-position mouse-secondary-start)))
1345 (progn
1346 (set-marker mouse-secondary-start nil)
1347 (move-overlay mouse-secondary-overlay
1348 (car range) (nth 1 range))))))
3b0aebe9
RS
1349 (t
1350 (let ((mouse-row (cdr (cdr (mouse-position)))))
1351 (cond
1352 ((null mouse-row))
1353 ((< mouse-row top)
e919a622
RS
1354 (mouse-scroll-subr start-window (- mouse-row top)
1355 mouse-secondary-overlay start-point))
d2287ded 1356 ((>= mouse-row bottom)
e919a622 1357 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
3b0aebe9 1358 mouse-secondary-overlay start-point)))))))))
d89a4a47 1359
4e399a53 1360 (if (consp event)
d89a4a47
RS
1361 (if (marker-position mouse-secondary-start)
1362 (save-window-excursion
1363 (delete-overlay mouse-secondary-overlay)
9a974c88 1364 (x-set-selection 'SECONDARY nil)
d89a4a47
RS
1365 (select-window start-window)
1366 (save-excursion
1367 (goto-char mouse-secondary-start)
efc10c97
RS
1368 (sit-for 1)
1369 nil))
9a974c88
RS
1370 (x-set-selection
1371 'SECONDARY
1372 (buffer-substring (overlay-start mouse-secondary-overlay)
1373 (overlay-end mouse-secondary-overlay)))))))))
e66feb07 1374
9a974c88 1375(defun mouse-yank-secondary (click)
50f58001
RS
1376 "Insert the secondary selection at the position clicked on.
1377Move point to the end of the inserted text.
1378If `mouse-yank-at-point' is non-nil, insert at point
1379regardless of where you click."
a4cabe41 1380 (interactive "e")
33c448cd
RS
1381 ;; Give temporary modes such as isearch a chance to turn off.
1382 (run-hooks 'mouse-leave-buffer-hook)
50f58001 1383 (or mouse-yank-at-point (mouse-set-point click))
b3709a53
RS
1384 (let ((secondary (x-get-selection 'SECONDARY)))
1385 (if secondary
aa2d4bd3 1386 (insert secondary)
b3709a53 1387 (error "No secondary selection"))))
9a974c88 1388
7e6404f6 1389(defun mouse-kill-secondary ()
9a974c88
RS
1390 "Kill the text in the secondary selection.
1391This is intended more as a keyboard command than as a mouse command
1392but it can work as either one.
1393
1394The current buffer (in case of keyboard use), or the buffer clicked on,
1395must be the one that the secondary selection is in. This requirement
1396is to prevent accidents."
7e6404f6
RS
1397 (interactive)
1398 (let* ((keys (this-command-keys))
1399 (click (elt keys (1- (length keys)))))
1400 (or (eq (overlay-buffer mouse-secondary-overlay)
1401 (if (listp click)
1402 (window-buffer (posn-window (event-start click)))
1403 (current-buffer)))
1404 (error "Select or click on the buffer where the secondary selection is")))
9dfab550 1405 (let (this-command)
aaf15b8b 1406 (with-current-buffer (overlay-buffer mouse-secondary-overlay)
9dfab550
RS
1407 (kill-region (overlay-start mouse-secondary-overlay)
1408 (overlay-end mouse-secondary-overlay))))
f9be2e35 1409 (delete-overlay mouse-secondary-overlay))
e66feb07
RS
1410
1411(defun mouse-secondary-save-then-kill (click)
d2625c3d
CY
1412 "Set the secondary selection and save it to the kill ring.
1413The second time, kill it. CLICK should be a mouse click event.
1414
1415If you have not called `mouse-start-secondary' in the clicked
1416buffer, activate the secondary selection and set it between point
1417and the click position CLICK.
1418
1419Otherwise, adjust the bounds of the secondary selection.
1420Normally, do this by moving its beginning or end, whichever is
1421closer, to CLICK. But if you have selected whole words or lines,
1422adjust to the word or line boundary closest to CLICK instead.
1423
1424If this command is called a second consecutive time with the same
1425CLICK position, kill the secondary selection."
e66feb07 1426 (interactive "e")
d65147f6 1427 (mouse-minibuffer-check click)
d2625c3d
CY
1428 (let* ((posn (event-start click))
1429 (click-pt (posn-point posn))
1430 (window (posn-window posn))
1431 (buf (window-buffer window))
1432 ;; Don't let a subsequent kill command append to this one.
1433 (this-command this-command)
1434 ;; Check if the user has multi-clicked to select words/lines.
1435 (click-count
1436 (if (eq (overlay-buffer mouse-secondary-overlay) buf)
1437 mouse-secondary-click-count
1438 0))
1439 (beg (overlay-start mouse-secondary-overlay))
1440 (end (overlay-end mouse-secondary-overlay)))
1441
1442 (cond
1443 ((not (numberp click-pt)) nil)
1444
1445 ;; If the secondary selection is not active in BUF, activate it.
1446 ((not (eq buf (or (overlay-buffer mouse-secondary-overlay)
1447 (if mouse-secondary-start
1448 (marker-buffer mouse-secondary-start)))))
1449 (select-window window)
1450 (setq mouse-secondary-start (make-marker))
1451 (move-marker mouse-secondary-start (point))
1452 (move-overlay mouse-secondary-overlay (point) click-pt buf)
1453 (kill-ring-save (point) click-pt))
1454
1455 ;; If the user clicked without moving point, delete the secondary
1456 ;; selection. This also resets `mouse-secondary-click-count'.
1457 ((and (eq last-command 'mouse-secondary-save-then-kill)
1458 (eq click-pt mouse-save-then-kill-posn)
1459 (eq window (selected-window)))
1460 (mouse-save-then-kill-delete-region beg end)
1461 (delete-overlay mouse-secondary-overlay)
1462 (setq mouse-secondary-click-count 0)
1463 (setq mouse-save-then-kill-posn nil))
1464
1465 ;; Otherwise, if there is a suitable secondary selection overlay,
1466 ;; adjust it by moving one end (whichever is closer) to CLICK-PT.
1467 ((and beg (eq buf (overlay-buffer mouse-secondary-overlay)))
1468 (let* ((range (mouse-start-end click-pt click-pt click-count)))
1469 (if (< (abs (- click-pt beg))
1470 (abs (- click-pt end)))
1471 (move-overlay mouse-secondary-overlay (car range) end)
1472 (move-overlay mouse-secondary-overlay beg (nth 1 range))))
1473 (setq deactivate-mark nil)
1474 (if (eq last-command 'mouse-secondary-save-then-kill)
1475 ;; If the front of the kill ring comes from an immediately
1476 ;; previous use of this command, replace the entry.
1477 (kill-new
1478 (buffer-substring (overlay-start mouse-secondary-overlay)
1479 (overlay-end mouse-secondary-overlay))
1480 t)
1481 (let (deactivate-mark)
1482 (copy-region-as-kill (overlay-start mouse-secondary-overlay)
1483 (overlay-end mouse-secondary-overlay))))
1484 (setq mouse-save-then-kill-posn click-pt))
1485
1486 ;; Otherwise, set the secondary selection overlay.
1487 (t
1488 (select-window window)
1489 (if mouse-secondary-start
1490 ;; All we have is one end of a selection, so put the other
1491 ;; end here.
1492 (let ((start (+ 0 mouse-secondary-start)))
1493 (kill-ring-save start click-pt)
1494 (move-overlay mouse-secondary-overlay start click-pt)))
1495 (setq mouse-save-then-kill-posn click-pt))))
1496
1497 ;; Finally, set the window system's secondary selection.
1498 (let (str)
1499 (and (overlay-buffer mouse-secondary-overlay)
1500 (setq str (buffer-substring (overlay-start mouse-secondary-overlay)
1501 (overlay-end mouse-secondary-overlay)))
1502 (> (length str) 0)
1503 (x-set-selection 'SECONDARY str))))
1504
e66feb07 1505\f
0d9be91c 1506(defcustom mouse-buffer-menu-maxlen 20
9201cc28 1507 "Number of buffers in one pane (submenu) of the buffer menu.
f1107960 1508If we have lots of buffers, divide them into groups of
0d9be91c 1509`mouse-buffer-menu-maxlen' and make a pane (or submenu) for each one."
3b558d41
RS
1510 :type 'integer
1511 :group 'mouse)
f1107960 1512
3ca87c7b 1513(defcustom mouse-buffer-menu-mode-mult 4
9201cc28 1514 "Group the buffers by the major mode groups on \\[mouse-buffer-menu]?
3ca87c7b
RS
1515This number which determines (in a hairy way) whether \\[mouse-buffer-menu]
1516will split the buffer menu by the major modes (see
1517`mouse-buffer-menu-mode-groups') or just by menu length.
1518Set to 1 (or even 0!) if you want to group by major mode always, and to
1519a large number if you prefer a mixed multitude. The default is 4."
1520 :type 'integer
1521 :group 'mouse
1522 :version "20.3")
1523
284a88a3 1524(defvar mouse-buffer-menu-mode-groups
e8e4d5c8 1525 (mapcar (lambda (arg) (cons (purecopy (car arg)) (purecopy (cdr arg))))
284a88a3
RS
1526 '(("Info\\|Help\\|Apropos\\|Man" . "Help")
1527 ("\\bVM\\b\\|\\bMH\\b\\|Message\\|Mail\\|Group\\|Score\\|Summary\\|Article"
1528 . "Mail/News")
1529 ("\\<C\\>" . "C")
1530 ("ObjC" . "C")
1531 ("Text" . "Text")
1532 ("Outline" . "Text")
c71a58a3 1533 ("\\(HT\\|SG\\|X\\|XHT\\)ML" . "SGML")
f399e4ad 1534 ("log\\|diff\\|vc\\|cvs\\|Annotate" . "Version Control") ; "Change Management"?
7bc61bb7
SS
1535 ("Threads\\|Memory\\|Disassembly\\|Breakpoints\\|Frames\\|Locals\\|Registers\\|Inferior I/O\\|Debugger"
1536 . "GDB")
a7610c52 1537 ("Lisp" . "Lisp")))
284a88a3
RS
1538 "How to group various major modes together in \\[mouse-buffer-menu].
1539Each element has the form (REGEXP . GROUPNAME).
1540If the major mode's name string matches REGEXP, use GROUPNAME instead.")
1541
8b34e79d 1542(defun mouse-buffer-menu (event)
2d82f7b9
RS
1543 "Pop up a menu of buffers for selection with the mouse.
1544This switches buffers in the window that you clicked on,
1545and selects that window."
ec558adc 1546 (interactive "e")
d65147f6 1547 (mouse-minibuffer-check event)
3ca87c7b 1548 (let ((buffers (buffer-list)) alist menu split-by-major-mode sum-of-squares)
284a88a3 1549 ;; Make an alist of elements that look like (MENU-ITEM . BUFFER).
cc2ee8ec
SS
1550 (dolist (buf buffers)
1551 ;; Divide all buffers into buckets for various major modes.
1552 ;; Each bucket looks like (MODE NAMESTRING BUFFERS...).
1553 (with-current-buffer buf
1554 (let* ((adjusted-major-mode major-mode) elt)
1555 (dolist (group mouse-buffer-menu-mode-groups)
1556 (when (string-match (car group) (format-mode-line mode-name))
1557 (setq adjusted-major-mode (cdr group))))
1558 (setq elt (assoc adjusted-major-mode split-by-major-mode))
1559 (unless elt
1560 (setq elt (list adjusted-major-mode
1561 (if (stringp adjusted-major-mode)
1562 adjusted-major-mode
48d33090 1563 (format-mode-line mode-name nil nil buf)))
cc2ee8ec
SS
1564 split-by-major-mode (cons elt split-by-major-mode)))
1565 (or (memq buf (cdr (cdr elt)))
1566 (setcdr (cdr elt) (cons buf (cdr (cdr elt))))))))
284a88a3
RS
1567 ;; Compute the sum of squares of sizes of the major-mode buckets.
1568 (let ((tail split-by-major-mode))
1569 (setq sum-of-squares 0)
1570 (while tail
1571 (setq sum-of-squares
1572 (+ sum-of-squares
3ca87c7b 1573 (let ((len (length (cdr (cdr (car tail)))))) (* len len))))
284a88a3 1574 (setq tail (cdr tail))))
3ca87c7b
RS
1575 (if (< (* sum-of-squares mouse-buffer-menu-mode-mult)
1576 (* (length buffers) (length buffers)))
284a88a3
RS
1577 ;; Subdividing by major modes really helps, so let's do it.
1578 (let (subdivided-menus (buffers-left (length buffers)))
1579 ;; Sort the list to put the most popular major modes first.
1580 (setq split-by-major-mode
1581 (sort split-by-major-mode
1582 (function (lambda (elt1 elt2)
1583 (> (length elt1) (length elt2))))))
1584 ;; Make a separate submenu for each major mode
1585 ;; that has more than one buffer,
1586 ;; unless all the remaining buffers are less than 1/10 of them.
1587 (while (and split-by-major-mode
1588 (and (> (length (car split-by-major-mode)) 3)
1589 (> (* buffers-left 10) (length buffers))))
4b4ea1dc
EZ
1590 (let ((this-mode-list (mouse-buffer-menu-alist
1591 (cdr (cdr (car split-by-major-mode))))))
1592 (and this-mode-list
1593 (setq subdivided-menus
1594 (cons (cons
1595 (nth 1 (car split-by-major-mode))
1596 this-mode-list)
1597 subdivided-menus))))
284a88a3
RS
1598 (setq buffers-left
1599 (- buffers-left (length (cdr (car split-by-major-mode)))))
1600 (setq split-by-major-mode (cdr split-by-major-mode)))
1601 ;; If any major modes are left over,
1602 ;; make a single submenu for them.
1603 (if split-by-major-mode
4b4ea1dc
EZ
1604 (let ((others-list
1605 (mouse-buffer-menu-alist
1606 ;; we don't need split-by-major-mode any more,
1607 ;; so we can ditch it with nconc.
1608 (apply 'nconc (mapcar 'cddr split-by-major-mode)))))
1609 (and others-list
1610 (setq subdivided-menus
1611 (cons (cons "Others" others-list)
1612 subdivided-menus)))))
3ca87c7b 1613 (setq menu (cons "Buffer Menu" (nreverse subdivided-menus))))
284a88a3
RS
1614 (progn
1615 (setq alist (mouse-buffer-menu-alist buffers))
1616 (setq menu (cons "Buffer Menu"
1617 (mouse-buffer-menu-split "Select Buffer" alist)))))
2d82f7b9
RS
1618 (let ((buf (x-popup-menu event menu))
1619 (window (posn-window (event-start event))))
3ca87c7b 1620 (when buf
f134ad18
RS
1621 (select-window
1622 (if (framep window) (frame-selected-window window)
1623 window))
3ca87c7b 1624 (switch-to-buffer buf)))))
284a88a3
RS
1625
1626(defun mouse-buffer-menu-alist (buffers)
1627 (let (tail
1628 (maxlen 0)
1629 head)
1630 (setq buffers
1631 (sort buffers
1632 (function (lambda (elt1 elt2)
1633 (string< (buffer-name elt1) (buffer-name elt2))))))
1634 (setq tail buffers)
1635 (while tail
fc2b429e 1636 (or (eq ?\s (aref (buffer-name (car tail)) 0))
284a88a3
RS
1637 (setq maxlen
1638 (max maxlen
1639 (length (buffer-name (car tail))))))
1640 (setq tail (cdr tail)))
1641 (setq tail buffers)
1642 (while tail
1643 (let ((elt (car tail)))
66564ab0 1644 (if (/= (aref (buffer-name elt) 0) ?\s)
284a88a3
RS
1645 (setq head
1646 (cons
1647 (cons
1648 (format
fc1f472b 1649 (format "%%-%ds %%s%%s %%s" maxlen)
284a88a3
RS
1650 (buffer-name elt)
1651 (if (buffer-modified-p elt) "*" " ")
7fdbcd83 1652 (with-current-buffer elt
284a88a3 1653 (if buffer-read-only "%" " "))
7b611de0 1654 (or (buffer-file-name elt)
7fdbcd83 1655 (with-current-buffer elt
284a88a3
RS
1656 (if list-buffers-directory
1657 (expand-file-name
1658 list-buffers-directory)))
1659 ""))
1660 elt)
1661 head))))
1662 (setq tail (cdr tail)))
1663 ;; Compensate for the reversal that the above loop does.
1664 (nreverse head)))
1665
1666(defun mouse-buffer-menu-split (title alist)
1667 ;; If we have lots of buffers, divide them into groups of 20
1668 ;; and make a pane (or submenu) for each one.
0d9be91c 1669 (if (> (length alist) (/ (* mouse-buffer-menu-maxlen 3) 2))
284a88a3
RS
1670 (let ((alist alist) sublists next
1671 (i 1))
1672 (while alist
0d9be91c 1673 ;; Pull off the next mouse-buffer-menu-maxlen buffers
284a88a3 1674 ;; and make them the next element of sublist.
0d9be91c 1675 (setq next (nthcdr mouse-buffer-menu-maxlen alist))
284a88a3 1676 (if next
0d9be91c 1677 (setcdr (nthcdr (1- mouse-buffer-menu-maxlen) alist)
284a88a3
RS
1678 nil))
1679 (setq sublists (cons (cons (format "Buffers %d" i) alist)
1680 sublists))
1681 (setq i (1+ i))
1682 (setq alist next))
1683 (nreverse sublists))
1684 ;; Few buffers--put them all in one pane.
1685 (list (cons title alist))))
72ea54a4 1686\f
d5e63715
SM
1687(define-obsolete-function-alias
1688 'mouse-choose-completion 'choose-completion "23.2")
f936ae06 1689
07a78410
RS
1690;; Font selection.
1691
0eb9fef3
RS
1692(defun font-menu-add-default ()
1693 (let* ((default (cdr (assq 'font (frame-parameters (selected-frame)))))
1694 (font-alist x-fixed-font-alist)
0d94f5ca 1695 (elt (or (assoc "Misc" font-alist) (nth 1 font-alist))))
0eb9fef3
RS
1696 (if (assoc "Default" elt)
1697 (delete (assoc "Default" elt) elt))
1698 (setcdr elt
6b8e486e 1699 (cons (list "Default" default)
0eb9fef3
RS
1700 (cdr elt)))))
1701
07a78410 1702(defvar x-fixed-font-alist
a7610c52
DN
1703 (list
1704 (purecopy "Font Menu")
1705 (cons
1706 (purecopy "Misc")
1707 (mapcar
1708 (lambda (arg) (cons (purecopy (car arg)) (purecopy (cdr arg))))
19d973e8 1709 ;; For these, we specify the pixel height and width.
a7610c52 1710 '(("fixed" "fixed")
19d973e8
RS
1711 ("6x10" "-misc-fixed-medium-r-normal--10-*-*-*-c-60-iso8859-1" "6x10")
1712 ("6x12"
1713 "-misc-fixed-medium-r-semicondensed--12-*-*-*-c-60-iso8859-1" "6x12")
1714 ("6x13"
1715 "-misc-fixed-medium-r-semicondensed--13-*-*-*-c-60-iso8859-1" "6x13")
1716 ("7x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-70-iso8859-1" "7x13")
1717 ("7x14" "-misc-fixed-medium-r-normal--14-*-*-*-c-70-iso8859-1" "7x14")
1718 ("8x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-80-iso8859-1" "8x13")
1719 ("9x15" "-misc-fixed-medium-r-normal--15-*-*-*-c-90-iso8859-1" "9x15")
1720 ("10x20" "-misc-fixed-medium-r-normal--20-*-*-*-c-100-iso8859-1" "10x20")
1721 ("11x18" "-misc-fixed-medium-r-normal--18-*-*-*-c-110-iso8859-1" "11x18")
1722 ("12x24" "-misc-fixed-medium-r-normal--24-*-*-*-c-120-iso8859-1" "12x24")
fa21fdec 1723 ("")
f29c3695
RS
1724 ("clean 5x8"
1725 "-schumacher-clean-medium-r-normal--8-*-*-*-c-50-iso8859-1")
1726 ("clean 6x8"
1727 "-schumacher-clean-medium-r-normal--8-*-*-*-c-60-iso8859-1")
19d973e8
RS
1728 ("clean 8x8"
1729 "-schumacher-clean-medium-r-normal--8-*-*-*-c-80-iso8859-1")
1730 ("clean 8x10"
1731 "-schumacher-clean-medium-r-normal--10-*-*-*-c-80-iso8859-1")
1732 ("clean 8x14"
1733 "-schumacher-clean-medium-r-normal--14-*-*-*-c-80-iso8859-1")
1734 ("clean 8x16"
1735 "-schumacher-clean-medium-r-normal--16-*-*-*-c-80-iso8859-1")
fa21fdec 1736 ("")
29a3028d 1737 ("sony 8x16" "-sony-fixed-medium-r-normal--16-*-*-*-c-80-iso8859-1")
ad0d18af
SM
1738 ;; We don't seem to have these; who knows what they are.
1739 ;; ("fg-18" "fg-18")
1740 ;; ("fg-25" "fg-25")
29a3028d
DL
1741 ("lucidasanstypewriter-12" "-b&h-lucidatypewriter-medium-r-normal-sans-*-120-*-*-*-*-iso8859-1")
1742 ("lucidasanstypewriter-bold-14" "-b&h-lucidatypewriter-bold-r-normal-sans-*-140-*-*-*-*-iso8859-1")
1743 ("lucidasanstypewriter-bold-24"
1744 "-b&h-lucidatypewriter-bold-r-normal-sans-*-240-*-*-*-*-iso8859-1")
ad0d18af
SM
1745 ;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
1746 ;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
a7610c52
DN
1747 )))
1748
1749 (cons
1750 (purecopy "Courier")
1751 (mapcar
1752 (lambda (arg) (cons (purecopy (car arg)) (purecopy (cdr arg))))
19d973e8 1753 ;; For these, we specify the point height.
a7610c52 1754 '(("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1")
82c048a9
RS
1755 ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1")
1756 ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1")
1757 ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1")
1758 ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1")
1759 ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1")
1760 ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1")
1761 ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1")
1762 ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1")
1763 ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1")
1764 ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1")
1765 ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1")
1766 ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1")
1767 ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1")
1768 ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1")
1769 ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1")
1770 ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1")
1771 ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1")
1772 ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1")
1773 ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1")
1774 ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1")
1775 ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1")
1776 ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1")
a7610c52
DN
1777 ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1")
1778 ))))
07a78410
RS
1779 "X fonts suitable for use in Emacs.")
1780
aa360da1
GM
1781(declare-function generate-fontset-menu "fontset" ())
1782
ecb044e1
CY
1783(defun mouse-select-font ()
1784 "Prompt for a font name, using `x-popup-menu', and return it."
1785 (interactive)
1786 (unless (display-multi-font-p)
1787 (error "Cannot change fonts on this display"))
c1202d4b
CY
1788 (car
1789 (x-popup-menu
1790 (if (listp last-nonmenu-event)
1791 last-nonmenu-event
1792 (list '(0 0) (selected-window)))
1793 (append x-fixed-font-alist
1794 (list (generate-fontset-menu))))))
ecb044e1 1795
3db09e26
CY
1796(declare-function text-scale-mode "face-remap")
1797
1900a92b 1798(defun mouse-set-font (&rest fonts)
ecb044e1
CY
1799 "Set the default font for the selected frame.
1800The argument FONTS is a list of font names; the first valid font
1801in this list is used.
1802
1803When called interactively, pop up a menu and allow the user to
1804choose a font."
07a78410 1805 (interactive
8eb1dc02
RS
1806 (progn (unless (display-multi-font-p)
1807 (error "Cannot change fonts on this display"))
1808 (x-popup-menu
91c51412
LT
1809 (if (listp last-nonmenu-event)
1810 last-nonmenu-event
1811 (list '(0 0) (selected-window)))
8eb1dc02
RS
1812 ;; Append list of fontsets currently defined.
1813 (append x-fixed-font-alist (list (generate-fontset-menu))))))
df4de8c6
KH
1814 (if fonts
1815 (let (font)
1816 (while fonts
1817 (condition-case nil
1818 (progn
b7d1d101 1819 (set-frame-font (car fonts))
df4de8c6
KH
1820 (setq font (car fonts))
1821 (setq fonts nil))
3fadec1a
RS
1822 (error
1823 (setq fonts (cdr fonts)))))
df4de8c6 1824 (if (null font)
8eb1dc02 1825 (error "Font not found")))))
3db09e26
CY
1826
1827(defvar mouse-appearance-menu-map nil)
9c257005 1828(declare-function x-select-font "xfns.c" (&optional frame ignored)) ; USE_GTK
b816c5e3
GM
1829(declare-function buffer-face-mode-invoke "face-remap"
1830 (face arg &optional interactive))
f2d9c15f 1831(declare-function font-face-attributes "font.c" (font &optional frame))
3db09e26
CY
1832
1833(defun mouse-appearance-menu (event)
e8579ebc 1834 "Show a menu for changing the default face in the current buffer."
3db09e26
CY
1835 (interactive "@e")
1836 (require 'face-remap)
1837 (when (display-multi-font-p)
1838 (with-selected-window (car (event-start event))
1839 (if mouse-appearance-menu-map
1840 nil ; regenerate new fonts
1841 ;; Initialize mouse-appearance-menu-map
1842 (setq mouse-appearance-menu-map
1843 (make-sparse-keymap "Change Default Buffer Face"))
1844 (define-key mouse-appearance-menu-map [face-remap-reset-base]
1845 '(menu-item "Reset to Default" face-remap-reset-base))
1846 (define-key mouse-appearance-menu-map [text-scale-decrease]
1847 '(menu-item "Decrease Buffer Text Size" text-scale-decrease))
1848 (define-key mouse-appearance-menu-map [text-scale-increase]
1849 '(menu-item "Increase Buffer Text Size" text-scale-increase))
1850 ;; Font selector
1851 (if (functionp 'x-select-font)
1852 (define-key mouse-appearance-menu-map [x-select-font]
1853 '(menu-item "Change Buffer Font..." x-select-font))
1854 ;; If the select-font is unavailable, construct a menu.
1855 (let ((font-submenu (make-sparse-keymap "Change Text Font"))
1856 (font-alist (cdr (append x-fixed-font-alist
1857 (list (generate-fontset-menu))))))
1858 (dolist (family font-alist)
1859 (let* ((submenu-name (car family))
1860 (submenu-map (make-sparse-keymap submenu-name)))
1861 (dolist (font (cdr family))
1862 (let ((font-name (car font))
1863 font-symbol)
1864 (if (string= font-name "")
1865 (define-key submenu-map [space]
1866 '("--"))
1867 (setq font-symbol (intern (cadr font)))
1868 (define-key submenu-map (vector font-symbol)
1869 (list 'menu-item (car font) font-symbol)))))
1870 (define-key font-submenu (vector (intern submenu-name))
1871 (list 'menu-item submenu-name submenu-map))))
1872 (define-key mouse-appearance-menu-map [font-submenu]
1873 (list 'menu-item "Change Text Font" font-submenu)))))
1874 (let ((choice (x-popup-menu event mouse-appearance-menu-map)))
1875 (setq choice (nth (1- (length choice)) choice))
1876 (cond ((eq choice 'text-scale-increase)
1877 (text-scale-increase 1))
1878 ((eq choice 'text-scale-decrease)
1879 (text-scale-increase -1))
1880 ((eq choice 'face-remap-reset-base)
1881 (text-scale-mode 0)
4271b424 1882 (buffer-face-mode 0))
520713e7 1883 (choice
3db09e26
CY
1884 ;; Either choice == 'x-select-font, or choice is a
1885 ;; symbol whose name is a font.
383dcbf9
CY
1886 (let ((font (if (eq choice 'x-select-font)
1887 (x-select-font)
1888 (symbol-name choice))))
1889 (buffer-face-mode-invoke
1890 (if (fontp font 'font-spec)
1891 (list :font font)
1892 (font-face-attributes font))
1893 t (called-interactively-p 'interactive)))))))))
3db09e26 1894
cc0a8174
JB
1895\f
1896;;; Bindings for mouse commands.
1897
fcfc3c63 1898(define-key global-map [down-mouse-1] 'mouse-drag-region)
dbc4e1c1 1899(global-set-key [mouse-1] 'mouse-set-point)
dbc4e1c1 1900(global-set-key [drag-mouse-1] 'mouse-set-region)
fcfc3c63 1901
e37de120
RS
1902;; These are tested for in mouse-drag-region.
1903(global-set-key [double-mouse-1] 'mouse-set-point)
1904(global-set-key [triple-mouse-1] 'mouse-set-point)
1905
fe3f64d5
SM
1906(defun mouse--strip-first-event (_prompt)
1907 (substring (this-single-command-raw-keys) 1))
1908
1909(define-key function-key-map [left-fringe mouse-1] 'mouse--strip-first-event)
1910(define-key function-key-map [right-fringe mouse-1] 'mouse--strip-first-event)
76693d12 1911
f9d71b42 1912(global-set-key [mouse-2] 'mouse-yank-primary)
3e9323d6 1913;; Allow yanking also when the corresponding cursor is "in the fringe".
fe3f64d5
SM
1914(define-key function-key-map [right-fringe mouse-2] 'mouse--strip-first-event)
1915(define-key function-key-map [left-fringe mouse-2] 'mouse--strip-first-event)
dbc4e1c1 1916(global-set-key [mouse-3] 'mouse-save-then-kill)
fe3f64d5
SM
1917(define-key function-key-map [right-fringe mouse-3] 'mouse--strip-first-event)
1918(define-key function-key-map [left-fringe mouse-3] 'mouse--strip-first-event)
8b34e79d 1919
dbc4e1c1
JB
1920;; By binding these to down-going events, we let the user use the up-going
1921;; event to make the selection, saving a click.
08a1c178
RS
1922(global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
1923(if (not (eq system-type 'ms-dos))
3db09e26 1924 (global-set-key [S-down-mouse-1] 'mouse-appearance-menu))
eef805d7 1925;; C-down-mouse-2 is bound in facemenu.el.
0b2b62ff 1926(global-set-key [C-down-mouse-3]
1e8780b1 1927 `(menu-item ,(purecopy "Menu Bar") ignore
0b2b62ff
SM
1928 :filter (lambda (_)
1929 (if (zerop (or (frame-parameter nil 'menu-bar-lines) 0))
1930 (mouse-menu-bar-map)
1931 (mouse-menu-major-mode-map)))))
95132d1c 1932
06a8c9f8
EZ
1933;; Binding mouse-1 to mouse-select-window when on mode-, header-, or
1934;; vertical-line prevents Emacs from signaling an error when the mouse
1935;; button is released after dragging these lines, on non-toolkit
1936;; versions.
3c2dd2c0 1937(global-set-key [mode-line mouse-1] 'mouse-select-window)
544e7e73
RS
1938(global-set-key [mode-line drag-mouse-1] 'mouse-select-window)
1939(global-set-key [mode-line down-mouse-1] 'mouse-drag-mode-line)
b0d22e20 1940(global-set-key [header-line down-mouse-1] 'mouse-drag-header-line)
06a8c9f8 1941(global-set-key [header-line mouse-1] 'mouse-select-window)
3c2dd2c0 1942(global-set-key [mode-line mouse-2] 'mouse-delete-other-windows)
dbc4e1c1 1943(global-set-key [mode-line mouse-3] 'mouse-delete-window)
3c2dd2c0 1944(global-set-key [mode-line C-mouse-2] 'mouse-split-window-horizontally)
9926ab64 1945(global-set-key [vertical-scroll-bar C-mouse-2] 'mouse-split-window-vertically)
b6522df6 1946(global-set-key [vertical-line C-mouse-2] 'mouse-split-window-vertically)
08a1c178 1947(global-set-key [vertical-line down-mouse-1] 'mouse-drag-vertical-line)
880e6158
MR
1948(global-set-key [right-divider down-mouse-1] 'mouse-drag-vertical-line)
1949(global-set-key [bottom-divider down-mouse-1] 'mouse-drag-mode-line)
08a1c178 1950(global-set-key [vertical-line mouse-1] 'mouse-select-window)
49116ac0
JB
1951
1952(provide 'mouse)
1953
6594deb0 1954;;; mouse.el ends here