1 ;;; mouse.el --- window system-independent mouse support -*- lexical-binding: t -*-
3 ;; Copyright (C) 1993-1995, 1999-2016 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 (when (and mouse-1-click-follows-link
98 (eq (if (eq mouse-1-click-follows-link 'double)
99 'double-down-mouse-1 'down-mouse-1)
100 (car-safe last-input-event))
101 (mouse-on-link-p (event-start last-input-event))
102 (or mouse-1-click-in-non-selected-windows
103 (eq (selected-window)
104 (posn-window (event-start last-input-event)))))
106 (sit-for (if (numberp mouse-1-click-follows-link)
107 (/ (abs mouse-1-click-follows-link) 1000.0)
109 (if (if (and (numberp mouse-1-click-follows-link)
110 (>= mouse-1-click-follows-link 0))
111 timedout (not timedout))
114 (let ((event (read-key))) ;Use read-key so it works for xterm-mouse-mode!
115 (if (eq (car-safe event) (if (eq mouse-1-click-follows-link 'double)
116 'double-mouse-1 'mouse-1))
117 ;; Turn the mouse-1 into a mouse-2 to follow links.
118 (let ((newup (if (eq mouse-1-click-follows-link 'double)
119 'double-mouse-2 'mouse-2)))
120 ;; If mouse-2 has never been done by the user, it doesn't have
121 ;; the necessary property to be interpreted correctly.
122 (unless (get newup 'event-kind)
123 (put newup 'event-kind (get (car event) 'event-kind)))
124 (push (cons newup (cdr event)) unread-command-events)
125 ;; Don't change the down event, only the up-event (bug#18212).
127 (push event unread-command-events)
130 (define-key key-translation-map [down-mouse-1]
131 #'mouse--down-1-maybe-follows-link)
132 (define-key key-translation-map [double-down-mouse-1]
133 #'mouse--down-1-maybe-follows-link)
136 ;; Provide a mode-specific menu on a mouse button.
138 (defun minor-mode-menu-from-indicator (indicator)
139 "Show menu for minor mode specified by INDICATOR.
140 Interactively, INDICATOR is read using completion.
141 If there is no menu defined for the minor mode, then create one with
142 items `Turn Off' and `Help'."
144 (list (completing-read
145 "Minor mode indicator: "
146 (describe-minor-mode-completion-table-for-indicator))))
147 (let* ((minor-mode (lookup-minor-mode-from-indicator indicator))
148 (mm-fun (or (get minor-mode :minor-mode-function) minor-mode)))
149 (unless minor-mode (error "Cannot find minor mode for `%s'" indicator))
150 (let* ((map (cdr-safe (assq minor-mode minor-mode-map-alist)))
151 (menu (and (keymapp map) (lookup-key map [menu-bar]))))
154 (mouse-menu-non-singleton menu)
155 (if (fboundp mm-fun) ; bug#20201
158 (turn-off menu-item "Turn Off minor mode" ,mm-fun)
159 (help menu-item "Help for minor mode"
160 (lambda () (interactive)
161 (describe-function ',mm-fun)))))))
164 (message "No menu available")))))
166 (defun mouse-minor-mode-menu (event)
167 "Show minor-mode menu for EVENT on minor modes area of the mode line."
169 (let ((indicator (car (nth 4 (car (cdr event))))))
170 (minor-mode-menu-from-indicator indicator)))
172 (defun mouse-menu-major-mode-map ()
173 (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
174 (let* (;; Keymap from which to inherit; may be null.
175 (ancestor (mouse-menu-non-singleton
176 (and (current-local-map)
177 (local-key-binding [menu-bar]))))
178 ;; Make a keymap in which our last command leads to a menu or
179 ;; default to the edit menu.
181 (make-sparse-keymap (concat (format-mode-line mode-name)
183 menu-bar-edit-menu)))
185 (set-keymap-parent newmap ancestor))
188 (defun mouse-menu-non-singleton (menubar)
189 "Return menu keybar MENUBAR, or a lone submenu inside it.
190 If MENUBAR defines exactly one submenu, return just that submenu.
191 Otherwise, return MENUBAR."
195 (lambda (k v) (setq submap (if submap t (cons k v))))
196 (keymap-canonicalize menubar))
199 (lookup-key menubar (vector (car submap)))))))
201 (defun mouse-menu-bar-map ()
202 "Return a keymap equivalent to the menu bar.
203 The contents are the items that would be in the menu bar whether or
204 not it is actually displayed."
205 (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
206 (let* ((local-menu (and (current-local-map)
207 (lookup-key (current-local-map) [menu-bar])))
208 (global-menu (lookup-key global-map [menu-bar]))
209 ;; If a keymap doesn't have a prompt string (a lazy
210 ;; programmer didn't bother to provide one), create it and
211 ;; insert it into the keymap; each keymap gets its own
212 ;; prompt. This is required for non-toolkit versions to
213 ;; display non-empty menu pane names.
217 (let* ((minor-mode (car menu))
219 (title-or-map (cadr menu)))
220 (or (stringp title-or-map)
224 (capitalize (subst-char-in-string
230 (minor-mode-key-binding [menu-bar])))
231 (local-title-or-map (and local-menu (cadr local-menu)))
232 (global-title-or-map (cadr global-menu)))
233 (or (null local-menu)
234 (stringp local-title-or-map)
235 (setq local-menu (cons 'keymap
236 (cons (concat (format-mode-line mode-name)
239 (or (stringp global-title-or-map)
240 (setq global-menu (cons 'keymap
242 (cdr global-menu)))))
243 ;; Supplying the list is faster than making a new map.
244 ;; FIXME: We have a problem here: we have to use the global/local/minor
245 ;; so they're displayed in the expected order, but later on in the command
246 ;; loop, they're actually looked up in the opposite order.
252 (defun mouse-major-mode-menu (event &optional prefix)
253 "Pop up a mode-specific menu of mouse commands.
254 Default to the Edit menu if the major mode doesn't define a menu."
255 (declare (obsolete mouse-menu-major-mode-map "23.1"))
256 (interactive "@e\nP")
257 (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
258 (popup-menu (mouse-menu-major-mode-map) event prefix))
260 (defun mouse-popup-menubar (event prefix)
261 "Pop up a menu equivalent to the menu bar for keyboard EVENT with PREFIX.
262 The contents are the items that would be in the menu bar whether or
263 not it is actually displayed."
264 (declare (obsolete mouse-menu-bar-map "23.1"))
265 (interactive "@e \nP")
266 (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
267 (popup-menu (mouse-menu-bar-map) (unless (integerp event) event) prefix))
269 (defun mouse-popup-menubar-stuff (event prefix)
270 "Popup a menu like either `mouse-major-mode-menu' or `mouse-popup-menubar'.
271 Use the former if the menu bar is showing, otherwise the latter."
272 (declare (obsolete nil "23.1"))
273 (interactive "@e\nP")
274 (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
276 (if (zerop (or (frame-parameter nil 'menu-bar-lines) 0))
278 (mouse-menu-major-mode-map))
281 ;; Commands that operate on windows.
283 (defun mouse-minibuffer-check (event)
284 (let ((w (posn-window (event-start event))))
285 (and (window-minibuffer-p w)
286 (not (minibuffer-window-active-p w))
287 (user-error "Minibuffer window is not active")))
288 ;; Give temporary modes such as isearch a chance to turn off.
289 (run-hooks 'mouse-leave-buffer-hook))
291 (defun mouse-delete-window (click)
292 "Delete the window you click on.
293 Do nothing if the frame has just one window.
294 This command must be bound to a mouse click."
296 (unless (one-window-p t)
297 (mouse-minibuffer-check click)
298 (delete-window (posn-window (event-start click)))))
300 (defun mouse-select-window (click)
301 "Select the window clicked on; don't move point."
303 (mouse-minibuffer-check click)
304 (let ((oframe (selected-frame))
305 (frame (window-frame (posn-window (event-start click)))))
306 (select-window (posn-window (event-start click)))
309 (or (eq frame oframe)
310 (set-mouse-position (selected-frame) (1- (frame-width)) 0))))
312 (define-obsolete-function-alias 'mouse-tear-off-window 'tear-off-window "24.4")
313 (defun tear-off-window (click)
314 "Delete the selected window, and create a new frame displaying its buffer."
316 (mouse-minibuffer-check click)
317 (let* ((window (posn-window (event-start click)))
318 (buf (window-buffer window))
319 (frame (make-frame))) ;FIXME: Use pop-to-buffer.
321 (switch-to-buffer buf)
322 (delete-window window)))
324 (defun mouse-delete-other-windows ()
325 "Delete all windows except the one you click on."
327 (delete-other-windows))
329 (defun mouse-split-window-vertically (click)
330 "Select Emacs window mouse is on, then split it vertically in half.
331 The window is split at the line clicked on.
332 This command must be bound to a mouse click."
334 (mouse-minibuffer-check click)
335 (let ((start (event-start click)))
336 (select-window (posn-window start))
337 (let ((new-height (1+ (cdr (posn-col-row (event-end click)))))
338 (first-line window-min-height)
339 (last-line (- (window-height) window-min-height)))
340 (if (< last-line first-line)
341 (user-error "Window too short to split")
342 ;; Bind `window-combination-resize' to nil so we are sure to get
343 ;; the split right at the line clicked on.
344 (let (window-combination-resize)
345 (split-window-vertically
346 (min (max new-height first-line) last-line)))))))
348 (defun mouse-split-window-horizontally (click)
349 "Select Emacs window mouse is on, then split it horizontally in half.
350 The window is split at the column clicked on.
351 This command must be bound to a mouse click."
353 (mouse-minibuffer-check click)
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)
360 (user-error "Window too narrow to split")
361 ;; Bind `window-combination-resize' to nil so we are sure to get
362 ;; the split right at the column clicked on.
363 (let (window-combination-resize)
364 (split-window-horizontally
365 (min (max new-width first-col) last-col)))))))
367 (defun mouse-drag-line (start-event line)
368 "Drag a mode line, header line, or vertical line with the mouse.
369 START-EVENT is the starting mouse-event of the drag action. LINE
370 must be one of the symbols `header', `mode', or `vertical'."
371 ;; Give temporary modes such as isearch a chance to turn off.
372 (run-hooks 'mouse-leave-buffer-hook)
373 (let* ((echo-keystrokes 0)
374 (start (event-start start-event))
375 (window (posn-window start))
376 (frame (window-frame window))
377 ;; `position' records the x- or y-coordinate of the last
379 (position (if (eq line 'vertical)
380 (+ (window-pixel-left window)
381 (car (posn-x-y start)))
382 (+ (window-pixel-top window)
383 (cdr (posn-x-y start)))))
384 ;; `last-position' records the x- or y-coordinate of the
385 ;; previously sampled position. The difference of `position'
386 ;; and `last-position' determines the size change of WINDOW.
387 (last-position position)
389 posn-window growth dragged)
390 ;; Decide on whether we are allowed to track at all and whose
391 ;; window's edge we drag.
394 (if (window-at-side-p window 'top)
395 ;; We can't drag the header line of a topmost window.
397 ;; Drag bottom edge of window above the header line.
398 (setq window (window-in-direction 'above window t))))
400 (if (and (window-at-side-p window 'bottom)
401 ;; Allow resizing the minibuffer window if it's on the
402 ;; same frame as and immediately below `window', and it's
403 ;; either active or `resize-mini-windows' is nil.
404 (let ((minibuffer-window (minibuffer-window frame)))
405 (not (and (eq (window-frame minibuffer-window) frame)
406 (or (not resize-mini-windows)
407 (eq minibuffer-window
408 (active-minibuffer-window)))))))
409 (setq draggable nil)))
411 (let ((divider-width (frame-right-divider-width frame)))
412 (when (and (or (not (numberp divider-width))
413 (zerop divider-width))
414 (eq (cdr (assq 'vertical-scroll-bars
415 (frame-parameters frame)))
417 (setq window (window-in-direction 'left window t))))))
421 (lambda (event) (interactive "e")
426 ;; Drag right edge of `window'.
427 (setq start (event-start event))
428 (setq position (car (posn-x-y start)))
429 ;; Set `posn-window' to the window where `event' was recorded.
430 ;; This can be `window' or the window on the left or right of
432 (when (window-live-p (setq posn-window (posn-window start)))
433 ;; Add left edge of `posn-window' to `position'.
434 (setq position (+ (window-pixel-left posn-window) position))
435 (unless (nth 1 start)
436 ;; Add width of objects on the left of the text area to
438 (when (eq (window-current-scroll-bars posn-window) 'left)
439 (setq position (+ (window-scroll-bar-width posn-window)
441 (setq position (+ (car (window-fringes posn-window))
442 (or (car (window-margins posn-window)) 0)
444 ;; When the cursor overshoots after shrinking a window to its
445 ;; minimum size and the dragging direction changes, have the
446 ;; cursor first catch up with the window edge.
447 (unless (or (zerop (setq growth (- position last-position)))
449 (< position (+ (window-pixel-left window)
450 (window-pixel-width window))))
452 (> position (+ (window-pixel-left window)
453 (window-pixel-width window)))))
455 (adjust-window-trailing-edge window growth t t))
456 (setq last-position position))
458 ;; Drag bottom edge of `window'.
459 (setq start (event-start event))
460 ;; Set `posn-window' to the window where `event' was recorded.
461 ;; This can be either `window' or the window above or below of
463 (setq posn-window (posn-window start))
464 (setq position (cdr (posn-x-y start)))
465 (when (window-live-p posn-window)
466 ;; Add top edge of `posn-window' to `position'.
467 (setq position (+ (window-pixel-top posn-window) position))
468 ;; If necessary, add height of header line to `position'
469 (when (memq (posn-area start)
470 '(nil left-fringe right-fringe left-margin right-margin))
471 (setq position (+ (window-header-line-height posn-window) position))))
472 ;; When the cursor overshoots after shrinking a window to its
473 ;; minimum size and the dragging direction changes, have the
474 ;; cursor first catch up with the window edge.
475 (unless (or (zerop (setq growth (- position last-position)))
477 (< position (+ (window-pixel-top window)
478 (window-pixel-height window))))
480 (> position (+ (window-pixel-top window)
481 (window-pixel-height window)))))
483 (adjust-window-trailing-edge window growth nil t))
484 (setq last-position position))))))
485 ;; Start tracking. The special value 'dragging' signals the
486 ;; display engine to freeze the mouse pointer shape for as long
488 (setq track-mouse 'dragging)
489 ;; Loop reading events and sampling the position of the mouse.
492 (let ((map (make-sparse-keymap)))
493 (define-key map [switch-frame] #'ignore)
494 (define-key map [select-window] #'ignore)
495 (define-key map [scroll-bar-movement] #'ignore)
496 (define-key map [mouse-movement] move)
497 ;; Swallow drag-mouse-1 events to avoid selecting some other window.
498 (define-key map [drag-mouse-1]
499 (lambda () (interactive) (funcall exitfun)))
500 ;; For vertical line dragging swallow also a mouse-1
501 ;; event (but only if we dragged at least once to allow mouse-1
502 ;; clicks to get through).
503 (when (eq line 'vertical)
504 (define-key map [mouse-1]
505 `(menu-item "" ,(lambda () (interactive) (funcall exitfun))
506 :filter ,(lambda (cmd) (if dragged cmd)))))
507 ;; Some of the events will of course end up looked up
508 ;; with a mode-line, header-line or vertical-line prefix ...
509 (define-key map [mode-line] map)
510 (define-key map [header-line] map)
511 (define-key map [vertical-line] map)
512 ;; ... and some maybe even with a right- or bottom-divider
514 (define-key map [right-divider] map)
515 (define-key map [bottom-divider] map)
517 t (lambda () (setq track-mouse nil)))))))
519 (defun mouse-drag-mode-line (start-event)
520 "Change the height of a window by dragging on the mode line."
522 (mouse-drag-line start-event 'mode))
524 (defun mouse-drag-header-line (start-event)
525 "Change the height of a window by dragging on the header line."
527 (mouse-drag-line start-event 'header))
529 (defun mouse-drag-vertical-line (start-event)
530 "Change the width of a window by dragging on the vertical line."
532 (mouse-drag-line start-event 'vertical))
534 (defun mouse-set-point (event &optional promote-to-region)
535 "Move point to the position clicked on with the mouse.
536 This should be bound to a mouse click event type.
537 If PROMOTE-TO-REGION is non-nil and event is a multiple-click,
538 select the corresponding element around point."
540 (mouse-minibuffer-check event)
541 (if (and promote-to-region (> (event-click-count event) 1))
542 (mouse-set-region event)
543 ;; Use event-end in case called from mouse-drag-region.
544 ;; If EVENT is a click, event-end and event-start give same value.
545 (posn-set-point (event-end event))))
547 (defvar mouse-last-region-beg nil)
548 (defvar mouse-last-region-end nil)
549 (defvar mouse-last-region-tick nil)
551 (defun mouse-region-match ()
552 "Return non-nil if there's an active region that was set with the mouse."
553 (and (mark t) mark-active
554 (eq mouse-last-region-beg (region-beginning))
555 (eq mouse-last-region-end (region-end))
556 (eq mouse-last-region-tick (buffer-modified-tick))))
558 (defvar mouse--drag-start-event nil)
560 (defun mouse-set-region (click)
561 "Set the region to the text dragged over, and copy to kill ring.
562 This should be bound to a mouse drag event.
563 See the `mouse-drag-copy-region' variable to control whether this
564 command alters the kill ring or not."
566 (mouse-minibuffer-check click)
567 (select-window (posn-window (event-start click)))
568 (let ((beg (posn-point (event-start click)))
570 (if (eq (posn-window (event-end click)) (selected-window))
571 (posn-point (event-end click))
572 ;; If the mouse ends up in any other window or on the menu
573 ;; bar, use `window-point' of selected window (Bug#23707).
575 (click-count (event-click-count click)))
576 (let ((drag-start (terminal-parameter nil 'mouse-drag-start)))
578 ;; Drag events don't come with a click count, sadly, so we hack
579 ;; our way around this problem by remembering the start-event in
580 ;; `mouse-drag-start' and fetching the click-count from there.
581 (when (and (<= click-count 1)
582 (equal beg (posn-point (event-start drag-start))))
583 (setq click-count (event-click-count drag-start)))
584 ;; Occasionally we get spurious drag events where the user hasn't
585 ;; dragged his mouse, but instead Emacs has dragged the text under the
586 ;; user's mouse. Try to recover those cases (bug#17562).
587 (when (and (equal (posn-x-y (event-start click))
588 (posn-x-y (event-end click)))
589 (not (eq (car drag-start) 'mouse-movement)))
591 (setf (terminal-parameter nil 'mouse-drag-start) nil)))
592 (when (and (integerp beg) (integerp end))
593 (let ((range (mouse-start-end beg end (1- click-count))))
595 (setq end (nth 0 range) beg (nth 1 range))
596 (setq beg (nth 0 range) end (nth 1 range)))))
597 (and mouse-drag-copy-region (integerp beg) (integerp end)
598 ;; Don't set this-command to `kill-region', so a following
599 ;; C-w won't double the text in the kill ring. Ignore
600 ;; `last-command' so we don't append to a preceding kill.
601 (let (this-command last-command deactivate-mark)
602 (copy-region-as-kill beg end)))
603 (if (numberp beg) (goto-char beg))
604 ;; On a text terminal, bounce the cursor.
605 (or transient-mark-mode
610 (if (numberp end) (goto-char end))
611 (mouse-set-region-1)))
613 (defun mouse-set-region-1 ()
614 ;; Set transient-mark-mode for a little while.
615 (unless (eq (car-safe transient-mark-mode) 'only)
616 (setq-local transient-mark-mode
618 (unless (eq transient-mark-mode 'lambda)
619 transient-mark-mode))))
620 (setq mouse-last-region-beg (region-beginning))
621 (setq mouse-last-region-end (region-end))
622 (setq mouse-last-region-tick (buffer-modified-tick)))
624 (defcustom mouse-scroll-delay 0.25
625 "The pause between scroll steps caused by mouse drags, in seconds.
626 If you drag the mouse beyond the edge of a window, Emacs scrolls the
627 window to bring the text beyond that edge into view, with a delay of
628 this many seconds between scroll steps. Scrolling stops when you move
629 the mouse back into the window, or release the button.
630 This variable's value may be non-integral.
631 Setting this to zero causes Emacs to scroll as fast as it can."
635 (defcustom mouse-scroll-min-lines 1
636 "The minimum number of lines scrolled by dragging mouse out of window.
637 Moving the mouse out the top or bottom edge of the window begins
638 scrolling repeatedly. The number of lines scrolled per repetition
639 is normally equal to the number of lines beyond the window edge that
640 the mouse has moved. However, it always scrolls at least the number
641 of lines specified by this variable."
645 (defun mouse-scroll-subr (window jump &optional overlay start)
646 "Scroll the window WINDOW, JUMP lines at a time, until new input arrives.
647 If OVERLAY is an overlay, let it stretch from START to the far edge of
648 the newly visible text.
649 Upon exit, point is at the far edge of the newly visible text."
651 ((and (> jump 0) (< jump mouse-scroll-min-lines))
652 (setq jump mouse-scroll-min-lines))
653 ((and (< jump 0) (< (- jump) mouse-scroll-min-lines))
654 (setq jump (- mouse-scroll-min-lines))))
655 (let ((opoint (point)))
657 (goto-char (window-start window))
658 (if (not (zerop (vertical-motion jump window)))
660 (set-window-start window (point))
662 (if (window-end window)
664 (goto-char (window-end window))
665 ;; window-end doesn't reflect the window's new
666 ;; start position until the next redisplay.
667 (vertical-motion (1- jump) window))
668 (vertical-motion (- (window-height window) 2)))
669 (goto-char (window-start window)))
671 (move-overlay overlay start (point)))
672 ;; Now that we have scrolled WINDOW properly,
673 ;; put point back where it was for the redisplay
674 ;; so that we don't mess up the selected window.
675 (or (eq window (selected-window))
677 (sit-for mouse-scroll-delay)))))
678 (or (eq window (selected-window))
679 (goto-char opoint))))
681 (defvar mouse-selection-click-count 0)
683 (defvar mouse-selection-click-count-buffer nil)
685 (defun mouse-drag-region (start-event)
686 "Set the region to the text that the mouse is dragged over.
687 Highlight the drag area as you move the mouse.
688 This must be bound to a button-down mouse event.
689 In Transient Mark mode, the highlighting remains as long as the mark
690 remains active. Otherwise, it remains until the next input event."
692 ;; Give temporary modes such as isearch a chance to turn off.
693 (run-hooks 'mouse-leave-buffer-hook)
694 (mouse-drag-track start-event))
697 (defun mouse-posn-property (pos property)
698 "Look for a property at click position.
699 POS may be either a buffer position or a click position like
700 those returned from `event-start'. If the click position is on
701 a string, the text property PROPERTY is examined.
702 If this is nil or the click is not on a string, then
703 the corresponding buffer position is searched for PROPERTY.
704 If PROPERTY is encountered in one of those places,
705 its value is returned."
707 (let ((w (posn-window pos)) (pt (posn-point pos))
708 (str (posn-string pos)))
710 (get-text-property (cdr str) property (car str)))
711 ;; Mouse clicks in the fringe come with a position in
712 ;; (nth 5). This is useful but is not exactly where we clicked, so
713 ;; don't look up that position's properties!
714 (and pt (not (memq (posn-area pos) '(left-fringe right-fringe
715 left-margin right-margin)))
716 (get-char-property pt property w))))
717 (get-char-property pos property)))
719 (defun mouse-on-link-p (pos)
720 "Return non-nil if POS is on a link in the current buffer.
721 POS must be a buffer position in the current buffer or a mouse
722 event location in the selected window (see `event-start').
723 However, if `mouse-1-click-in-non-selected-windows' is non-nil,
724 POS may be a mouse event location in any window.
726 A clickable link is identified by one of the following methods:
728 - If the character at POS has a non-nil `follow-link' text or
729 overlay property, the value of that property determines what to do.
731 - If there is a local key-binding or a keybinding at position POS
732 for the `follow-link' event, the binding of that event determines
735 The resulting value determine whether POS is inside a link:
737 - If the value is `mouse-face', POS is inside a link if there
738 is a non-nil `mouse-face' property at POS. Return t in this case.
740 - If the value is a function, FUNC, POS is inside a link if
741 the call \(FUNC POS) returns non-nil. Return the return value
742 from that call. Arg is \(posn-point POS) if POS is a mouse event.
744 - Otherwise, return the value itself.
746 The return value is interpreted as follows:
748 - If it is a string, the mouse-1 event is translated into the
749 first character of the string, i.e. the action of the mouse-1
750 click is the local or global binding of that character.
752 - If it is a vector, the mouse-1 event is translated into the
753 first element of that vector, i.e. the action of the mouse-1
754 click is the local or global binding of that event.
756 - Otherwise, the mouse-1 event is translated into a mouse-2 event
757 at the same position."
759 (and (or (not (consp pos))
760 mouse-1-click-in-non-selected-windows
761 (eq (selected-window) (posn-window pos)))
762 (or (mouse-posn-property pos 'follow-link)
763 (let ((area (posn-area pos)))
765 (key-binding (vector area 'follow-link) nil t pos)))
766 (key-binding [follow-link] nil t pos)))))
768 ((eq action 'mouse-face)
769 (and (mouse-posn-property pos 'mouse-face) t))
771 ;; FIXME: This seems questionable if the click is not in a buffer.
772 ;; Should we instead decide that `action' takes a `posn'?
774 (with-current-buffer (window-buffer (posn-window pos))
775 (funcall action (posn-point pos)))
776 (funcall action pos)))
779 (defun mouse-fixup-help-message (msg)
780 "Fix help message MSG for `mouse-1-click-follows-link'."
782 (if (and mouse-1-click-follows-link
784 (string-match-p "\\`mouse-2" msg)
785 (setq mp (mouse-pixel-position))
786 (consp (setq pos (cdr mp)))
787 (car pos) (>= (car pos) 0)
788 (cdr pos) (>= (cdr pos) 0)
789 (setq pos (posn-at-x-y (car pos) (cdr pos) (car mp)))
790 (windowp (posn-window pos)))
791 (with-current-buffer (window-buffer (posn-window pos))
792 (if (mouse-on-link-p pos)
795 ((eq mouse-1-click-follows-link 'double) "double-")
796 ((and (integerp mouse-1-click-follows-link)
797 (< mouse-1-click-follows-link 0)) "Long ")
799 "mouse-1" (substring msg 7)))))))
802 (defun mouse-drag-track (start-event)
803 "Track mouse drags by highlighting area between point and cursor.
804 The region will be defined with mark and point."
805 (mouse-minibuffer-check start-event)
806 (setq mouse-selection-click-count-buffer (current-buffer))
808 (let* ((scroll-margin 0) ; Avoid margin scrolling (Bug#9541).
809 ;; We've recorded what we needed from the current buffer and
810 ;; window, now let's jump to the place of the event, where things
812 (_ (mouse-set-point start-event))
814 (start-posn (event-start start-event))
815 (start-point (posn-point start-posn))
816 (start-window (posn-window start-posn))
817 (bounds (window-edges start-window))
818 (make-cursor-line-fully-visible nil)
820 (bottom (if (window-minibuffer-p start-window)
822 ;; Don't count the mode line.
823 (1- (nth 3 bounds))))
824 (click-count (1- (event-click-count start-event)))
825 ;; Suppress automatic hscrolling, because that is a nuisance
826 ;; when setting point near the right fringe (but see below).
827 (auto-hscroll-mode-saved auto-hscroll-mode))
829 (setq mouse-selection-click-count click-count)
830 ;; In case the down click is in the middle of some intangible text,
831 ;; use the end of that text, and put it in START-POINT.
832 (if (< (point) start-point)
833 (goto-char start-point))
834 (setq start-point (point))
836 ;; Activate the region, using `mouse-start-end' to determine where
837 ;; to put point and mark (e.g., double-click will select a word).
838 (setq-local transient-mark-mode
839 (if (eq transient-mark-mode 'lambda)
841 (cons 'only transient-mark-mode)))
842 (let ((range (mouse-start-end start-point start-point click-count)))
843 (push-mark (nth 0 range) t t)
844 (goto-char (nth 1 range)))
846 (setf (terminal-parameter nil 'mouse-drag-start) start-event)
848 (setq auto-hscroll-mode nil)
851 (let ((map (make-sparse-keymap)))
852 (define-key map [switch-frame] #'ignore)
853 (define-key map [select-window] #'ignore)
854 (define-key map [mouse-movement]
855 (lambda (event) (interactive "e")
856 (let* ((end (event-end event))
857 (end-point (posn-point end)))
858 (unless (eq end-point start-point)
859 ;; As soon as the user moves, we can re-enable auto-hscroll.
860 (setq auto-hscroll-mode auto-hscroll-mode-saved)
861 ;; And remember that we have moved, so mouse-set-region can know
862 ;; its event is really a drag event.
863 (setcar start-event 'mouse-movement))
864 (if (and (eq (posn-window end) start-window)
865 (integer-or-marker-p end-point))
866 (mouse--drag-set-mark-and-point start-point
867 end-point click-count)
868 (let ((mouse-row (cdr (cdr (mouse-position)))))
872 (mouse-scroll-subr start-window (- mouse-row top)
874 ((>= mouse-row bottom)
875 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
876 nil start-point))))))))
879 (setq track-mouse nil)
880 (setq auto-hscroll-mode auto-hscroll-mode-saved)
884 (defun mouse--drag-set-mark-and-point (start click click-count)
885 (let* ((range (mouse-start-end start click click-count))
888 (cond ((eq (mark) beg)
899 ;; Commands to handle xterm-style multiple clicks.
900 (defun mouse-skip-word (dir)
901 "Skip over word, over whitespace, or over identical punctuation.
902 If DIR is positive skip forward; if negative, skip backward."
903 (let* ((char (following-char))
904 (syntax (char-to-string (char-syntax char))))
905 (cond ((string= syntax "w")
906 ;; Here, we can't use skip-syntax-forward/backward because
907 ;; they don't pay attention to word-separating-categories,
908 ;; and thus they will skip over a true word boundary. So,
909 ;; we simulate the original behavior by using forward-word.
911 (if (not (looking-at "\\<"))
913 (if (or (looking-at "\\<") (not (looking-at "\\>")))
915 ((string= syntax " ")
917 (skip-syntax-backward syntax)
918 (skip-syntax-forward syntax)))
919 ((string= syntax "_")
921 (skip-syntax-backward "w_")
922 (skip-syntax-forward "w_")))
924 (while (and (not (bobp)) (= (preceding-char) char))
927 (while (and (not (eobp)) (= (following-char) char))
928 (forward-char 1))))))
930 (defun mouse-start-end (start end mode)
931 "Return a list of region bounds based on START and END according to MODE.
932 If MODE is 0 then set point to (min START END), mark to (max START END).
933 If MODE is 1 then set point to start of word at (min START END),
934 mark to end of word at (max START END).
935 If MODE is 2 then do the same for lines."
940 (setq mode (mod mode 3))
946 (= (char-syntax (char-after start)) ?\())
947 (if (/= (syntax-class (syntax-after start)) 4) ; raw syntax code for ?\(
948 ;; This happens in CC Mode when unbalanced parens in CPP
949 ;; constructs are given punctuation syntax with
950 ;; syntax-table text properties. (2016-02-21).
951 (signal 'scan-error (list "Containing expression ends prematurely"
961 (= (char-syntax (char-after start)) ?\)))
962 (if (/= (syntax-class (syntax-after start)) 5) ; raw syntax code for ?\)
963 ;; See above comment about CC Mode.
964 (signal 'scan-error (list "Unbalanced parentheses" start start))
965 (list (save-excursion
966 (goto-char (1+ start))
973 (= (char-syntax (char-after start)) ?\"))
974 (let ((open (or (eq start (point-min))
976 (goto-char (- start 1))
977 (looking-at "\\s(\\|\\s \\|\\s>")))))
987 (list (save-excursion
990 (goto-char (1+ start))
996 (list (save-excursion
1005 (list (save-excursion
1007 (line-beginning-position 1))
1013 ;; Subroutine: set the mark where CLICK happened,
1014 ;; but don't do anything else.
1015 (defun mouse-set-mark-fast (click)
1016 (mouse-minibuffer-check click)
1017 (let ((posn (event-start click)))
1018 (select-window (posn-window posn))
1019 (if (numberp (posn-point posn))
1020 (push-mark (posn-point posn) t t))))
1022 (defun mouse-undouble-last-event (events)
1023 (let* ((index (1- (length events)))
1024 (last (nthcdr index events))
1026 (basic (event-basic-type event))
1027 (old-modifiers (event-modifiers event))
1028 (modifiers (delq 'double (delq 'triple (copy-sequence old-modifiers))))
1031 ;; Use reverse, not nreverse, since event-modifiers
1032 ;; does not copy the list it returns.
1033 (cons (event-convert-list (reverse (cons basic modifiers)))
1037 (if (and (not (equal modifiers old-modifiers))
1038 (key-binding (apply 'vector events)))
1043 ;; Momentarily show where the mark is, if highlighting doesn't show it.
1045 (defun mouse-set-mark (click)
1046 "Set mark at the position clicked on with the mouse.
1047 Display cursor at that position for a second.
1048 This must be bound to a mouse click."
1050 (mouse-minibuffer-check click)
1051 (select-window (posn-window (event-start click)))
1052 ;; FIXME: Use save-excursion
1053 (let ((point-save (point)))
1055 (progn (mouse-set-point click)
1057 (or transient-mark-mode
1059 (goto-char point-save))))
1061 (defun mouse-kill (click)
1062 "Kill the region between point and the mouse click.
1063 The text is saved in the kill ring, as with \\[kill-region]."
1065 (mouse-minibuffer-check click)
1066 (let* ((posn (event-start click))
1067 (click-posn (posn-point posn)))
1068 (select-window (posn-window posn))
1069 (if (numberp click-posn)
1070 (kill-region (min (point) click-posn)
1071 (max (point) click-posn)))))
1073 (defun mouse-yank-at-click (click arg)
1074 "Insert the last stretch of killed text at the position clicked on.
1075 Also move point to one end of the text thus inserted (normally the end),
1076 and set mark at the beginning.
1077 Prefix arguments are interpreted as with \\[yank].
1078 If `mouse-yank-at-point' is non-nil, insert at point
1079 regardless of where you click."
1080 (interactive "e\nP")
1081 ;; Give temporary modes such as isearch a chance to turn off.
1082 (run-hooks 'mouse-leave-buffer-hook)
1083 (when select-active-regions
1084 ;; Without this, confusing things happen upon e.g. inserting into
1085 ;; the middle of an active region.
1087 (or mouse-yank-at-point (mouse-set-point click))
1088 (setq this-command 'yank)
1089 (setq mouse-selection-click-count 0)
1092 (defun mouse-yank-primary (click)
1093 "Insert the primary selection at the position clicked on.
1094 Move point to the end of the inserted text, and set mark at
1095 beginning. If `mouse-yank-at-point' is non-nil, insert at point
1096 regardless of where you click."
1098 ;; Give temporary modes such as isearch a chance to turn off.
1099 (run-hooks 'mouse-leave-buffer-hook)
1100 ;; Without this, confusing things happen upon e.g. inserting into
1101 ;; the middle of an active region.
1102 (when select-active-regions
1103 (let (select-active-regions)
1105 (or mouse-yank-at-point (mouse-set-point click))
1106 (let ((primary (gui-get-primary-selection)))
1108 (insert-for-yank primary)))
1110 (defun mouse-kill-ring-save (click)
1111 "Copy the region between point and the mouse click in the kill ring.
1112 This does not delete the region; it acts like \\[kill-ring-save]."
1114 (mouse-set-mark-fast click)
1115 (let (this-command last-command)
1116 (kill-ring-save (point) (mark t))))
1118 ;; This function used to delete the text between point and the mouse
1119 ;; whenever it was equal to the front of the kill ring, but some
1120 ;; people found that confusing.
1122 ;; The position of the last invocation of `mouse-save-then-kill'.
1123 (defvar mouse-save-then-kill-posn nil)
1125 (defun mouse-save-then-kill-delete-region (beg end)
1126 ;; We must make our own undo boundaries
1127 ;; because they happen automatically only for the current buffer.
1129 (if (or (= beg end) (eq buffer-undo-list t))
1130 ;; If we have no undo list in this buffer,
1132 (delete-region beg end)
1133 ;; Delete, but make the undo-list entry share with the kill ring.
1134 ;; First, delete just one char, so in case buffer is being modified
1135 ;; for the first time, the undo list records that fact.
1136 (let ((inhibit-modification-hooks t))
1138 (+ beg (if (> end beg) 1 -1))))
1139 (let ((buffer-undo-list buffer-undo-list))
1140 ;; Undo that deletion--but don't change the undo list!
1141 (let ((inhibit-modification-hooks t))
1142 (primitive-undo 1 buffer-undo-list))
1143 ;; Now delete the rest of the specified region,
1144 ;; but don't record it.
1145 (setq buffer-undo-list t)
1146 (if (/= (length (car kill-ring)) (- (max end beg) (min end beg)))
1147 (error "Lossage in mouse-save-then-kill-delete-region"))
1148 (delete-region beg end))
1149 (let ((tail buffer-undo-list))
1150 ;; Search back in buffer-undo-list for the string
1151 ;; that came from deleting one character.
1152 (while (and tail (not (stringp (car (car tail)))))
1153 (setq tail (cdr tail)))
1154 ;; Replace it with an entry for the entire deleted text.
1156 (setcar tail (cons (car kill-ring) (min beg end))))))
1159 (defun mouse-save-then-kill (click)
1160 "Set the region according to CLICK; the second time, kill it.
1161 CLICK should be a mouse click event.
1163 If the region is inactive, activate it temporarily. Set mark at
1164 the original point, and move point to the position of CLICK.
1166 If the region is already active, adjust it. Normally, do this by
1167 moving point or mark, whichever is closer, to CLICK. But if you
1168 have selected whole words or lines, move point or mark to the
1169 word or line boundary closest to CLICK instead.
1171 If `mouse-drag-copy-region' is non-nil, this command also saves the
1172 new region to the kill ring (replacing the previous kill if the
1173 previous region was just saved to the kill ring).
1175 If this command is called a second consecutive time with the same
1176 CLICK position, kill the region (or delete it
1177 if `mouse-drag-copy-region' is non-nil)"
1179 (mouse-minibuffer-check click)
1180 (let* ((posn (event-start click))
1181 (click-pt (posn-point posn))
1182 (window (posn-window posn))
1183 (buf (window-buffer window))
1184 ;; Don't let a subsequent kill command append to this one.
1185 (this-command this-command)
1186 ;; Check if the user has multi-clicked to select words/lines.
1188 (if (and (eq mouse-selection-click-count-buffer buf)
1189 (with-current-buffer buf (mark t)))
1190 mouse-selection-click-count
1193 ((not (numberp click-pt)) nil)
1194 ;; If the user clicked without moving point, kill the region.
1195 ;; This also resets `mouse-selection-click-count'.
1196 ((and (eq last-command 'mouse-save-then-kill)
1197 (eq click-pt mouse-save-then-kill-posn)
1198 (eq window (selected-window)))
1199 (if mouse-drag-copy-region
1200 ;; Region already saved in the previous click;
1201 ;; don't make a duplicate entry, just delete.
1202 (delete-region (mark t) (point))
1203 (kill-region (mark t) (point)))
1204 (setq mouse-selection-click-count 0)
1205 (setq mouse-save-then-kill-posn nil))
1207 ;; Otherwise, if there is a suitable region, adjust it by moving
1208 ;; one end (whichever is closer) to CLICK-PT.
1209 ((or (with-current-buffer buf (region-active-p))
1210 (and (eq window (selected-window))
1212 (or (and (eq last-command 'mouse-save-then-kill)
1213 mouse-save-then-kill-posn)
1214 (and (memq last-command '(mouse-drag-region
1216 (or mark-even-if-inactive
1217 (not transient-mark-mode))))))
1218 (select-window window)
1219 (let* ((range (mouse-start-end click-pt click-pt click-count)))
1220 (if (< (abs (- click-pt (mark t)))
1221 (abs (- click-pt (point))))
1222 (set-mark (car range))
1223 (goto-char (nth 1 range)))
1224 (setq deactivate-mark nil)
1225 (mouse-set-region-1)
1226 (when mouse-drag-copy-region
1227 ;; Region already copied to kill-ring once, so replace.
1228 (kill-new (filter-buffer-substring (mark t) (point)) t))
1229 ;; Arrange for a repeated mouse-3 to kill the region.
1230 (setq mouse-save-then-kill-posn click-pt)))
1232 ;; Otherwise, set the mark where point is and move to CLICK-PT.
1234 (select-window window)
1235 (mouse-set-mark-fast click)
1236 (let ((before-scroll (with-current-buffer buf point-before-scroll)))
1237 (if before-scroll (goto-char before-scroll)))
1238 (exchange-point-and-mark)
1239 (mouse-set-region-1)
1240 (when mouse-drag-copy-region
1241 (kill-new (filter-buffer-substring (mark t) (point))))
1242 (setq mouse-save-then-kill-posn click-pt)))))
1245 (global-set-key [M-mouse-1] 'mouse-start-secondary)
1246 (global-set-key [M-drag-mouse-1] 'mouse-set-secondary)
1247 (global-set-key [M-down-mouse-1] 'mouse-drag-secondary)
1248 (global-set-key [M-mouse-3] 'mouse-secondary-save-then-kill)
1249 (global-set-key [M-mouse-2] 'mouse-yank-secondary)
1251 (defconst mouse-secondary-overlay
1252 (let ((ol (make-overlay (point-min) (point-min))))
1254 (overlay-put ol 'face 'secondary-selection)
1256 "An overlay which records the current secondary selection.
1257 It is deleted when there is no secondary selection.")
1259 (defvar mouse-secondary-click-count 0)
1261 ;; A marker which records the specified first end for a secondary selection.
1263 (defvar mouse-secondary-start nil)
1265 (defun mouse-start-secondary (click)
1266 "Set one end of the secondary selection to the position clicked on.
1267 Use \\[mouse-secondary-save-then-kill] to set the other end
1268 and complete the secondary selection."
1270 (mouse-minibuffer-check click)
1271 (let ((posn (event-start click)))
1272 (with-current-buffer (window-buffer (posn-window posn))
1273 ;; Cancel any preexisting secondary selection.
1274 (delete-overlay mouse-secondary-overlay)
1275 (if (numberp (posn-point posn))
1277 (or mouse-secondary-start
1278 (setq mouse-secondary-start (make-marker)))
1279 (move-marker mouse-secondary-start (posn-point posn)))))))
1281 (defun mouse-set-secondary (click)
1282 "Set the secondary selection to the text that the mouse is dragged over.
1283 This must be bound to a mouse drag event."
1285 (mouse-minibuffer-check click)
1286 (let ((posn (event-start click))
1288 (end (event-end click)))
1289 (with-current-buffer (window-buffer (posn-window posn))
1290 (if (numberp (posn-point posn))
1291 (setq beg (posn-point posn)))
1292 (move-overlay mouse-secondary-overlay beg (posn-point end))
1295 (buffer-substring (overlay-start mouse-secondary-overlay)
1296 (overlay-end mouse-secondary-overlay))))))
1298 (defun mouse-drag-secondary (start-event)
1299 "Set the secondary selection to the text that the mouse is dragged over.
1300 Highlight the drag area as you move the mouse.
1301 This must be bound to a button-down mouse event.
1302 The function returns a non-nil value if it creates a secondary selection."
1304 (mouse-minibuffer-check start-event)
1305 (let* ((echo-keystrokes 0)
1306 (start-posn (event-start start-event))
1307 (start-point (posn-point start-posn))
1308 (start-window (posn-window start-posn))
1309 (bounds (window-edges start-window))
1310 (top (nth 1 bounds))
1311 (bottom (if (window-minibuffer-p start-window)
1313 ;; Don't count the mode line.
1314 (1- (nth 3 bounds))))
1315 (click-count (1- (event-click-count start-event))))
1316 (with-current-buffer (window-buffer start-window)
1317 (setq mouse-secondary-click-count click-count)
1318 (if (> (mod click-count 3) 0)
1319 ;; Double or triple press: make an initial selection
1320 ;; of one word or line.
1321 (let ((range (mouse-start-end start-point start-point click-count)))
1322 (set-marker mouse-secondary-start nil)
1323 (move-overlay mouse-secondary-overlay (car range) (nth 1 range)
1324 (window-buffer start-window)))
1325 ;; Single-press: cancel any preexisting secondary selection.
1326 (or mouse-secondary-start
1327 (setq mouse-secondary-start (make-marker)))
1328 (set-marker mouse-secondary-start start-point)
1329 (delete-overlay mouse-secondary-overlay))
1330 ;; FIXME: Use mouse-drag-track!
1331 (let (event end end-point)
1334 (setq event (read-event))
1335 (or (mouse-movement-p event)
1336 (memq (car-safe event) '(switch-frame select-window))))
1338 (if (memq (car-safe event) '(switch-frame select-window))
1340 (setq end (event-end event)
1341 end-point (posn-point end))
1343 ;; Are we moving within the original window?
1344 ((and (eq (posn-window end) start-window)
1345 (integer-or-marker-p end-point))
1346 (let ((range (mouse-start-end start-point end-point
1348 (if (or (/= start-point end-point)
1349 (null (marker-position mouse-secondary-start)))
1351 (set-marker mouse-secondary-start nil)
1352 (move-overlay mouse-secondary-overlay
1353 (car range) (nth 1 range))))))
1355 (let ((mouse-row (cdr (cdr (mouse-position)))))
1359 (mouse-scroll-subr start-window (- mouse-row top)
1360 mouse-secondary-overlay start-point))
1361 ((>= mouse-row bottom)
1362 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
1363 mouse-secondary-overlay start-point)))))))))
1366 (if (marker-position mouse-secondary-start)
1367 (save-window-excursion
1368 (delete-overlay mouse-secondary-overlay)
1369 (gui-set-selection 'SECONDARY nil)
1370 (select-window start-window)
1372 (goto-char mouse-secondary-start)
1377 (buffer-substring (overlay-start mouse-secondary-overlay)
1378 (overlay-end mouse-secondary-overlay)))))))))
1380 (defun mouse-yank-secondary (click)
1381 "Insert the secondary selection at the position clicked on.
1382 Move point to the end of the inserted text.
1383 If `mouse-yank-at-point' is non-nil, insert at point
1384 regardless of where you click."
1386 ;; Give temporary modes such as isearch a chance to turn off.
1387 (run-hooks 'mouse-leave-buffer-hook)
1388 (or mouse-yank-at-point (mouse-set-point click))
1389 (let ((secondary (gui-get-selection 'SECONDARY)))
1391 (insert-for-yank secondary)
1392 (error "No secondary selection"))))
1394 (defun mouse-kill-secondary ()
1395 "Kill the text in the secondary selection.
1396 This is intended more as a keyboard command than as a mouse command
1397 but it can work as either one.
1399 The current buffer (in case of keyboard use), or the buffer clicked on,
1400 must be the one that the secondary selection is in. This requirement
1401 is to prevent accidents."
1403 (let* ((keys (this-command-keys))
1404 (click (elt keys (1- (length keys)))))
1405 (or (eq (overlay-buffer mouse-secondary-overlay)
1407 (window-buffer (posn-window (event-start click)))
1409 (error "Select or click on the buffer where the secondary selection is")))
1411 (with-current-buffer (overlay-buffer mouse-secondary-overlay)
1412 (kill-region (overlay-start mouse-secondary-overlay)
1413 (overlay-end mouse-secondary-overlay))))
1414 (delete-overlay mouse-secondary-overlay))
1416 (defun mouse-secondary-save-then-kill (click)
1417 "Set the secondary selection and save it to the kill ring.
1418 The second time, kill it. CLICK should be a mouse click event.
1420 If you have not called `mouse-start-secondary' in the clicked
1421 buffer, activate the secondary selection and set it between point
1422 and the click position CLICK.
1424 Otherwise, adjust the bounds of the secondary selection.
1425 Normally, do this by moving its beginning or end, whichever is
1426 closer, to CLICK. But if you have selected whole words or lines,
1427 adjust to the word or line boundary closest to CLICK instead.
1429 If this command is called a second consecutive time with the same
1430 CLICK position, kill the secondary selection."
1432 (mouse-minibuffer-check click)
1433 (let* ((posn (event-start click))
1434 (click-pt (posn-point posn))
1435 (window (posn-window posn))
1436 (buf (window-buffer window))
1437 ;; Don't let a subsequent kill command append to this one.
1438 (this-command this-command)
1439 ;; Check if the user has multi-clicked to select words/lines.
1441 (if (eq (overlay-buffer mouse-secondary-overlay) buf)
1442 mouse-secondary-click-count
1444 (beg (overlay-start mouse-secondary-overlay))
1445 (end (overlay-end mouse-secondary-overlay)))
1448 ((not (numberp click-pt)) nil)
1450 ;; If the secondary selection is not active in BUF, activate it.
1451 ((not (eq buf (or (overlay-buffer mouse-secondary-overlay)
1452 (if mouse-secondary-start
1453 (marker-buffer mouse-secondary-start)))))
1454 (select-window window)
1455 (setq mouse-secondary-start (make-marker))
1456 (move-marker mouse-secondary-start (point))
1457 (move-overlay mouse-secondary-overlay (point) click-pt buf)
1458 (kill-ring-save (point) click-pt))
1460 ;; If the user clicked without moving point, delete the secondary
1461 ;; selection. This also resets `mouse-secondary-click-count'.
1462 ((and (eq last-command 'mouse-secondary-save-then-kill)
1463 (eq click-pt mouse-save-then-kill-posn)
1464 (eq window (selected-window)))
1465 (mouse-save-then-kill-delete-region beg end)
1466 (delete-overlay mouse-secondary-overlay)
1467 (setq mouse-secondary-click-count 0)
1468 (setq mouse-save-then-kill-posn nil))
1470 ;; Otherwise, if there is a suitable secondary selection overlay,
1471 ;; adjust it by moving one end (whichever is closer) to CLICK-PT.
1472 ((and beg (eq buf (overlay-buffer mouse-secondary-overlay)))
1473 (let* ((range (mouse-start-end click-pt click-pt click-count)))
1474 (if (< (abs (- click-pt beg))
1475 (abs (- click-pt end)))
1476 (move-overlay mouse-secondary-overlay (car range) end)
1477 (move-overlay mouse-secondary-overlay beg (nth 1 range))))
1478 (setq deactivate-mark nil)
1479 (if (eq last-command 'mouse-secondary-save-then-kill)
1480 ;; If the front of the kill ring comes from an immediately
1481 ;; previous use of this command, replace the entry.
1483 (buffer-substring (overlay-start mouse-secondary-overlay)
1484 (overlay-end mouse-secondary-overlay))
1486 (let (deactivate-mark)
1487 (copy-region-as-kill (overlay-start mouse-secondary-overlay)
1488 (overlay-end mouse-secondary-overlay))))
1489 (setq mouse-save-then-kill-posn click-pt))
1491 ;; Otherwise, set the secondary selection overlay.
1493 (select-window window)
1494 (if mouse-secondary-start
1495 ;; All we have is one end of a selection, so put the other
1497 (let ((start (+ 0 mouse-secondary-start)))
1498 (kill-ring-save start click-pt)
1499 (move-overlay mouse-secondary-overlay start click-pt)))
1500 (setq mouse-save-then-kill-posn click-pt))))
1502 ;; Finally, set the window system's secondary selection.
1504 (and (overlay-buffer mouse-secondary-overlay)
1505 (setq str (buffer-substring (overlay-start mouse-secondary-overlay)
1506 (overlay-end mouse-secondary-overlay)))
1508 (gui-set-selection 'SECONDARY str))))
1511 (defcustom mouse-buffer-menu-maxlen 20
1512 "Number of buffers in one pane (submenu) of the buffer menu.
1513 If we have lots of buffers, divide them into groups of
1514 `mouse-buffer-menu-maxlen' and make a pane (or submenu) for each one."
1518 (defcustom mouse-buffer-menu-mode-mult 4
1519 "Group the buffers by the major mode groups on \\[mouse-buffer-menu]?
1520 This number which determines (in a hairy way) whether \\[mouse-buffer-menu]
1521 will split the buffer menu by the major modes (see
1522 `mouse-buffer-menu-mode-groups') or just by menu length.
1523 Set to 1 (or even 0!) if you want to group by major mode always, and to
1524 a large number if you prefer a mixed multitude. The default is 4."
1529 (defvar mouse-buffer-menu-mode-groups
1530 (mapcar (lambda (arg) (cons (purecopy (car arg)) (purecopy (cdr arg))))
1531 '(("Info\\|Help\\|Apropos\\|Man" . "Help")
1532 ("\\bVM\\b\\|\\bMH\\b\\|Message\\|Mail\\|Group\\|Score\\|Summary\\|Article"
1537 ("Outline" . "Text")
1538 ("\\(HT\\|SG\\|X\\|XHT\\)ML" . "SGML")
1539 ("log\\|diff\\|vc\\|cvs\\|Annotate" . "Version Control") ; "Change Management"?
1540 ("Threads\\|Memory\\|Disassembly\\|Breakpoints\\|Frames\\|Locals\\|Registers\\|Inferior I/O\\|Debugger"
1543 "How to group various major modes together in \\[mouse-buffer-menu].
1544 Each element has the form (REGEXP . GROUPNAME).
1545 If the major mode's name string matches REGEXP, use GROUPNAME instead.")
1547 (defun mouse-buffer-menu (event)
1548 "Pop up a menu of buffers for selection with the mouse.
1549 This switches buffers in the window that you clicked on,
1550 and selects that window."
1552 (mouse-minibuffer-check event)
1553 (let ((buf (x-popup-menu event (mouse-buffer-menu-map)))
1554 (window (posn-window (event-start event))))
1557 (if (framep window) (frame-selected-window window)
1559 (switch-to-buffer buf))))
1561 (defun mouse-buffer-menu-map ()
1562 ;; Make an alist of elements that look like (MENU-ITEM . BUFFER).
1563 (let ((buffers (buffer-list)) split-by-major-mode sum-of-squares)
1564 (dolist (buf buffers)
1565 ;; Divide all buffers into buckets for various major modes.
1566 ;; Each bucket looks like (MODE NAMESTRING BUFFERS...).
1567 (with-current-buffer buf
1568 (let* ((adjusted-major-mode major-mode) elt)
1569 (dolist (group mouse-buffer-menu-mode-groups)
1570 (when (string-match (car group) (format-mode-line mode-name))
1571 (setq adjusted-major-mode (cdr group))))
1572 (setq elt (assoc adjusted-major-mode split-by-major-mode))
1574 (setq elt (list adjusted-major-mode
1575 (if (stringp adjusted-major-mode)
1577 (format-mode-line mode-name nil nil buf)))
1578 split-by-major-mode (cons elt split-by-major-mode)))
1579 (or (memq buf (cdr (cdr elt)))
1580 (setcdr (cdr elt) (cons buf (cdr (cdr elt))))))))
1581 ;; Compute the sum of squares of sizes of the major-mode buckets.
1582 (let ((tail split-by-major-mode))
1583 (setq sum-of-squares 0)
1585 (setq sum-of-squares
1587 (let ((len (length (cdr (cdr (car tail)))))) (* len len))))
1588 (setq tail (cdr tail))))
1589 (if (< (* sum-of-squares mouse-buffer-menu-mode-mult)
1590 (* (length buffers) (length buffers)))
1591 ;; Subdividing by major modes really helps, so let's do it.
1592 (let (subdivided-menus (buffers-left (length buffers)))
1593 ;; Sort the list to put the most popular major modes first.
1594 (setq split-by-major-mode
1595 (sort split-by-major-mode
1596 (function (lambda (elt1 elt2)
1597 (> (length elt1) (length elt2))))))
1598 ;; Make a separate submenu for each major mode
1599 ;; that has more than one buffer,
1600 ;; unless all the remaining buffers are less than 1/10 of them.
1601 (while (and split-by-major-mode
1602 (and (> (length (car split-by-major-mode)) 3)
1603 (> (* buffers-left 10) (length buffers))))
1604 (let ((this-mode-list (mouse-buffer-menu-alist
1605 (cdr (cdr (car split-by-major-mode))))))
1607 (setq subdivided-menus
1609 (nth 1 (car split-by-major-mode))
1611 subdivided-menus))))
1613 (- buffers-left (length (cdr (car split-by-major-mode)))))
1614 (setq split-by-major-mode (cdr split-by-major-mode)))
1615 ;; If any major modes are left over,
1616 ;; make a single submenu for them.
1617 (if split-by-major-mode
1619 (mouse-buffer-menu-alist
1620 ;; we don't need split-by-major-mode any more,
1621 ;; so we can ditch it with nconc.
1622 (apply 'nconc (mapcar 'cddr split-by-major-mode)))))
1624 (setq subdivided-menus
1625 (cons (cons "Others" others-list)
1626 subdivided-menus)))))
1627 (cons "Buffer Menu" (nreverse subdivided-menus)))
1629 (mouse-buffer-menu-split "Select Buffer"
1630 (mouse-buffer-menu-alist buffers))))))
1632 (defun mouse-buffer-menu-alist (buffers)
1638 (function (lambda (elt1 elt2)
1639 (string< (buffer-name elt1) (buffer-name elt2))))))
1642 (or (eq ?\s (aref (buffer-name (car tail)) 0))
1645 (length (buffer-name (car tail))))))
1646 (setq tail (cdr tail)))
1649 (let ((elt (car tail)))
1650 (if (/= (aref (buffer-name elt) 0) ?\s)
1655 (format "%%-%ds %%s%%s %%s" maxlen)
1657 (if (buffer-modified-p elt) "*" " ")
1658 (with-current-buffer elt
1659 (if buffer-read-only "%" " "))
1660 (or (buffer-file-name elt)
1661 (with-current-buffer elt
1662 (if list-buffers-directory
1664 list-buffers-directory)))
1668 (setq tail (cdr tail)))
1669 ;; Compensate for the reversal that the above loop does.
1672 (defun mouse-buffer-menu-split (title alist)
1673 ;; If we have lots of buffers, divide them into groups of 20
1674 ;; and make a pane (or submenu) for each one.
1675 (if (> (length alist) (/ (* mouse-buffer-menu-maxlen 3) 2))
1676 (let ((alist alist) sublists next
1679 ;; Pull off the next mouse-buffer-menu-maxlen buffers
1680 ;; and make them the next element of sublist.
1681 (setq next (nthcdr mouse-buffer-menu-maxlen alist))
1683 (setcdr (nthcdr (1- mouse-buffer-menu-maxlen) alist)
1685 (setq sublists (cons (cons (format "Buffers %d" i) alist)
1689 (nreverse sublists))
1690 ;; Few buffers--put them all in one pane.
1691 (list (cons title alist))))
1693 (define-obsolete-function-alias
1694 'mouse-choose-completion 'choose-completion "23.2")
1698 (defun font-menu-add-default ()
1699 (let* ((default (cdr (assq 'font (frame-parameters (selected-frame)))))
1700 (font-alist x-fixed-font-alist)
1701 (elt (or (assoc "Misc" font-alist) (nth 1 font-alist))))
1702 (if (assoc "Default" elt)
1703 (delete (assoc "Default" elt) elt))
1705 (cons (list "Default" default)
1708 (defvar x-fixed-font-alist
1710 (purecopy "Font Menu")
1714 (lambda (arg) (cons (purecopy (car arg)) (purecopy (cdr arg))))
1715 ;; For these, we specify the pixel height and width.
1717 ("6x10" "-misc-fixed-medium-r-normal--10-*-*-*-c-60-iso8859-1" "6x10")
1719 "-misc-fixed-medium-r-semicondensed--12-*-*-*-c-60-iso8859-1" "6x12")
1721 "-misc-fixed-medium-r-semicondensed--13-*-*-*-c-60-iso8859-1" "6x13")
1722 ("7x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-70-iso8859-1" "7x13")
1723 ("7x14" "-misc-fixed-medium-r-normal--14-*-*-*-c-70-iso8859-1" "7x14")
1724 ("8x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-80-iso8859-1" "8x13")
1725 ("9x15" "-misc-fixed-medium-r-normal--15-*-*-*-c-90-iso8859-1" "9x15")
1726 ("10x20" "-misc-fixed-medium-r-normal--20-*-*-*-c-100-iso8859-1" "10x20")
1727 ("11x18" "-misc-fixed-medium-r-normal--18-*-*-*-c-110-iso8859-1" "11x18")
1728 ("12x24" "-misc-fixed-medium-r-normal--24-*-*-*-c-120-iso8859-1" "12x24")
1731 "-schumacher-clean-medium-r-normal--8-*-*-*-c-50-iso8859-1")
1733 "-schumacher-clean-medium-r-normal--8-*-*-*-c-60-iso8859-1")
1735 "-schumacher-clean-medium-r-normal--8-*-*-*-c-80-iso8859-1")
1737 "-schumacher-clean-medium-r-normal--10-*-*-*-c-80-iso8859-1")
1739 "-schumacher-clean-medium-r-normal--14-*-*-*-c-80-iso8859-1")
1741 "-schumacher-clean-medium-r-normal--16-*-*-*-c-80-iso8859-1")
1743 ("sony 8x16" "-sony-fixed-medium-r-normal--16-*-*-*-c-80-iso8859-1")
1744 ;; We don't seem to have these; who knows what they are.
1745 ;; ("fg-18" "fg-18")
1746 ;; ("fg-25" "fg-25")
1747 ("lucidasanstypewriter-12" "-b&h-lucidatypewriter-medium-r-normal-sans-*-120-*-*-*-*-iso8859-1")
1748 ("lucidasanstypewriter-bold-14" "-b&h-lucidatypewriter-bold-r-normal-sans-*-140-*-*-*-*-iso8859-1")
1749 ("lucidasanstypewriter-bold-24"
1750 "-b&h-lucidatypewriter-bold-r-normal-sans-*-240-*-*-*-*-iso8859-1")
1751 ;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
1752 ;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
1756 (purecopy "Courier")
1758 (lambda (arg) (cons (purecopy (car arg)) (purecopy (cdr arg))))
1759 ;; For these, we specify the point height.
1760 '(("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1")
1761 ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1")
1762 ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1")
1763 ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1")
1764 ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1")
1765 ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1")
1766 ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1")
1767 ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1")
1768 ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1")
1769 ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1")
1770 ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1")
1771 ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1")
1772 ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1")
1773 ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1")
1774 ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1")
1775 ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1")
1776 ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1")
1777 ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1")
1778 ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1")
1779 ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1")
1780 ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1")
1781 ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1")
1782 ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1")
1783 ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1")
1785 "X fonts suitable for use in Emacs.")
1787 (declare-function generate-fontset-menu "fontset" ())
1789 (defun mouse-select-font ()
1790 "Prompt for a font name, using `x-popup-menu', and return it."
1792 (unless (display-multi-font-p)
1793 (error "Cannot change fonts on this display"))
1796 (if (listp last-nonmenu-event)
1798 (list '(0 0) (selected-window)))
1799 (append x-fixed-font-alist
1800 (list (generate-fontset-menu))))))
1802 (declare-function text-scale-mode "face-remap")
1804 (defun mouse-set-font (&rest fonts)
1805 "Set the default font for the selected frame.
1806 The argument FONTS is a list of font names; the first valid font
1807 in this list is used.
1809 When called interactively, pop up a menu and allow the user to
1812 (progn (unless (display-multi-font-p)
1813 (error "Cannot change fonts on this display"))
1815 (if (listp last-nonmenu-event)
1817 (list '(0 0) (selected-window)))
1818 ;; Append list of fontsets currently defined.
1819 (append x-fixed-font-alist (list (generate-fontset-menu))))))
1825 (set-frame-font (car fonts))
1826 (setq font (car fonts))
1829 (setq fonts (cdr fonts)))))
1831 (error "Font not found")))))
1833 (defvar mouse-appearance-menu-map nil)
1834 (declare-function x-select-font "xfns.c" (&optional frame ignored)) ; USE_GTK
1835 (declare-function buffer-face-mode-invoke "face-remap"
1836 (face arg &optional interactive))
1837 (declare-function font-face-attributes "font.c" (font &optional frame))
1838 (defvar w32-use-w32-font-dialog)
1839 (defvar w32-fixed-font-alist)
1841 (defun mouse-appearance-menu (event)
1842 "Show a menu for changing the default face in the current buffer."
1844 (require 'face-remap)
1845 (when (display-multi-font-p)
1846 (with-selected-window (car (event-start event))
1847 (if mouse-appearance-menu-map
1848 nil ; regenerate new fonts
1849 ;; Initialize mouse-appearance-menu-map
1850 (setq mouse-appearance-menu-map
1851 (make-sparse-keymap "Change Default Buffer Face"))
1852 (define-key mouse-appearance-menu-map [face-remap-reset-base]
1853 '(menu-item "Reset to Default" face-remap-reset-base))
1854 (define-key mouse-appearance-menu-map [text-scale-decrease]
1855 '(menu-item "Decrease Buffer Text Size" text-scale-decrease))
1856 (define-key mouse-appearance-menu-map [text-scale-increase]
1857 '(menu-item "Increase Buffer Text Size" text-scale-increase))
1859 (if (and (functionp 'x-select-font)
1860 (or (not (boundp 'w32-use-w32-font-dialog))
1861 w32-use-w32-font-dialog))
1862 (define-key mouse-appearance-menu-map [x-select-font]
1863 '(menu-item "Change Buffer Font..." x-select-font))
1864 ;; If the select-font is unavailable, construct a menu.
1865 (let ((font-submenu (make-sparse-keymap "Change Text Font"))
1866 (font-alist (cdr (append
1867 (if (eq system-type 'windows-nt)
1868 w32-fixed-font-alist
1870 (list (generate-fontset-menu))))))
1871 (dolist (family font-alist)
1872 (let* ((submenu-name (car family))
1873 (submenu-map (make-sparse-keymap submenu-name)))
1874 (dolist (font (cdr family))
1875 (let ((font-name (car font))
1877 (if (string= font-name "")
1878 (define-key submenu-map [space]
1880 (setq font-symbol (intern (cadr font)))
1881 (define-key submenu-map (vector font-symbol)
1882 (list 'menu-item (car font) font-symbol)))))
1883 (define-key font-submenu (vector (intern submenu-name))
1884 (list 'menu-item submenu-name submenu-map))))
1885 (define-key mouse-appearance-menu-map [font-submenu]
1886 (list 'menu-item "Change Text Font" font-submenu)))))
1887 (let ((choice (x-popup-menu event mouse-appearance-menu-map)))
1888 (setq choice (nth (1- (length choice)) choice))
1889 (cond ((eq choice 'text-scale-increase)
1890 (text-scale-increase 1))
1891 ((eq choice 'text-scale-decrease)
1892 (text-scale-increase -1))
1893 ((eq choice 'face-remap-reset-base)
1895 (buffer-face-mode 0))
1897 ;; Either choice == 'x-select-font, or choice is a
1898 ;; symbol whose name is a font.
1899 (let ((font (if (eq choice 'x-select-font)
1901 (symbol-name choice))))
1902 (buffer-face-mode-invoke
1903 (if (fontp font 'font-spec)
1905 (font-face-attributes font))
1906 t (called-interactively-p 'interactive)))))))))
1909 ;;; Bindings for mouse commands.
1911 (global-set-key [down-mouse-1] 'mouse-drag-region)
1912 (global-set-key [mouse-1] 'mouse-set-point)
1913 (global-set-key [drag-mouse-1] 'mouse-set-region)
1915 (defun mouse--strip-first-event (_prompt)
1916 (substring (this-single-command-raw-keys) 1))
1918 (define-key function-key-map [left-fringe mouse-1] 'mouse--strip-first-event)
1919 (define-key function-key-map [right-fringe mouse-1] 'mouse--strip-first-event)
1921 (global-set-key [mouse-2] 'mouse-yank-primary)
1922 ;; Allow yanking also when the corresponding cursor is "in the fringe".
1923 (define-key function-key-map [right-fringe mouse-2] 'mouse--strip-first-event)
1924 (define-key function-key-map [left-fringe mouse-2] 'mouse--strip-first-event)
1925 (global-set-key [mouse-3] 'mouse-save-then-kill)
1926 (define-key function-key-map [right-fringe mouse-3] 'mouse--strip-first-event)
1927 (define-key function-key-map [left-fringe mouse-3] 'mouse--strip-first-event)
1929 ;; By binding these to down-going events, we let the user use the up-going
1930 ;; event to make the selection, saving a click.
1931 (global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
1932 (if (not (eq system-type 'ms-dos))
1933 (global-set-key [S-down-mouse-1] 'mouse-appearance-menu))
1934 ;; C-down-mouse-2 is bound in facemenu.el.
1935 (global-set-key [C-down-mouse-3]
1936 `(menu-item ,(purecopy "Menu Bar") ignore
1938 (if (zerop (or (frame-parameter nil 'menu-bar-lines) 0))
1939 (mouse-menu-bar-map)
1940 (mouse-menu-major-mode-map)))))
1942 ;; Binding mouse-1 to mouse-select-window when on mode-, header-, or
1943 ;; vertical-line prevents Emacs from signaling an error when the mouse
1944 ;; button is released after dragging these lines, on non-toolkit
1946 (global-set-key [header-line down-mouse-1] 'mouse-drag-header-line)
1947 (global-set-key [header-line mouse-1] 'mouse-select-window)
1948 ;; (global-set-key [mode-line drag-mouse-1] 'mouse-select-window)
1949 (global-set-key [mode-line down-mouse-1] 'mouse-drag-mode-line)
1950 (global-set-key [mode-line mouse-1] 'mouse-select-window)
1951 (global-set-key [mode-line mouse-2] 'mouse-delete-other-windows)
1952 (global-set-key [mode-line mouse-3] 'mouse-delete-window)
1953 (global-set-key [mode-line C-mouse-2] 'mouse-split-window-horizontally)
1954 (global-set-key [vertical-scroll-bar C-mouse-2] 'mouse-split-window-vertically)
1955 (global-set-key [horizontal-scroll-bar C-mouse-2] 'mouse-split-window-horizontally)
1956 (global-set-key [vertical-line down-mouse-1] 'mouse-drag-vertical-line)
1957 (global-set-key [vertical-line mouse-1] 'mouse-select-window)
1958 (global-set-key [vertical-line C-mouse-2] 'mouse-split-window-vertically)
1959 (global-set-key [right-divider down-mouse-1] 'mouse-drag-vertical-line)
1960 (global-set-key [right-divider mouse-1] 'ignore)
1961 (global-set-key [right-divider C-mouse-2] 'mouse-split-window-vertically)
1962 (global-set-key [bottom-divider down-mouse-1] 'mouse-drag-mode-line)
1963 (global-set-key [bottom-divider mouse-1] 'ignore)
1964 (global-set-key [bottom-divider C-mouse-2] 'mouse-split-window-horizontally)
1968 ;;; mouse.el ends here