1 ;;; mouse.el --- window system-independent mouse support -*- lexical-binding: t -*-
3 ;; Copyright (C) 1993-1995, 1999-2015 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
)
157 (turn-off menu-item
"Turn Off minor mode" ,mm-fun
)
158 (help menu-item
"Help for minor mode"
159 (lambda () (interactive)
160 (describe-function ',mm-fun
))))))
163 (defun mouse-minor-mode-menu (event)
164 "Show minor-mode menu for EVENT on minor modes area of the mode line."
166 (let ((indicator (car (nth 4 (car (cdr event
))))))
167 (minor-mode-menu-from-indicator indicator
)))
169 (defun mouse-menu-major-mode-map ()
170 (run-hooks 'activate-menubar-hook
'menu-bar-update-hook
)
171 (let* (;; Keymap from which to inherit; may be null.
172 (ancestor (mouse-menu-non-singleton
173 (and (current-local-map)
174 (local-key-binding [menu-bar
]))))
175 ;; Make a keymap in which our last command leads to a menu or
176 ;; default to the edit menu.
178 (make-sparse-keymap (concat (format-mode-line mode-name
)
180 menu-bar-edit-menu
)))
182 (set-keymap-parent newmap ancestor
))
185 (defun mouse-menu-non-singleton (menubar)
186 "Return menu keybar MENUBAR, or a lone submenu inside it.
187 If MENUBAR defines exactly one submenu, return just that submenu.
188 Otherwise, return MENUBAR."
192 (lambda (k v
) (setq submap
(if submap t
(cons k v
))))
193 (keymap-canonicalize menubar
))
196 (lookup-key menubar
(vector (car submap
)))))))
198 (defun mouse-menu-bar-map ()
199 "Return a keymap equivalent to the menu bar.
200 The contents are the items that would be in the menu bar whether or
201 not it is actually displayed."
202 (run-hooks 'activate-menubar-hook
'menu-bar-update-hook
)
203 (let* ((local-menu (and (current-local-map)
204 (lookup-key (current-local-map) [menu-bar
])))
205 (global-menu (lookup-key global-map
[menu-bar
]))
206 ;; If a keymap doesn't have a prompt string (a lazy
207 ;; programmer didn't bother to provide one), create it and
208 ;; insert it into the keymap; each keymap gets its own
209 ;; prompt. This is required for non-toolkit versions to
210 ;; display non-empty menu pane names.
214 (let* ((minor-mode (car menu
))
216 (title-or-map (cadr menu
)))
217 (or (stringp title-or-map
)
221 (capitalize (subst-char-in-string
227 (minor-mode-key-binding [menu-bar
])))
228 (local-title-or-map (and local-menu
(cadr local-menu
)))
229 (global-title-or-map (cadr global-menu
)))
230 (or (null local-menu
)
231 (stringp local-title-or-map
)
232 (setq local-menu
(cons 'keymap
233 (cons (concat (format-mode-line mode-name
)
236 (or (stringp global-title-or-map
)
237 (setq global-menu
(cons 'keymap
239 (cdr global-menu
)))))
240 ;; Supplying the list is faster than making a new map.
241 ;; FIXME: We have a problem here: we have to use the global/local/minor
242 ;; so they're displayed in the expected order, but later on in the command
243 ;; loop, they're actually looked up in the opposite order.
249 (defun mouse-major-mode-menu (event &optional prefix
)
250 "Pop up a mode-specific menu of mouse commands.
251 Default to the Edit menu if the major mode doesn't define a menu."
252 (declare (obsolete mouse-menu-major-mode-map
"23.1"))
253 (interactive "@e\nP")
254 (run-hooks 'activate-menubar-hook
'menu-bar-update-hook
)
255 (popup-menu (mouse-menu-major-mode-map) event prefix
))
257 (defun mouse-popup-menubar (event prefix
)
258 "Pop up a menu equivalent to the menu bar for keyboard EVENT with PREFIX.
259 The contents are the items that would be in the menu bar whether or
260 not it is actually displayed."
261 (declare (obsolete mouse-menu-bar-map
"23.1"))
262 (interactive "@e \nP")
263 (run-hooks 'activate-menubar-hook
'menu-bar-update-hook
)
264 (popup-menu (mouse-menu-bar-map) (unless (integerp event
) event
) prefix
))
266 (defun mouse-popup-menubar-stuff (event prefix
)
267 "Popup a menu like either `mouse-major-mode-menu' or `mouse-popup-menubar'.
268 Use the former if the menu bar is showing, otherwise the latter."
269 (declare (obsolete nil
"23.1"))
270 (interactive "@e\nP")
271 (run-hooks 'activate-menubar-hook
'menu-bar-update-hook
)
273 (if (zerop (or (frame-parameter nil
'menu-bar-lines
) 0))
275 (mouse-menu-major-mode-map))
278 ;; Commands that operate on windows.
280 (defun mouse-minibuffer-check (event)
281 (let ((w (posn-window (event-start event
))))
282 (and (window-minibuffer-p w
)
283 (not (minibuffer-window-active-p w
))
284 (user-error "Minibuffer window is not active")))
285 ;; Give temporary modes such as isearch a chance to turn off.
286 (run-hooks 'mouse-leave-buffer-hook
))
288 (defun mouse-delete-window (click)
289 "Delete the window you click on.
290 Do nothing if the frame has just one window.
291 This command must be bound to a mouse click."
293 (unless (one-window-p t
)
294 (mouse-minibuffer-check click
)
295 (delete-window (posn-window (event-start click
)))))
297 (defun mouse-select-window (click)
298 "Select the window clicked on; don't move point."
300 (mouse-minibuffer-check click
)
301 (let ((oframe (selected-frame))
302 (frame (window-frame (posn-window (event-start click
)))))
303 (select-window (posn-window (event-start click
)))
306 (or (eq frame oframe
)
307 (set-mouse-position (selected-frame) (1- (frame-width)) 0))))
309 (define-obsolete-function-alias 'mouse-tear-off-window
'tear-off-window
"24.4")
310 (defun tear-off-window (click)
311 "Delete the selected window, and create a new frame displaying its buffer."
313 (mouse-minibuffer-check click
)
314 (let* ((window (posn-window (event-start click
)))
315 (buf (window-buffer window
))
316 (frame (make-frame))) ;FIXME: Use pop-to-buffer.
318 (switch-to-buffer buf
)
319 (delete-window window
)))
321 (defun mouse-delete-other-windows ()
322 "Delete all windows except the one you click on."
324 (delete-other-windows))
326 (defun mouse-split-window-vertically (click)
327 "Select Emacs window mouse is on, then split it vertically in half.
328 The window is split at the line clicked on.
329 This command must be bound to a mouse click."
331 (mouse-minibuffer-check click
)
332 (let ((start (event-start click
)))
333 (select-window (posn-window start
))
334 (let ((new-height (1+ (cdr (posn-col-row (event-end click
)))))
335 (first-line window-min-height
)
336 (last-line (- (window-height) window-min-height
)))
337 (if (< last-line first-line
)
338 (error "Window too short to split")
339 (split-window-vertically
340 (min (max new-height first-line
) last-line
))))))
342 (defun mouse-split-window-horizontally (click)
343 "Select Emacs window mouse is on, then split it horizontally in half.
344 The window is split at the column clicked on.
345 This command must be bound to a mouse click."
347 (mouse-minibuffer-check click
)
348 (let ((start (event-start click
)))
349 (select-window (posn-window start
))
350 (let ((new-width (1+ (car (posn-col-row (event-end click
)))))
351 (first-col window-min-width
)
352 (last-col (- (window-width) window-min-width
)))
353 (if (< last-col first-col
)
354 (error "Window too narrow to split")
355 (split-window-horizontally
356 (min (max new-width first-col
) last-col
))))))
358 (defun mouse-drag-line (start-event line
)
359 "Drag a mode line, header line, or vertical line with the mouse.
360 START-EVENT is the starting mouse-event of the drag action. LINE
361 must be one of the symbols `header', `mode', or `vertical'."
362 ;; Give temporary modes such as isearch a chance to turn off.
363 (run-hooks 'mouse-leave-buffer-hook
)
364 (let* ((echo-keystrokes 0)
365 (start (event-start start-event
))
366 (window (posn-window start
))
367 (frame (window-frame window
))
368 ;; `position' records the x- or y-coordinate of the last
370 (position (if (eq line
'vertical
)
371 (+ (window-pixel-left window
)
372 (car (posn-x-y start
)))
373 (+ (window-pixel-top window
)
374 (cdr (posn-x-y start
)))))
375 ;; `last-position' records the x- or y-coordinate of the
376 ;; previously sampled position. The difference of `position'
377 ;; and `last-position' determines the size change of WINDOW.
378 (last-position position
)
380 posn-window growth dragged
)
381 ;; Decide on whether we are allowed to track at all and whose
382 ;; window's edge we drag.
385 (if (window-at-side-p window
'top
)
386 ;; We can't drag the header line of a topmost window.
388 ;; Drag bottom edge of window above the header line.
389 (setq window
(window-in-direction 'above window t
))))
391 (if (and (window-at-side-p window
'bottom
)
392 ;; Allow resizing the minibuffer window if it's on the
393 ;; same frame as and immediately below `window', and it's
394 ;; either active or `resize-mini-windows' is nil.
395 (let ((minibuffer-window (minibuffer-window frame
)))
396 (not (and (eq (window-frame minibuffer-window
) frame
)
397 (or (not resize-mini-windows
)
398 (eq minibuffer-window
399 (active-minibuffer-window)))))))
400 (setq draggable nil
))))
404 (lambda (event) (interactive "e")
409 ;; Drag right edge of `window'.
410 (setq start
(event-start event
))
411 (setq position
(car (posn-x-y start
)))
412 ;; Set `posn-window' to the window where `event' was recorded.
413 ;; This can be `window' or the window on the left or right of
415 (when (window-live-p (setq posn-window
(posn-window start
)))
416 ;; Add left edge of `posn-window' to `position'.
417 (setq position
(+ (window-pixel-left posn-window
) position
))
418 (unless (nth 1 start
)
419 ;; Add width of objects on the left of the text area to
421 (when (eq (window-current-scroll-bars posn-window
) 'left
)
422 (setq position
(+ (window-scroll-bar-width posn-window
)
424 (setq position
(+ (car (window-fringes posn-window
))
425 (or (car (window-margins posn-window
)) 0)
427 ;; When the cursor overshoots after shrinking a window to its
428 ;; minimum size and the dragging direction changes, have the
429 ;; cursor first catch up with the window edge.
430 (unless (or (zerop (setq growth
(- position last-position
)))
432 (< position
(+ (window-pixel-left window
)
433 (window-pixel-width window
))))
435 (> position
(+ (window-pixel-left window
)
436 (window-pixel-width window
)))))
438 (adjust-window-trailing-edge window growth t t
))
439 (setq last-position position
))
441 ;; Drag bottom edge of `window'.
442 (setq start
(event-start event
))
443 ;; Set `posn-window' to the window where `event' was recorded.
444 ;; This can be either `window' or the window above or below of
446 (setq posn-window
(posn-window start
))
447 (setq position
(cdr (posn-x-y start
)))
448 (when (window-live-p posn-window
)
449 ;; Add top edge of `posn-window' to `position'.
450 (setq position
(+ (window-pixel-top posn-window
) position
))
451 ;; If necessary, add height of header line to `position'
452 (when (memq (posn-area start
)
453 '(nil left-fringe right-fringe left-margin right-margin
))
454 (setq position
(+ (window-header-line-height posn-window
) position
))))
455 ;; When the cursor overshoots after shrinking a window to its
456 ;; minimum size and the dragging direction changes, have the
457 ;; cursor first catch up with the window edge.
458 (unless (or (zerop (setq growth
(- position last-position
)))
460 (< position
(+ (window-pixel-top window
)
461 (window-pixel-height window
))))
463 (> position
(+ (window-pixel-top window
)
464 (window-pixel-height window
)))))
466 (adjust-window-trailing-edge window growth nil t
))
467 (setq last-position position
))))))
470 ;; Loop reading events and sampling the position of the mouse.
473 (let ((map (make-sparse-keymap)))
474 (define-key map
[switch-frame
] #'ignore
)
475 (define-key map
[select-window
] #'ignore
)
476 (define-key map
[scroll-bar-movement
] #'ignore
)
477 (define-key map
[mouse-movement
] move
)
478 ;; Swallow drag-mouse-1 events to avoid selecting some other window.
479 (define-key map
[drag-mouse-1
]
480 (lambda () (interactive) (funcall exitfun
)))
481 ;; For vertical line dragging swallow also a mouse-1
482 ;; event (but only if we dragged at least once to allow mouse-1
483 ;; clicks to get through).
484 (when (eq line
'vertical
)
485 (define-key map
[mouse-1
]
486 `(menu-item "" ,(lambda () (interactive) (funcall exitfun
))
487 :filter
,(lambda (cmd) (if dragged cmd
)))))
488 ;; Some of the events will of course end up looked up
489 ;; with a mode-line, header-line or vertical-line prefix ...
490 (define-key map
[mode-line
] map
)
491 (define-key map
[header-line
] map
)
492 (define-key map
[vertical-line
] map
)
493 ;; ... and some maybe even with a right- or bottom-divider
495 (define-key map
[right-divider
] map
)
496 (define-key map
[bottom-divider
] map
)
498 t
(lambda () (setq track-mouse nil
)))))))
500 (defun mouse-drag-mode-line (start-event)
501 "Change the height of a window by dragging on the mode line."
503 (mouse-drag-line start-event
'mode
))
505 (defun mouse-drag-header-line (start-event)
506 "Change the height of a window by dragging on the header line."
508 (mouse-drag-line start-event
'header
))
510 (defun mouse-drag-vertical-line (start-event)
511 "Change the width of a window by dragging on the vertical line."
513 (mouse-drag-line start-event
'vertical
))
515 (defun mouse-set-point (event &optional promote-to-region
)
516 "Move point to the position clicked on with the mouse.
517 This should be bound to a mouse click event type.
518 If PROMOTE-TO-REGION is non-nil and event is a multiple-click,
519 select the corresponding element around point."
521 (mouse-minibuffer-check event
)
522 (if (and promote-to-region
(> (event-click-count event
) 1))
523 (mouse-set-region event
)
524 ;; Use event-end in case called from mouse-drag-region.
525 ;; If EVENT is a click, event-end and event-start give same value.
526 (posn-set-point (event-end event
))))
528 (defvar mouse-last-region-beg nil
)
529 (defvar mouse-last-region-end nil
)
530 (defvar mouse-last-region-tick nil
)
532 (defun mouse-region-match ()
533 "Return non-nil if there's an active region that was set with the mouse."
534 (and (mark t
) mark-active
535 (eq mouse-last-region-beg
(region-beginning))
536 (eq mouse-last-region-end
(region-end))
537 (eq mouse-last-region-tick
(buffer-modified-tick))))
539 (defvar mouse--drag-start-event nil
)
541 (defun mouse-set-region (click)
542 "Set the region to the text dragged over, and copy to kill ring.
543 This should be bound to a mouse drag event.
544 See the `mouse-drag-copy-region' variable to control whether this
545 command alters the kill ring or not."
547 (mouse-minibuffer-check click
)
548 (select-window (posn-window (event-start click
)))
549 (let ((beg (posn-point (event-start click
)))
550 (end (posn-point (event-end click
)))
551 (click-count (event-click-count click
)))
552 (let ((drag-start (terminal-parameter nil
'mouse-drag-start
)))
554 ;; Drag events don't come with a click count, sadly, so we hack
555 ;; our way around this problem by remembering the start-event in
556 ;; `mouse-drag-start' and fetching the click-count from there.
557 (when (and (<= click-count
1)
558 (equal beg
(posn-point (event-start drag-start
))))
559 (setq click-count
(event-click-count drag-start
)))
560 ;; Occasionally we get spurious drag events where the user hasn't
561 ;; dragged his mouse, but instead Emacs has dragged the text under the
562 ;; user's mouse. Try to recover those cases (bug#17562).
563 (when (and (equal (posn-x-y (event-start click
))
564 (posn-x-y (event-end click
)))
565 (not (eq (car drag-start
) 'mouse-movement
)))
567 (setf (terminal-parameter nil
'mouse-drag-start
) nil
)))
568 (when (and (integerp beg
) (integerp end
))
569 (let ((range (mouse-start-end beg end
(1- click-count
))))
571 (setq end
(nth 0 range
) beg
(nth 1 range
))
572 (setq beg
(nth 0 range
) end
(nth 1 range
)))))
573 (and mouse-drag-copy-region
(integerp beg
) (integerp end
)
574 ;; Don't set this-command to `kill-region', so a following
575 ;; C-w won't double the text in the kill ring. Ignore
576 ;; `last-command' so we don't append to a preceding kill.
577 (let (this-command last-command deactivate-mark
)
578 (copy-region-as-kill beg end
)))
579 (if (numberp beg
) (goto-char beg
))
580 ;; On a text terminal, bounce the cursor.
581 (or transient-mark-mode
586 (if (numberp end
) (goto-char end
))
587 (mouse-set-region-1)))
589 (defun mouse-set-region-1 ()
590 ;; Set transient-mark-mode for a little while.
591 (unless (eq (car-safe transient-mark-mode
) 'only
)
592 (setq-local transient-mark-mode
594 (unless (eq transient-mark-mode
'lambda
)
595 transient-mark-mode
))))
596 (setq mouse-last-region-beg
(region-beginning))
597 (setq mouse-last-region-end
(region-end))
598 (setq mouse-last-region-tick
(buffer-modified-tick)))
600 (defcustom mouse-scroll-delay
0.25
601 "The pause between scroll steps caused by mouse drags, in seconds.
602 If you drag the mouse beyond the edge of a window, Emacs scrolls the
603 window to bring the text beyond that edge into view, with a delay of
604 this many seconds between scroll steps. Scrolling stops when you move
605 the mouse back into the window, or release the button.
606 This variable's value may be non-integral.
607 Setting this to zero causes Emacs to scroll as fast as it can."
611 (defcustom mouse-scroll-min-lines
1
612 "The minimum number of lines scrolled by dragging mouse out of window.
613 Moving the mouse out the top or bottom edge of the window begins
614 scrolling repeatedly. The number of lines scrolled per repetition
615 is normally equal to the number of lines beyond the window edge that
616 the mouse has moved. However, it always scrolls at least the number
617 of lines specified by this variable."
621 (defun mouse-scroll-subr (window jump
&optional overlay start
)
622 "Scroll the window WINDOW, JUMP lines at a time, until new input arrives.
623 If OVERLAY is an overlay, let it stretch from START to the far edge of
624 the newly visible text.
625 Upon exit, point is at the far edge of the newly visible text."
627 ((and (> jump
0) (< jump mouse-scroll-min-lines
))
628 (setq jump mouse-scroll-min-lines
))
629 ((and (< jump
0) (< (- jump
) mouse-scroll-min-lines
))
630 (setq jump
(- mouse-scroll-min-lines
))))
631 (let ((opoint (point)))
633 (goto-char (window-start window
))
634 (if (not (zerop (vertical-motion jump window
)))
636 (set-window-start window
(point))
638 (if (window-end window
)
640 (goto-char (window-end window
))
641 ;; window-end doesn't reflect the window's new
642 ;; start position until the next redisplay.
643 (vertical-motion (1- jump
) window
))
644 (vertical-motion (- (window-height window
) 2)))
645 (goto-char (window-start window
)))
647 (move-overlay overlay start
(point)))
648 ;; Now that we have scrolled WINDOW properly,
649 ;; put point back where it was for the redisplay
650 ;; so that we don't mess up the selected window.
651 (or (eq window
(selected-window))
653 (sit-for mouse-scroll-delay
)))))
654 (or (eq window
(selected-window))
655 (goto-char opoint
))))
657 (defvar mouse-selection-click-count
0)
659 (defvar mouse-selection-click-count-buffer nil
)
661 (defun mouse-drag-region (start-event)
662 "Set the region to the text that the mouse is dragged over.
663 Highlight the drag area as you move the mouse.
664 This must be bound to a button-down mouse event.
665 In Transient Mark mode, the highlighting remains as long as the mark
666 remains active. Otherwise, it remains until the next input event."
668 ;; Give temporary modes such as isearch a chance to turn off.
669 (run-hooks 'mouse-leave-buffer-hook
)
670 (mouse-drag-track start-event
))
673 (defun mouse-posn-property (pos property
)
674 "Look for a property at click position.
675 POS may be either a buffer position or a click position like
676 those returned from `event-start'. If the click position is on
677 a string, the text property PROPERTY is examined.
678 If this is nil or the click is not on a string, then
679 the corresponding buffer position is searched for PROPERTY.
680 If PROPERTY is encountered in one of those places,
681 its value is returned."
683 (let ((w (posn-window pos
)) (pt (posn-point pos
))
684 (str (posn-string pos
)))
686 (get-text-property (cdr str
) property
(car str
)))
687 ;; Mouse clicks in the fringe come with a position in
688 ;; (nth 5). This is useful but is not exactly where we clicked, so
689 ;; don't look up that position's properties!
690 (and pt
(not (memq (posn-area pos
) '(left-fringe right-fringe
691 left-margin right-margin
)))
692 (get-char-property pt property w
))))
693 (get-char-property pos property
)))
695 (defun mouse-on-link-p (pos)
696 "Return non-nil if POS is on a link in the current buffer.
697 POS must be a buffer position in the current buffer or a mouse
698 event location in the selected window (see `event-start').
699 However, if `mouse-1-click-in-non-selected-windows' is non-nil,
700 POS may be a mouse event location in any window.
702 A clickable link is identified by one of the following methods:
704 - If the character at POS has a non-nil `follow-link' text or
705 overlay property, the value of that property determines what to do.
707 - If there is a local key-binding or a keybinding at position POS
708 for the `follow-link' event, the binding of that event determines
711 The resulting value determine whether POS is inside a link:
713 - If the value is `mouse-face', POS is inside a link if there
714 is a non-nil `mouse-face' property at POS. Return t in this case.
716 - If the value is a function, FUNC, POS is inside a link if
717 the call \(FUNC POS) returns non-nil. Return the return value
718 from that call. Arg is \(posn-point POS) if POS is a mouse event.
720 - Otherwise, return the value itself.
722 The return value is interpreted as follows:
724 - If it is a string, the mouse-1 event is translated into the
725 first character of the string, i.e. the action of the mouse-1
726 click is the local or global binding of that character.
728 - If it is a vector, the mouse-1 event is translated into the
729 first element of that vector, i.e. the action of the mouse-1
730 click is the local or global binding of that event.
732 - Otherwise, the mouse-1 event is translated into a mouse-2 event
733 at the same position."
735 (and (or (not (consp pos
))
736 mouse-1-click-in-non-selected-windows
737 (eq (selected-window) (posn-window pos
)))
738 (or (mouse-posn-property pos
'follow-link
)
739 (let ((area (posn-area pos
)))
741 (key-binding (vector area
'follow-link
) nil t pos
)))
742 (key-binding [follow-link
] nil t pos
)))))
744 ((eq action
'mouse-face
)
745 (and (mouse-posn-property pos
'mouse-face
) t
))
747 ;; FIXME: This seems questionable if the click is not in a buffer.
748 ;; Should we instead decide that `action' takes a `posn'?
750 (with-current-buffer (window-buffer (posn-window pos
))
751 (funcall action
(posn-point pos
)))
752 (funcall action pos
)))
755 (defun mouse-fixup-help-message (msg)
756 "Fix help message MSG for `mouse-1-click-follows-link'."
758 (if (and mouse-1-click-follows-link
760 (string-match-p "\\`mouse-2" msg
)
761 (setq mp
(mouse-pixel-position))
762 (consp (setq pos
(cdr mp
)))
763 (car pos
) (>= (car pos
) 0)
764 (cdr pos
) (>= (cdr pos
) 0)
765 (setq pos
(posn-at-x-y (car pos
) (cdr pos
) (car mp
)))
766 (windowp (posn-window pos
)))
767 (with-current-buffer (window-buffer (posn-window pos
))
768 (if (mouse-on-link-p pos
)
771 ((eq mouse-1-click-follows-link
'double
) "double-")
772 ((and (integerp mouse-1-click-follows-link
)
773 (< mouse-1-click-follows-link
0)) "Long ")
775 "mouse-1" (substring msg
7)))))))
778 (defun mouse-drag-track (start-event)
779 "Track mouse drags by highlighting area between point and cursor.
780 The region will be defined with mark and point."
781 (mouse-minibuffer-check start-event
)
782 (setq mouse-selection-click-count-buffer
(current-buffer))
784 (let* ((scroll-margin 0) ; Avoid margin scrolling (Bug#9541).
785 ;; We've recorded what we needed from the current buffer and
786 ;; window, now let's jump to the place of the event, where things
788 (_ (mouse-set-point start-event
))
790 (start-posn (event-start start-event
))
791 (start-point (posn-point start-posn
))
792 (start-window (posn-window start-posn
))
793 (bounds (window-edges start-window
))
794 (make-cursor-line-fully-visible nil
)
796 (bottom (if (window-minibuffer-p start-window
)
798 ;; Don't count the mode line.
799 (1- (nth 3 bounds
))))
800 (click-count (1- (event-click-count start-event
)))
801 ;; Suppress automatic hscrolling, because that is a nuisance
802 ;; when setting point near the right fringe (but see below).
803 (auto-hscroll-mode-saved auto-hscroll-mode
))
805 (setq mouse-selection-click-count click-count
)
806 ;; In case the down click is in the middle of some intangible text,
807 ;; use the end of that text, and put it in START-POINT.
808 (if (< (point) start-point
)
809 (goto-char start-point
))
810 (setq start-point
(point))
812 ;; Activate the region, using `mouse-start-end' to determine where
813 ;; to put point and mark (e.g., double-click will select a word).
814 (setq-local transient-mark-mode
815 (if (eq transient-mark-mode
'lambda
)
817 (cons 'only transient-mark-mode
)))
818 (let ((range (mouse-start-end start-point start-point click-count
)))
819 (push-mark (nth 0 range
) t t
)
820 (goto-char (nth 1 range
)))
822 (setf (terminal-parameter nil
'mouse-drag-start
) start-event
)
824 (setq auto-hscroll-mode nil
)
827 (let ((map (make-sparse-keymap)))
828 (define-key map
[switch-frame
] #'ignore
)
829 (define-key map
[select-window
] #'ignore
)
830 (define-key map
[mouse-movement
]
831 (lambda (event) (interactive "e")
832 (let* ((end (event-end event
))
833 (end-point (posn-point end
)))
834 (unless (eq end-point start-point
)
835 ;; As soon as the user moves, we can re-enable auto-hscroll.
836 (setq auto-hscroll-mode auto-hscroll-mode-saved
)
837 ;; And remember that we have moved, so mouse-set-region can know
838 ;; its event is really a drag event.
839 (setcar start-event
'mouse-movement
))
840 (if (and (eq (posn-window end
) start-window
)
841 (integer-or-marker-p end-point
))
842 (mouse--drag-set-mark-and-point start-point
843 end-point click-count
)
844 (let ((mouse-row (cdr (cdr (mouse-position)))))
848 (mouse-scroll-subr start-window
(- mouse-row top
)
850 ((>= mouse-row bottom
)
851 (mouse-scroll-subr start-window
(1+ (- mouse-row bottom
))
852 nil start-point
))))))))
855 (setq track-mouse nil
)
856 (setq auto-hscroll-mode auto-hscroll-mode-saved
)
860 (defun mouse--drag-set-mark-and-point (start click click-count
)
861 (let* ((range (mouse-start-end start click click-count
))
864 (cond ((eq (mark) beg
)
875 ;; Commands to handle xterm-style multiple clicks.
876 (defun mouse-skip-word (dir)
877 "Skip over word, over whitespace, or over identical punctuation.
878 If DIR is positive skip forward; if negative, skip backward."
879 (let* ((char (following-char))
880 (syntax (char-to-string (char-syntax char
))))
881 (cond ((string= syntax
"w")
882 ;; Here, we can't use skip-syntax-forward/backward because
883 ;; they don't pay attention to word-separating-categories,
884 ;; and thus they will skip over a true word boundary. So,
885 ;; we simulate the original behavior by using forward-word.
887 (if (not (looking-at "\\<"))
889 (if (or (looking-at "\\<") (not (looking-at "\\>")))
891 ((string= syntax
" ")
893 (skip-syntax-backward syntax
)
894 (skip-syntax-forward syntax
)))
895 ((string= syntax
"_")
897 (skip-syntax-backward "w_")
898 (skip-syntax-forward "w_")))
900 (while (and (not (bobp)) (= (preceding-char) char
))
903 (while (and (not (eobp)) (= (following-char) char
))
904 (forward-char 1))))))
906 (defun mouse-start-end (start end mode
)
907 "Return a list of region bounds based on START and END according to MODE.
908 If MODE is 0 then set point to (min START END), mark to (max START END).
909 If MODE is 1 then set point to start of word at (min START END),
910 mark to end of word at (max START END).
911 If MODE is 2 then do the same for lines."
916 (setq mode
(mod mode
3))
922 (= (char-syntax (char-after start
)) ?\
())
931 (= (char-syntax (char-after start
)) ?\
)))
932 (list (save-excursion
933 (goto-char (1+ start
))
940 (= (char-syntax (char-after start
)) ?
\"))
941 (let ((open (or (eq start
(point-min))
943 (goto-char (- start
1))
944 (looking-at "\\s(\\|\\s \\|\\s>")))))
954 (list (save-excursion
957 (goto-char (1+ start
))
963 (list (save-excursion
972 (list (save-excursion
974 (line-beginning-position 1))
980 ;; Subroutine: set the mark where CLICK happened,
981 ;; but don't do anything else.
982 (defun mouse-set-mark-fast (click)
983 (mouse-minibuffer-check click
)
984 (let ((posn (event-start click
)))
985 (select-window (posn-window posn
))
986 (if (numberp (posn-point posn
))
987 (push-mark (posn-point posn
) t t
))))
989 (defun mouse-undouble-last-event (events)
990 (let* ((index (1- (length events
)))
991 (last (nthcdr index events
))
993 (basic (event-basic-type event
))
994 (old-modifiers (event-modifiers event
))
995 (modifiers (delq 'double
(delq 'triple
(copy-sequence old-modifiers
))))
998 ;; Use reverse, not nreverse, since event-modifiers
999 ;; does not copy the list it returns.
1000 (cons (event-convert-list (reverse (cons basic modifiers
)))
1004 (if (and (not (equal modifiers old-modifiers
))
1005 (key-binding (apply 'vector events
)))
1010 ;; Momentarily show where the mark is, if highlighting doesn't show it.
1012 (defun mouse-set-mark (click)
1013 "Set mark at the position clicked on with the mouse.
1014 Display cursor at that position for a second.
1015 This must be bound to a mouse click."
1017 (mouse-minibuffer-check click
)
1018 (select-window (posn-window (event-start click
)))
1019 ;; We don't use save-excursion because that preserves the mark too.
1020 (let ((point-save (point)))
1022 (progn (mouse-set-point click
)
1024 (or transient-mark-mode
1026 (goto-char point-save
))))
1028 (defun mouse-kill (click)
1029 "Kill the region between point and the mouse click.
1030 The text is saved in the kill ring, as with \\[kill-region]."
1032 (mouse-minibuffer-check click
)
1033 (let* ((posn (event-start click
))
1034 (click-posn (posn-point posn
)))
1035 (select-window (posn-window posn
))
1036 (if (numberp click-posn
)
1037 (kill-region (min (point) click-posn
)
1038 (max (point) click-posn
)))))
1040 (defun mouse-yank-at-click (click arg
)
1041 "Insert the last stretch of killed text at the position clicked on.
1042 Also move point to one end of the text thus inserted (normally the end),
1043 and set mark at the beginning.
1044 Prefix arguments are interpreted as with \\[yank].
1045 If `mouse-yank-at-point' is non-nil, insert at point
1046 regardless of where you click."
1047 (interactive "e\nP")
1048 ;; Give temporary modes such as isearch a chance to turn off.
1049 (run-hooks 'mouse-leave-buffer-hook
)
1050 (when select-active-regions
1051 ;; Without this, confusing things happen upon e.g. inserting into
1052 ;; the middle of an active region.
1054 (or mouse-yank-at-point
(mouse-set-point click
))
1055 (setq this-command
'yank
)
1056 (setq mouse-selection-click-count
0)
1059 (defun mouse-yank-primary (click)
1060 "Insert the primary selection at the position clicked on.
1061 Move point to the end of the inserted text, and set mark at
1062 beginning. If `mouse-yank-at-point' is non-nil, insert at point
1063 regardless of where you click."
1065 ;; Give temporary modes such as isearch a chance to turn off.
1066 (run-hooks 'mouse-leave-buffer-hook
)
1067 ;; Without this, confusing things happen upon e.g. inserting into
1068 ;; the middle of an active region.
1069 (when select-active-regions
1070 (let (select-active-regions)
1072 (or mouse-yank-at-point
(mouse-set-point click
))
1073 (let ((primary (gui-get-primary-selection)))
1075 (insert-for-yank primary
)))
1077 (defun mouse-kill-ring-save (click)
1078 "Copy the region between point and the mouse click in the kill ring.
1079 This does not delete the region; it acts like \\[kill-ring-save]."
1081 (mouse-set-mark-fast click
)
1082 (let (this-command last-command
)
1083 (kill-ring-save (point) (mark t
))))
1085 ;; This function used to delete the text between point and the mouse
1086 ;; whenever it was equal to the front of the kill ring, but some
1087 ;; people found that confusing.
1089 ;; The position of the last invocation of `mouse-save-then-kill'.
1090 (defvar mouse-save-then-kill-posn nil
)
1092 (defun mouse-save-then-kill-delete-region (beg end
)
1093 ;; We must make our own undo boundaries
1094 ;; because they happen automatically only for the current buffer.
1096 (if (or (= beg end
) (eq buffer-undo-list t
))
1097 ;; If we have no undo list in this buffer,
1099 (delete-region beg end
)
1100 ;; Delete, but make the undo-list entry share with the kill ring.
1101 ;; First, delete just one char, so in case buffer is being modified
1102 ;; for the first time, the undo list records that fact.
1103 (let (before-change-functions after-change-functions
)
1105 (+ beg
(if (> end beg
) 1 -
1))))
1106 (let ((buffer-undo-list buffer-undo-list
))
1107 ;; Undo that deletion--but don't change the undo list!
1108 (let (before-change-functions after-change-functions
)
1109 (primitive-undo 1 buffer-undo-list
))
1110 ;; Now delete the rest of the specified region,
1111 ;; but don't record it.
1112 (setq buffer-undo-list t
)
1113 (if (/= (length (car kill-ring
)) (- (max end beg
) (min end beg
)))
1114 (error "Lossage in mouse-save-then-kill-delete-region"))
1115 (delete-region beg end
))
1116 (let ((tail buffer-undo-list
))
1117 ;; Search back in buffer-undo-list for the string
1118 ;; that came from deleting one character.
1119 (while (and tail
(not (stringp (car (car tail
)))))
1120 (setq tail
(cdr tail
)))
1121 ;; Replace it with an entry for the entire deleted text.
1123 (setcar tail
(cons (car kill-ring
) (min beg end
))))))
1126 (defun mouse-save-then-kill (click)
1127 "Set the region according to CLICK; the second time, kill it.
1128 CLICK should be a mouse click event.
1130 If the region is inactive, activate it temporarily. Set mark at
1131 the original point, and move point to the position of CLICK.
1133 If the region is already active, adjust it. Normally, do this by
1134 moving point or mark, whichever is closer, to CLICK. But if you
1135 have selected whole words or lines, move point or mark to the
1136 word or line boundary closest to CLICK instead.
1138 If `mouse-drag-copy-region' is non-nil, this command also saves the
1139 new region to the kill ring (replacing the previous kill if the
1140 previous region was just saved to the kill ring).
1142 If this command is called a second consecutive time with the same
1143 CLICK position, kill the region (or delete it
1144 if `mouse-drag-copy-region' is non-nil)"
1146 (mouse-minibuffer-check click
)
1147 (let* ((posn (event-start click
))
1148 (click-pt (posn-point posn
))
1149 (window (posn-window posn
))
1150 (buf (window-buffer window
))
1151 ;; Don't let a subsequent kill command append to this one.
1152 (this-command this-command
)
1153 ;; Check if the user has multi-clicked to select words/lines.
1155 (if (and (eq mouse-selection-click-count-buffer buf
)
1156 (with-current-buffer buf
(mark t
)))
1157 mouse-selection-click-count
1160 ((not (numberp click-pt
)) nil
)
1161 ;; If the user clicked without moving point, kill the region.
1162 ;; This also resets `mouse-selection-click-count'.
1163 ((and (eq last-command
'mouse-save-then-kill
)
1164 (eq click-pt mouse-save-then-kill-posn
)
1165 (eq window
(selected-window)))
1166 (if mouse-drag-copy-region
1167 ;; Region already saved in the previous click;
1168 ;; don't make a duplicate entry, just delete.
1169 (delete-region (mark t
) (point))
1170 (kill-region (mark t
) (point)))
1171 (setq mouse-selection-click-count
0)
1172 (setq mouse-save-then-kill-posn nil
))
1174 ;; Otherwise, if there is a suitable region, adjust it by moving
1175 ;; one end (whichever is closer) to CLICK-PT.
1176 ((or (with-current-buffer buf
(region-active-p))
1177 (and (eq window
(selected-window))
1179 (or (and (eq last-command
'mouse-save-then-kill
)
1180 mouse-save-then-kill-posn
)
1181 (and (memq last-command
'(mouse-drag-region
1183 (or mark-even-if-inactive
1184 (not transient-mark-mode
))))))
1185 (select-window window
)
1186 (let* ((range (mouse-start-end click-pt click-pt click-count
)))
1187 (if (< (abs (- click-pt
(mark t
)))
1188 (abs (- click-pt
(point))))
1189 (set-mark (car range
))
1190 (goto-char (nth 1 range
)))
1191 (setq deactivate-mark nil
)
1192 (mouse-set-region-1)
1193 (when mouse-drag-copy-region
1194 ;; Region already copied to kill-ring once, so replace.
1195 (kill-new (filter-buffer-substring (mark t
) (point)) t
))
1196 ;; Arrange for a repeated mouse-3 to kill the region.
1197 (setq mouse-save-then-kill-posn click-pt
)))
1199 ;; Otherwise, set the mark where point is and move to CLICK-PT.
1201 (select-window window
)
1202 (mouse-set-mark-fast click
)
1203 (let ((before-scroll (with-current-buffer buf point-before-scroll
)))
1204 (if before-scroll
(goto-char before-scroll
)))
1205 (exchange-point-and-mark)
1206 (mouse-set-region-1)
1207 (when mouse-drag-copy-region
1208 (kill-new (filter-buffer-substring (mark t
) (point))))
1209 (setq mouse-save-then-kill-posn click-pt
)))))
1212 (global-set-key [M-mouse-1
] 'mouse-start-secondary
)
1213 (global-set-key [M-drag-mouse-1
] 'mouse-set-secondary
)
1214 (global-set-key [M-down-mouse-1
] 'mouse-drag-secondary
)
1215 (global-set-key [M-mouse-3
] 'mouse-secondary-save-then-kill
)
1216 (global-set-key [M-mouse-2
] 'mouse-yank-secondary
)
1218 (defconst mouse-secondary-overlay
1219 (let ((ol (make-overlay (point-min) (point-min))))
1221 (overlay-put ol
'face
'secondary-selection
)
1223 "An overlay which records the current secondary selection.
1224 It is deleted when there is no secondary selection.")
1226 (defvar mouse-secondary-click-count
0)
1228 ;; A marker which records the specified first end for a secondary selection.
1230 (defvar mouse-secondary-start nil
)
1232 (defun mouse-start-secondary (click)
1233 "Set one end of the secondary selection to the position clicked on.
1234 Use \\[mouse-secondary-save-then-kill] to set the other end
1235 and complete the secondary selection."
1237 (mouse-minibuffer-check click
)
1238 (let ((posn (event-start click
)))
1239 (with-current-buffer (window-buffer (posn-window posn
))
1240 ;; Cancel any preexisting secondary selection.
1241 (delete-overlay mouse-secondary-overlay
)
1242 (if (numberp (posn-point posn
))
1244 (or mouse-secondary-start
1245 (setq mouse-secondary-start
(make-marker)))
1246 (move-marker mouse-secondary-start
(posn-point posn
)))))))
1248 (defun mouse-set-secondary (click)
1249 "Set the secondary selection to the text that the mouse is dragged over.
1250 This must be bound to a mouse drag event."
1252 (mouse-minibuffer-check click
)
1253 (let ((posn (event-start click
))
1255 (end (event-end click
)))
1256 (with-current-buffer (window-buffer (posn-window posn
))
1257 (if (numberp (posn-point posn
))
1258 (setq beg
(posn-point posn
)))
1259 (move-overlay mouse-secondary-overlay beg
(posn-point end
))
1262 (buffer-substring (overlay-start mouse-secondary-overlay
)
1263 (overlay-end mouse-secondary-overlay
))))))
1265 (defun mouse-drag-secondary (start-event)
1266 "Set the secondary selection to the text that the mouse is dragged over.
1267 Highlight the drag area as you move the mouse.
1268 This must be bound to a button-down mouse event.
1269 The function returns a non-nil value if it creates a secondary selection."
1271 (mouse-minibuffer-check start-event
)
1272 (let* ((echo-keystrokes 0)
1273 (start-posn (event-start start-event
))
1274 (start-point (posn-point start-posn
))
1275 (start-window (posn-window start-posn
))
1276 (bounds (window-edges start-window
))
1277 (top (nth 1 bounds
))
1278 (bottom (if (window-minibuffer-p start-window
)
1280 ;; Don't count the mode line.
1281 (1- (nth 3 bounds
))))
1282 (click-count (1- (event-click-count start-event
))))
1283 (with-current-buffer (window-buffer start-window
)
1284 (setq mouse-secondary-click-count click-count
)
1285 (if (> (mod click-count
3) 0)
1286 ;; Double or triple press: make an initial selection
1287 ;; of one word or line.
1288 (let ((range (mouse-start-end start-point start-point click-count
)))
1289 (set-marker mouse-secondary-start nil
)
1290 (move-overlay mouse-secondary-overlay
(car range
) (nth 1 range
)
1291 (window-buffer start-window
)))
1292 ;; Single-press: cancel any preexisting secondary selection.
1293 (or mouse-secondary-start
1294 (setq mouse-secondary-start
(make-marker)))
1295 (set-marker mouse-secondary-start start-point
)
1296 (delete-overlay mouse-secondary-overlay
))
1297 ;; FIXME: Use mouse-drag-track!
1298 (let (event end end-point
)
1301 (setq event
(read-event))
1302 (or (mouse-movement-p event
)
1303 (memq (car-safe event
) '(switch-frame select-window
))))
1305 (if (memq (car-safe event
) '(switch-frame select-window
))
1307 (setq end
(event-end event
)
1308 end-point
(posn-point end
))
1310 ;; Are we moving within the original window?
1311 ((and (eq (posn-window end
) start-window
)
1312 (integer-or-marker-p end-point
))
1313 (let ((range (mouse-start-end start-point end-point
1315 (if (or (/= start-point end-point
)
1316 (null (marker-position mouse-secondary-start
)))
1318 (set-marker mouse-secondary-start nil
)
1319 (move-overlay mouse-secondary-overlay
1320 (car range
) (nth 1 range
))))))
1322 (let ((mouse-row (cdr (cdr (mouse-position)))))
1326 (mouse-scroll-subr start-window
(- mouse-row top
)
1327 mouse-secondary-overlay start-point
))
1328 ((>= mouse-row bottom
)
1329 (mouse-scroll-subr start-window
(1+ (- mouse-row bottom
))
1330 mouse-secondary-overlay start-point
)))))))))
1333 (if (marker-position mouse-secondary-start
)
1334 (save-window-excursion
1335 (delete-overlay mouse-secondary-overlay
)
1336 (gui-set-selection 'SECONDARY nil
)
1337 (select-window start-window
)
1339 (goto-char mouse-secondary-start
)
1344 (buffer-substring (overlay-start mouse-secondary-overlay
)
1345 (overlay-end mouse-secondary-overlay
)))))))))
1347 (defun mouse-yank-secondary (click)
1348 "Insert the secondary selection at the position clicked on.
1349 Move point to the end of the inserted text.
1350 If `mouse-yank-at-point' is non-nil, insert at point
1351 regardless of where you click."
1353 ;; Give temporary modes such as isearch a chance to turn off.
1354 (run-hooks 'mouse-leave-buffer-hook
)
1355 (or mouse-yank-at-point
(mouse-set-point click
))
1356 (let ((secondary (gui-get-selection 'SECONDARY
)))
1358 (insert-for-yank secondary
)
1359 (error "No secondary selection"))))
1361 (defun mouse-kill-secondary ()
1362 "Kill the text in the secondary selection.
1363 This is intended more as a keyboard command than as a mouse command
1364 but it can work as either one.
1366 The current buffer (in case of keyboard use), or the buffer clicked on,
1367 must be the one that the secondary selection is in. This requirement
1368 is to prevent accidents."
1370 (let* ((keys (this-command-keys))
1371 (click (elt keys
(1- (length keys
)))))
1372 (or (eq (overlay-buffer mouse-secondary-overlay
)
1374 (window-buffer (posn-window (event-start click
)))
1376 (error "Select or click on the buffer where the secondary selection is")))
1378 (with-current-buffer (overlay-buffer mouse-secondary-overlay
)
1379 (kill-region (overlay-start mouse-secondary-overlay
)
1380 (overlay-end mouse-secondary-overlay
))))
1381 (delete-overlay mouse-secondary-overlay
))
1383 (defun mouse-secondary-save-then-kill (click)
1384 "Set the secondary selection and save it to the kill ring.
1385 The second time, kill it. CLICK should be a mouse click event.
1387 If you have not called `mouse-start-secondary' in the clicked
1388 buffer, activate the secondary selection and set it between point
1389 and the click position CLICK.
1391 Otherwise, adjust the bounds of the secondary selection.
1392 Normally, do this by moving its beginning or end, whichever is
1393 closer, to CLICK. But if you have selected whole words or lines,
1394 adjust to the word or line boundary closest to CLICK instead.
1396 If this command is called a second consecutive time with the same
1397 CLICK position, kill the secondary selection."
1399 (mouse-minibuffer-check click
)
1400 (let* ((posn (event-start click
))
1401 (click-pt (posn-point posn
))
1402 (window (posn-window posn
))
1403 (buf (window-buffer window
))
1404 ;; Don't let a subsequent kill command append to this one.
1405 (this-command this-command
)
1406 ;; Check if the user has multi-clicked to select words/lines.
1408 (if (eq (overlay-buffer mouse-secondary-overlay
) buf
)
1409 mouse-secondary-click-count
1411 (beg (overlay-start mouse-secondary-overlay
))
1412 (end (overlay-end mouse-secondary-overlay
)))
1415 ((not (numberp click-pt
)) nil
)
1417 ;; If the secondary selection is not active in BUF, activate it.
1418 ((not (eq buf
(or (overlay-buffer mouse-secondary-overlay
)
1419 (if mouse-secondary-start
1420 (marker-buffer mouse-secondary-start
)))))
1421 (select-window window
)
1422 (setq mouse-secondary-start
(make-marker))
1423 (move-marker mouse-secondary-start
(point))
1424 (move-overlay mouse-secondary-overlay
(point) click-pt buf
)
1425 (kill-ring-save (point) click-pt
))
1427 ;; If the user clicked without moving point, delete the secondary
1428 ;; selection. This also resets `mouse-secondary-click-count'.
1429 ((and (eq last-command
'mouse-secondary-save-then-kill
)
1430 (eq click-pt mouse-save-then-kill-posn
)
1431 (eq window
(selected-window)))
1432 (mouse-save-then-kill-delete-region beg end
)
1433 (delete-overlay mouse-secondary-overlay
)
1434 (setq mouse-secondary-click-count
0)
1435 (setq mouse-save-then-kill-posn nil
))
1437 ;; Otherwise, if there is a suitable secondary selection overlay,
1438 ;; adjust it by moving one end (whichever is closer) to CLICK-PT.
1439 ((and beg
(eq buf
(overlay-buffer mouse-secondary-overlay
)))
1440 (let* ((range (mouse-start-end click-pt click-pt click-count
)))
1441 (if (< (abs (- click-pt beg
))
1442 (abs (- click-pt end
)))
1443 (move-overlay mouse-secondary-overlay
(car range
) end
)
1444 (move-overlay mouse-secondary-overlay beg
(nth 1 range
))))
1445 (setq deactivate-mark nil
)
1446 (if (eq last-command
'mouse-secondary-save-then-kill
)
1447 ;; If the front of the kill ring comes from an immediately
1448 ;; previous use of this command, replace the entry.
1450 (buffer-substring (overlay-start mouse-secondary-overlay
)
1451 (overlay-end mouse-secondary-overlay
))
1453 (let (deactivate-mark)
1454 (copy-region-as-kill (overlay-start mouse-secondary-overlay
)
1455 (overlay-end mouse-secondary-overlay
))))
1456 (setq mouse-save-then-kill-posn click-pt
))
1458 ;; Otherwise, set the secondary selection overlay.
1460 (select-window window
)
1461 (if mouse-secondary-start
1462 ;; All we have is one end of a selection, so put the other
1464 (let ((start (+ 0 mouse-secondary-start
)))
1465 (kill-ring-save start click-pt
)
1466 (move-overlay mouse-secondary-overlay start click-pt
)))
1467 (setq mouse-save-then-kill-posn click-pt
))))
1469 ;; Finally, set the window system's secondary selection.
1471 (and (overlay-buffer mouse-secondary-overlay
)
1472 (setq str
(buffer-substring (overlay-start mouse-secondary-overlay
)
1473 (overlay-end mouse-secondary-overlay
)))
1475 (gui-set-selection 'SECONDARY str
))))
1478 (defcustom mouse-buffer-menu-maxlen
20
1479 "Number of buffers in one pane (submenu) of the buffer menu.
1480 If we have lots of buffers, divide them into groups of
1481 `mouse-buffer-menu-maxlen' and make a pane (or submenu) for each one."
1485 (defcustom mouse-buffer-menu-mode-mult
4
1486 "Group the buffers by the major mode groups on \\[mouse-buffer-menu]?
1487 This number which determines (in a hairy way) whether \\[mouse-buffer-menu]
1488 will split the buffer menu by the major modes (see
1489 `mouse-buffer-menu-mode-groups') or just by menu length.
1490 Set to 1 (or even 0!) if you want to group by major mode always, and to
1491 a large number if you prefer a mixed multitude. The default is 4."
1496 (defvar mouse-buffer-menu-mode-groups
1497 (mapcar (lambda (arg) (cons (purecopy (car arg
)) (purecopy (cdr arg
))))
1498 '(("Info\\|Help\\|Apropos\\|Man" .
"Help")
1499 ("\\bVM\\b\\|\\bMH\\b\\|Message\\|Mail\\|Group\\|Score\\|Summary\\|Article"
1504 ("Outline" .
"Text")
1505 ("\\(HT\\|SG\\|X\\|XHT\\)ML" .
"SGML")
1506 ("log\\|diff\\|vc\\|cvs\\|Annotate" .
"Version Control") ; "Change Management"?
1507 ("Threads\\|Memory\\|Disassembly\\|Breakpoints\\|Frames\\|Locals\\|Registers\\|Inferior I/O\\|Debugger"
1510 "How to group various major modes together in \\[mouse-buffer-menu].
1511 Each element has the form (REGEXP . GROUPNAME).
1512 If the major mode's name string matches REGEXP, use GROUPNAME instead.")
1514 (defun mouse-buffer-menu (event)
1515 "Pop up a menu of buffers for selection with the mouse.
1516 This switches buffers in the window that you clicked on,
1517 and selects that window."
1519 (mouse-minibuffer-check event
)
1520 (let ((buf (x-popup-menu event
(mouse-buffer-menu-map)))
1521 (window (posn-window (event-start event
))))
1524 (if (framep window
) (frame-selected-window window
)
1526 (switch-to-buffer buf
))))
1528 (defun mouse-buffer-menu-map ()
1529 ;; Make an alist of elements that look like (MENU-ITEM . BUFFER).
1530 (let ((buffers (buffer-list)) split-by-major-mode sum-of-squares
)
1531 (dolist (buf buffers
)
1532 ;; Divide all buffers into buckets for various major modes.
1533 ;; Each bucket looks like (MODE NAMESTRING BUFFERS...).
1534 (with-current-buffer buf
1535 (let* ((adjusted-major-mode major-mode
) elt
)
1536 (dolist (group mouse-buffer-menu-mode-groups
)
1537 (when (string-match (car group
) (format-mode-line mode-name
))
1538 (setq adjusted-major-mode
(cdr group
))))
1539 (setq elt
(assoc adjusted-major-mode split-by-major-mode
))
1541 (setq elt
(list adjusted-major-mode
1542 (if (stringp adjusted-major-mode
)
1544 (format-mode-line mode-name nil nil buf
)))
1545 split-by-major-mode
(cons elt split-by-major-mode
)))
1546 (or (memq buf
(cdr (cdr elt
)))
1547 (setcdr (cdr elt
) (cons buf
(cdr (cdr elt
))))))))
1548 ;; Compute the sum of squares of sizes of the major-mode buckets.
1549 (let ((tail split-by-major-mode
))
1550 (setq sum-of-squares
0)
1552 (setq sum-of-squares
1554 (let ((len (length (cdr (cdr (car tail
)))))) (* len len
))))
1555 (setq tail
(cdr tail
))))
1556 (if (< (* sum-of-squares mouse-buffer-menu-mode-mult
)
1557 (* (length buffers
) (length buffers
)))
1558 ;; Subdividing by major modes really helps, so let's do it.
1559 (let (subdivided-menus (buffers-left (length buffers
)))
1560 ;; Sort the list to put the most popular major modes first.
1561 (setq split-by-major-mode
1562 (sort split-by-major-mode
1563 (function (lambda (elt1 elt2
)
1564 (> (length elt1
) (length elt2
))))))
1565 ;; Make a separate submenu for each major mode
1566 ;; that has more than one buffer,
1567 ;; unless all the remaining buffers are less than 1/10 of them.
1568 (while (and split-by-major-mode
1569 (and (> (length (car split-by-major-mode
)) 3)
1570 (> (* buffers-left
10) (length buffers
))))
1571 (let ((this-mode-list (mouse-buffer-menu-alist
1572 (cdr (cdr (car split-by-major-mode
))))))
1574 (setq subdivided-menus
1576 (nth 1 (car split-by-major-mode
))
1578 subdivided-menus
))))
1580 (- buffers-left
(length (cdr (car split-by-major-mode
)))))
1581 (setq split-by-major-mode
(cdr split-by-major-mode
)))
1582 ;; If any major modes are left over,
1583 ;; make a single submenu for them.
1584 (if split-by-major-mode
1586 (mouse-buffer-menu-alist
1587 ;; we don't need split-by-major-mode any more,
1588 ;; so we can ditch it with nconc.
1589 (apply 'nconc
(mapcar 'cddr split-by-major-mode
)))))
1591 (setq subdivided-menus
1592 (cons (cons "Others" others-list
)
1593 subdivided-menus
)))))
1594 (cons "Buffer Menu" (nreverse subdivided-menus
)))
1596 (mouse-buffer-menu-split "Select Buffer"
1597 (mouse-buffer-menu-alist buffers
))))))
1599 (defun mouse-buffer-menu-alist (buffers)
1605 (function (lambda (elt1 elt2
)
1606 (string< (buffer-name elt1
) (buffer-name elt2
))))))
1609 (or (eq ?\s
(aref (buffer-name (car tail
)) 0))
1612 (length (buffer-name (car tail
))))))
1613 (setq tail
(cdr tail
)))
1616 (let ((elt (car tail
)))
1617 (if (/= (aref (buffer-name elt
) 0) ?\s
)
1622 (format "%%-%ds %%s%%s %%s" maxlen
)
1624 (if (buffer-modified-p elt
) "*" " ")
1625 (with-current-buffer elt
1626 (if buffer-read-only
"%" " "))
1627 (or (buffer-file-name elt
)
1628 (with-current-buffer elt
1629 (if list-buffers-directory
1631 list-buffers-directory
)))
1635 (setq tail
(cdr tail
)))
1636 ;; Compensate for the reversal that the above loop does.
1639 (defun mouse-buffer-menu-split (title alist
)
1640 ;; If we have lots of buffers, divide them into groups of 20
1641 ;; and make a pane (or submenu) for each one.
1642 (if (> (length alist
) (/ (* mouse-buffer-menu-maxlen
3) 2))
1643 (let ((alist alist
) sublists next
1646 ;; Pull off the next mouse-buffer-menu-maxlen buffers
1647 ;; and make them the next element of sublist.
1648 (setq next
(nthcdr mouse-buffer-menu-maxlen alist
))
1650 (setcdr (nthcdr (1- mouse-buffer-menu-maxlen
) alist
)
1652 (setq sublists
(cons (cons (format "Buffers %d" i
) alist
)
1656 (nreverse sublists
))
1657 ;; Few buffers--put them all in one pane.
1658 (list (cons title alist
))))
1660 (define-obsolete-function-alias
1661 'mouse-choose-completion
'choose-completion
"23.2")
1665 (defun font-menu-add-default ()
1666 (let* ((default (cdr (assq 'font
(frame-parameters (selected-frame)))))
1667 (font-alist x-fixed-font-alist
)
1668 (elt (or (assoc "Misc" font-alist
) (nth 1 font-alist
))))
1669 (if (assoc "Default" elt
)
1670 (delete (assoc "Default" elt
) elt
))
1672 (cons (list "Default" default
)
1675 (defvar x-fixed-font-alist
1677 (purecopy "Font Menu")
1681 (lambda (arg) (cons (purecopy (car arg
)) (purecopy (cdr arg
))))
1682 ;; For these, we specify the pixel height and width.
1684 ("6x10" "-misc-fixed-medium-r-normal--10-*-*-*-c-60-iso8859-1" "6x10")
1686 "-misc-fixed-medium-r-semicondensed--12-*-*-*-c-60-iso8859-1" "6x12")
1688 "-misc-fixed-medium-r-semicondensed--13-*-*-*-c-60-iso8859-1" "6x13")
1689 ("7x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-70-iso8859-1" "7x13")
1690 ("7x14" "-misc-fixed-medium-r-normal--14-*-*-*-c-70-iso8859-1" "7x14")
1691 ("8x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-80-iso8859-1" "8x13")
1692 ("9x15" "-misc-fixed-medium-r-normal--15-*-*-*-c-90-iso8859-1" "9x15")
1693 ("10x20" "-misc-fixed-medium-r-normal--20-*-*-*-c-100-iso8859-1" "10x20")
1694 ("11x18" "-misc-fixed-medium-r-normal--18-*-*-*-c-110-iso8859-1" "11x18")
1695 ("12x24" "-misc-fixed-medium-r-normal--24-*-*-*-c-120-iso8859-1" "12x24")
1698 "-schumacher-clean-medium-r-normal--8-*-*-*-c-50-iso8859-1")
1700 "-schumacher-clean-medium-r-normal--8-*-*-*-c-60-iso8859-1")
1702 "-schumacher-clean-medium-r-normal--8-*-*-*-c-80-iso8859-1")
1704 "-schumacher-clean-medium-r-normal--10-*-*-*-c-80-iso8859-1")
1706 "-schumacher-clean-medium-r-normal--14-*-*-*-c-80-iso8859-1")
1708 "-schumacher-clean-medium-r-normal--16-*-*-*-c-80-iso8859-1")
1710 ("sony 8x16" "-sony-fixed-medium-r-normal--16-*-*-*-c-80-iso8859-1")
1711 ;; We don't seem to have these; who knows what they are.
1712 ;; ("fg-18" "fg-18")
1713 ;; ("fg-25" "fg-25")
1714 ("lucidasanstypewriter-12" "-b&h-lucidatypewriter-medium-r-normal-sans-*-120-*-*-*-*-iso8859-1")
1715 ("lucidasanstypewriter-bold-14" "-b&h-lucidatypewriter-bold-r-normal-sans-*-140-*-*-*-*-iso8859-1")
1716 ("lucidasanstypewriter-bold-24"
1717 "-b&h-lucidatypewriter-bold-r-normal-sans-*-240-*-*-*-*-iso8859-1")
1718 ;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
1719 ;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
1723 (purecopy "Courier")
1725 (lambda (arg) (cons (purecopy (car arg
)) (purecopy (cdr arg
))))
1726 ;; For these, we specify the point height.
1727 '(("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1")
1728 ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1")
1729 ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1")
1730 ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1")
1731 ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1")
1732 ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1")
1733 ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1")
1734 ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1")
1735 ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1")
1736 ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1")
1737 ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1")
1738 ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1")
1739 ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1")
1740 ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1")
1741 ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1")
1742 ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1")
1743 ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1")
1744 ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1")
1745 ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1")
1746 ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1")
1747 ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1")
1748 ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1")
1749 ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1")
1750 ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1")
1752 "X fonts suitable for use in Emacs.")
1754 (declare-function generate-fontset-menu
"fontset" ())
1756 (defun mouse-select-font ()
1757 "Prompt for a font name, using `x-popup-menu', and return it."
1759 (unless (display-multi-font-p)
1760 (error "Cannot change fonts on this display"))
1763 (if (listp last-nonmenu-event
)
1765 (list '(0 0) (selected-window)))
1766 (append x-fixed-font-alist
1767 (list (generate-fontset-menu))))))
1769 (declare-function text-scale-mode
"face-remap")
1771 (defun mouse-set-font (&rest fonts
)
1772 "Set the default font for the selected frame.
1773 The argument FONTS is a list of font names; the first valid font
1774 in this list is used.
1776 When called interactively, pop up a menu and allow the user to
1779 (progn (unless (display-multi-font-p)
1780 (error "Cannot change fonts on this display"))
1782 (if (listp last-nonmenu-event
)
1784 (list '(0 0) (selected-window)))
1785 ;; Append list of fontsets currently defined.
1786 (append x-fixed-font-alist
(list (generate-fontset-menu))))))
1792 (set-frame-font (car fonts
))
1793 (setq font
(car fonts
))
1796 (setq fonts
(cdr fonts
)))))
1798 (error "Font not found")))))
1800 (defvar mouse-appearance-menu-map nil
)
1801 (declare-function x-select-font
"xfns.c" (&optional frame ignored
)) ; USE_GTK
1802 (declare-function buffer-face-mode-invoke
"face-remap"
1803 (face arg
&optional interactive
))
1804 (declare-function font-face-attributes
"font.c" (font &optional frame
))
1805 (defvar w32-use-w32-font-dialog
)
1806 (defvar w32-fixed-font-alist
)
1808 (defun mouse-appearance-menu (event)
1809 "Show a menu for changing the default face in the current buffer."
1811 (require 'face-remap
)
1812 (when (display-multi-font-p)
1813 (with-selected-window (car (event-start event
))
1814 (if mouse-appearance-menu-map
1815 nil
; regenerate new fonts
1816 ;; Initialize mouse-appearance-menu-map
1817 (setq mouse-appearance-menu-map
1818 (make-sparse-keymap "Change Default Buffer Face"))
1819 (define-key mouse-appearance-menu-map
[face-remap-reset-base
]
1820 '(menu-item "Reset to Default" face-remap-reset-base
))
1821 (define-key mouse-appearance-menu-map
[text-scale-decrease
]
1822 '(menu-item "Decrease Buffer Text Size" text-scale-decrease
))
1823 (define-key mouse-appearance-menu-map
[text-scale-increase
]
1824 '(menu-item "Increase Buffer Text Size" text-scale-increase
))
1826 (if (and (functionp 'x-select-font
)
1827 (or (not (boundp 'w32-use-w32-font-dialog
))
1828 w32-use-w32-font-dialog
))
1829 (define-key mouse-appearance-menu-map
[x-select-font
]
1830 '(menu-item "Change Buffer Font..." x-select-font
))
1831 ;; If the select-font is unavailable, construct a menu.
1832 (let ((font-submenu (make-sparse-keymap "Change Text Font"))
1833 (font-alist (cdr (append
1834 (if (eq system-type
'windows-nt
)
1835 w32-fixed-font-alist
1837 (list (generate-fontset-menu))))))
1838 (dolist (family font-alist
)
1839 (let* ((submenu-name (car family
))
1840 (submenu-map (make-sparse-keymap submenu-name
)))
1841 (dolist (font (cdr family
))
1842 (let ((font-name (car font
))
1844 (if (string= font-name
"")
1845 (define-key submenu-map
[space]
1847 (setq font-symbol (intern (cadr font)))
1848 (define-key submenu-map (vector font-symbol)
1849 (list 'menu-item (car font) font-symbol)))))
1850 (define-key font-submenu (vector (intern submenu-name))
1851 (list 'menu-item submenu-name submenu-map))))
1852 (define-key mouse-appearance-menu-map [font-submenu]
1853 (list 'menu-item "Change Text Font" font-submenu)))))
1854 (let ((choice (x-popup-menu event mouse-appearance-menu-map)))
1855 (setq choice (nth (1- (length choice)) choice))
1856 (cond ((eq choice 'text-scale-increase)
1857 (text-scale-increase 1))
1858 ((eq choice 'text-scale-decrease)
1859 (text-scale-increase -1))
1860 ((eq choice 'face-remap-reset-base)
1862 (buffer-face-mode 0))
1864 ;; Either choice == 'x-select-font, or choice is a
1865 ;; symbol whose name is a font.
1866 (let ((font (if (eq choice 'x-select-font)
1868 (symbol-name choice))))
1869 (buffer-face-mode-invoke
1870 (if (fontp font 'font-spec)
1872 (font-face-attributes font))
1873 t (called-interactively-p 'interactive)))))))))
1876 ;;; Bindings for mouse commands.
1878 (global-set-key [down-mouse-1] 'mouse-drag-region)
1879 (global-set-key [mouse-1] 'mouse-set-point)
1880 (global-set-key [drag-mouse-1] 'mouse-set-region)
1882 (defun mouse--strip-first-event (_prompt)
1883 (substring (this-single-command-raw-keys) 1))
1885 (define-key function-key-map [left-fringe mouse-1] 'mouse--strip-first-event)
1886 (define-key function-key-map [right-fringe mouse-1] 'mouse--strip-first-event)
1888 (global-set-key [mouse-2] 'mouse-yank-primary)
1889 ;; Allow yanking also when the corresponding cursor is "in the fringe".
1890 (define-key function-key-map [right-fringe mouse-2] 'mouse--strip-first-event)
1891 (define-key function-key-map [left-fringe mouse-2] 'mouse--strip-first-event)
1892 (global-set-key [mouse-3] 'mouse-save-then-kill)
1893 (define-key function-key-map [right-fringe mouse-3] 'mouse--strip-first-event)
1894 (define-key function-key-map [left-fringe mouse-3] 'mouse--strip-first-event)
1896 ;; By binding these to down-going events, we let the user use the up-going
1897 ;; event to make the selection, saving a click.
1898 (global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
1899 (if (not (eq system-type 'ms-dos))
1900 (global-set-key [S-down-mouse-1] 'mouse-appearance-menu))
1901 ;; C-down-mouse-2 is bound in facemenu.el.
1902 (global-set-key [C-down-mouse-3]
1903 `(menu-item ,(purecopy "Menu Bar") ignore
1905 (if (zerop (or (frame-parameter nil 'menu-bar-lines) 0))
1906 (mouse-menu-bar-map)
1907 (mouse-menu-major-mode-map)))))
1909 ;; Binding mouse-1 to mouse-select-window when on mode-, header-, or
1910 ;; vertical-line prevents Emacs from signaling an error when the mouse
1911 ;; button is released after dragging these lines, on non-toolkit
1913 (global-set-key [mode-line mouse-1] 'mouse-select-window)
1914 (global-set-key [mode-line drag-mouse-1] 'mouse-select-window)
1915 (global-set-key [mode-line down-mouse-1] 'mouse-drag-mode-line)
1916 (global-set-key [header-line down-mouse-1] 'mouse-drag-header-line)
1917 (global-set-key [header-line mouse-1] 'mouse-select-window)
1918 (global-set-key [mode-line mouse-2] 'mouse-delete-other-windows)
1919 (global-set-key [mode-line mouse-3] 'mouse-delete-window)
1920 (global-set-key [mode-line C-mouse-2] 'mouse-split-window-horizontally)
1921 (global-set-key [vertical-scroll-bar C-mouse-2] 'mouse-split-window-vertically)
1922 (global-set-key [vertical-line C-mouse-2] 'mouse-split-window-vertically)
1923 (global-set-key [vertical-line down-mouse-1] 'mouse-drag-vertical-line)
1924 (global-set-key [right-divider down-mouse-1] 'mouse-drag-vertical-line)
1925 (global-set-key [bottom-divider down-mouse-1] 'mouse-drag-mode-line)
1926 (global-set-key [vertical-line mouse-1] 'mouse-select-window)
1930 ;;; mouse.el ends here