1 ;;; mouse.el --- window system-independent mouse support -*- lexical-binding: t -*-
3 ;; Copyright (C) 1993-1995, 1999-2014 Free Software Foundation, Inc.
5 ;; Maintainer: emacs-devel@gnu.org
6 ;; Keywords: hardware, mouse
9 ;; This file is part of GNU Emacs.
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 3 of the License, or
14 ;; (at your option) any later version.
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.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
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.
32 ;;; Utility functions.
34 ;; Indent track-mouse like progn.
35 (put 'track-mouse 'lisp-indent-function 0)
37 (defcustom mouse-yank-at-point nil
38 "If non-nil, mouse yank commands yank at point instead of at click."
42 (defcustom mouse-drag-copy-region nil
43 "If non-nil, copy to kill-ring upon mouse adjustments of the region.
45 This affects `mouse-save-then-kill' (\\[mouse-save-then-kill]) in
46 addition to mouse drags."
51 (defcustom mouse-1-click-follows-link 450
52 "Non-nil means that clicking Mouse-1 on a link follows the link.
54 With the default setting, an ordinary Mouse-1 click on a link
55 performs the same action as Mouse-2 on that link, while a longer
56 Mouse-1 click \(hold down the Mouse-1 button for more than 450
57 milliseconds) performs the original Mouse-1 binding \(which
58 typically sets point where you click the mouse).
60 If value is an integer, the time elapsed between pressing and
61 releasing the mouse button determines whether to follow the link
62 or perform the normal Mouse-1 action (typically set point).
63 The absolute numeric value specifies the maximum duration of a
64 \"short click\" in milliseconds. A positive value means that a
65 short click follows the link, and a longer click performs the
66 normal action. A negative value gives the opposite behavior.
68 If value is `double', a double click follows the link.
70 Otherwise, a single Mouse-1 click unconditionally follows the link.
72 Note that dragging the mouse never follows the link.
74 This feature only works in modes that specifically identify
75 clickable text as links, so it may not work with some external
76 packages. See `mouse-on-link-p' for details."
78 :type '(choice (const :tag "Disabled" nil)
79 (const :tag "Double click" double)
80 (number :tag "Single click time limit" :value 450)
81 (other :tag "Single click" t))
84 (defcustom mouse-1-click-in-non-selected-windows t
85 "If non-nil, a Mouse-1 click also follows links in non-selected windows.
87 If nil, a Mouse-1 click on a link in a non-selected window performs
88 the normal mouse-1 binding, typically selects the window and sets
89 point at the click position."
94 (defun mouse--down-1-maybe-follows-link (&optional _prompt)
95 "Turn `mouse-1' events into `mouse-2' events if follows-link.
96 Expects 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))))))
106 (let ((this-event last-input-event)
108 (sit-for (if (numberp mouse-1-click-follows-link)
109 (/ (abs mouse-1-click-follows-link) 1000.0)
111 (if (if (and (numberp mouse-1-click-follows-link)
112 (>= mouse-1-click-follows-link 0))
113 timedout (not timedout))
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)
129 ;; Modify the event in place, so read-key-sequence doesn't
130 ;; generate a second fake prefix key (see fake_prefixed_keys in
132 (setcar this-event newdown)
134 (push event unread-command-events)
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)
143 ;; Provide a mode-specific menu on a mouse button.
145 (defun minor-mode-menu-from-indicator (indicator)
146 "Show menu for minor mode specified by INDICATOR.
147 Interactively, INDICATOR is read using completion.
148 If there is no menu defined for the minor mode, then create one with
149 items `Turn Off' and `Help'."
151 (list (completing-read
152 "Minor mode indicator: "
153 (describe-minor-mode-completion-table-for-indicator))))
154 (let* ((minor-mode (lookup-minor-mode-from-indicator indicator))
155 (mm-fun (or (get minor-mode :minor-mode-function) minor-mode)))
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]))))
161 (mouse-menu-non-singleton menu)
164 (turn-off menu-item "Turn Off minor mode" ,mm-fun)
165 (help menu-item "Help for minor mode"
166 (lambda () (interactive)
167 (describe-function ',mm-fun))))))
170 (defun mouse-minor-mode-menu (event)
171 "Show minor-mode menu for EVENT on minor modes area of the mode line."
173 (let ((indicator (car (nth 4 (car (cdr event))))))
174 (minor-mode-menu-from-indicator indicator)))
176 (defun mouse-menu-major-mode-map ()
177 (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
178 (let* (;; Keymap from which to inherit; may be null.
179 (ancestor (mouse-menu-non-singleton
180 (and (current-local-map)
181 (local-key-binding [menu-bar]))))
182 ;; Make a keymap in which our last command leads to a menu or
183 ;; default to the edit menu.
185 (make-sparse-keymap (concat (format-mode-line mode-name)
187 menu-bar-edit-menu)))
189 (set-keymap-parent newmap ancestor))
192 (defun mouse-menu-non-singleton (menubar)
193 "Return menu keybar MENUBAR, or a lone submenu inside it.
194 If MENUBAR defines exactly one submenu, return just that submenu.
195 Otherwise, return MENUBAR."
199 (lambda (k v) (setq submap (if submap t (cons k v))))
200 (keymap-canonicalize menubar))
203 (lookup-key menubar (vector (car submap)))))))
205 (defun mouse-menu-bar-map ()
206 "Return a keymap equivalent to the menu bar.
207 The contents are the items that would be in the menu bar whether or
208 not it is actually displayed."
209 (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
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]))
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.
221 (let* ((minor-mode (car menu))
223 (title-or-map (cadr menu)))
224 (or (stringp title-or-map)
228 (capitalize (subst-char-in-string
234 (minor-mode-key-binding [menu-bar])))
235 (local-title-or-map (and local-menu (cadr local-menu)))
236 (global-title-or-map (cadr global-menu)))
237 (or (null local-menu)
238 (stringp local-title-or-map)
239 (setq local-menu (cons 'keymap
240 (cons (concat (format-mode-line mode-name)
243 (or (stringp global-title-or-map)
244 (setq global-menu (cons 'keymap
246 (cdr global-menu)))))
247 ;; Supplying the list is faster than making a new map.
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.
256 (defun mouse-major-mode-menu (event &optional prefix)
257 "Pop up a mode-specific menu of mouse commands.
258 Default to the Edit menu if the major mode doesn't define a menu."
259 (declare (obsolete mouse-menu-major-mode-map "23.1"))
260 (interactive "@e\nP")
261 (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
262 (popup-menu (mouse-menu-major-mode-map) event prefix))
264 (defun mouse-popup-menubar (event prefix)
265 "Pop up a menu equivalent to the menu bar for keyboard EVENT with PREFIX.
266 The contents are the items that would be in the menu bar whether or
267 not it is actually displayed."
268 (declare (obsolete mouse-menu-bar-map "23.1"))
269 (interactive "@e \nP")
270 (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
271 (popup-menu (mouse-menu-bar-map) (unless (integerp event) event) prefix))
273 (defun mouse-popup-menubar-stuff (event prefix)
274 "Popup a menu like either `mouse-major-mode-menu' or `mouse-popup-menubar'.
275 Use the former if the menu bar is showing, otherwise the latter."
276 (declare (obsolete nil "23.1"))
277 (interactive "@e\nP")
278 (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
280 (if (zerop (or (frame-parameter nil 'menu-bar-lines) 0))
282 (mouse-menu-major-mode-map))
285 ;; Commands that operate on windows.
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))
291 (user-error "Minibuffer window is not active")))
292 ;; Give temporary modes such as isearch a chance to turn off.
293 (run-hooks 'mouse-leave-buffer-hook))
295 (defun mouse-delete-window (click)
296 "Delete the window you click on.
297 Do nothing if the frame has just one window.
298 This command must be bound to a mouse click."
300 (unless (one-window-p t)
301 (mouse-minibuffer-check click)
302 (delete-window (posn-window (event-start click)))))
304 (defun mouse-select-window (click)
305 "Select the window clicked on; don't move point."
307 (mouse-minibuffer-check click)
308 (let ((oframe (selected-frame))
309 (frame (window-frame (posn-window (event-start click)))))
310 (select-window (posn-window (event-start click)))
313 (or (eq frame oframe)
314 (set-mouse-position (selected-frame) (1- (frame-width)) 0))))
316 (define-obsolete-function-alias 'mouse-tear-off-window 'tear-off-window "24.4")
317 (defun tear-off-window (click)
318 "Delete the selected window, and create a new frame displaying its buffer."
320 (mouse-minibuffer-check click)
321 (let* ((window (posn-window (event-start click)))
322 (buf (window-buffer window))
323 (frame (make-frame))) ;FIXME: Use pop-to-buffer.
325 (switch-to-buffer buf)
326 (delete-window window)))
328 (defun mouse-delete-other-windows ()
329 "Delete all windows except the one you click on."
331 (delete-other-windows))
333 (defun mouse-split-window-vertically (click)
334 "Select Emacs window mouse is on, then split it vertically in half.
335 The window is split at the line clicked on.
336 This command must be bound to a mouse click."
338 (mouse-minibuffer-check click)
339 (let ((start (event-start click)))
340 (select-window (posn-window start))
341 (let ((new-height (1+ (cdr (posn-col-row (event-end click)))))
342 (first-line window-min-height)
343 (last-line (- (window-height) window-min-height)))
344 (if (< last-line first-line)
345 (error "Window too short to split")
346 (split-window-vertically
347 (min (max new-height first-line) last-line))))))
349 (defun mouse-split-window-horizontally (click)
350 "Select Emacs window mouse is on, then split it horizontally in half.
351 The window is split at the column clicked on.
352 This command must be bound to a mouse click."
354 (mouse-minibuffer-check click)
355 (let ((start (event-start click)))
356 (select-window (posn-window start))
357 (let ((new-width (1+ (car (posn-col-row (event-end click)))))
358 (first-col window-min-width)
359 (last-col (- (window-width) window-min-width)))
360 (if (< last-col first-col)
361 (error "Window too narrow to split")
362 (split-window-horizontally
363 (min (max new-width first-col) last-col))))))
365 ;; `mouse-drag-line' is now the common routine for handling all line
366 ;; dragging events combining the earlier `mouse-drag-mode-line-1' and
367 ;; `mouse-drag-vertical-line'. It should improve the behavior of line
368 ;; dragging wrt Emacs 23 as follows:
370 ;; (1) Gratuitous error messages and restrictions have been (hopefully)
371 ;; removed. (The help-echo that dragging the mode-line can resize a
372 ;; one-window-frame's window will still show through via bindings.el.)
374 ;; (2) No gratuitous selection of other windows should happen. (This
375 ;; has not been completely fixed for mouse-autoselected windows yet.)
377 ;; (3) Mouse clicks below a scroll-bar should pass through via unread
380 ;; Note that `window-in-direction' replaces `mouse-drag-window-above'
381 ;; and `mouse-drag-vertical-line-rightward-window' with Emacs 24.1.
383 (defun mouse-drag-line (start-event line)
384 "Drag a mode line, header line, or vertical line with the mouse.
385 START-EVENT is the starting mouse-event of the drag action. LINE
386 must be one of the symbols `header', `mode', or `vertical'."
387 ;; Give temporary modes such as isearch a chance to turn off.
388 (run-hooks 'mouse-leave-buffer-hook)
389 (let* ((echo-keystrokes 0)
390 (start (event-start start-event))
391 (window (posn-window start))
392 (frame (window-frame window))
393 (minibuffer-window (minibuffer-window frame))
394 (side (and (eq line 'vertical)
395 (or (cdr (assq 'vertical-scroll-bars
396 (frame-parameters frame)))
399 height finished event position growth dragged)
402 ;; Check whether header-line can be dragged at all.
403 (if (window-at-side-p window 'top)
405 (setq height (/ (window-header-line-height window) 2))
406 (setq window (window-in-direction 'above window t))))
408 ;; Check whether mode-line can be dragged at all.
409 (if (and (window-at-side-p window 'bottom)
410 ;; Allow resizing the minibuffer window if it's on the same
411 ;; frame as and immediately below the clicked window, and
412 ;; it's active or `resize-mini-windows' is nil.
413 (not (and (eq (window-frame minibuffer-window) frame)
414 (= (nth 1 (window-pixel-edges minibuffer-window))
415 (nth 3 (window-pixel-edges window)))
416 (or (not resize-mini-windows)
417 (eq minibuffer-window
418 (active-minibuffer-window))))))
420 (setq height (/ (window-mode-line-height window) 2))))
422 ;; Get the window to adjust for the vertical case. If the scroll
423 ;; bar is on the window's right or we drag a vertical divider,
424 ;; adjust the window where the start-event occurred. If the
425 ;; scroll bar is on the start-event window's left or there are no
426 ;; scrollbars, adjust the window on the left of it.
427 (unless (or (eq side 'right)
428 (not (zerop (window-right-divider-width window))))
429 (setq window (window-in-direction 'left window t)))))
433 ;; Loop reading events and sampling the position of the mouse.
434 (while (not finished)
435 (setq event (read-event))
436 (setq position (mouse-pixel-position))
438 ;; - there is a switch-frame event.
439 ;; - the mouse isn't in the frame that we started in
440 ;; - the mouse isn't in any Emacs frame
442 ;; - there is a mouse-movement event
443 ;; - there is a scroll-bar-movement event (Why? -- cyd)
444 ;; (same as mouse movement for our purposes)
446 ;; - there is a keyboard event or some other unknown event.
450 ((memq (car event) '(switch-frame select-window))
452 ((not (memq (car event) '(mouse-movement scroll-bar-movement)))
454 ;; Do not unread a drag-mouse-1 event to avoid selecting
455 ;; some other window. For vertical line dragging do not
456 ;; unread mouse-1 events either (but only if we dragged at
457 ;; least once to allow mouse-1 clicks get through).
459 (if (eq line 'vertical)
460 (memq (car event) '(drag-mouse-1 mouse-1))
461 (eq (car event) 'drag-mouse-1)))
462 (push event unread-command-events)))
464 ((not (and (eq (car position) frame)
468 ;; Drag vertical divider. This must be probably fixed like
469 ;; for the mode-line.
470 (setq growth (- (cadr position)
471 (if (eq side 'right) 0 2)
472 (nth 2 (window-pixel-edges window))
474 (unless (zerop growth)
476 (adjust-window-trailing-edge window growth t t)))
478 ;; Drag horizontal divider.
481 (- (+ (cddr position) height)
482 (nth 3 (window-pixel-edges window)))
483 ;; The window's top includes the header line!
484 (- (+ (nth 3 (window-pixel-edges window)) height)
486 (unless (zerop growth)
488 (adjust-window-trailing-edge
489 window (if (eq line 'mode) growth (- growth)) nil t))))))))
491 (defun mouse-drag-mode-line (start-event)
492 "Change the height of a window by dragging on the mode line."
494 (mouse-drag-line start-event 'mode))
496 (defun mouse-drag-header-line (start-event)
497 "Change the height of a window by dragging on the header line."
499 (mouse-drag-line start-event 'header))
501 (defun mouse-drag-vertical-line (start-event)
502 "Change the width of a window by dragging on the vertical line."
504 (mouse-drag-line start-event 'vertical))
506 (defun mouse-set-point (event &optional promote-to-region)
507 "Move point to the position clicked on with the mouse.
508 This should be bound to a mouse click event type.
509 If PROMOTE-TO-REGION is non-nil and event is a multiple-click,
510 select the corresponding element around point."
512 (mouse-minibuffer-check event)
513 (if (and promote-to-region (> (event-click-count event) 1))
514 (mouse-set-region event)
515 ;; Use event-end in case called from mouse-drag-region.
516 ;; If EVENT is a click, event-end and event-start give same value.
517 (posn-set-point (event-end event))))
519 (defvar mouse-last-region-beg nil)
520 (defvar mouse-last-region-end nil)
521 (defvar mouse-last-region-tick nil)
523 (defun mouse-region-match ()
524 "Return non-nil if there's an active region that was set with the mouse."
525 (and (mark t) mark-active
526 (eq mouse-last-region-beg (region-beginning))
527 (eq mouse-last-region-end (region-end))
528 (eq mouse-last-region-tick (buffer-modified-tick))))
530 (defvar mouse--drag-start-event nil)
532 (defun mouse-set-region (click)
533 "Set the region to the text dragged over, and copy to kill ring.
534 This should be bound to a mouse drag event.
535 See the `mouse-drag-copy-region' variable to control whether this
536 command alters the kill ring or not."
538 (mouse-minibuffer-check click)
539 (select-window (posn-window (event-start click)))
540 (let ((beg (posn-point (event-start click)))
541 (end (posn-point (event-end click)))
542 (click-count (event-click-count click)))
543 (let ((drag-start (terminal-parameter nil 'mouse-drag-start)))
545 ;; Drag events don't come with a click count, sadly, so we hack
546 ;; our way around this problem by remembering the start-event in
547 ;; `mouse-drag-start' and fetching the click-count from there.
548 (when (and (<= click-count 1)
549 (equal beg (posn-point (event-start drag-start))))
550 (setq click-count (event-click-count drag-start)))
551 ;; Occasionally we get spurious drag events where the user hasn't
552 ;; dragged his mouse, but instead Emacs has dragged the text under the
553 ;; user's mouse. Try to recover those cases (bug#17562).
554 (when (and (equal (posn-x-y (event-start click))
555 (posn-x-y (event-end click)))
556 (not (eq (car drag-start) 'mouse-movement)))
558 (setf (terminal-parameter nil 'mouse-drag-start) nil)))
559 (when (and (integerp beg) (integerp end))
560 (let ((range (mouse-start-end beg end (1- click-count))))
562 (setq end (nth 0 range) beg (nth 1 range))
563 (setq beg (nth 0 range) end (nth 1 range)))))
564 (and mouse-drag-copy-region (integerp beg) (integerp end)
565 ;; Don't set this-command to `kill-region', so a following
566 ;; C-w won't double the text in the kill ring. Ignore
567 ;; `last-command' so we don't append to a preceding kill.
568 (let (this-command last-command deactivate-mark)
569 (copy-region-as-kill beg end)))
570 (if (numberp beg) (goto-char beg))
571 ;; On a text terminal, bounce the cursor.
572 (or transient-mark-mode
577 (if (numberp end) (goto-char end))
578 (mouse-set-region-1)))
580 (defun mouse-set-region-1 ()
581 ;; Set transient-mark-mode for a little while.
582 (unless (eq (car-safe transient-mark-mode) 'only)
583 (setq-local transient-mark-mode
585 (unless (eq transient-mark-mode 'lambda)
586 transient-mark-mode))))
587 (setq mouse-last-region-beg (region-beginning))
588 (setq mouse-last-region-end (region-end))
589 (setq mouse-last-region-tick (buffer-modified-tick)))
591 (defcustom mouse-scroll-delay 0.25
592 "The pause between scroll steps caused by mouse drags, in seconds.
593 If you drag the mouse beyond the edge of a window, Emacs scrolls the
594 window to bring the text beyond that edge into view, with a delay of
595 this many seconds between scroll steps. Scrolling stops when you move
596 the mouse back into the window, or release the button.
597 This variable's value may be non-integral.
598 Setting this to zero causes Emacs to scroll as fast as it can."
602 (defcustom mouse-scroll-min-lines 1
603 "The minimum number of lines scrolled by dragging mouse out of window.
604 Moving the mouse out the top or bottom edge of the window begins
605 scrolling repeatedly. The number of lines scrolled per repetition
606 is normally equal to the number of lines beyond the window edge that
607 the mouse has moved. However, it always scrolls at least the number
608 of lines specified by this variable."
612 (defun mouse-scroll-subr (window jump &optional overlay start)
613 "Scroll the window WINDOW, JUMP lines at a time, until new input arrives.
614 If OVERLAY is an overlay, let it stretch from START to the far edge of
615 the newly visible text.
616 Upon exit, point is at the far edge of the newly visible text."
618 ((and (> jump 0) (< jump mouse-scroll-min-lines))
619 (setq jump mouse-scroll-min-lines))
620 ((and (< jump 0) (< (- jump) mouse-scroll-min-lines))
621 (setq jump (- mouse-scroll-min-lines))))
622 (let ((opoint (point)))
624 (goto-char (window-start window))
625 (if (not (zerop (vertical-motion jump window)))
627 (set-window-start window (point))
629 (if (window-end window)
631 (goto-char (window-end window))
632 ;; window-end doesn't reflect the window's new
633 ;; start position until the next redisplay.
634 (vertical-motion (1- jump) window))
635 (vertical-motion (- (window-height window) 2)))
636 (goto-char (window-start window)))
638 (move-overlay overlay start (point)))
639 ;; Now that we have scrolled WINDOW properly,
640 ;; put point back where it was for the redisplay
641 ;; so that we don't mess up the selected window.
642 (or (eq window (selected-window))
644 (sit-for mouse-scroll-delay)))))
645 (or (eq window (selected-window))
646 (goto-char opoint))))
648 (defvar mouse-selection-click-count 0)
650 (defvar mouse-selection-click-count-buffer nil)
652 (defun mouse-drag-region (start-event)
653 "Set the region to the text that the mouse is dragged over.
654 Highlight the drag area as you move the mouse.
655 This must be bound to a button-down mouse event.
656 In Transient Mark mode, the highlighting remains as long as the mark
657 remains active. Otherwise, it remains until the next input event."
659 ;; Give temporary modes such as isearch a chance to turn off.
660 (run-hooks 'mouse-leave-buffer-hook)
661 (mouse-drag-track start-event))
664 (defun mouse-posn-property (pos property)
665 "Look for a property at click position.
666 POS may be either a buffer position or a click position like
667 those returned from `event-start'. If the click position is on
668 a string, the text property PROPERTY is examined.
669 If this is nil or the click is not on a string, then
670 the corresponding buffer position is searched for PROPERTY.
671 If PROPERTY is encountered in one of those places,
672 its value is returned."
674 (let ((w (posn-window pos)) (pt (posn-point pos))
675 (str (posn-string pos)))
677 (get-text-property (cdr str) property (car str)))
678 ;; Mouse clicks in the fringe come with a position in
679 ;; (nth 5). This is useful but is not exactly where we clicked, so
680 ;; don't look up that position's properties!
681 (and pt (not (memq (posn-area pos) '(left-fringe right-fringe
682 left-margin right-margin)))
683 (get-char-property pt property w))))
684 (get-char-property pos property)))
686 (defun mouse-on-link-p (pos)
687 "Return non-nil if POS is on a link in the current buffer.
688 POS must be a buffer position in the current buffer or a mouse
689 event location in the selected window (see `event-start').
690 However, if `mouse-1-click-in-non-selected-windows' is non-nil,
691 POS may be a mouse event location in any window.
693 A clickable link is identified by one of the following methods:
695 - If the character at POS has a non-nil `follow-link' text or
696 overlay property, the value of that property determines what to do.
698 - If there is a local key-binding or a keybinding at position POS
699 for the `follow-link' event, the binding of that event determines
702 The resulting value determine whether POS is inside a link:
704 - If the value is `mouse-face', POS is inside a link if there
705 is a non-nil `mouse-face' property at POS. Return t in this case.
707 - If the value is a function, FUNC, POS is inside a link if
708 the call \(FUNC POS) returns non-nil. Return the return value
709 from that call. Arg is \(posn-point POS) if POS is a mouse event.
711 - Otherwise, return the value itself.
713 The return value is interpreted as follows:
715 - If it is a string, the mouse-1 event is translated into the
716 first character of the string, i.e. the action of the mouse-1
717 click is the local or global binding of that character.
719 - If it is a vector, the mouse-1 event is translated into the
720 first element of that vector, i.e. the action of the mouse-1
721 click is the local or global binding of that event.
723 - Otherwise, the mouse-1 event is translated into a mouse-2 event
724 at the same position."
726 (and (or (not (consp pos))
727 mouse-1-click-in-non-selected-windows
728 (eq (selected-window) (posn-window pos)))
729 (or (mouse-posn-property pos 'follow-link)
730 (let ((area (posn-area pos)))
732 (key-binding (vector area 'follow-link) nil t pos)))
733 (key-binding [follow-link] nil t pos)))))
735 ((eq action 'mouse-face)
736 (and (mouse-posn-property pos 'mouse-face) t))
738 ;; FIXME: This seems questionable if the click is not in a buffer.
739 ;; Should we instead decide that `action' takes a `posn'?
741 (with-current-buffer (window-buffer (posn-window pos))
742 (funcall action (posn-point pos)))
743 (funcall action pos)))
746 (defun mouse-fixup-help-message (msg)
747 "Fix help message MSG for `mouse-1-click-follows-link'."
749 (if (and mouse-1-click-follows-link
751 (string-match-p "\\`mouse-2" msg)
752 (setq mp (mouse-pixel-position))
753 (consp (setq pos (cdr mp)))
754 (car pos) (>= (car pos) 0)
755 (cdr pos) (>= (cdr pos) 0)
756 (setq pos (posn-at-x-y (car pos) (cdr pos) (car mp)))
757 (windowp (posn-window pos)))
758 (with-current-buffer (window-buffer (posn-window pos))
759 (if (mouse-on-link-p pos)
762 ((eq mouse-1-click-follows-link 'double) "double-")
763 ((and (integerp mouse-1-click-follows-link)
764 (< mouse-1-click-follows-link 0)) "Long ")
766 "mouse-1" (substring msg 7)))))))
769 (defun mouse-drag-track (start-event)
770 "Track mouse drags by highlighting area between point and cursor.
771 The region will be defined with mark and point."
772 (mouse-minibuffer-check start-event)
773 (setq mouse-selection-click-count-buffer (current-buffer))
775 (let* ((scroll-margin 0) ; Avoid margin scrolling (Bug#9541).
776 ;; We've recorded what we needed from the current buffer and
777 ;; window, now let's jump to the place of the event, where things
779 (_ (mouse-set-point start-event))
781 (start-posn (event-start start-event))
782 (start-point (posn-point start-posn))
783 (start-window (posn-window start-posn))
784 (bounds (window-edges start-window))
785 (make-cursor-line-fully-visible nil)
787 (bottom (if (window-minibuffer-p start-window)
789 ;; Don't count the mode line.
790 (1- (nth 3 bounds))))
791 (click-count (1- (event-click-count start-event)))
792 ;; Suppress automatic hscrolling, because that is a nuisance
793 ;; when setting point near the right fringe (but see below).
794 (auto-hscroll-mode-saved auto-hscroll-mode))
796 (setq mouse-selection-click-count click-count)
797 ;; In case the down click is in the middle of some intangible text,
798 ;; use the end of that text, and put it in START-POINT.
799 (if (< (point) start-point)
800 (goto-char start-point))
801 (setq start-point (point))
803 ;; Activate the region, using `mouse-start-end' to determine where
804 ;; to put point and mark (e.g., double-click will select a word).
805 (setq-local transient-mark-mode
806 (if (eq transient-mark-mode 'lambda)
808 (cons 'only transient-mark-mode)))
809 (let ((range (mouse-start-end start-point start-point click-count)))
810 (push-mark (nth 0 range) t t)
811 (goto-char (nth 1 range)))
813 (setf (terminal-parameter nil 'mouse-drag-start) start-event)
815 (setq auto-hscroll-mode nil)
818 (let ((map (make-sparse-keymap)))
819 (define-key map [switch-frame] #'ignore)
820 (define-key map [select-window] #'ignore)
821 (define-key map [mouse-movement]
822 (lambda (event) (interactive "e")
823 (let* ((end (event-end event))
824 (end-point (posn-point end)))
825 (unless (eq end-point start-point)
826 ;; As soon as the user moves, we can re-enable auto-hscroll.
827 (setq auto-hscroll-mode auto-hscroll-mode-saved)
828 ;; And remember that we have moved, so mouse-set-region can know
829 ;; its event is really a drag event.
830 (setcar start-event 'mouse-movement))
831 (if (and (eq (posn-window end) start-window)
832 (integer-or-marker-p end-point))
833 (mouse--drag-set-mark-and-point start-point
834 end-point click-count)
835 (let ((mouse-row (cdr (cdr (mouse-position)))))
839 (mouse-scroll-subr start-window (- mouse-row top)
841 ((>= mouse-row bottom)
842 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
843 nil start-point))))))))
846 (setq track-mouse nil)
847 (setq auto-hscroll-mode auto-hscroll-mode-saved)
851 (defun mouse--drag-set-mark-and-point (start click click-count)
852 (let* ((range (mouse-start-end start click click-count))
855 (cond ((eq (mark) beg)
866 ;; Commands to handle xterm-style multiple clicks.
867 (defun mouse-skip-word (dir)
868 "Skip over word, over whitespace, or over identical punctuation.
869 If DIR is positive skip forward; if negative, skip backward."
870 (let* ((char (following-char))
871 (syntax (char-to-string (char-syntax char))))
872 (cond ((string= syntax "w")
873 ;; Here, we can't use skip-syntax-forward/backward because
874 ;; they don't pay attention to word-separating-categories,
875 ;; and thus they will skip over a true word boundary. So,
876 ;; we simulate the original behavior by using forward-word.
878 (if (not (looking-at "\\<"))
880 (if (or (looking-at "\\<") (not (looking-at "\\>")))
882 ((string= syntax " ")
884 (skip-syntax-backward syntax)
885 (skip-syntax-forward syntax)))
886 ((string= syntax "_")
888 (skip-syntax-backward "w_")
889 (skip-syntax-forward "w_")))
891 (while (and (not (bobp)) (= (preceding-char) char))
894 (while (and (not (eobp)) (= (following-char) char))
895 (forward-char 1))))))
897 (defun mouse-start-end (start end mode)
898 "Return a list of region bounds based on START and END according to MODE.
899 If MODE is 0 then set point to (min START END), mark to (max START END).
900 If MODE is 1 then set point to start of word at (min START END),
901 mark to end of word at (max START END).
902 If MODE is 2 then do the same for lines."
907 (setq mode (mod mode 3))
913 (= (char-syntax (char-after start)) ?\())
922 (= (char-syntax (char-after start)) ?\)))
923 (list (save-excursion
924 (goto-char (1+ start))
931 (= (char-syntax (char-after start)) ?\"))
932 (let ((open (or (eq start (point-min))
934 (goto-char (- start 1))
935 (looking-at "\\s(\\|\\s \\|\\s>")))))
945 (list (save-excursion
948 (goto-char (1+ start))
954 (list (save-excursion
963 (list (save-excursion
965 (line-beginning-position 1))
971 ;; Subroutine: set the mark where CLICK happened,
972 ;; but don't do anything else.
973 (defun mouse-set-mark-fast (click)
974 (mouse-minibuffer-check click)
975 (let ((posn (event-start click)))
976 (select-window (posn-window posn))
977 (if (numberp (posn-point posn))
978 (push-mark (posn-point posn) t t))))
980 (defun mouse-undouble-last-event (events)
981 (let* ((index (1- (length events)))
982 (last (nthcdr index events))
984 (basic (event-basic-type event))
985 (old-modifiers (event-modifiers event))
986 (modifiers (delq 'double (delq 'triple (copy-sequence old-modifiers))))
989 ;; Use reverse, not nreverse, since event-modifiers
990 ;; does not copy the list it returns.
991 (cons (event-convert-list (reverse (cons basic modifiers)))
995 (if (and (not (equal modifiers old-modifiers))
996 (key-binding (apply 'vector events)))
1001 ;; Momentarily show where the mark is, if highlighting doesn't show it.
1003 (defun mouse-set-mark (click)
1004 "Set mark at the position clicked on with the mouse.
1005 Display cursor at that position for a second.
1006 This must be bound to a mouse click."
1008 (mouse-minibuffer-check click)
1009 (select-window (posn-window (event-start click)))
1010 ;; We don't use save-excursion because that preserves the mark too.
1011 (let ((point-save (point)))
1013 (progn (mouse-set-point click)
1015 (or transient-mark-mode
1017 (goto-char point-save))))
1019 (defun mouse-kill (click)
1020 "Kill the region between point and the mouse click.
1021 The text is saved in the kill ring, as with \\[kill-region]."
1023 (mouse-minibuffer-check click)
1024 (let* ((posn (event-start click))
1025 (click-posn (posn-point posn)))
1026 (select-window (posn-window posn))
1027 (if (numberp click-posn)
1028 (kill-region (min (point) click-posn)
1029 (max (point) click-posn)))))
1031 (defun mouse-yank-at-click (click arg)
1032 "Insert the last stretch of killed text at the position clicked on.
1033 Also move point to one end of the text thus inserted (normally the end),
1034 and set mark at the beginning.
1035 Prefix arguments are interpreted as with \\[yank].
1036 If `mouse-yank-at-point' is non-nil, insert at point
1037 regardless of where you click."
1038 (interactive "e\nP")
1039 ;; Give temporary modes such as isearch a chance to turn off.
1040 (run-hooks 'mouse-leave-buffer-hook)
1041 (when select-active-regions
1042 ;; Without this, confusing things happen upon e.g. inserting into
1043 ;; the middle of an active region.
1045 (or mouse-yank-at-point (mouse-set-point click))
1046 (setq this-command 'yank)
1047 (setq mouse-selection-click-count 0)
1050 (defun mouse-yank-primary (click)
1051 "Insert the primary selection at the position clicked on.
1052 Move point to the end of the inserted text, and set mark at
1053 beginning. If `mouse-yank-at-point' is non-nil, insert at point
1054 regardless of where you click."
1056 ;; Give temporary modes such as isearch a chance to turn off.
1057 (run-hooks 'mouse-leave-buffer-hook)
1058 ;; Without this, confusing things happen upon e.g. inserting into
1059 ;; the middle of an active region.
1060 (when select-active-regions
1061 (let (select-active-regions)
1063 (or mouse-yank-at-point (mouse-set-point click))
1065 (if (fboundp 'x-get-selection-value)
1066 (if (eq (framep (selected-frame)) 'w32)
1067 ;; MS-Windows emulates PRIMARY in x-get-selection, but not
1068 ;; in x-get-selection-value (the latter only accesses the
1069 ;; clipboard). So try PRIMARY first, in case they selected
1070 ;; something with the mouse in the current Emacs session.
1071 (or (x-get-selection 'PRIMARY)
1072 (x-get-selection-value))
1073 ;; Else MS-DOS or X.
1074 ;; On X, x-get-selection-value supports more formats and
1075 ;; encodings, so use it in preference to x-get-selection.
1076 (or (x-get-selection-value)
1077 (x-get-selection 'PRIMARY)))
1078 ;; FIXME: What about xterm-mouse-mode etc.?
1079 (x-get-selection 'PRIMARY))))
1081 (error "No selection is available"))
1083 (insert-for-yank primary)))
1085 (defun mouse-kill-ring-save (click)
1086 "Copy the region between point and the mouse click in the kill ring.
1087 This does not delete the region; it acts like \\[kill-ring-save]."
1089 (mouse-set-mark-fast click)
1090 (let (this-command last-command)
1091 (kill-ring-save (point) (mark t))))
1093 ;; This function used to delete the text between point and the mouse
1094 ;; whenever it was equal to the front of the kill ring, but some
1095 ;; people found that confusing.
1097 ;; The position of the last invocation of `mouse-save-then-kill'.
1098 (defvar mouse-save-then-kill-posn nil)
1100 (defun mouse-save-then-kill-delete-region (beg end)
1101 ;; We must make our own undo boundaries
1102 ;; because they happen automatically only for the current buffer.
1104 (if (or (= beg end) (eq buffer-undo-list t))
1105 ;; If we have no undo list in this buffer,
1107 (delete-region beg end)
1108 ;; Delete, but make the undo-list entry share with the kill ring.
1109 ;; First, delete just one char, so in case buffer is being modified
1110 ;; for the first time, the undo list records that fact.
1111 (let (before-change-functions after-change-functions)
1113 (+ beg (if (> end beg) 1 -1))))
1114 (let ((buffer-undo-list buffer-undo-list))
1115 ;; Undo that deletion--but don't change the undo list!
1116 (let (before-change-functions after-change-functions)
1117 (primitive-undo 1 buffer-undo-list))
1118 ;; Now delete the rest of the specified region,
1119 ;; but don't record it.
1120 (setq buffer-undo-list t)
1121 (if (/= (length (car kill-ring)) (- (max end beg) (min end beg)))
1122 (error "Lossage in mouse-save-then-kill-delete-region"))
1123 (delete-region beg end))
1124 (let ((tail buffer-undo-list))
1125 ;; Search back in buffer-undo-list for the string
1126 ;; that came from deleting one character.
1127 (while (and tail (not (stringp (car (car tail)))))
1128 (setq tail (cdr tail)))
1129 ;; Replace it with an entry for the entire deleted text.
1131 (setcar tail (cons (car kill-ring) (min beg end))))))
1134 (defun mouse-save-then-kill (click)
1135 "Set the region according to CLICK; the second time, kill it.
1136 CLICK should be a mouse click event.
1138 If the region is inactive, activate it temporarily. Set mark at
1139 the original point, and move point to the position of CLICK.
1141 If the region is already active, adjust it. Normally, do this by
1142 moving point or mark, whichever is closer, to CLICK. But if you
1143 have selected whole words or lines, move point or mark to the
1144 word or line boundary closest to CLICK instead.
1146 If `mouse-drag-copy-region' is non-nil, this command also saves the
1147 new region to the kill ring (replacing the previous kill if the
1148 previous region was just saved to the kill ring).
1150 If this command is called a second consecutive time with the same
1151 CLICK position, kill the region (or delete it
1152 if `mouse-drag-copy-region' is non-nil)"
1154 (mouse-minibuffer-check click)
1155 (let* ((posn (event-start click))
1156 (click-pt (posn-point posn))
1157 (window (posn-window posn))
1158 (buf (window-buffer window))
1159 ;; Don't let a subsequent kill command append to this one.
1160 (this-command this-command)
1161 ;; Check if the user has multi-clicked to select words/lines.
1163 (if (and (eq mouse-selection-click-count-buffer buf)
1164 (with-current-buffer buf (mark t)))
1165 mouse-selection-click-count
1168 ((not (numberp click-pt)) nil)
1169 ;; If the user clicked without moving point, kill the region.
1170 ;; This also resets `mouse-selection-click-count'.
1171 ((and (eq last-command 'mouse-save-then-kill)
1172 (eq click-pt mouse-save-then-kill-posn)
1173 (eq window (selected-window)))
1174 (if mouse-drag-copy-region
1175 ;; Region already saved in the previous click;
1176 ;; don't make a duplicate entry, just delete.
1177 (delete-region (mark t) (point))
1178 (kill-region (mark t) (point)))
1179 (setq mouse-selection-click-count 0)
1180 (setq mouse-save-then-kill-posn nil))
1182 ;; Otherwise, if there is a suitable region, adjust it by moving
1183 ;; one end (whichever is closer) to CLICK-PT.
1184 ((or (with-current-buffer buf (region-active-p))
1185 (and (eq window (selected-window))
1187 (or (and (eq last-command 'mouse-save-then-kill)
1188 mouse-save-then-kill-posn)
1189 (and (memq last-command '(mouse-drag-region
1191 (or mark-even-if-inactive
1192 (not transient-mark-mode))))))
1193 (select-window window)
1194 (let* ((range (mouse-start-end click-pt click-pt click-count)))
1195 (if (< (abs (- click-pt (mark t)))
1196 (abs (- click-pt (point))))
1197 (set-mark (car range))
1198 (goto-char (nth 1 range)))
1199 (setq deactivate-mark nil)
1200 (mouse-set-region-1)
1201 (when mouse-drag-copy-region
1202 ;; Region already copied to kill-ring once, so replace.
1203 (kill-new (filter-buffer-substring (mark t) (point)) t))
1204 ;; Arrange for a repeated mouse-3 to kill the region.
1205 (setq mouse-save-then-kill-posn click-pt)))
1207 ;; Otherwise, set the mark where point is and move to CLICK-PT.
1209 (select-window window)
1210 (mouse-set-mark-fast click)
1211 (let ((before-scroll (with-current-buffer buf point-before-scroll)))
1212 (if before-scroll (goto-char before-scroll)))
1213 (exchange-point-and-mark)
1214 (mouse-set-region-1)
1215 (when mouse-drag-copy-region
1216 (kill-new (filter-buffer-substring (mark t) (point))))
1217 (setq mouse-save-then-kill-posn click-pt)))))
1220 (global-set-key [M-mouse-1] 'mouse-start-secondary)
1221 (global-set-key [M-drag-mouse-1] 'mouse-set-secondary)
1222 (global-set-key [M-down-mouse-1] 'mouse-drag-secondary)
1223 (global-set-key [M-mouse-3] 'mouse-secondary-save-then-kill)
1224 (global-set-key [M-mouse-2] 'mouse-yank-secondary)
1226 (defconst mouse-secondary-overlay
1227 (let ((ol (make-overlay (point-min) (point-min))))
1229 (overlay-put ol 'face 'secondary-selection)
1231 "An overlay which records the current secondary selection.
1232 It is deleted when there is no secondary selection.")
1234 (defvar mouse-secondary-click-count 0)
1236 ;; A marker which records the specified first end for a secondary selection.
1238 (defvar mouse-secondary-start nil)
1240 (defun mouse-start-secondary (click)
1241 "Set one end of the secondary selection to the position clicked on.
1242 Use \\[mouse-secondary-save-then-kill] to set the other end
1243 and complete the secondary selection."
1245 (mouse-minibuffer-check click)
1246 (let ((posn (event-start click)))
1247 (with-current-buffer (window-buffer (posn-window posn))
1248 ;; Cancel any preexisting secondary selection.
1249 (delete-overlay mouse-secondary-overlay)
1250 (if (numberp (posn-point posn))
1252 (or mouse-secondary-start
1253 (setq mouse-secondary-start (make-marker)))
1254 (move-marker mouse-secondary-start (posn-point posn)))))))
1256 (defun mouse-set-secondary (click)
1257 "Set the secondary selection to the text that the mouse is dragged over.
1258 This must be bound to a mouse drag event."
1260 (mouse-minibuffer-check click)
1261 (let ((posn (event-start click))
1263 (end (event-end click)))
1264 (with-current-buffer (window-buffer (posn-window posn))
1265 (if (numberp (posn-point posn))
1266 (setq beg (posn-point posn)))
1267 (move-overlay mouse-secondary-overlay beg (posn-point end))
1270 (buffer-substring (overlay-start mouse-secondary-overlay)
1271 (overlay-end mouse-secondary-overlay))))))
1273 (defun mouse-drag-secondary (start-event)
1274 "Set the secondary selection to the text that the mouse is dragged over.
1275 Highlight the drag area as you move the mouse.
1276 This must be bound to a button-down mouse event.
1277 The function returns a non-nil value if it creates a secondary selection."
1279 (mouse-minibuffer-check start-event)
1280 (let* ((echo-keystrokes 0)
1281 (start-posn (event-start start-event))
1282 (start-point (posn-point start-posn))
1283 (start-window (posn-window start-posn))
1284 (bounds (window-edges start-window))
1285 (top (nth 1 bounds))
1286 (bottom (if (window-minibuffer-p start-window)
1288 ;; Don't count the mode line.
1289 (1- (nth 3 bounds))))
1290 (click-count (1- (event-click-count start-event))))
1291 (with-current-buffer (window-buffer start-window)
1292 (setq mouse-secondary-click-count click-count)
1293 (if (> (mod click-count 3) 0)
1294 ;; Double or triple press: make an initial selection
1295 ;; of one word or line.
1296 (let ((range (mouse-start-end start-point start-point click-count)))
1297 (set-marker mouse-secondary-start nil)
1298 (move-overlay mouse-secondary-overlay (car range) (nth 1 range)
1299 (window-buffer start-window)))
1300 ;; Single-press: cancel any preexisting secondary selection.
1301 (or mouse-secondary-start
1302 (setq mouse-secondary-start (make-marker)))
1303 (set-marker mouse-secondary-start start-point)
1304 (delete-overlay mouse-secondary-overlay))
1305 (let (event end end-point)
1308 (setq event (read-event))
1309 (or (mouse-movement-p event)
1310 (memq (car-safe event) '(switch-frame select-window))))
1312 (if (memq (car-safe event) '(switch-frame select-window))
1314 (setq end (event-end event)
1315 end-point (posn-point end))
1317 ;; Are we moving within the original window?
1318 ((and (eq (posn-window end) start-window)
1319 (integer-or-marker-p end-point))
1320 (let ((range (mouse-start-end start-point end-point
1322 (if (or (/= start-point end-point)
1323 (null (marker-position mouse-secondary-start)))
1325 (set-marker mouse-secondary-start nil)
1326 (move-overlay mouse-secondary-overlay
1327 (car range) (nth 1 range))))))
1329 (let ((mouse-row (cdr (cdr (mouse-position)))))
1333 (mouse-scroll-subr start-window (- mouse-row top)
1334 mouse-secondary-overlay start-point))
1335 ((>= mouse-row bottom)
1336 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
1337 mouse-secondary-overlay start-point)))))))))
1340 (if (marker-position mouse-secondary-start)
1341 (save-window-excursion
1342 (delete-overlay mouse-secondary-overlay)
1343 (x-set-selection 'SECONDARY nil)
1344 (select-window start-window)
1346 (goto-char mouse-secondary-start)
1351 (buffer-substring (overlay-start mouse-secondary-overlay)
1352 (overlay-end mouse-secondary-overlay)))))))))
1354 (defun mouse-yank-secondary (click)
1355 "Insert the secondary selection at the position clicked on.
1356 Move point to the end of the inserted text.
1357 If `mouse-yank-at-point' is non-nil, insert at point
1358 regardless of where you click."
1360 ;; Give temporary modes such as isearch a chance to turn off.
1361 (run-hooks 'mouse-leave-buffer-hook)
1362 (or mouse-yank-at-point (mouse-set-point click))
1363 (let ((secondary (x-get-selection 'SECONDARY)))
1365 (insert-for-yank secondary)
1366 (error "No secondary selection"))))
1368 (defun mouse-kill-secondary ()
1369 "Kill the text in the secondary selection.
1370 This is intended more as a keyboard command than as a mouse command
1371 but it can work as either one.
1373 The current buffer (in case of keyboard use), or the buffer clicked on,
1374 must be the one that the secondary selection is in. This requirement
1375 is to prevent accidents."
1377 (let* ((keys (this-command-keys))
1378 (click (elt keys (1- (length keys)))))
1379 (or (eq (overlay-buffer mouse-secondary-overlay)
1381 (window-buffer (posn-window (event-start click)))
1383 (error "Select or click on the buffer where the secondary selection is")))
1385 (with-current-buffer (overlay-buffer mouse-secondary-overlay)
1386 (kill-region (overlay-start mouse-secondary-overlay)
1387 (overlay-end mouse-secondary-overlay))))
1388 (delete-overlay mouse-secondary-overlay))
1390 (defun mouse-secondary-save-then-kill (click)
1391 "Set the secondary selection and save it to the kill ring.
1392 The second time, kill it. CLICK should be a mouse click event.
1394 If you have not called `mouse-start-secondary' in the clicked
1395 buffer, activate the secondary selection and set it between point
1396 and the click position CLICK.
1398 Otherwise, adjust the bounds of the secondary selection.
1399 Normally, do this by moving its beginning or end, whichever is
1400 closer, to CLICK. But if you have selected whole words or lines,
1401 adjust to the word or line boundary closest to CLICK instead.
1403 If this command is called a second consecutive time with the same
1404 CLICK position, kill the secondary selection."
1406 (mouse-minibuffer-check click)
1407 (let* ((posn (event-start click))
1408 (click-pt (posn-point posn))
1409 (window (posn-window posn))
1410 (buf (window-buffer window))
1411 ;; Don't let a subsequent kill command append to this one.
1412 (this-command this-command)
1413 ;; Check if the user has multi-clicked to select words/lines.
1415 (if (eq (overlay-buffer mouse-secondary-overlay) buf)
1416 mouse-secondary-click-count
1418 (beg (overlay-start mouse-secondary-overlay))
1419 (end (overlay-end mouse-secondary-overlay)))
1422 ((not (numberp click-pt)) nil)
1424 ;; If the secondary selection is not active in BUF, activate it.
1425 ((not (eq buf (or (overlay-buffer mouse-secondary-overlay)
1426 (if mouse-secondary-start
1427 (marker-buffer mouse-secondary-start)))))
1428 (select-window window)
1429 (setq mouse-secondary-start (make-marker))
1430 (move-marker mouse-secondary-start (point))
1431 (move-overlay mouse-secondary-overlay (point) click-pt buf)
1432 (kill-ring-save (point) click-pt))
1434 ;; If the user clicked without moving point, delete the secondary
1435 ;; selection. This also resets `mouse-secondary-click-count'.
1436 ((and (eq last-command 'mouse-secondary-save-then-kill)
1437 (eq click-pt mouse-save-then-kill-posn)
1438 (eq window (selected-window)))
1439 (mouse-save-then-kill-delete-region beg end)
1440 (delete-overlay mouse-secondary-overlay)
1441 (setq mouse-secondary-click-count 0)
1442 (setq mouse-save-then-kill-posn nil))
1444 ;; Otherwise, if there is a suitable secondary selection overlay,
1445 ;; adjust it by moving one end (whichever is closer) to CLICK-PT.
1446 ((and beg (eq buf (overlay-buffer mouse-secondary-overlay)))
1447 (let* ((range (mouse-start-end click-pt click-pt click-count)))
1448 (if (< (abs (- click-pt beg))
1449 (abs (- click-pt end)))
1450 (move-overlay mouse-secondary-overlay (car range) end)
1451 (move-overlay mouse-secondary-overlay beg (nth 1 range))))
1452 (setq deactivate-mark nil)
1453 (if (eq last-command 'mouse-secondary-save-then-kill)
1454 ;; If the front of the kill ring comes from an immediately
1455 ;; previous use of this command, replace the entry.
1457 (buffer-substring (overlay-start mouse-secondary-overlay)
1458 (overlay-end mouse-secondary-overlay))
1460 (let (deactivate-mark)
1461 (copy-region-as-kill (overlay-start mouse-secondary-overlay)
1462 (overlay-end mouse-secondary-overlay))))
1463 (setq mouse-save-then-kill-posn click-pt))
1465 ;; Otherwise, set the secondary selection overlay.
1467 (select-window window)
1468 (if mouse-secondary-start
1469 ;; All we have is one end of a selection, so put the other
1471 (let ((start (+ 0 mouse-secondary-start)))
1472 (kill-ring-save start click-pt)
1473 (move-overlay mouse-secondary-overlay start click-pt)))
1474 (setq mouse-save-then-kill-posn click-pt))))
1476 ;; Finally, set the window system's secondary selection.
1478 (and (overlay-buffer mouse-secondary-overlay)
1479 (setq str (buffer-substring (overlay-start mouse-secondary-overlay)
1480 (overlay-end mouse-secondary-overlay)))
1482 (x-set-selection 'SECONDARY str))))
1485 (defcustom mouse-buffer-menu-maxlen 20
1486 "Number of buffers in one pane (submenu) of the buffer menu.
1487 If we have lots of buffers, divide them into groups of
1488 `mouse-buffer-menu-maxlen' and make a pane (or submenu) for each one."
1492 (defcustom mouse-buffer-menu-mode-mult 4
1493 "Group the buffers by the major mode groups on \\[mouse-buffer-menu]?
1494 This number which determines (in a hairy way) whether \\[mouse-buffer-menu]
1495 will split the buffer menu by the major modes (see
1496 `mouse-buffer-menu-mode-groups') or just by menu length.
1497 Set to 1 (or even 0!) if you want to group by major mode always, and to
1498 a large number if you prefer a mixed multitude. The default is 4."
1503 (defvar mouse-buffer-menu-mode-groups
1504 (mapcar (lambda (arg) (cons (purecopy (car arg)) (purecopy (cdr arg))))
1505 '(("Info\\|Help\\|Apropos\\|Man" . "Help")
1506 ("\\bVM\\b\\|\\bMH\\b\\|Message\\|Mail\\|Group\\|Score\\|Summary\\|Article"
1511 ("Outline" . "Text")
1512 ("\\(HT\\|SG\\|X\\|XHT\\)ML" . "SGML")
1513 ("log\\|diff\\|vc\\|cvs\\|Annotate" . "Version Control") ; "Change Management"?
1514 ("Threads\\|Memory\\|Disassembly\\|Breakpoints\\|Frames\\|Locals\\|Registers\\|Inferior I/O\\|Debugger"
1517 "How to group various major modes together in \\[mouse-buffer-menu].
1518 Each element has the form (REGEXP . GROUPNAME).
1519 If the major mode's name string matches REGEXP, use GROUPNAME instead.")
1521 (defun mouse-buffer-menu (event)
1522 "Pop up a menu of buffers for selection with the mouse.
1523 This switches buffers in the window that you clicked on,
1524 and selects that window."
1526 (mouse-minibuffer-check event)
1527 (let ((buffers (buffer-list)) alist menu split-by-major-mode sum-of-squares)
1528 ;; Make an alist of elements that look like (MENU-ITEM . BUFFER).
1529 (dolist (buf buffers)
1530 ;; Divide all buffers into buckets for various major modes.
1531 ;; Each bucket looks like (MODE NAMESTRING BUFFERS...).
1532 (with-current-buffer buf
1533 (let* ((adjusted-major-mode major-mode) elt)
1534 (dolist (group mouse-buffer-menu-mode-groups)
1535 (when (string-match (car group) (format-mode-line mode-name))
1536 (setq adjusted-major-mode (cdr group))))
1537 (setq elt (assoc adjusted-major-mode split-by-major-mode))
1539 (setq elt (list adjusted-major-mode
1540 (if (stringp adjusted-major-mode)
1542 (format-mode-line mode-name nil nil buf)))
1543 split-by-major-mode (cons elt split-by-major-mode)))
1544 (or (memq buf (cdr (cdr elt)))
1545 (setcdr (cdr elt) (cons buf (cdr (cdr elt))))))))
1546 ;; Compute the sum of squares of sizes of the major-mode buckets.
1547 (let ((tail split-by-major-mode))
1548 (setq sum-of-squares 0)
1550 (setq sum-of-squares
1552 (let ((len (length (cdr (cdr (car tail)))))) (* len len))))
1553 (setq tail (cdr tail))))
1554 (if (< (* sum-of-squares mouse-buffer-menu-mode-mult)
1555 (* (length buffers) (length buffers)))
1556 ;; Subdividing by major modes really helps, so let's do it.
1557 (let (subdivided-menus (buffers-left (length buffers)))
1558 ;; Sort the list to put the most popular major modes first.
1559 (setq split-by-major-mode
1560 (sort split-by-major-mode
1561 (function (lambda (elt1 elt2)
1562 (> (length elt1) (length elt2))))))
1563 ;; Make a separate submenu for each major mode
1564 ;; that has more than one buffer,
1565 ;; unless all the remaining buffers are less than 1/10 of them.
1566 (while (and split-by-major-mode
1567 (and (> (length (car split-by-major-mode)) 3)
1568 (> (* buffers-left 10) (length buffers))))
1569 (let ((this-mode-list (mouse-buffer-menu-alist
1570 (cdr (cdr (car split-by-major-mode))))))
1572 (setq subdivided-menus
1574 (nth 1 (car split-by-major-mode))
1576 subdivided-menus))))
1578 (- buffers-left (length (cdr (car split-by-major-mode)))))
1579 (setq split-by-major-mode (cdr split-by-major-mode)))
1580 ;; If any major modes are left over,
1581 ;; make a single submenu for them.
1582 (if split-by-major-mode
1584 (mouse-buffer-menu-alist
1585 ;; we don't need split-by-major-mode any more,
1586 ;; so we can ditch it with nconc.
1587 (apply 'nconc (mapcar 'cddr split-by-major-mode)))))
1589 (setq subdivided-menus
1590 (cons (cons "Others" others-list)
1591 subdivided-menus)))))
1592 (setq menu (cons "Buffer Menu" (nreverse subdivided-menus))))
1594 (setq alist (mouse-buffer-menu-alist buffers))
1595 (setq menu (cons "Buffer Menu"
1596 (mouse-buffer-menu-split "Select Buffer" alist)))))
1597 (let ((buf (x-popup-menu event menu))
1598 (window (posn-window (event-start event))))
1601 (if (framep window) (frame-selected-window window)
1603 (switch-to-buffer buf)))))
1605 (defun mouse-buffer-menu-alist (buffers)
1611 (function (lambda (elt1 elt2)
1612 (string< (buffer-name elt1) (buffer-name elt2))))))
1615 (or (eq ?\s (aref (buffer-name (car tail)) 0))
1618 (length (buffer-name (car tail))))))
1619 (setq tail (cdr tail)))
1622 (let ((elt (car tail)))
1623 (if (/= (aref (buffer-name elt) 0) ?\s)
1628 (format "%%-%ds %%s%%s %%s" maxlen)
1630 (if (buffer-modified-p elt) "*" " ")
1631 (with-current-buffer elt
1632 (if buffer-read-only "%" " "))
1633 (or (buffer-file-name elt)
1634 (with-current-buffer elt
1635 (if list-buffers-directory
1637 list-buffers-directory)))
1641 (setq tail (cdr tail)))
1642 ;; Compensate for the reversal that the above loop does.
1645 (defun mouse-buffer-menu-split (title alist)
1646 ;; If we have lots of buffers, divide them into groups of 20
1647 ;; and make a pane (or submenu) for each one.
1648 (if (> (length alist) (/ (* mouse-buffer-menu-maxlen 3) 2))
1649 (let ((alist alist) sublists next
1652 ;; Pull off the next mouse-buffer-menu-maxlen buffers
1653 ;; and make them the next element of sublist.
1654 (setq next (nthcdr mouse-buffer-menu-maxlen alist))
1656 (setcdr (nthcdr (1- mouse-buffer-menu-maxlen) alist)
1658 (setq sublists (cons (cons (format "Buffers %d" i) alist)
1662 (nreverse sublists))
1663 ;; Few buffers--put them all in one pane.
1664 (list (cons title alist))))
1666 (define-obsolete-function-alias
1667 'mouse-choose-completion 'choose-completion "23.2")
1671 (defun font-menu-add-default ()
1672 (let* ((default (cdr (assq 'font (frame-parameters (selected-frame)))))
1673 (font-alist x-fixed-font-alist)
1674 (elt (or (assoc "Misc" font-alist) (nth 1 font-alist))))
1675 (if (assoc "Default" elt)
1676 (delete (assoc "Default" elt) elt))
1678 (cons (list "Default" default)
1681 (defvar x-fixed-font-alist
1683 (purecopy "Font Menu")
1687 (lambda (arg) (cons (purecopy (car arg)) (purecopy (cdr arg))))
1688 ;; For these, we specify the pixel height and width.
1690 ("6x10" "-misc-fixed-medium-r-normal--10-*-*-*-c-60-iso8859-1" "6x10")
1692 "-misc-fixed-medium-r-semicondensed--12-*-*-*-c-60-iso8859-1" "6x12")
1694 "-misc-fixed-medium-r-semicondensed--13-*-*-*-c-60-iso8859-1" "6x13")
1695 ("7x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-70-iso8859-1" "7x13")
1696 ("7x14" "-misc-fixed-medium-r-normal--14-*-*-*-c-70-iso8859-1" "7x14")
1697 ("8x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-80-iso8859-1" "8x13")
1698 ("9x15" "-misc-fixed-medium-r-normal--15-*-*-*-c-90-iso8859-1" "9x15")
1699 ("10x20" "-misc-fixed-medium-r-normal--20-*-*-*-c-100-iso8859-1" "10x20")
1700 ("11x18" "-misc-fixed-medium-r-normal--18-*-*-*-c-110-iso8859-1" "11x18")
1701 ("12x24" "-misc-fixed-medium-r-normal--24-*-*-*-c-120-iso8859-1" "12x24")
1704 "-schumacher-clean-medium-r-normal--8-*-*-*-c-50-iso8859-1")
1706 "-schumacher-clean-medium-r-normal--8-*-*-*-c-60-iso8859-1")
1708 "-schumacher-clean-medium-r-normal--8-*-*-*-c-80-iso8859-1")
1710 "-schumacher-clean-medium-r-normal--10-*-*-*-c-80-iso8859-1")
1712 "-schumacher-clean-medium-r-normal--14-*-*-*-c-80-iso8859-1")
1714 "-schumacher-clean-medium-r-normal--16-*-*-*-c-80-iso8859-1")
1716 ("sony 8x16" "-sony-fixed-medium-r-normal--16-*-*-*-c-80-iso8859-1")
1717 ;; We don't seem to have these; who knows what they are.
1718 ;; ("fg-18" "fg-18")
1719 ;; ("fg-25" "fg-25")
1720 ("lucidasanstypewriter-12" "-b&h-lucidatypewriter-medium-r-normal-sans-*-120-*-*-*-*-iso8859-1")
1721 ("lucidasanstypewriter-bold-14" "-b&h-lucidatypewriter-bold-r-normal-sans-*-140-*-*-*-*-iso8859-1")
1722 ("lucidasanstypewriter-bold-24"
1723 "-b&h-lucidatypewriter-bold-r-normal-sans-*-240-*-*-*-*-iso8859-1")
1724 ;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
1725 ;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
1729 (purecopy "Courier")
1731 (lambda (arg) (cons (purecopy (car arg)) (purecopy (cdr arg))))
1732 ;; For these, we specify the point height.
1733 '(("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1")
1734 ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1")
1735 ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1")
1736 ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1")
1737 ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1")
1738 ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1")
1739 ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1")
1740 ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1")
1741 ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1")
1742 ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1")
1743 ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1")
1744 ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1")
1745 ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1")
1746 ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1")
1747 ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1")
1748 ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1")
1749 ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1")
1750 ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1")
1751 ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1")
1752 ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1")
1753 ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1")
1754 ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1")
1755 ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1")
1756 ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1")
1758 "X fonts suitable for use in Emacs.")
1760 (declare-function generate-fontset-menu "fontset" ())
1762 (defun mouse-select-font ()
1763 "Prompt for a font name, using `x-popup-menu', and return it."
1765 (unless (display-multi-font-p)
1766 (error "Cannot change fonts on this display"))
1769 (if (listp last-nonmenu-event)
1771 (list '(0 0) (selected-window)))
1772 (append x-fixed-font-alist
1773 (list (generate-fontset-menu))))))
1775 (declare-function text-scale-mode "face-remap")
1777 (defun mouse-set-font (&rest fonts)
1778 "Set the default font for the selected frame.
1779 The argument FONTS is a list of font names; the first valid font
1780 in this list is used.
1782 When called interactively, pop up a menu and allow the user to
1785 (progn (unless (display-multi-font-p)
1786 (error "Cannot change fonts on this display"))
1788 (if (listp last-nonmenu-event)
1790 (list '(0 0) (selected-window)))
1791 ;; Append list of fontsets currently defined.
1792 (append x-fixed-font-alist (list (generate-fontset-menu))))))
1798 (set-frame-font (car fonts))
1799 (setq font (car fonts))
1802 (setq fonts (cdr fonts)))))
1804 (error "Font not found")))))
1806 (defvar mouse-appearance-menu-map nil)
1807 (declare-function x-select-font "xfns.c" (&optional frame ignored)) ; USE_GTK
1808 (declare-function buffer-face-mode-invoke "face-remap"
1809 (face arg &optional interactive))
1810 (declare-function font-face-attributes "font.c" (font &optional frame))
1812 (defun mouse-appearance-menu (event)
1813 "Show a menu for changing the default face in the current buffer."
1815 (require 'face-remap)
1816 (when (display-multi-font-p)
1817 (with-selected-window (car (event-start event))
1818 (if mouse-appearance-menu-map
1819 nil ; regenerate new fonts
1820 ;; Initialize mouse-appearance-menu-map
1821 (setq mouse-appearance-menu-map
1822 (make-sparse-keymap "Change Default Buffer Face"))
1823 (define-key mouse-appearance-menu-map [face-remap-reset-base]
1824 '(menu-item "Reset to Default" face-remap-reset-base))
1825 (define-key mouse-appearance-menu-map [text-scale-decrease]
1826 '(menu-item "Decrease Buffer Text Size" text-scale-decrease))
1827 (define-key mouse-appearance-menu-map [text-scale-increase]
1828 '(menu-item "Increase Buffer Text Size" text-scale-increase))
1830 (if (functionp 'x-select-font)
1831 (define-key mouse-appearance-menu-map [x-select-font]
1832 '(menu-item "Change Buffer Font..." x-select-font))
1833 ;; If the select-font is unavailable, construct a menu.
1834 (let ((font-submenu (make-sparse-keymap "Change Text Font"))
1835 (font-alist (cdr (append x-fixed-font-alist
1836 (list (generate-fontset-menu))))))
1837 (dolist (family font-alist)
1838 (let* ((submenu-name (car family))
1839 (submenu-map (make-sparse-keymap submenu-name)))
1840 (dolist (font (cdr family))
1841 (let ((font-name (car font))
1843 (if (string= font-name "")
1844 (define-key submenu-map [space]
1846 (setq font-symbol (intern (cadr font)))
1847 (define-key submenu-map (vector font-symbol)
1848 (list 'menu-item (car font) font-symbol)))))
1849 (define-key font-submenu (vector (intern submenu-name))
1850 (list 'menu-item submenu-name submenu-map))))
1851 (define-key mouse-appearance-menu-map [font-submenu]
1852 (list 'menu-item "Change Text Font" font-submenu)))))
1853 (let ((choice (x-popup-menu event mouse-appearance-menu-map)))
1854 (setq choice (nth (1- (length choice)) choice))
1855 (cond ((eq choice 'text-scale-increase)
1856 (text-scale-increase 1))
1857 ((eq choice 'text-scale-decrease)
1858 (text-scale-increase -1))
1859 ((eq choice 'face-remap-reset-base)
1861 (buffer-face-mode 0))
1863 ;; Either choice == 'x-select-font, or choice is a
1864 ;; symbol whose name is a font.
1865 (let ((font (if (eq choice 'x-select-font)
1867 (symbol-name choice))))
1868 (buffer-face-mode-invoke
1869 (if (fontp font 'font-spec)
1871 (font-face-attributes font))
1872 t (called-interactively-p 'interactive)))))))))
1875 ;;; Bindings for mouse commands.
1877 (global-set-key [down-mouse-1] 'mouse-drag-region)
1878 (global-set-key [mouse-1] 'mouse-set-point)
1879 (global-set-key [drag-mouse-1] 'mouse-set-region)
1881 (defun mouse--strip-first-event (_prompt)
1882 (substring (this-single-command-raw-keys) 1))
1884 (define-key function-key-map [left-fringe mouse-1] 'mouse--strip-first-event)
1885 (define-key function-key-map [right-fringe mouse-1] 'mouse--strip-first-event)
1887 (global-set-key [mouse-2] 'mouse-yank-primary)
1888 ;; Allow yanking also when the corresponding cursor is "in the fringe".
1889 (define-key function-key-map [right-fringe mouse-2] 'mouse--strip-first-event)
1890 (define-key function-key-map [left-fringe mouse-2] 'mouse--strip-first-event)
1891 (global-set-key [mouse-3] 'mouse-save-then-kill)
1892 (define-key function-key-map [right-fringe mouse-3] 'mouse--strip-first-event)
1893 (define-key function-key-map [left-fringe mouse-3] 'mouse--strip-first-event)
1895 ;; By binding these to down-going events, we let the user use the up-going
1896 ;; event to make the selection, saving a click.
1897 (global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
1898 (if (not (eq system-type 'ms-dos))
1899 (global-set-key [S-down-mouse-1] 'mouse-appearance-menu))
1900 ;; C-down-mouse-2 is bound in facemenu.el.
1901 (global-set-key [C-down-mouse-3]
1902 `(menu-item ,(purecopy "Menu Bar") ignore
1904 (if (zerop (or (frame-parameter nil 'menu-bar-lines) 0))
1905 (mouse-menu-bar-map)
1906 (mouse-menu-major-mode-map)))))
1908 ;; Binding mouse-1 to mouse-select-window when on mode-, header-, or
1909 ;; vertical-line prevents Emacs from signaling an error when the mouse
1910 ;; button is released after dragging these lines, on non-toolkit
1912 (global-set-key [mode-line mouse-1] 'mouse-select-window)
1913 (global-set-key [mode-line drag-mouse-1] 'mouse-select-window)
1914 (global-set-key [mode-line down-mouse-1] 'mouse-drag-mode-line)
1915 (global-set-key [header-line down-mouse-1] 'mouse-drag-header-line)
1916 (global-set-key [header-line mouse-1] 'mouse-select-window)
1917 (global-set-key [mode-line mouse-2] 'mouse-delete-other-windows)
1918 (global-set-key [mode-line mouse-3] 'mouse-delete-window)
1919 (global-set-key [mode-line C-mouse-2] 'mouse-split-window-horizontally)
1920 (global-set-key [vertical-scroll-bar C-mouse-2] 'mouse-split-window-vertically)
1921 (global-set-key [vertical-line C-mouse-2] 'mouse-split-window-vertically)
1922 (global-set-key [vertical-line down-mouse-1] 'mouse-drag-vertical-line)
1923 (global-set-key [right-divider down-mouse-1] 'mouse-drag-vertical-line)
1924 (global-set-key [bottom-divider down-mouse-1] 'mouse-drag-mode-line)
1925 (global-set-key [vertical-line mouse-1] 'mouse-select-window)
1929 ;;; mouse.el ends here