1 ;;; mouse.el --- window system-independent mouse support -*- lexical-binding: t -*-
3 ;; Copyright (C) 1993-1995, 1999-2014 Free Software Foundation, Inc.
5 ;; Maintainer: emacs-devel@gnu.org
6 ;; Keywords: hardware, mouse
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; This package provides various useful commands (including help
27 ;; system access) through the mouse. All this code assumes that mouse
28 ;; interpretation has been abstracted into Emacs input events.
30 ;; The code is rather X-dependent.
34 ;;; Utility functions.
36 ;; Indent track-mouse like progn.
37 (put 'track-mouse
'lisp-indent-function
0)
39 (defcustom mouse-yank-at-point nil
40 "If non-nil, mouse yank commands yank at point instead of at click."
44 (defcustom mouse-drag-copy-region nil
45 "If non-nil, copy to kill-ring upon mouse adjustments of the region.
47 This affects `mouse-save-then-kill' (\\[mouse-save-then-kill]) in
48 addition to mouse drags."
53 (defcustom mouse-1-click-follows-link
450
54 "Non-nil means that clicking Mouse-1 on a link follows the link.
56 With the default setting, an ordinary Mouse-1 click on a link
57 performs the same action as Mouse-2 on that link, while a longer
58 Mouse-1 click \(hold down the Mouse-1 button for more than 450
59 milliseconds) performs the original Mouse-1 binding \(which
60 typically sets point where you click the mouse).
62 If value is an integer, the time elapsed between pressing and
63 releasing the mouse button determines whether to follow the link
64 or perform the normal Mouse-1 action (typically set point).
65 The absolute numeric value specifies the maximum duration of a
66 \"short click\" in milliseconds. A positive value means that a
67 short click follows the link, and a longer click performs the
68 normal action. A negative value gives the opposite behavior.
70 If value is `double', a double click follows the link.
72 Otherwise, a single Mouse-1 click unconditionally follows the link.
74 Note that dragging the mouse never follows the link.
76 This feature only works in modes that specifically identify
77 clickable text as links, so it may not work with some external
78 packages. See `mouse-on-link-p' for details."
80 :type
'(choice (const :tag
"Disabled" nil
)
81 (const :tag
"Double click" double
)
82 (number :tag
"Single click time limit" :value
450)
83 (other :tag
"Single click" t
))
86 (defcustom mouse-1-click-in-non-selected-windows t
87 "If non-nil, a Mouse-1 click also follows links in non-selected windows.
89 If nil, a Mouse-1 click on a link in a non-selected window performs
90 the normal mouse-1 binding, typically selects the window and sets
91 point at the click position."
96 (defun mouse--down-1-maybe-follows-link (&optional _prompt
)
97 "Turn `mouse-1' events into `mouse-2' events if follows-link.
98 Expects to be bound to `down-mouse-1' in `key-translation-map'."
99 (if (or (null mouse-1-click-follows-link
)
100 (not (eq (if (eq mouse-1-click-follows-link
'double
)
101 'double-down-mouse-1
'down-mouse-1
)
102 (car-safe last-input-event
)))
103 (not (mouse-on-link-p (event-start last-input-event
)))
104 (and (not mouse-1-click-in-non-selected-windows
)
105 (not (eq (selected-window)
106 (posn-window (event-start last-input-event
))))))
108 (let ((this-event last-input-event
)
110 (sit-for (if (numberp mouse-1-click-follows-link
)
111 (/ (abs mouse-1-click-follows-link
) 1000.0)
113 (if (if (and (numberp mouse-1-click-follows-link
)
114 (>= mouse-1-click-follows-link
0))
115 timedout
(not timedout
))
118 (let ((event (read-event)))
119 (if (eq (car-safe event
) (if (eq mouse-1-click-follows-link
'double
)
120 'double-mouse-1
'mouse-1
))
121 ;; Turn the mouse-1 into a mouse-2 to follow links.
122 (let ((newup (if (eq mouse-1-click-follows-link
'double
)
123 'double-mouse-2
'mouse-2
))
124 (newdown (if (eq mouse-1-click-follows-link
'double
)
125 'double-down-mouse-2
'down-mouse-2
)))
126 ;; If mouse-2 has never been done by the user, it doesn't have
127 ;; the necessary property to be interpreted correctly.
128 (put newup
'event-kind
(get (car event
) 'event-kind
))
129 (put newdown
'event-kind
(get (car this-event
) 'event-kind
))
130 (push (cons newup
(cdr event
)) unread-command-events
)
131 ;; Modify the event in place, so read-key-sequence doesn't
132 ;; generate a second fake prefix key (see fake_prefixed_keys in
134 (setcar this-event newdown
)
136 (push event unread-command-events
)
139 (define-key key-translation-map
[down-mouse-1
]
140 #'mouse--down-1-maybe-follows-link
)
141 (define-key key-translation-map
[double-down-mouse-1
]
142 #'mouse--down-1-maybe-follows-link
)
145 ;; Provide a mode-specific menu on a mouse button.
147 (defun minor-mode-menu-from-indicator (indicator)
148 "Show menu for minor mode specified by INDICATOR.
149 Interactively, INDICATOR is read using completion.
150 If there is no menu defined for the minor mode, then create one with
151 items `Turn Off' and `Help'."
153 (list (completing-read
154 "Minor mode indicator: "
155 (describe-minor-mode-completion-table-for-indicator))))
156 (let* ((minor-mode (lookup-minor-mode-from-indicator indicator
))
157 (mm-fun (or (get minor-mode
:minor-mode-function
) minor-mode
)))
158 (unless minor-mode
(error "Cannot find minor mode for `%s'" indicator
))
159 (let* ((map (cdr-safe (assq minor-mode minor-mode-map-alist
)))
160 (menu (and (keymapp map
) (lookup-key map
[menu-bar
]))))
163 (mouse-menu-non-singleton menu
)
166 (turn-off menu-item
"Turn Off minor mode" ,mm-fun
)
167 (help menu-item
"Help for minor mode"
168 (lambda () (interactive)
169 (describe-function ',mm-fun
))))))
172 (defun mouse-minor-mode-menu (event)
173 "Show minor-mode menu for EVENT on minor modes area of the mode line."
175 (let ((indicator (car (nth 4 (car (cdr event
))))))
176 (minor-mode-menu-from-indicator indicator
)))
178 (defun mouse-menu-major-mode-map ()
179 (run-hooks 'activate-menubar-hook
'menu-bar-update-hook
)
180 (let* (;; Keymap from which to inherit; may be null.
181 (ancestor (mouse-menu-non-singleton
182 (and (current-local-map)
183 (local-key-binding [menu-bar
]))))
184 ;; Make a keymap in which our last command leads to a menu or
185 ;; default to the edit menu.
187 (make-sparse-keymap (concat (format-mode-line mode-name
)
189 menu-bar-edit-menu
)))
191 (set-keymap-parent newmap ancestor
))
194 (defun mouse-menu-non-singleton (menubar)
195 "Return menu keybar MENUBAR, or a lone submenu inside it.
196 If MENUBAR defines exactly one submenu, return just that submenu.
197 Otherwise, return MENUBAR."
201 (lambda (k v
) (setq submap
(if submap t
(cons k v
))))
202 (keymap-canonicalize menubar
))
205 (lookup-key menubar
(vector (car submap
)))))))
207 (defun mouse-menu-bar-map ()
208 "Return a keymap equivalent to the menu bar.
209 The contents are the items that would be in the menu bar whether or
210 not it is actually displayed."
211 (run-hooks 'activate-menubar-hook
'menu-bar-update-hook
)
212 (let* ((local-menu (and (current-local-map)
213 (lookup-key (current-local-map) [menu-bar
])))
214 (global-menu (lookup-key global-map
[menu-bar
]))
215 ;; If a keymap doesn't have a prompt string (a lazy
216 ;; programmer didn't bother to provide one), create it and
217 ;; insert it into the keymap; each keymap gets its own
218 ;; prompt. This is required for non-toolkit versions to
219 ;; display non-empty menu pane names.
223 (let* ((minor-mode (car menu
))
225 (title-or-map (cadr menu
)))
226 (or (stringp title-or-map
)
230 (capitalize (subst-char-in-string
236 (minor-mode-key-binding [menu-bar
])))
237 (local-title-or-map (and local-menu
(cadr local-menu
)))
238 (global-title-or-map (cadr global-menu
)))
239 (or (null local-menu
)
240 (stringp local-title-or-map
)
241 (setq local-menu
(cons 'keymap
242 (cons (concat (format-mode-line mode-name
)
245 (or (stringp global-title-or-map
)
246 (setq global-menu
(cons 'keymap
248 (cdr global-menu
)))))
249 ;; Supplying the list is faster than making a new map.
250 ;; FIXME: We have a problem here: we have to use the global/local/minor
251 ;; so they're displayed in the expected order, but later on in the command
252 ;; loop, they're actually looked up in the opposite order.
258 (defun mouse-major-mode-menu (event &optional prefix
)
259 "Pop up a mode-specific menu of mouse commands.
260 Default to the Edit menu if the major mode doesn't define a menu."
261 (declare (obsolete mouse-menu-major-mode-map
"23.1"))
262 (interactive "@e\nP")
263 (run-hooks 'activate-menubar-hook
'menu-bar-update-hook
)
264 (popup-menu (mouse-menu-major-mode-map) event prefix
))
266 (defun mouse-popup-menubar (event prefix
)
267 "Pop up a menu equivalent to the menu bar for keyboard EVENT with PREFIX.
268 The contents are the items that would be in the menu bar whether or
269 not it is actually displayed."
270 (declare (obsolete mouse-menu-bar-map
"23.1"))
271 (interactive "@e \nP")
272 (run-hooks 'activate-menubar-hook
'menu-bar-update-hook
)
273 (popup-menu (mouse-menu-bar-map) (unless (integerp event
) event
) prefix
))
275 (defun mouse-popup-menubar-stuff (event prefix
)
276 "Popup a menu like either `mouse-major-mode-menu' or `mouse-popup-menubar'.
277 Use the former if the menu bar is showing, otherwise the latter."
278 (declare (obsolete nil
"23.1"))
279 (interactive "@e\nP")
280 (run-hooks 'activate-menubar-hook
'menu-bar-update-hook
)
282 (if (zerop (or (frame-parameter nil
'menu-bar-lines
) 0))
284 (mouse-menu-major-mode-map))
287 ;; Commands that operate on windows.
289 (defun mouse-minibuffer-check (event)
290 (let ((w (posn-window (event-start event
))))
291 (and (window-minibuffer-p w
)
292 (not (minibuffer-window-active-p w
))
293 (user-error "Minibuffer window is not active")))
294 ;; Give temporary modes such as isearch a chance to turn off.
295 (run-hooks 'mouse-leave-buffer-hook
))
297 (defun mouse-delete-window (click)
298 "Delete the window you click on.
299 Do nothing if the frame has just one window.
300 This command must be bound to a mouse click."
302 (unless (one-window-p t
)
303 (mouse-minibuffer-check click
)
304 (delete-window (posn-window (event-start click
)))))
306 (defun mouse-select-window (click)
307 "Select the window clicked on; don't move point."
309 (mouse-minibuffer-check click
)
310 (let ((oframe (selected-frame))
311 (frame (window-frame (posn-window (event-start click
)))))
312 (select-window (posn-window (event-start click
)))
315 (or (eq frame oframe
)
316 (set-mouse-position (selected-frame) (1- (frame-width)) 0))))
318 (defun mouse-tear-off-window (click)
319 "Delete the window clicked on, and create a new frame displaying its buffer."
321 (mouse-minibuffer-check click
)
322 (let* ((window (posn-window (event-start click
)))
323 (buf (window-buffer window
))
324 (frame (make-frame)))
326 (switch-to-buffer buf
)
327 (delete-window window
)))
329 (defun mouse-delete-other-windows ()
330 "Delete all windows except the one you click on."
332 (delete-other-windows))
334 (defun mouse-split-window-vertically (click)
335 "Select Emacs window mouse is on, then split it vertically in half.
336 The window is split at the line clicked on.
337 This command must be bound to a mouse click."
339 (mouse-minibuffer-check click
)
340 (let ((start (event-start click
)))
341 (select-window (posn-window start
))
342 (let ((new-height (1+ (cdr (posn-col-row (event-end click
)))))
343 (first-line window-min-height
)
344 (last-line (- (window-height) window-min-height
)))
345 (if (< last-line first-line
)
346 (error "Window too short to split")
347 (split-window-vertically
348 (min (max new-height first-line
) last-line
))))))
350 (defun mouse-split-window-horizontally (click)
351 "Select Emacs window mouse is on, then split it horizontally in half.
352 The window is split at the column clicked on.
353 This command must be bound to a mouse click."
355 (mouse-minibuffer-check click
)
356 (let ((start (event-start click
)))
357 (select-window (posn-window start
))
358 (let ((new-width (1+ (car (posn-col-row (event-end click
)))))
359 (first-col window-min-width
)
360 (last-col (- (window-width) window-min-width
)))
361 (if (< last-col first-col
)
362 (error "Window too narrow to split")
363 (split-window-horizontally
364 (min (max new-width first-col
) last-col
))))))
366 ;; `mouse-drag-line' is now the common routine for handling all line
367 ;; dragging events combining the earlier `mouse-drag-mode-line-1' and
368 ;; `mouse-drag-vertical-line'. It should improve the behavior of line
369 ;; dragging wrt Emacs 23 as follows:
371 ;; (1) Gratuitous error messages and restrictions have been (hopefully)
372 ;; removed. (The help-echo that dragging the mode-line can resize a
373 ;; one-window-frame's window will still show through via bindings.el.)
375 ;; (2) No gratuitous selection of other windows should happen. (This
376 ;; has not been completely fixed for mouse-autoselected windows yet.)
378 ;; (3) Mouse clicks below a scroll-bar should pass through via unread
381 ;; Note that `window-in-direction' replaces `mouse-drag-window-above'
382 ;; and `mouse-drag-vertical-line-rightward-window' with Emacs 24.1.
384 (defun mouse-drag-line (start-event line
)
385 "Drag a mode line, header line, or vertical line with the mouse.
386 START-EVENT is the starting mouse-event of the drag action. LINE
387 must be one of the symbols `header', `mode', or `vertical'."
388 ;; Give temporary modes such as isearch a chance to turn off.
389 (run-hooks 'mouse-leave-buffer-hook
)
390 (let* ((echo-keystrokes 0)
391 (start (event-start start-event
))
392 (window (posn-window start
))
393 (frame (window-frame window
))
394 (minibuffer-window (minibuffer-window frame
))
395 (on-link (and mouse-1-click-follows-link
396 (mouse-on-link-p start
)))
397 (side (and (eq line
'vertical
)
398 (or (cdr (assq 'vertical-scroll-bars
399 (frame-parameters frame
)))
402 height finished event position growth dragged
)
405 ;; Check whether header-line can be dragged at all.
406 (if (window-at-side-p window
'top
)
408 (setq height
(/ (window-header-line-height window
) 2))
409 (setq window
(window-in-direction 'above window t
))))
411 ;; Check whether mode-line can be dragged at all.
412 (if (and (window-at-side-p window
'bottom
)
413 ;; Allow resizing the minibuffer window if it's on the same
414 ;; frame as and immediately below the clicked window, and
415 ;; it's active or `resize-mini-windows' is nil.
416 (not (and (eq (window-frame minibuffer-window
) frame
)
417 (= (nth 1 (window-pixel-edges minibuffer-window
))
418 (nth 3 (window-pixel-edges window
)))
419 (or (not resize-mini-windows
)
420 (eq minibuffer-window
421 (active-minibuffer-window))))))
423 (setq height
(/ (window-mode-line-height window
) 2))))
425 ;; Get the window to adjust for the vertical case. If the scroll
426 ;; bar is on the window's right or we drag a vertical divider,
427 ;; adjust the window where the start-event occurred. If the
428 ;; scroll bar is on the start-event window's left or there are no
429 ;; scrollbars, adjust the window on the left of it.
430 (unless (or (eq side
'right
)
431 (not (zerop (window-right-divider-width window
))))
432 (setq window
(window-in-direction 'left window t
)))))
436 ;; Loop reading events and sampling the position of the mouse.
437 (while (not finished
)
438 (setq event
(read-event))
439 (setq position
(mouse-pixel-position))
441 ;; - there is a switch-frame event.
442 ;; - the mouse isn't in the frame that we started in
443 ;; - the mouse isn't in any Emacs frame
445 ;; - there is a mouse-movement event
446 ;; - there is a scroll-bar-movement event (Why? -- cyd)
447 ;; (same as mouse movement for our purposes)
449 ;; - there is a keyboard event or some other unknown event.
453 ((memq (car event
) '(switch-frame select-window
))
455 ((not (memq (car event
) '(mouse-movement scroll-bar-movement
)))
457 ;; Do not unread a drag-mouse-1 event to avoid selecting
458 ;; some other window. For vertical line dragging do not
459 ;; unread mouse-1 events either (but only if we dragged at
460 ;; least once to allow mouse-1 clicks get through).
462 (if (eq line
'vertical
)
463 (memq (car event
) '(drag-mouse-1 mouse-1
))
464 (eq (car event
) 'drag-mouse-1
)))
465 (push event unread-command-events
)))
467 ((not (and (eq (car position
) frame
)
471 ;; Drag vertical divider. This must be probably fixed like
472 ;; for the mode-line.
473 (setq growth
(- (cadr position
)
474 (if (eq side
'right
) 0 2)
475 (nth 2 (window-pixel-edges window
))
477 (unless (zerop growth
)
479 (adjust-window-trailing-edge window growth t t
)))
481 ;; Drag horizontal divider.
484 (- (+ (cddr position
) height
)
485 (nth 3 (window-pixel-edges window
)))
486 ;; The window's top includes the header line!
487 (- (+ (nth 3 (window-pixel-edges window
)) height
)
489 (unless (zerop growth
)
491 (adjust-window-trailing-edge
492 window
(if (eq line
'mode
) growth
(- growth
)) nil t
))))))
493 ;; Process the terminating event.
494 (when (and (mouse-event-p event
) on-link
(not dragged
)
495 (mouse--remap-link-click-p start-event event
))
496 ;; If mouse-2 has never been done by the user, it doesn't have
497 ;; the necessary property to be interpreted correctly.
498 (put 'mouse-2
'event-kind
'mouse-click
)
499 (setcar event
'mouse-2
)
500 (push event unread-command-events
))))
502 (defun mouse-drag-mode-line (start-event)
503 "Change the height of a window by dragging on the mode line."
505 (mouse-drag-line start-event
'mode
))
507 (defun mouse-drag-header-line (start-event)
508 "Change the height of a window by dragging on the header line."
510 (mouse-drag-line start-event
'header
))
512 (defun mouse-drag-vertical-line (start-event)
513 "Change the width of a window by dragging on the vertical line."
515 (mouse-drag-line start-event
'vertical
))
517 (defun mouse-set-point (event &optional promote-to-region
)
518 "Move point to the position clicked on with the mouse.
519 This should be bound to a mouse click event type.
520 If PROMOTE-TO-REGION is non-nil and event is a multiple-click,
521 select the corresponding element around point."
523 (mouse-minibuffer-check event
)
524 (if (and promote-to-region
(> (event-click-count event
) 1))
525 (mouse-set-region event
)
526 ;; Use event-end in case called from mouse-drag-region.
527 ;; If EVENT is a click, event-end and event-start give same value.
528 (posn-set-point (event-end event
))))
530 (defvar mouse-last-region-beg nil
)
531 (defvar mouse-last-region-end nil
)
532 (defvar mouse-last-region-tick nil
)
534 (defun mouse-region-match ()
535 "Return non-nil if there's an active region that was set with the mouse."
536 (and (mark t
) mark-active
537 (eq mouse-last-region-beg
(region-beginning))
538 (eq mouse-last-region-end
(region-end))
539 (eq mouse-last-region-tick
(buffer-modified-tick))))
541 (defvar mouse--drag-start-event nil
)
543 (defun mouse-set-region (click)
544 "Set the region to the text dragged over, and copy to kill ring.
545 This should be bound to a mouse drag event.
546 See the `mouse-drag-copy-region' variable to control whether this
547 command alters the kill ring or not."
549 (mouse-minibuffer-check click
)
550 (select-window (posn-window (event-start click
)))
551 (let ((beg (posn-point (event-start click
)))
552 (end (posn-point (event-end click
)))
553 (click-count (event-click-count click
)))
554 (let ((drag-start (terminal-parameter nil
'mouse-drag-start
)))
555 ;; Drag events don't come with a click count, sadly, so we hack
556 ;; our way around this problem by remembering the start-event in
557 ;; `mouse-drag-start' and fetching the click-count from there.
559 (when (and (<= click-count
1)
560 (equal beg
(posn-point (event-start drag-start
))))
561 (setq click-count
(event-click-count drag-start
)))
562 (setf (terminal-parameter nil
'mouse-drag-start
) nil
)))
563 (when (and (integerp beg
) (integerp end
))
564 (let ((range (mouse-start-end beg end
(1- click-count
))))
566 (setq end
(nth 0 range
) beg
(nth 1 range
))
567 (setq beg
(nth 0 range
) end
(nth 1 range
)))))
568 (and mouse-drag-copy-region
(integerp beg
) (integerp end
)
569 ;; Don't set this-command to `kill-region', so a following
570 ;; C-w won't double the text in the kill ring. Ignore
571 ;; `last-command' so we don't append to a preceding kill.
572 (let (this-command last-command deactivate-mark
)
573 (copy-region-as-kill beg end
)))
574 (if (numberp beg
) (goto-char beg
))
575 ;; On a text terminal, bounce the cursor.
576 (or transient-mark-mode
581 (if (numberp end
) (goto-char end
))
582 (mouse-set-region-1)))
584 (defun mouse-set-region-1 ()
585 ;; Set transient-mark-mode for a little while.
586 (unless (eq (car-safe transient-mark-mode
) 'only
)
587 (setq transient-mark-mode
589 (unless (eq transient-mark-mode
'lambda
)
590 transient-mark-mode
))))
591 (setq mouse-last-region-beg
(region-beginning))
592 (setq mouse-last-region-end
(region-end))
593 (setq mouse-last-region-tick
(buffer-modified-tick)))
595 (defcustom mouse-scroll-delay
0.25
596 "The pause between scroll steps caused by mouse drags, in seconds.
597 If you drag the mouse beyond the edge of a window, Emacs scrolls the
598 window to bring the text beyond that edge into view, with a delay of
599 this many seconds between scroll steps. Scrolling stops when you move
600 the mouse back into the window, or release the button.
601 This variable's value may be non-integral.
602 Setting this to zero causes Emacs to scroll as fast as it can."
606 (defcustom mouse-scroll-min-lines
1
607 "The minimum number of lines scrolled by dragging mouse out of window.
608 Moving the mouse out the top or bottom edge of the window begins
609 scrolling repeatedly. The number of lines scrolled per repetition
610 is normally equal to the number of lines beyond the window edge that
611 the mouse has moved. However, it always scrolls at least the number
612 of lines specified by this variable."
616 (defun mouse-scroll-subr (window jump
&optional overlay start
)
617 "Scroll the window WINDOW, JUMP lines at a time, until new input arrives.
618 If OVERLAY is an overlay, let it stretch from START to the far edge of
619 the newly visible text.
620 Upon exit, point is at the far edge of the newly visible text."
622 ((and (> jump
0) (< jump mouse-scroll-min-lines
))
623 (setq jump mouse-scroll-min-lines
))
624 ((and (< jump
0) (< (- jump
) mouse-scroll-min-lines
))
625 (setq jump
(- mouse-scroll-min-lines
))))
626 (let ((opoint (point)))
628 (goto-char (window-start window
))
629 (if (not (zerop (vertical-motion jump window
)))
631 (set-window-start window
(point))
633 (if (window-end window
)
635 (goto-char (window-end window
))
636 ;; window-end doesn't reflect the window's new
637 ;; start position until the next redisplay.
638 (vertical-motion (1- jump
) window
))
639 (vertical-motion (- (window-height window
) 2)))
640 (goto-char (window-start window
)))
642 (move-overlay overlay start
(point)))
643 ;; Now that we have scrolled WINDOW properly,
644 ;; put point back where it was for the redisplay
645 ;; so that we don't mess up the selected window.
646 (or (eq window
(selected-window))
648 (sit-for mouse-scroll-delay
)))))
649 (or (eq window
(selected-window))
650 (goto-char opoint
))))
652 (defvar mouse-selection-click-count
0)
654 (defvar mouse-selection-click-count-buffer nil
)
656 (defun mouse-drag-region (start-event)
657 "Set the region to the text that the mouse is dragged over.
658 Highlight the drag area as you move the mouse.
659 This must be bound to a button-down mouse event.
660 In Transient Mark mode, the highlighting remains as long as the mark
661 remains active. Otherwise, it remains until the next input event."
663 ;; Give temporary modes such as isearch a chance to turn off.
664 (run-hooks 'mouse-leave-buffer-hook
)
665 (mouse-drag-track start-event
))
668 (defun mouse-posn-property (pos property
)
669 "Look for a property at click position.
670 POS may be either a buffer position or a click position like
671 those returned from `event-start'. If the click position is on
672 a string, the text property PROPERTY is examined.
673 If this is nil or the click is not on a string, then
674 the corresponding buffer position is searched for PROPERTY.
675 If PROPERTY is encountered in one of those places,
676 its value is returned."
678 (let ((w (posn-window pos
)) (pt (posn-point pos
))
679 (str (posn-string pos
)))
681 (get-text-property (cdr str
) property
(car str
)))
683 (get-char-property pt property w
))))
684 (get-char-property pos property
)))
686 (defun mouse-on-link-p (pos)
687 "Return non-nil if POS is on a link in the current buffer.
688 POS must be a buffer position in the current buffer or a mouse
689 event location in the selected window (see `event-start').
690 However, if `mouse-1-click-in-non-selected-windows' is non-nil,
691 POS may be a mouse event location in any window.
693 A clickable link is identified by one of the following methods:
695 - If the character at POS has a non-nil `follow-link' text or
696 overlay property, the value of that property determines what to do.
698 - If there is a local key-binding or a keybinding at position POS
699 for the `follow-link' event, the binding of that event determines
702 The resulting value determine whether POS is inside a link:
704 - If the value is `mouse-face', POS is inside a link if there
705 is a non-nil `mouse-face' property at POS. Return t in this case.
707 - If the value is a function, FUNC, POS is inside a link if
708 the call \(FUNC POS) returns non-nil. Return the return value
709 from that call. Arg is \(posn-point POS) if POS is a mouse event.
711 - Otherwise, return the value itself.
713 The return value is interpreted as follows:
715 - If it is a string, the mouse-1 event is translated into the
716 first character of the string, i.e. the action of the mouse-1
717 click is the local or global binding of that character.
719 - If it is a vector, the mouse-1 event is translated into the
720 first element of that vector, i.e. the action of the mouse-1
721 click is the local or global binding of that event.
723 - Otherwise, the mouse-1 event is translated into a mouse-2 event
724 at the same position."
726 (and (or (not (consp pos
))
727 mouse-1-click-in-non-selected-windows
728 (eq (selected-window) (posn-window pos
)))
729 (or (mouse-posn-property pos
'follow-link
)
730 (let ((area (posn-area pos
)))
732 (key-binding (vector area
'follow-link
) nil t pos
)))
733 (key-binding [follow-link
] nil t pos
)))))
735 ((eq action
'mouse-face
)
736 (and (mouse-posn-property pos
'mouse-face
) t
))
738 ;; FIXME: This seems questionable if the click is not in a buffer.
739 ;; Should we instead decide that `action' takes a `posn'?
741 (with-current-buffer (window-buffer (posn-window pos
))
742 (funcall action
(posn-point pos
)))
743 (funcall action pos
)))
746 (defun mouse-fixup-help-message (msg)
747 "Fix help message MSG for `mouse-1-click-follows-link'."
749 (if (and mouse-1-click-follows-link
751 (string-match-p "\\`mouse-2" msg
)
752 (setq mp
(mouse-pixel-position))
753 (consp (setq pos
(cdr mp
)))
754 (car pos
) (>= (car pos
) 0)
755 (cdr pos
) (>= (cdr pos
) 0)
756 (setq pos
(posn-at-x-y (car pos
) (cdr pos
) (car mp
)))
757 (windowp (posn-window pos
)))
758 (with-current-buffer (window-buffer (posn-window pos
))
759 (if (mouse-on-link-p pos
)
762 ((eq mouse-1-click-follows-link
'double
) "double-")
763 ((and (integerp mouse-1-click-follows-link
)
764 (< mouse-1-click-follows-link
0)) "Long ")
766 "mouse-1" (substring msg
7)))))))
769 (defun mouse-drag-track (start-event)
770 "Track mouse drags by highlighting area between point and cursor.
771 The region will be defined with mark and point."
772 (mouse-minibuffer-check start-event
)
773 (setq mouse-selection-click-count-buffer
(current-buffer))
775 (let* ((scroll-margin 0) ; Avoid margin scrolling (Bug#9541).
776 ;; We've recorded what we needed from the current buffer and
777 ;; window, now let's jump to the place of the event, where things
779 (_ (mouse-set-point start-event
))
781 (start-posn (event-start start-event
))
782 (start-point (posn-point start-posn
))
783 (start-window (posn-window start-posn
))
784 (bounds (window-edges start-window
))
785 (make-cursor-line-fully-visible nil
)
787 (bottom (if (window-minibuffer-p start-window
)
789 ;; Don't count the mode line.
790 (1- (nth 3 bounds
))))
791 (click-count (1- (event-click-count start-event
)))
792 ;; Suppress automatic hscrolling, because that is a nuisance
793 ;; when setting point near the right fringe (but see below).
794 (auto-hscroll-mode-saved auto-hscroll-mode
))
796 (setq mouse-selection-click-count click-count
)
797 ;; In case the down click is in the middle of some intangible text,
798 ;; use the end of that text, and put it in START-POINT.
799 (if (< (point) start-point
)
800 (goto-char start-point
))
801 (setq start-point
(point))
803 ;; Activate the region, using `mouse-start-end' to determine where
804 ;; to put point and mark (e.g., double-click will select a word).
805 (setq transient-mark-mode
806 (if (eq transient-mark-mode
'lambda
)
808 (cons 'only transient-mark-mode
)))
809 (let ((range (mouse-start-end start-point start-point click-count
)))
810 (push-mark (nth 0 range
) t t
)
811 (goto-char (nth 1 range
)))
813 (setf (terminal-parameter nil
'mouse-drag-start
) start-event
)
815 (setq auto-hscroll-mode nil
)
818 (let ((map (make-sparse-keymap)))
819 (define-key map
[switch-frame
] #'ignore
)
820 (define-key map
[select-window
] #'ignore
)
821 (define-key map
[mouse-movement
]
822 (lambda (event) (interactive "e")
823 (let* ((end (event-end event
))
824 (end-point (posn-point end
)))
825 (unless (eq end-point start-point
)
826 ;; As soon as the user moves, we can re-enable auto-hscroll.
827 (setq auto-hscroll-mode auto-hscroll-mode-saved
))
828 (if (and (eq (posn-window end
) start-window
)
829 (integer-or-marker-p end-point
))
830 (mouse--drag-set-mark-and-point start-point
831 end-point click-count
)
832 (let ((mouse-row (cdr (cdr (mouse-position)))))
836 (mouse-scroll-subr start-window
(- mouse-row top
)
838 ((>= mouse-row bottom
)
839 (mouse-scroll-subr start-window
(1+ (- mouse-row bottom
))
840 nil start-point
))))))))
843 (setq track-mouse nil
)
844 (setq auto-hscroll-mode auto-hscroll-mode-saved
)
848 (defun mouse--drag-set-mark-and-point (start click click-count
)
849 (let* ((range (mouse-start-end start click click-count
))
852 (cond ((eq (mark) beg
)
863 ;; Commands to handle xterm-style multiple clicks.
864 (defun mouse-skip-word (dir)
865 "Skip over word, over whitespace, or over identical punctuation.
866 If DIR is positive skip forward; if negative, skip backward."
867 (let* ((char (following-char))
868 (syntax (char-to-string (char-syntax char
))))
869 (cond ((string= syntax
"w")
870 ;; Here, we can't use skip-syntax-forward/backward because
871 ;; they don't pay attention to word-separating-categories,
872 ;; and thus they will skip over a true word boundary. So,
873 ;; we simulate the original behavior by using forward-word.
875 (if (not (looking-at "\\<"))
877 (if (or (looking-at "\\<") (not (looking-at "\\>")))
879 ((string= syntax
" ")
881 (skip-syntax-backward syntax
)
882 (skip-syntax-forward syntax
)))
883 ((string= syntax
"_")
885 (skip-syntax-backward "w_")
886 (skip-syntax-forward "w_")))
888 (while (and (not (bobp)) (= (preceding-char) char
))
891 (while (and (not (eobp)) (= (following-char) char
))
892 (forward-char 1))))))
894 (defun mouse-start-end (start end mode
)
895 "Return a list of region bounds based on START and END according to MODE.
896 If MODE is 0 then set point to (min START END), mark to (max START END).
897 If MODE is 1 then set point to start of word at (min START END),
898 mark to end of word at (max START END).
899 If MODE is 2 then do the same for lines."
904 (setq mode
(mod mode
3))
910 (= (char-syntax (char-after start
)) ?\
())
919 (= (char-syntax (char-after start
)) ?\
)))
920 (list (save-excursion
921 (goto-char (1+ start
))
928 (= (char-syntax (char-after start
)) ?
\"))
929 (let ((open (or (eq start
(point-min))
931 (goto-char (- start
1))
932 (looking-at "\\s(\\|\\s \\|\\s>")))))
942 (list (save-excursion
945 (goto-char (1+ start
))
951 (list (save-excursion
960 (list (save-excursion
962 (line-beginning-position 1))
968 ;; Subroutine: set the mark where CLICK happened,
969 ;; but don't do anything else.
970 (defun mouse-set-mark-fast (click)
971 (mouse-minibuffer-check click
)
972 (let ((posn (event-start click
)))
973 (select-window (posn-window posn
))
974 (if (numberp (posn-point posn
))
975 (push-mark (posn-point posn
) t t
))))
977 (defun mouse-undouble-last-event (events)
978 (let* ((index (1- (length events
)))
979 (last (nthcdr index events
))
981 (basic (event-basic-type event
))
982 (old-modifiers (event-modifiers event
))
983 (modifiers (delq 'double
(delq 'triple
(copy-sequence old-modifiers
))))
986 ;; Use reverse, not nreverse, since event-modifiers
987 ;; does not copy the list it returns.
988 (cons (event-convert-list (reverse (cons basic modifiers
)))
992 (if (and (not (equal modifiers old-modifiers
))
993 (key-binding (apply 'vector events
)))
998 ;; Momentarily show where the mark is, if highlighting doesn't show it.
1000 (defun mouse-set-mark (click)
1001 "Set mark at the position clicked on with the mouse.
1002 Display cursor at that position for a second.
1003 This must be bound to a mouse click."
1005 (mouse-minibuffer-check click
)
1006 (select-window (posn-window (event-start click
)))
1007 ;; We don't use save-excursion because that preserves the mark too.
1008 (let ((point-save (point)))
1010 (progn (mouse-set-point click
)
1012 (or transient-mark-mode
1014 (goto-char point-save
))))
1016 (defun mouse-kill (click)
1017 "Kill the region between point and the mouse click.
1018 The text is saved in the kill ring, as with \\[kill-region]."
1020 (mouse-minibuffer-check click
)
1021 (let* ((posn (event-start click
))
1022 (click-posn (posn-point posn
)))
1023 (select-window (posn-window posn
))
1024 (if (numberp click-posn
)
1025 (kill-region (min (point) click-posn
)
1026 (max (point) click-posn
)))))
1028 (defun mouse-yank-at-click (click arg
)
1029 "Insert the last stretch of killed text at the position clicked on.
1030 Also move point to one end of the text thus inserted (normally the end),
1031 and set mark at the beginning.
1032 Prefix arguments are interpreted as with \\[yank].
1033 If `mouse-yank-at-point' is non-nil, insert at point
1034 regardless of where you click."
1035 (interactive "e\nP")
1036 ;; Give temporary modes such as isearch a chance to turn off.
1037 (run-hooks 'mouse-leave-buffer-hook
)
1038 (when select-active-regions
1039 ;; Without this, confusing things happen upon e.g. inserting into
1040 ;; the middle of an active region.
1042 (or mouse-yank-at-point
(mouse-set-point click
))
1043 (setq this-command
'yank
)
1044 (setq mouse-selection-click-count
0)
1047 (defun mouse-yank-primary (click)
1048 "Insert the primary selection at the position clicked on.
1049 Move point to the end of the inserted text, and set mark at
1050 beginning. If `mouse-yank-at-point' is non-nil, insert at point
1051 regardless of where you click."
1053 ;; Give temporary modes such as isearch a chance to turn off.
1054 (run-hooks 'mouse-leave-buffer-hook
)
1055 ;; Without this, confusing things happen upon e.g. inserting into
1056 ;; the middle of an active region.
1057 (when select-active-regions
1058 (let (select-active-regions)
1060 (or mouse-yank-at-point
(mouse-set-point click
))
1062 (if (fboundp 'x-get-selection-value
)
1063 (if (eq (framep (selected-frame)) 'w32
)
1064 ;; MS-Windows emulates PRIMARY in x-get-selection, but not
1065 ;; in x-get-selection-value (the latter only accesses the
1066 ;; clipboard). So try PRIMARY first, in case they selected
1067 ;; something with the mouse in the current Emacs session.
1068 (or (x-get-selection 'PRIMARY
)
1069 (x-get-selection-value))
1070 ;; Else MS-DOS or X.
1071 ;; On X, x-get-selection-value supports more formats and
1072 ;; encodings, so use it in preference to x-get-selection.
1073 (or (x-get-selection-value)
1074 (x-get-selection 'PRIMARY
)))
1075 ;; FIXME: What about xterm-mouse-mode etc.?
1076 (x-get-selection 'PRIMARY
))))
1078 (error "No selection is available"))
1082 (defun mouse-kill-ring-save (click)
1083 "Copy the region between point and the mouse click in the kill ring.
1084 This does not delete the region; it acts like \\[kill-ring-save]."
1086 (mouse-set-mark-fast click
)
1087 (let (this-command last-command
)
1088 (kill-ring-save (point) (mark t
))))
1090 ;; This function used to delete the text between point and the mouse
1091 ;; whenever it was equal to the front of the kill ring, but some
1092 ;; people found that confusing.
1094 ;; The position of the last invocation of `mouse-save-then-kill'.
1095 (defvar mouse-save-then-kill-posn nil
)
1097 (defun mouse-save-then-kill-delete-region (beg end
)
1098 ;; We must make our own undo boundaries
1099 ;; because they happen automatically only for the current buffer.
1101 (if (or (= beg end
) (eq buffer-undo-list t
))
1102 ;; If we have no undo list in this buffer,
1104 (delete-region beg end
)
1105 ;; Delete, but make the undo-list entry share with the kill ring.
1106 ;; First, delete just one char, so in case buffer is being modified
1107 ;; for the first time, the undo list records that fact.
1108 (let (before-change-functions after-change-functions
)
1110 (+ beg
(if (> end beg
) 1 -
1))))
1111 (let ((buffer-undo-list buffer-undo-list
))
1112 ;; Undo that deletion--but don't change the undo list!
1113 (let (before-change-functions after-change-functions
)
1114 (primitive-undo 1 buffer-undo-list
))
1115 ;; Now delete the rest of the specified region,
1116 ;; but don't record it.
1117 (setq buffer-undo-list t
)
1118 (if (/= (length (car kill-ring
)) (- (max end beg
) (min end beg
)))
1119 (error "Lossage in mouse-save-then-kill-delete-region"))
1120 (delete-region beg end
))
1121 (let ((tail buffer-undo-list
))
1122 ;; Search back in buffer-undo-list for the string
1123 ;; that came from deleting one character.
1124 (while (and tail
(not (stringp (car (car tail
)))))
1125 (setq tail
(cdr tail
)))
1126 ;; Replace it with an entry for the entire deleted text.
1128 (setcar tail
(cons (car kill-ring
) (min beg end
))))))
1131 (defun mouse-save-then-kill (click)
1132 "Set the region according to CLICK; the second time, kill it.
1133 CLICK should be a mouse click event.
1135 If the region is inactive, activate it temporarily. Set mark at
1136 the original point, and move point to the position of CLICK.
1138 If the region is already active, adjust it. Normally, do this by
1139 moving point or mark, whichever is closer, to CLICK. But if you
1140 have selected whole words or lines, move point or mark to the
1141 word or line boundary closest to CLICK instead.
1143 If `mouse-drag-copy-region' is non-nil, this command also saves the
1144 new region to the kill ring (replacing the previous kill if the
1145 previous region was just saved to the kill ring).
1147 If this command is called a second consecutive time with the same
1148 CLICK position, kill the region (or delete it
1149 if `mouse-drag-copy-region' is non-nil)"
1151 (mouse-minibuffer-check click
)
1152 (let* ((posn (event-start click
))
1153 (click-pt (posn-point posn
))
1154 (window (posn-window posn
))
1155 (buf (window-buffer window
))
1156 ;; Don't let a subsequent kill command append to this one.
1157 (this-command this-command
)
1158 ;; Check if the user has multi-clicked to select words/lines.
1160 (if (and (eq mouse-selection-click-count-buffer buf
)
1161 (with-current-buffer buf
(mark t
)))
1162 mouse-selection-click-count
1165 ((not (numberp click-pt
)) nil
)
1166 ;; If the user clicked without moving point, kill the region.
1167 ;; This also resets `mouse-selection-click-count'.
1168 ((and (eq last-command
'mouse-save-then-kill
)
1169 (eq click-pt mouse-save-then-kill-posn
)
1170 (eq window
(selected-window)))
1171 (if mouse-drag-copy-region
1172 ;; Region already saved in the previous click;
1173 ;; don't make a duplicate entry, just delete.
1174 (delete-region (mark t
) (point))
1175 (kill-region (mark t
) (point)))
1176 (setq mouse-selection-click-count
0)
1177 (setq mouse-save-then-kill-posn nil
))
1179 ;; Otherwise, if there is a suitable region, adjust it by moving
1180 ;; one end (whichever is closer) to CLICK-PT.
1181 ((or (with-current-buffer buf
(region-active-p))
1182 (and (eq window
(selected-window))
1184 (or (and (eq last-command
'mouse-save-then-kill
)
1185 mouse-save-then-kill-posn
)
1186 (and (memq last-command
'(mouse-drag-region
1188 (or mark-even-if-inactive
1189 (not transient-mark-mode
))))))
1190 (select-window window
)
1191 (let* ((range (mouse-start-end click-pt click-pt click-count
)))
1192 (if (< (abs (- click-pt
(mark t
)))
1193 (abs (- click-pt
(point))))
1194 (set-mark (car range
))
1195 (goto-char (nth 1 range
)))
1196 (setq deactivate-mark nil
)
1197 (mouse-set-region-1)
1198 (when mouse-drag-copy-region
1199 ;; Region already copied to kill-ring once, so replace.
1200 (kill-new (filter-buffer-substring (mark t
) (point)) t
))
1201 ;; Arrange for a repeated mouse-3 to kill the region.
1202 (setq mouse-save-then-kill-posn click-pt
)))
1204 ;; Otherwise, set the mark where point is and move to CLICK-PT.
1206 (select-window window
)
1207 (mouse-set-mark-fast click
)
1208 (let ((before-scroll (with-current-buffer buf point-before-scroll
)))
1209 (if before-scroll
(goto-char before-scroll
)))
1210 (exchange-point-and-mark)
1211 (mouse-set-region-1)
1212 (when mouse-drag-copy-region
1213 (kill-new (filter-buffer-substring (mark t
) (point))))
1214 (setq mouse-save-then-kill-posn click-pt
)))))
1217 (global-set-key [M-mouse-1
] 'mouse-start-secondary
)
1218 (global-set-key [M-drag-mouse-1
] 'mouse-set-secondary
)
1219 (global-set-key [M-down-mouse-1
] 'mouse-drag-secondary
)
1220 (global-set-key [M-mouse-3
] 'mouse-secondary-save-then-kill
)
1221 (global-set-key [M-mouse-2
] 'mouse-yank-secondary
)
1223 (defconst mouse-secondary-overlay
1224 (let ((ol (make-overlay (point-min) (point-min))))
1226 (overlay-put ol
'face
'secondary-selection
)
1228 "An overlay which records the current secondary selection.
1229 It is deleted when there is no secondary selection.")
1231 (defvar mouse-secondary-click-count
0)
1233 ;; A marker which records the specified first end for a secondary selection.
1235 (defvar mouse-secondary-start nil
)
1237 (defun mouse-start-secondary (click)
1238 "Set one end of the secondary selection to the position clicked on.
1239 Use \\[mouse-secondary-save-then-kill] to set the other end
1240 and complete the secondary selection."
1242 (mouse-minibuffer-check click
)
1243 (let ((posn (event-start click
)))
1244 (with-current-buffer (window-buffer (posn-window posn
))
1245 ;; Cancel any preexisting secondary selection.
1246 (delete-overlay mouse-secondary-overlay
)
1247 (if (numberp (posn-point posn
))
1249 (or mouse-secondary-start
1250 (setq mouse-secondary-start
(make-marker)))
1251 (move-marker mouse-secondary-start
(posn-point posn
)))))))
1253 (defun mouse-set-secondary (click)
1254 "Set the secondary selection to the text that the mouse is dragged over.
1255 This must be bound to a mouse drag event."
1257 (mouse-minibuffer-check click
)
1258 (let ((posn (event-start click
))
1260 (end (event-end click
)))
1261 (with-current-buffer (window-buffer (posn-window posn
))
1262 (if (numberp (posn-point posn
))
1263 (setq beg
(posn-point posn
)))
1264 (move-overlay mouse-secondary-overlay beg
(posn-point end
))
1267 (buffer-substring (overlay-start mouse-secondary-overlay
)
1268 (overlay-end mouse-secondary-overlay
))))))
1270 (defun mouse-drag-secondary (start-event)
1271 "Set the secondary selection to the text that the mouse is dragged over.
1272 Highlight the drag area as you move the mouse.
1273 This must be bound to a button-down mouse event.
1274 The function returns a non-nil value if it creates a secondary selection."
1276 (mouse-minibuffer-check start-event
)
1277 (let* ((echo-keystrokes 0)
1278 (start-posn (event-start start-event
))
1279 (start-point (posn-point start-posn
))
1280 (start-window (posn-window start-posn
))
1281 (bounds (window-edges start-window
))
1282 (top (nth 1 bounds
))
1283 (bottom (if (window-minibuffer-p start-window
)
1285 ;; Don't count the mode line.
1286 (1- (nth 3 bounds
))))
1287 (click-count (1- (event-click-count start-event
))))
1288 (with-current-buffer (window-buffer start-window
)
1289 (setq mouse-secondary-click-count click-count
)
1290 (if (> (mod click-count
3) 0)
1291 ;; Double or triple press: make an initial selection
1292 ;; of one word or line.
1293 (let ((range (mouse-start-end start-point start-point click-count
)))
1294 (set-marker mouse-secondary-start nil
)
1295 (move-overlay mouse-secondary-overlay
(car range
) (nth 1 range
)
1296 (window-buffer start-window
)))
1297 ;; Single-press: cancel any preexisting secondary selection.
1298 (or mouse-secondary-start
1299 (setq mouse-secondary-start
(make-marker)))
1300 (set-marker mouse-secondary-start start-point
)
1301 (delete-overlay mouse-secondary-overlay
))
1302 (let (event end end-point
)
1305 (setq event
(read-event))
1306 (or (mouse-movement-p event
)
1307 (memq (car-safe event
) '(switch-frame select-window
))))
1309 (if (memq (car-safe event
) '(switch-frame select-window
))
1311 (setq end
(event-end event
)
1312 end-point
(posn-point end
))
1314 ;; Are we moving within the original window?
1315 ((and (eq (posn-window end
) start-window
)
1316 (integer-or-marker-p end-point
))
1317 (let ((range (mouse-start-end start-point end-point
1319 (if (or (/= start-point end-point
)
1320 (null (marker-position mouse-secondary-start
)))
1322 (set-marker mouse-secondary-start nil
)
1323 (move-overlay mouse-secondary-overlay
1324 (car range
) (nth 1 range
))))))
1326 (let ((mouse-row (cdr (cdr (mouse-position)))))
1330 (mouse-scroll-subr start-window
(- mouse-row top
)
1331 mouse-secondary-overlay start-point
))
1332 ((>= mouse-row bottom
)
1333 (mouse-scroll-subr start-window
(1+ (- mouse-row bottom
))
1334 mouse-secondary-overlay start-point
)))))))))
1337 (if (marker-position mouse-secondary-start
)
1338 (save-window-excursion
1339 (delete-overlay mouse-secondary-overlay
)
1340 (x-set-selection 'SECONDARY nil
)
1341 (select-window start-window
)
1343 (goto-char mouse-secondary-start
)
1348 (buffer-substring (overlay-start mouse-secondary-overlay
)
1349 (overlay-end mouse-secondary-overlay
)))))))))
1351 (defun mouse-yank-secondary (click)
1352 "Insert the secondary selection at the position clicked on.
1353 Move point to the end of the inserted text.
1354 If `mouse-yank-at-point' is non-nil, insert at point
1355 regardless of where you click."
1357 ;; Give temporary modes such as isearch a chance to turn off.
1358 (run-hooks 'mouse-leave-buffer-hook
)
1359 (or mouse-yank-at-point
(mouse-set-point click
))
1360 (let ((secondary (x-get-selection 'SECONDARY
)))
1363 (error "No secondary selection"))))
1365 (defun mouse-kill-secondary ()
1366 "Kill the text in the secondary selection.
1367 This is intended more as a keyboard command than as a mouse command
1368 but it can work as either one.
1370 The current buffer (in case of keyboard use), or the buffer clicked on,
1371 must be the one that the secondary selection is in. This requirement
1372 is to prevent accidents."
1374 (let* ((keys (this-command-keys))
1375 (click (elt keys
(1- (length keys
)))))
1376 (or (eq (overlay-buffer mouse-secondary-overlay
)
1378 (window-buffer (posn-window (event-start click
)))
1380 (error "Select or click on the buffer where the secondary selection is")))
1382 (with-current-buffer (overlay-buffer mouse-secondary-overlay
)
1383 (kill-region (overlay-start mouse-secondary-overlay
)
1384 (overlay-end mouse-secondary-overlay
))))
1385 (delete-overlay mouse-secondary-overlay
))
1387 (defun mouse-secondary-save-then-kill (click)
1388 "Set the secondary selection and save it to the kill ring.
1389 The second time, kill it. CLICK should be a mouse click event.
1391 If you have not called `mouse-start-secondary' in the clicked
1392 buffer, activate the secondary selection and set it between point
1393 and the click position CLICK.
1395 Otherwise, adjust the bounds of the secondary selection.
1396 Normally, do this by moving its beginning or end, whichever is
1397 closer, to CLICK. But if you have selected whole words or lines,
1398 adjust to the word or line boundary closest to CLICK instead.
1400 If this command is called a second consecutive time with the same
1401 CLICK position, kill the secondary selection."
1403 (mouse-minibuffer-check click
)
1404 (let* ((posn (event-start click
))
1405 (click-pt (posn-point posn
))
1406 (window (posn-window posn
))
1407 (buf (window-buffer window
))
1408 ;; Don't let a subsequent kill command append to this one.
1409 (this-command this-command
)
1410 ;; Check if the user has multi-clicked to select words/lines.
1412 (if (eq (overlay-buffer mouse-secondary-overlay
) buf
)
1413 mouse-secondary-click-count
1415 (beg (overlay-start mouse-secondary-overlay
))
1416 (end (overlay-end mouse-secondary-overlay
)))
1419 ((not (numberp click-pt
)) nil
)
1421 ;; If the secondary selection is not active in BUF, activate it.
1422 ((not (eq buf
(or (overlay-buffer mouse-secondary-overlay
)
1423 (if mouse-secondary-start
1424 (marker-buffer mouse-secondary-start
)))))
1425 (select-window window
)
1426 (setq mouse-secondary-start
(make-marker))
1427 (move-marker mouse-secondary-start
(point))
1428 (move-overlay mouse-secondary-overlay
(point) click-pt buf
)
1429 (kill-ring-save (point) click-pt
))
1431 ;; If the user clicked without moving point, delete the secondary
1432 ;; selection. This also resets `mouse-secondary-click-count'.
1433 ((and (eq last-command
'mouse-secondary-save-then-kill
)
1434 (eq click-pt mouse-save-then-kill-posn
)
1435 (eq window
(selected-window)))
1436 (mouse-save-then-kill-delete-region beg end
)
1437 (delete-overlay mouse-secondary-overlay
)
1438 (setq mouse-secondary-click-count
0)
1439 (setq mouse-save-then-kill-posn nil
))
1441 ;; Otherwise, if there is a suitable secondary selection overlay,
1442 ;; adjust it by moving one end (whichever is closer) to CLICK-PT.
1443 ((and beg
(eq buf
(overlay-buffer mouse-secondary-overlay
)))
1444 (let* ((range (mouse-start-end click-pt click-pt click-count
)))
1445 (if (< (abs (- click-pt beg
))
1446 (abs (- click-pt end
)))
1447 (move-overlay mouse-secondary-overlay
(car range
) end
)
1448 (move-overlay mouse-secondary-overlay beg
(nth 1 range
))))
1449 (setq deactivate-mark nil
)
1450 (if (eq last-command
'mouse-secondary-save-then-kill
)
1451 ;; If the front of the kill ring comes from an immediately
1452 ;; previous use of this command, replace the entry.
1454 (buffer-substring (overlay-start mouse-secondary-overlay
)
1455 (overlay-end mouse-secondary-overlay
))
1457 (let (deactivate-mark)
1458 (copy-region-as-kill (overlay-start mouse-secondary-overlay
)
1459 (overlay-end mouse-secondary-overlay
))))
1460 (setq mouse-save-then-kill-posn click-pt
))
1462 ;; Otherwise, set the secondary selection overlay.
1464 (select-window window
)
1465 (if mouse-secondary-start
1466 ;; All we have is one end of a selection, so put the other
1468 (let ((start (+ 0 mouse-secondary-start
)))
1469 (kill-ring-save start click-pt
)
1470 (move-overlay mouse-secondary-overlay start click-pt
)))
1471 (setq mouse-save-then-kill-posn click-pt
))))
1473 ;; Finally, set the window system's secondary selection.
1475 (and (overlay-buffer mouse-secondary-overlay
)
1476 (setq str
(buffer-substring (overlay-start mouse-secondary-overlay
)
1477 (overlay-end mouse-secondary-overlay
)))
1479 (x-set-selection 'SECONDARY str
))))
1482 (defcustom mouse-buffer-menu-maxlen
20
1483 "Number of buffers in one pane (submenu) of the buffer menu.
1484 If we have lots of buffers, divide them into groups of
1485 `mouse-buffer-menu-maxlen' and make a pane (or submenu) for each one."
1489 (defcustom mouse-buffer-menu-mode-mult
4
1490 "Group the buffers by the major mode groups on \\[mouse-buffer-menu]?
1491 This number which determines (in a hairy way) whether \\[mouse-buffer-menu]
1492 will split the buffer menu by the major modes (see
1493 `mouse-buffer-menu-mode-groups') or just by menu length.
1494 Set to 1 (or even 0!) if you want to group by major mode always, and to
1495 a large number if you prefer a mixed multitude. The default is 4."
1500 (defvar mouse-buffer-menu-mode-groups
1501 (mapcar (lambda (arg) (cons (purecopy (car arg
)) (purecopy (cdr arg
))))
1502 '(("Info\\|Help\\|Apropos\\|Man" .
"Help")
1503 ("\\bVM\\b\\|\\bMH\\b\\|Message\\|Mail\\|Group\\|Score\\|Summary\\|Article"
1508 ("Outline" .
"Text")
1509 ("\\(HT\\|SG\\|X\\|XHT\\)ML" .
"SGML")
1510 ("log\\|diff\\|vc\\|cvs\\|Annotate" .
"Version Control") ; "Change Management"?
1511 ("Threads\\|Memory\\|Disassembly\\|Breakpoints\\|Frames\\|Locals\\|Registers\\|Inferior I/O\\|Debugger"
1514 "How to group various major modes together in \\[mouse-buffer-menu].
1515 Each element has the form (REGEXP . GROUPNAME).
1516 If the major mode's name string matches REGEXP, use GROUPNAME instead.")
1518 (defun mouse-buffer-menu (event)
1519 "Pop up a menu of buffers for selection with the mouse.
1520 This switches buffers in the window that you clicked on,
1521 and selects that window."
1523 (mouse-minibuffer-check event
)
1524 (let ((buffers (buffer-list)) alist menu split-by-major-mode sum-of-squares
)
1525 ;; Make an alist of elements that look like (MENU-ITEM . BUFFER).
1526 (dolist (buf buffers
)
1527 ;; Divide all buffers into buckets for various major modes.
1528 ;; Each bucket looks like (MODE NAMESTRING BUFFERS...).
1529 (with-current-buffer buf
1530 (let* ((adjusted-major-mode major-mode
) elt
)
1531 (dolist (group mouse-buffer-menu-mode-groups
)
1532 (when (string-match (car group
) (format-mode-line mode-name
))
1533 (setq adjusted-major-mode
(cdr group
))))
1534 (setq elt
(assoc adjusted-major-mode split-by-major-mode
))
1536 (setq elt
(list adjusted-major-mode
1537 (if (stringp adjusted-major-mode
)
1539 (format-mode-line mode-name nil nil buf
)))
1540 split-by-major-mode
(cons elt split-by-major-mode
)))
1541 (or (memq buf
(cdr (cdr elt
)))
1542 (setcdr (cdr elt
) (cons buf
(cdr (cdr elt
))))))))
1543 ;; Compute the sum of squares of sizes of the major-mode buckets.
1544 (let ((tail split-by-major-mode
))
1545 (setq sum-of-squares
0)
1547 (setq sum-of-squares
1549 (let ((len (length (cdr (cdr (car tail
)))))) (* len len
))))
1550 (setq tail
(cdr tail
))))
1551 (if (< (* sum-of-squares mouse-buffer-menu-mode-mult
)
1552 (* (length buffers
) (length buffers
)))
1553 ;; Subdividing by major modes really helps, so let's do it.
1554 (let (subdivided-menus (buffers-left (length buffers
)))
1555 ;; Sort the list to put the most popular major modes first.
1556 (setq split-by-major-mode
1557 (sort split-by-major-mode
1558 (function (lambda (elt1 elt2
)
1559 (> (length elt1
) (length elt2
))))))
1560 ;; Make a separate submenu for each major mode
1561 ;; that has more than one buffer,
1562 ;; unless all the remaining buffers are less than 1/10 of them.
1563 (while (and split-by-major-mode
1564 (and (> (length (car split-by-major-mode
)) 3)
1565 (> (* buffers-left
10) (length buffers
))))
1566 (let ((this-mode-list (mouse-buffer-menu-alist
1567 (cdr (cdr (car split-by-major-mode
))))))
1569 (setq subdivided-menus
1571 (nth 1 (car split-by-major-mode
))
1573 subdivided-menus
))))
1575 (- buffers-left
(length (cdr (car split-by-major-mode
)))))
1576 (setq split-by-major-mode
(cdr split-by-major-mode
)))
1577 ;; If any major modes are left over,
1578 ;; make a single submenu for them.
1579 (if split-by-major-mode
1581 (mouse-buffer-menu-alist
1582 ;; we don't need split-by-major-mode any more,
1583 ;; so we can ditch it with nconc.
1584 (apply 'nconc
(mapcar 'cddr split-by-major-mode
)))))
1586 (setq subdivided-menus
1587 (cons (cons "Others" others-list
)
1588 subdivided-menus
)))))
1589 (setq menu
(cons "Buffer Menu" (nreverse subdivided-menus
))))
1591 (setq alist
(mouse-buffer-menu-alist buffers
))
1592 (setq menu
(cons "Buffer Menu"
1593 (mouse-buffer-menu-split "Select Buffer" alist
)))))
1594 (let ((buf (x-popup-menu event menu
))
1595 (window (posn-window (event-start event
))))
1598 (if (framep window
) (frame-selected-window window
)
1600 (switch-to-buffer buf
)))))
1602 (defun mouse-buffer-menu-alist (buffers)
1608 (function (lambda (elt1 elt2
)
1609 (string< (buffer-name elt1
) (buffer-name elt2
))))))
1612 (or (eq ?\s
(aref (buffer-name (car tail
)) 0))
1615 (length (buffer-name (car tail
))))))
1616 (setq tail
(cdr tail
)))
1619 (let ((elt (car tail
)))
1620 (if (/= (aref (buffer-name elt
) 0) ?\s
)
1625 (format "%%-%ds %%s%%s %%s" maxlen
)
1627 (if (buffer-modified-p elt
) "*" " ")
1628 (with-current-buffer elt
1629 (if buffer-read-only
"%" " "))
1630 (or (buffer-file-name elt
)
1631 (with-current-buffer elt
1632 (if list-buffers-directory
1634 list-buffers-directory
)))
1638 (setq tail
(cdr tail
)))
1639 ;; Compensate for the reversal that the above loop does.
1642 (defun mouse-buffer-menu-split (title alist
)
1643 ;; If we have lots of buffers, divide them into groups of 20
1644 ;; and make a pane (or submenu) for each one.
1645 (if (> (length alist
) (/ (* mouse-buffer-menu-maxlen
3) 2))
1646 (let ((alist alist
) sublists next
1649 ;; Pull off the next mouse-buffer-menu-maxlen buffers
1650 ;; and make them the next element of sublist.
1651 (setq next
(nthcdr mouse-buffer-menu-maxlen alist
))
1653 (setcdr (nthcdr (1- mouse-buffer-menu-maxlen
) alist
)
1655 (setq sublists
(cons (cons (format "Buffers %d" i
) alist
)
1659 (nreverse sublists
))
1660 ;; Few buffers--put them all in one pane.
1661 (list (cons title alist
))))
1663 (define-obsolete-function-alias
1664 'mouse-choose-completion
'choose-completion
"23.2")
1668 (defun font-menu-add-default ()
1669 (let* ((default (cdr (assq 'font
(frame-parameters (selected-frame)))))
1670 (font-alist x-fixed-font-alist
)
1671 (elt (or (assoc "Misc" font-alist
) (nth 1 font-alist
))))
1672 (if (assoc "Default" elt
)
1673 (delete (assoc "Default" elt
) elt
))
1675 (cons (list "Default" default
)
1678 (defvar x-fixed-font-alist
1680 (purecopy "Font Menu")
1684 (lambda (arg) (cons (purecopy (car arg
)) (purecopy (cdr arg
))))
1685 ;; For these, we specify the pixel height and width.
1687 ("6x10" "-misc-fixed-medium-r-normal--10-*-*-*-c-60-iso8859-1" "6x10")
1689 "-misc-fixed-medium-r-semicondensed--12-*-*-*-c-60-iso8859-1" "6x12")
1691 "-misc-fixed-medium-r-semicondensed--13-*-*-*-c-60-iso8859-1" "6x13")
1692 ("7x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-70-iso8859-1" "7x13")
1693 ("7x14" "-misc-fixed-medium-r-normal--14-*-*-*-c-70-iso8859-1" "7x14")
1694 ("8x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-80-iso8859-1" "8x13")
1695 ("9x15" "-misc-fixed-medium-r-normal--15-*-*-*-c-90-iso8859-1" "9x15")
1696 ("10x20" "-misc-fixed-medium-r-normal--20-*-*-*-c-100-iso8859-1" "10x20")
1697 ("11x18" "-misc-fixed-medium-r-normal--18-*-*-*-c-110-iso8859-1" "11x18")
1698 ("12x24" "-misc-fixed-medium-r-normal--24-*-*-*-c-120-iso8859-1" "12x24")
1701 "-schumacher-clean-medium-r-normal--8-*-*-*-c-50-iso8859-1")
1703 "-schumacher-clean-medium-r-normal--8-*-*-*-c-60-iso8859-1")
1705 "-schumacher-clean-medium-r-normal--8-*-*-*-c-80-iso8859-1")
1707 "-schumacher-clean-medium-r-normal--10-*-*-*-c-80-iso8859-1")
1709 "-schumacher-clean-medium-r-normal--14-*-*-*-c-80-iso8859-1")
1711 "-schumacher-clean-medium-r-normal--16-*-*-*-c-80-iso8859-1")
1713 ("sony 8x16" "-sony-fixed-medium-r-normal--16-*-*-*-c-80-iso8859-1")
1714 ;; We don't seem to have these; who knows what they are.
1715 ;; ("fg-18" "fg-18")
1716 ;; ("fg-25" "fg-25")
1717 ("lucidasanstypewriter-12" "-b&h-lucidatypewriter-medium-r-normal-sans-*-120-*-*-*-*-iso8859-1")
1718 ("lucidasanstypewriter-bold-14" "-b&h-lucidatypewriter-bold-r-normal-sans-*-140-*-*-*-*-iso8859-1")
1719 ("lucidasanstypewriter-bold-24"
1720 "-b&h-lucidatypewriter-bold-r-normal-sans-*-240-*-*-*-*-iso8859-1")
1721 ;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
1722 ;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
1726 (purecopy "Courier")
1728 (lambda (arg) (cons (purecopy (car arg
)) (purecopy (cdr arg
))))
1729 ;; For these, we specify the point height.
1730 '(("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1")
1731 ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1")
1732 ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1")
1733 ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1")
1734 ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1")
1735 ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1")
1736 ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1")
1737 ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1")
1738 ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1")
1739 ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1")
1740 ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1")
1741 ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1")
1742 ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1")
1743 ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1")
1744 ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1")
1745 ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1")
1746 ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1")
1747 ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1")
1748 ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1")
1749 ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1")
1750 ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1")
1751 ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1")
1752 ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1")
1753 ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1")
1755 "X fonts suitable for use in Emacs.")
1757 (declare-function generate-fontset-menu
"fontset" ())
1759 (defun mouse-select-font ()
1760 "Prompt for a font name, using `x-popup-menu', and return it."
1762 (unless (display-multi-font-p)
1763 (error "Cannot change fonts on this display"))
1766 (if (listp last-nonmenu-event
)
1768 (list '(0 0) (selected-window)))
1769 (append x-fixed-font-alist
1770 (list (generate-fontset-menu))))))
1772 (declare-function text-scale-mode
"face-remap")
1774 (defun mouse-set-font (&rest fonts
)
1775 "Set the default font for the selected frame.
1776 The argument FONTS is a list of font names; the first valid font
1777 in this list is used.
1779 When called interactively, pop up a menu and allow the user to
1782 (progn (unless (display-multi-font-p)
1783 (error "Cannot change fonts on this display"))
1785 (if (listp last-nonmenu-event
)
1787 (list '(0 0) (selected-window)))
1788 ;; Append list of fontsets currently defined.
1789 (append x-fixed-font-alist
(list (generate-fontset-menu))))))
1795 (set-frame-font (car fonts
))
1796 (setq font
(car fonts
))
1799 (setq fonts
(cdr fonts
)))))
1801 (error "Font not found")))))
1803 (defvar mouse-appearance-menu-map nil
)
1804 (declare-function x-select-font
"xfns.c" (&optional frame ignored
)) ; USE_GTK
1805 (declare-function buffer-face-mode-invoke
"face-remap"
1806 (face arg
&optional interactive
))
1807 (declare-function font-face-attributes
"font.c" (font &optional frame
))
1809 (defun mouse-appearance-menu (event)
1810 "Show a menu for changing the default face in the current buffer."
1812 (require 'face-remap
)
1813 (when (display-multi-font-p)
1814 (with-selected-window (car (event-start event
))
1815 (if mouse-appearance-menu-map
1816 nil
; regenerate new fonts
1817 ;; Initialize mouse-appearance-menu-map
1818 (setq mouse-appearance-menu-map
1819 (make-sparse-keymap "Change Default Buffer Face"))
1820 (define-key mouse-appearance-menu-map
[face-remap-reset-base
]
1821 '(menu-item "Reset to Default" face-remap-reset-base
))
1822 (define-key mouse-appearance-menu-map
[text-scale-decrease
]
1823 '(menu-item "Decrease Buffer Text Size" text-scale-decrease
))
1824 (define-key mouse-appearance-menu-map
[text-scale-increase
]
1825 '(menu-item "Increase Buffer Text Size" text-scale-increase
))
1827 (if (functionp 'x-select-font
)
1828 (define-key mouse-appearance-menu-map
[x-select-font
]
1829 '(menu-item "Change Buffer Font..." x-select-font
))
1830 ;; If the select-font is unavailable, construct a menu.
1831 (let ((font-submenu (make-sparse-keymap "Change Text Font"))
1832 (font-alist (cdr (append x-fixed-font-alist
1833 (list (generate-fontset-menu))))))
1834 (dolist (family font-alist
)
1835 (let* ((submenu-name (car family
))
1836 (submenu-map (make-sparse-keymap submenu-name
)))
1837 (dolist (font (cdr family
))
1838 (let ((font-name (car font
))
1840 (if (string= font-name
"")
1841 (define-key submenu-map
[space]
1843 (setq font-symbol (intern (cadr font)))
1844 (define-key submenu-map (vector font-symbol)
1845 (list 'menu-item (car font) font-symbol)))))
1846 (define-key font-submenu (vector (intern submenu-name))
1847 (list 'menu-item submenu-name submenu-map))))
1848 (define-key mouse-appearance-menu-map [font-submenu]
1849 (list 'menu-item "Change Text Font" font-submenu)))))
1850 (let ((choice (x-popup-menu event mouse-appearance-menu-map)))
1851 (setq choice (nth (1- (length choice)) choice))
1852 (cond ((eq choice 'text-scale-increase)
1853 (text-scale-increase 1))
1854 ((eq choice 'text-scale-decrease)
1855 (text-scale-increase -1))
1856 ((eq choice 'face-remap-reset-base)
1858 (buffer-face-mode 0))
1860 ;; Either choice == 'x-select-font, or choice is a
1861 ;; symbol whose name is a font.
1862 (let ((font (if (eq choice 'x-select-font)
1864 (symbol-name choice))))
1865 (buffer-face-mode-invoke
1866 (if (fontp font 'font-spec)
1868 (font-face-attributes font))
1869 t (called-interactively-p 'interactive)))))))))
1872 ;;; Bindings for mouse commands.
1874 (global-set-key [down-mouse-1] 'mouse-drag-region)
1875 (global-set-key [mouse-1] 'mouse-set-point)
1876 (global-set-key [drag-mouse-1] 'mouse-set-region)
1878 (defun mouse--strip-first-event (_prompt)
1879 (substring (this-single-command-raw-keys) 1))
1881 (define-key function-key-map [left-fringe mouse-1] 'mouse--strip-first-event)
1882 (define-key function-key-map [right-fringe mouse-1] 'mouse--strip-first-event)
1884 (global-set-key [mouse-2] 'mouse-yank-primary)
1885 ;; Allow yanking also when the corresponding cursor is "in the fringe".
1886 (define-key function-key-map [right-fringe mouse-2] 'mouse--strip-first-event)
1887 (define-key function-key-map [left-fringe mouse-2] 'mouse--strip-first-event)
1888 (global-set-key [mouse-3] 'mouse-save-then-kill)
1889 (define-key function-key-map [right-fringe mouse-3] 'mouse--strip-first-event)
1890 (define-key function-key-map [left-fringe mouse-3] 'mouse--strip-first-event)
1892 ;; By binding these to down-going events, we let the user use the up-going
1893 ;; event to make the selection, saving a click.
1894 (global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
1895 (if (not (eq system-type 'ms-dos))
1896 (global-set-key [S-down-mouse-1] 'mouse-appearance-menu))
1897 ;; C-down-mouse-2 is bound in facemenu.el.
1898 (global-set-key [C-down-mouse-3]
1899 `(menu-item ,(purecopy "Menu Bar") ignore
1901 (if (zerop (or (frame-parameter nil 'menu-bar-lines) 0))
1902 (mouse-menu-bar-map)
1903 (mouse-menu-major-mode-map)))))
1905 ;; Binding mouse-1 to mouse-select-window when on mode-, header-, or
1906 ;; vertical-line prevents Emacs from signaling an error when the mouse
1907 ;; button is released after dragging these lines, on non-toolkit
1909 (global-set-key [mode-line mouse-1] 'mouse-select-window)
1910 (global-set-key [mode-line drag-mouse-1] 'mouse-select-window)
1911 (global-set-key [mode-line down-mouse-1] 'mouse-drag-mode-line)
1912 (global-set-key [header-line down-mouse-1] 'mouse-drag-header-line)
1913 (global-set-key [header-line mouse-1] 'mouse-select-window)
1914 (global-set-key [mode-line mouse-2] 'mouse-delete-other-windows)
1915 (global-set-key [mode-line mouse-3] 'mouse-delete-window)
1916 (global-set-key [mode-line C-mouse-2] 'mouse-split-window-horizontally)
1917 (global-set-key [vertical-scroll-bar C-mouse-2] 'mouse-split-window-vertically)
1918 (global-set-key [vertical-line C-mouse-2] 'mouse-split-window-vertically)
1919 (global-set-key [vertical-line down-mouse-1] 'mouse-drag-vertical-line)
1920 (global-set-key [right-divider down-mouse-1] 'mouse-drag-vertical-line)
1921 (global-set-key [bottom-divider down-mouse-1] 'mouse-drag-mode-line)
1922 (global-set-key [vertical-line mouse-1] 'mouse-select-window)
1926 ;;; mouse.el ends here