1 ;;; mouse.el --- window system-independent mouse support
3 ;; Copyright (C) 1993, 1994, 1995, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
7 ;; 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, mouse drag copies region to kill-ring."
50 (defcustom mouse-1-click-follows-link 450
51 "Non-nil means that clicking Mouse-1 on a link follows the link.
53 With the default setting, an ordinary Mouse-1 click on a link
54 performs the same action as Mouse-2 on that link, while a longer
55 Mouse-1 click \(hold down the Mouse-1 button for more than 450
56 milliseconds) performs the original Mouse-1 binding \(which
57 typically sets point where you click the mouse).
59 If value is an integer, the time elapsed between pressing and
60 releasing the mouse button determines whether to follow the link
61 or perform the normal Mouse-1 action (typically set point).
62 The absolute numeric value specifices the maximum duration of a
63 \"short click\" in milliseconds. A positive value means that a
64 short click follows the link, and a longer click performs the
65 normal action. A negative value gives the opposite behavior.
67 If value is `double', a double click follows the link.
69 Otherwise, a single Mouse-1 click unconditionally follows the link.
71 Note that dragging the mouse never follows the link.
73 This feature only works in modes that specifically identify
74 clickable text as links, so it may not work with some external
75 packages. See `mouse-on-link-p' for details."
77 :type '(choice (const :tag "Disabled" nil)
78 (const :tag "Double click" double)
79 (number :tag "Single click time limit" :value 450)
80 (other :tag "Single click" t))
83 (defcustom mouse-1-click-in-non-selected-windows t
84 "If non-nil, a Mouse-1 click also follows links in non-selected windows.
86 If nil, a Mouse-1 click on a link in a non-selected window performs
87 the normal mouse-1 binding, typically selects the window and sets
88 point at the click position."
95 ;; Provide a mode-specific menu on a mouse button.
97 (defun popup-menu (menu &optional position prefix)
98 "Popup the given menu and call the selected option.
99 MENU can be a keymap, an easymenu-style menu or a list of keymaps as for
101 POSITION can be a click event or ((XOFFSET YOFFSET) WINDOW) and defaults to
102 the current mouse position.
103 PREFIX is the prefix argument (if any) to pass to the command."
105 ((keymapp menu) menu)
106 ((and (listp menu) (keymapp (car menu))) menu)
107 (t (let* ((map (easy-menu-create-menu (car menu) (cdr menu)))
108 (filter (when (symbolp map)
109 (plist-get (get map 'menu-prop) :filter))))
110 (if filter (funcall filter (symbol-function map)) map)))))
113 (let ((mp (mouse-pixel-position)))
114 (setq position (list (list (cadr mp) (cddr mp)) (car mp)))))
115 ;; The looping behavior was taken from lmenu's popup-menu-popup
116 (while (and map (setq event
117 ;; map could be a prefix key, in which case
118 ;; we need to get its function cell
120 (x-popup-menu position (indirect-function map))))
121 ;; Strangely x-popup-menu returns a list.
122 ;; mouse-major-mode-menu was using a weird:
123 ;; (key-binding (apply 'vector (append '(menu-bar) menu-prefix events)))
125 (if (and (not (keymapp map)) (listp map))
126 ;; We were given a list of keymaps. Search them all
127 ;; in sequence until a first binding is found.
128 (let ((mouse-click (apply 'vector event))
130 (while (and map (null binding))
131 (setq binding (lookup-key (car map) mouse-click))
132 (if (numberp binding) ; `too long'
134 (setq map (cdr map)))
136 ;; We were given a single keymap.
137 (lookup-key map (apply 'vector event))))
138 ;; Clear out echoing, which perhaps shows a prefix arg.
140 ;; Maybe try again but with the submap.
141 (setq map (if (keymapp cmd) cmd)))
142 ;; If the user did not cancel by refusing to select,
143 ;; and if the result is a command, run it.
144 (when (and (null map) (commandp cmd))
145 (setq prefix-arg prefix)
146 ;; `setup-specified-language-environment', for instance,
147 ;; expects this to be set from a menu keymap.
148 (setq last-command-event (car (last event)))
149 ;; mouse-major-mode-menu was using `command-execute' instead.
150 (call-interactively cmd))))
152 (defun minor-mode-menu-from-indicator (indicator)
153 "Show menu for minor mode specified by INDICATOR.
154 Interactively, INDICATOR is read using completion.
155 If there is no menu defined for the minor mode, then create one with
156 items `Turn Off' and `Help'."
158 (list (completing-read
159 "Minor mode indicator: "
160 (describe-minor-mode-completion-table-for-indicator))))
161 (let* ((minor-mode (lookup-minor-mode-from-indicator indicator))
162 (mm-fun (or (get minor-mode :minor-mode-function) minor-mode)))
163 (unless minor-mode (error "Cannot find minor mode for `%s'" indicator))
164 (let* ((map (cdr-safe (assq minor-mode minor-mode-map-alist)))
165 (menu (and (keymapp map) (lookup-key map [menu-bar]))))
168 (mouse-menu-non-singleton menu)
171 (turn-off menu-item "Turn Off minor mode" ,mm-fun)
172 (help menu-item "Help for minor mode"
173 (lambda () (interactive)
174 (describe-function ',mm-fun))))))
177 (defun mouse-minor-mode-menu (event)
178 "Show minor-mode menu for EVENT on minor modes area of the mode line."
180 (let ((indicator (car (nth 4 (car (cdr event))))))
181 (minor-mode-menu-from-indicator indicator)))
183 (defun mouse-menu-major-mode-map ()
184 (let* (;; Keymap from which to inherit; may be null.
185 (ancestor (mouse-menu-non-singleton
186 (and (current-local-map)
187 (local-key-binding [menu-bar]))))
188 ;; Make a keymap in which our last command leads to a menu or
189 ;; default to the edit menu.
191 (make-sparse-keymap (concat (format-mode-line mode-name)
196 (set-keymap-parent newmap ancestor))
199 (defun mouse-menu-non-singleton (menubar)
201 if it defines exactly one submenu, return just that submenu.
202 Otherwise return the whole menu."
206 (lambda (k v) (setq submap (if submap t (cons k v))))
207 (keymap-canonicalize menubar))
210 (lookup-key menubar (vector (car submap)))))))
212 (defun mouse-menu-bar-map ()
213 "Return a keymap equivalent to the menu bar.
214 The contents are the items that would be in the menu bar whether or
215 not it is actually displayed."
216 (let* ((local-menu (and (current-local-map)
217 (lookup-key (current-local-map) [menu-bar])))
218 (global-menu (lookup-key global-map [menu-bar]))
219 ;; If a keymap doesn't have a prompt string (a lazy
220 ;; programmer didn't bother to provide one), create it and
221 ;; insert it into the keymap; each keymap gets its own
222 ;; prompt. This is required for non-toolkit versions to
223 ;; display non-empty menu pane names.
227 (let* ((minor-mode (car menu))
229 (title-or-map (cadr menu)))
230 (or (stringp title-or-map)
234 (capitalize (subst-char-in-string
240 (minor-mode-key-binding [menu-bar])))
241 (local-title-or-map (and local-menu (cadr local-menu)))
242 (global-title-or-map (cadr global-menu)))
243 (or (null local-menu)
244 (stringp local-title-or-map)
245 (setq local-menu (cons 'keymap
246 (cons (concat (format-mode-line mode-name)
249 (or (stringp global-title-or-map)
250 (setq global-menu (cons 'keymap
252 (cdr global-menu)))))
253 ;; Supplying the list is faster than making a new map.
254 ;; FIXME: We have a problem here: we have to use the global/local/minor
255 ;; so they're displayed in the expected order, but later on in the command
256 ;; loop, they're actually looked up in the opposite order.
262 (defun mouse-major-mode-menu (event &optional prefix)
263 "Pop up a mode-specific menu of mouse commands.
264 Default to the Edit menu if the major mode doesn't define a menu."
265 (interactive "@e\nP")
266 (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
267 (popup-menu (mouse-menu-major-mode-map) event prefix))
268 (make-obsolete 'mouse-major-mode-menu 'mouse-menu-major-mode-map "23.1")
270 (defun mouse-popup-menubar (event prefix)
271 "Pop up a menu equivalent to the menu bar for keyboard EVENT with PREFIX.
272 The contents are the items that would be in the menu bar whether or
273 not it is actually displayed."
274 (interactive "@e \nP")
275 (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
276 (popup-menu (mouse-menu-bar-map) event prefix))
277 (make-obsolete 'mouse-popup-menubar 'mouse-menu-bar-map "23.1")
279 (defun mouse-popup-menubar-stuff (event prefix)
280 "Popup a menu like either `mouse-major-mode-menu' or `mouse-popup-menubar'.
281 Use the former if the menu bar is showing, otherwise the latter."
282 (interactive "@e\nP")
283 (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
285 (if (zerop (or (frame-parameter nil 'menu-bar-lines) 0))
287 (mouse-menu-major-mode-map))
289 (make-obsolete 'mouse-popup-menubar-stuff nil "23.1")
291 ;; Commands that operate on windows.
293 (defun mouse-minibuffer-check (event)
294 (let ((w (posn-window (event-start event))))
295 (and (window-minibuffer-p w)
296 (not (minibuffer-window-active-p w))
297 (error "Minibuffer window is not active")))
298 ;; Give temporary modes such as isearch a chance to turn off.
299 (run-hooks 'mouse-leave-buffer-hook))
301 (defun mouse-delete-window (click)
302 "Delete the window you click on.
303 Do nothing if the frame has just one window.
304 This command must be bound to a mouse click."
306 (unless (one-window-p t)
307 (mouse-minibuffer-check click)
308 (delete-window (posn-window (event-start click)))))
310 (defun mouse-select-window (click)
311 "Select the window clicked on; don't move point."
313 (mouse-minibuffer-check click)
314 (let ((oframe (selected-frame))
315 (frame (window-frame (posn-window (event-start click)))))
316 (select-window (posn-window (event-start click)))
319 (or (eq frame oframe)
320 (set-mouse-position (selected-frame) (1- (frame-width)) 0))))
322 (defun mouse-tear-off-window (click)
323 "Delete the window clicked on, and create a new frame displaying its buffer."
325 (mouse-minibuffer-check click)
326 (let* ((window (posn-window (event-start click)))
327 (buf (window-buffer window))
328 (frame (make-frame)))
330 (switch-to-buffer buf)
331 (delete-window window)))
333 (defun mouse-delete-other-windows ()
334 "Delete all windows except the one you click on."
336 (delete-other-windows))
338 (defun mouse-split-window-vertically (click)
339 "Select Emacs window mouse is on, then split it vertically in half.
340 The window is split at the line clicked on.
341 This command must be bound to a mouse click."
343 (mouse-minibuffer-check click)
344 (let ((start (event-start click)))
345 (select-window (posn-window start))
346 (let ((new-height (1+ (cdr (posn-col-row (event-end click)))))
347 (first-line window-min-height)
348 (last-line (- (window-height) window-min-height)))
349 (if (< last-line first-line)
350 (error "Window too short to split")
351 (split-window-vertically
352 (min (max new-height first-line) last-line))))))
354 (defun mouse-split-window-horizontally (click)
355 "Select Emacs window mouse is on, then split it horizontally in half.
356 The window is split at the column clicked on.
357 This command must be bound to a mouse click."
359 (mouse-minibuffer-check click)
360 (let ((start (event-start click)))
361 (select-window (posn-window start))
362 (let ((new-width (1+ (car (posn-col-row (event-end click)))))
363 (first-col window-min-width)
364 (last-col (- (window-width) window-min-width)))
365 (if (< last-col first-col)
366 (error "Window too narrow to split")
367 (split-window-horizontally
368 (min (max new-width first-col) last-col))))))
370 (defun mouse-drag-window-above (window)
371 "Return the (or a) window directly above WINDOW.
372 That means one whose bottom edge is at the same height as WINDOW's top edge."
373 (let ((start-top (nth 1 (window-edges window)))
374 (start-left (nth 0 (window-edges window)))
375 (start-right (nth 2 (window-edges window)))
376 (start-window window)
378 (setq window (previous-window window 0))
379 (while (and (not above-window) (not (eq window start-window)))
380 (let ((left (nth 0 (window-edges window)))
381 (right (nth 2 (window-edges window))))
382 (when (and (= (+ (window-height window) (nth 1 (window-edges window)))
384 (or (and (<= left start-left) (<= start-right right))
385 (and (<= start-left left) (<= left start-right))
386 (and (<= start-left right) (<= right start-right))))
387 (setq above-window window)))
388 (setq window (previous-window window)))
391 (defun mouse-drag-move-window-bottom (window growth)
392 "Move the bottom of WINDOW up or down by GROWTH lines.
393 Move it down if GROWTH is positive, or up if GROWTH is negative.
394 If this would make WINDOW too short,
395 shrink the window or windows above it to make room."
397 (adjust-window-trailing-edge window growth nil)
400 (defsubst mouse-drag-move-window-top (window growth)
401 "Move the top of WINDOW up or down by GROWTH lines.
402 Move it down if GROWTH is positive, or up if GROWTH is negative.
403 If this would make WINDOW too short, shrink the window or windows
404 above it to make room."
405 ;; Moving the top of WINDOW is actually moving the bottom of the
407 (let ((window-above (mouse-drag-window-above window)))
409 (mouse-drag-move-window-bottom window-above (- growth)))))
411 (defun mouse-drag-mode-line-1 (start-event mode-line-p)
412 "Change the height of a window by dragging on the mode or header line.
413 START-EVENT is the starting mouse-event of the drag action.
414 MODE-LINE-P non-nil means dragging a mode line; nil means a header line."
415 ;; Give temporary modes such as isearch a chance to turn off.
416 (run-hooks 'mouse-leave-buffer-hook)
419 (start (event-start start-event))
420 (start-event-window (posn-window start))
421 (start-event-frame (window-frame start-event-window))
422 (start-nwindows (count-windows t))
423 (on-link (and mouse-1-click-follows-link
424 (or mouse-1-click-in-non-selected-windows
425 (eq (posn-window start) (selected-window)))
426 (mouse-on-link-p start)))
427 (minibuffer (frame-parameter nil 'minibuffer))
428 should-enlarge-minibuffer event mouse y top bot edges wconfig growth)
431 ;; if this is the bottommost ordinary window, then to
432 ;; move its modeline the minibuffer must be enlarged.
433 (setq should-enlarge-minibuffer
436 (not (one-window-p t))
437 (= (nth 1 (window-edges minibuffer))
438 (nth 3 (window-edges start-event-window)))))
440 ;; loop reading events and sampling the position of
443 (setq event (read-event)
444 mouse (mouse-position))
447 ;; - there is a switch-frame event.
448 ;; - the mouse isn't in the frame that we started in
449 ;; - the mouse isn't in any Emacs frame
451 ;; - there is a mouse-movement event
452 ;; - there is a scroll-bar-movement event
453 ;; (same as mouse movement for our purposes)
455 ;; - there is a keyboard event or some other unknown event.
456 (cond ((not (consp event))
459 ((memq (car event) '(switch-frame select-window))
462 ((not (memq (car event) '(mouse-movement scroll-bar-movement)))
464 ;; Do not unread a drag-mouse-1 event since it will cause the
465 ;; selection of the window above when dragging the modeline
466 ;; above the selected window.
467 (unless (eq (car event) 'drag-mouse-1)
468 (push event unread-command-events)))
471 ((not (eq (car mouse) start-event-frame))
474 ((null (car (cdr mouse)))
478 (setq y (cdr (cdr mouse))
479 edges (window-edges start-event-window)
483 ;; compute size change needed
485 (setq growth (- y bot -1)))
487 (when (< (- bot y) window-min-height)
488 (setq y (- bot window-min-height)))
489 ;; The window's top includes the header line!
490 (setq growth (- top y))))
491 (setq wconfig (current-window-configuration))
493 ;; Check for an error case.
494 (when (and (/= growth 0)
497 (error "Attempt to resize sole window"))
499 ;; If we ever move, make sure we don't mistakenly treat
500 ;; some unexpected `mouse-1' final event as a sign that
501 ;; this whole drag was nothing more than a click.
502 (if (/= growth 0) (setq on-link nil))
504 ;; grow/shrink minibuffer?
505 (if should-enlarge-minibuffer
506 (unless resize-mini-windows
507 (mouse-drag-move-window-bottom start-event-window growth))
508 ;; no. grow/shrink the selected window
509 ;(message "growth = %d" growth)
511 (mouse-drag-move-window-bottom start-event-window growth)
512 (mouse-drag-move-window-top start-event-window growth)))
514 ;; if this window's growth caused another
515 ;; window to be deleted because it was too
516 ;; short, rescind the change.
518 ;; if size change caused space to be stolen
519 ;; from a window above this one, rescind the
520 ;; change, but only if we didn't grow/shrink
521 ;; the minibuffer. minibuffer size changes
522 ;; can cause all windows to shrink... no way
524 (when (or (/= start-nwindows (count-windows t))
525 (and (not should-enlarge-minibuffer)
530 ;; Choose right window.
531 start-event-window)))))
532 (set-window-configuration wconfig)))))
534 ;; Presumably if this was just a click, the last event should
535 ;; be `mouse-1', whereas if this did move the mouse, it should be
536 ;; a `drag-mouse-1'. In any case `on-link' would have been nulled
537 ;; above if there had been any significant mouse movement.
538 (when (and on-link (eq 'mouse-1 (car-safe event)))
539 (push (cons 'mouse-2 (cdr event)) unread-command-events))))))
541 (defun mouse-drag-mode-line (start-event)
542 "Change the height of a window by dragging on the mode line."
544 (mouse-drag-mode-line-1 start-event t))
546 (defun mouse-drag-header-line (start-event)
547 "Change the height of a window by dragging on the header line.
548 Windows whose header-lines are at the top of the frame cannot be
549 resized by dragging their header-line."
551 ;; Changing the window's size by dragging its header-line when the
552 ;; header-line is at the top of the frame is somewhat strange,
553 ;; because the header-line doesn't move, so don't do it.
554 (let* ((start (event-start start-event))
555 (window (posn-window start))
556 (frame (window-frame window))
557 (first-window (frame-first-window frame)))
558 (unless (or (eq window first-window)
559 (= (nth 1 (window-edges window))
560 (nth 1 (window-edges first-window))))
561 (mouse-drag-mode-line-1 start-event nil))))
564 (defun mouse-drag-vertical-line-rightward-window (window)
565 "Return a window that is immediately to the right of WINDOW, or nil."
566 (let ((bottom (nth 3 (window-inside-edges window)))
567 (left (nth 0 (window-inside-edges window)))
569 (try (previous-window window)))
570 (while (not (eq try window))
571 (let ((try-top (nth 1 (window-inside-edges try)))
572 (try-bottom (nth 3 (window-inside-edges try)))
573 (try-right (nth 2 (window-inside-edges try))))
574 (if (and (< try-top bottom)
575 (>= try-bottom bottom)
577 (or (null best-right) (> try-right best-right)))
578 (setq best-right try-right best try)))
579 (setq try (previous-window try)))
582 (defun mouse-drag-vertical-line (start-event)
583 "Change the width of a window by dragging on the vertical line."
585 ;; Give temporary modes such as isearch a chance to turn off.
586 (run-hooks 'mouse-leave-buffer-hook)
589 (start-event-frame (window-frame (car (car (cdr start-event)))))
590 (start-event-window (car (car (cdr start-event))))
591 event mouse x left right edges growth
593 (or (cdr (assq 'vertical-scroll-bars (frame-parameters start-event-frame)))
597 (error "Attempt to resize sole ordinary window"))
598 ((and (eq which-side 'right)
599 (>= (nth 2 (window-inside-edges start-event-window))
600 (frame-width start-event-frame)))
601 (error "Attempt to drag rightmost scrollbar"))
602 ((and (eq which-side 'left)
603 (= (nth 0 (window-inside-edges start-event-window)) 0))
604 (error "Attempt to drag leftmost scrollbar")))
607 ;; loop reading events and sampling the position of
610 (setq event (read-event)
611 mouse (mouse-position))
613 ;; - there is a switch-frame event.
614 ;; - the mouse isn't in the frame that we started in
615 ;; - the mouse isn't in any Emacs frame
617 ;; - there is a mouse-movement event
618 ;; - there is a scroll-bar-movement event
619 ;; (same as mouse movement for our purposes)
621 ;; - there is a keyboard event or some other unknown event
623 (cond ((integerp event)
625 ((memq (car event) '(switch-frame select-window))
627 ((not (memq (car event)
628 '(mouse-movement scroll-bar-movement)))
630 (setq unread-command-events
631 (cons event unread-command-events)))
633 ((not (eq (car mouse) start-event-frame))
635 ((null (car (cdr mouse)))
639 ;; If the scroll bar is on the window's left,
640 ;; adjust the window on the left.
641 (if (eq which-side 'right)
643 (mouse-drag-vertical-line-rightward-window
644 start-event-window))))
645 (setq x (- (car (cdr mouse))
646 (if (eq which-side 'right) 0 2))
647 edges (window-edges window)
650 ;; scale back a move that would make the
652 (if (< (- x left -1) window-min-width)
653 (setq x (+ left window-min-width -1)))
654 ;; compute size change needed
655 (setq growth (- x right -1))
657 (adjust-window-trailing-edge window growth t)
660 (defun mouse-set-point (event)
661 "Move point to the position clicked on with the mouse.
662 This should be bound to a mouse click event type."
664 (mouse-minibuffer-check event)
665 ;; Use event-end in case called from mouse-drag-region.
666 ;; If EVENT is a click, event-end and event-start give same value.
667 (posn-set-point (event-end event)))
669 (defvar mouse-last-region-beg nil)
670 (defvar mouse-last-region-end nil)
671 (defvar mouse-last-region-tick nil)
673 (defun mouse-region-match ()
674 "Return non-nil if there's an active region that was set with the mouse."
675 (and (mark t) mark-active
676 (eq mouse-last-region-beg (region-beginning))
677 (eq mouse-last-region-end (region-end))
678 (eq mouse-last-region-tick (buffer-modified-tick))))
680 (defun mouse-set-region (click)
681 "Set the region to the text dragged over, and copy to kill ring.
682 This should be bound to a mouse drag event."
684 (mouse-minibuffer-check click)
685 (select-window (posn-window (event-start click)))
686 (let ((beg (posn-point (event-start click)))
687 (end (posn-point (event-end click))))
688 (and mouse-drag-copy-region (integerp beg) (integerp end)
689 ;; Don't set this-command to `kill-region', so a following
690 ;; C-w won't double the text in the kill ring. Ignore
691 ;; `last-command' so we don't append to a preceding kill.
692 (let (this-command last-command deactivate-mark)
693 (copy-region-as-kill beg end)))
694 (if (numberp beg) (goto-char beg))
695 ;; On a text terminal, bounce the cursor.
696 (or transient-mark-mode
701 (if (numberp end) (goto-char end))
702 (mouse-set-region-1)))
704 (defun mouse-set-region-1 ()
705 ;; Set transient-mark-mode for a little while.
706 (unless (eq (car-safe transient-mark-mode) 'only)
707 (setq transient-mark-mode
709 (unless (eq transient-mark-mode 'lambda)
710 transient-mark-mode))))
711 (setq mouse-last-region-beg (region-beginning))
712 (setq mouse-last-region-end (region-end))
713 (setq mouse-last-region-tick (buffer-modified-tick)))
715 (defcustom mouse-scroll-delay 0.25
716 "The pause between scroll steps caused by mouse drags, in seconds.
717 If you drag the mouse beyond the edge of a window, Emacs scrolls the
718 window to bring the text beyond that edge into view, with a delay of
719 this many seconds between scroll steps. Scrolling stops when you move
720 the mouse back into the window, or release the button.
721 This variable's value may be non-integral.
722 Setting this to zero causes Emacs to scroll as fast as it can."
726 (defcustom mouse-scroll-min-lines 1
727 "The minimum number of lines scrolled by dragging mouse out of window.
728 Moving the mouse out the top or bottom edge of the window begins
729 scrolling repeatedly. The number of lines scrolled per repetition
730 is normally equal to the number of lines beyond the window edge that
731 the mouse has moved. However, it always scrolls at least the number
732 of lines specified by this variable."
736 (defun mouse-scroll-subr (window jump &optional overlay start)
737 "Scroll the window WINDOW, JUMP lines at a time, until new input arrives.
738 If OVERLAY is an overlay, let it stretch from START to the far edge of
739 the newly visible text.
740 Upon exit, point is at the far edge of the newly visible text."
742 ((and (> jump 0) (< jump mouse-scroll-min-lines))
743 (setq jump mouse-scroll-min-lines))
744 ((and (< jump 0) (< (- jump) mouse-scroll-min-lines))
745 (setq jump (- mouse-scroll-min-lines))))
746 (let ((opoint (point)))
748 (goto-char (window-start window))
749 (if (not (zerop (vertical-motion jump window)))
751 (set-window-start window (point))
753 (if (window-end window)
755 (goto-char (window-end window))
756 ;; window-end doesn't reflect the window's new
757 ;; start position until the next redisplay.
758 (vertical-motion (1- jump) window))
759 (vertical-motion (- (window-height window) 2)))
760 (goto-char (window-start window)))
762 (move-overlay overlay start (point)))
763 ;; Now that we have scrolled WINDOW properly,
764 ;; put point back where it was for the redisplay
765 ;; so that we don't mess up the selected window.
766 (or (eq window (selected-window))
768 (sit-for mouse-scroll-delay)))))
769 (or (eq window (selected-window))
770 (goto-char opoint))))
772 (defvar mouse-selection-click-count 0)
774 (defvar mouse-selection-click-count-buffer nil)
776 (defun mouse-drag-region (start-event)
777 "Set the region to the text that the mouse is dragged over.
778 Highlight the drag area as you move the mouse.
779 This must be bound to a button-down mouse event.
780 In Transient Mark mode, the highlighting remains as long as the mark
781 remains active. Otherwise, it remains until the next input event.
783 If the click is in the echo area, display the `*Messages*' buffer."
785 (let ((w (posn-window (event-start start-event))))
786 (if (and (window-minibuffer-p w)
787 (not (minibuffer-window-active-p w)))
789 ;; Swallow the up-event.
791 (set-buffer (get-buffer-create "*Messages*"))
792 (goto-char (point-max))
793 (display-buffer (current-buffer)))
794 ;; Give temporary modes such as isearch a chance to turn off.
795 (run-hooks 'mouse-leave-buffer-hook)
796 (mouse-drag-track start-event t))))
799 (defun mouse-posn-property (pos property)
800 "Look for a property at click position.
801 POS may be either a buffer position or a click position like
802 those returned from `event-start'. If the click position is on
803 a string, the text property PROPERTY is examined.
804 If this is nil or the click is not on a string, then
805 the corresponding buffer position is searched for PROPERTY.
806 If PROPERTY is encountered in one of those places,
807 its value is returned."
809 (let ((w (posn-window pos)) (pt (posn-point pos))
810 (str (posn-string pos)))
812 (get-text-property (cdr str) property (car str)))
814 (get-char-property pt property w))))
815 (get-char-property pos property)))
817 (defun mouse-on-link-p (pos)
818 "Return non-nil if POS is on a link in the current buffer.
819 POS must be a buffer position in the current buffer or a mouse
820 event location in the selected window (see `event-start').
821 However, if `mouse-1-click-in-non-selected-windows' is non-nil,
822 POS may be a mouse event location in any window.
824 A clickable link is identified by one of the following methods:
826 - If the character at POS has a non-nil `follow-link' text or
827 overlay property, the value of that property determines what to do.
829 - If there is a local key-binding or a keybinding at position POS
830 for the `follow-link' event, the binding of that event determines
833 The resulting value determine whether POS is inside a link:
835 - If the value is `mouse-face', POS is inside a link if there
836 is a non-nil `mouse-face' property at POS. Return t in this case.
838 - If the value is a function, FUNC, POS is inside a link if
839 the call \(FUNC POS) returns non-nil. Return the return value
840 from that call. Arg is \(posn-point POS) if POS is a mouse event.
842 - Otherwise, return the value itself.
844 The return value is interpreted as follows:
846 - If it is a string, the mouse-1 event is translated into the
847 first character of the string, i.e. the action of the mouse-1
848 click is the local or global binding of that character.
850 - If it is a vector, the mouse-1 event is translated into the
851 first element of that vector, i.e. the action of the mouse-1
852 click is the local or global binding of that event.
854 - Otherwise, the mouse-1 event is translated into a mouse-2 event
855 at the same position."
857 (and (or (not (consp pos))
858 mouse-1-click-in-non-selected-windows
859 (eq (selected-window) (posn-window pos)))
860 (or (mouse-posn-property pos 'follow-link)
861 (key-binding [follow-link] nil t pos)))))
863 ((eq action 'mouse-face)
864 (and (mouse-posn-property pos 'mouse-face) t))
866 ;; FIXME: This seems questionable if the click is not in a buffer.
867 ;; Should we instead decide that `action' takes a `posn'?
869 (with-current-buffer (window-buffer (posn-window pos))
870 (funcall action (posn-point pos)))
871 (funcall action pos)))
874 (defun mouse-fixup-help-message (msg)
875 "Fix help message MSG for `mouse-1-click-follows-link'."
877 (if (and mouse-1-click-follows-link
879 (string-match-p "\\`mouse-2" msg)
880 (setq mp (mouse-pixel-position))
881 (consp (setq pos (cdr mp)))
882 (car pos) (>= (car pos) 0)
883 (cdr pos) (>= (cdr pos) 0)
884 (setq pos (posn-at-x-y (car pos) (cdr pos) (car mp)))
885 (windowp (posn-window pos)))
886 (with-current-buffer (window-buffer (posn-window pos))
887 (if (mouse-on-link-p pos)
890 ((eq mouse-1-click-follows-link 'double) "double-")
891 ((and (integerp mouse-1-click-follows-link)
892 (< mouse-1-click-follows-link 0)) "Long ")
894 "mouse-1" (substring msg 7)))))))
897 (defun mouse-drag-track (start-event &optional
898 do-mouse-drag-region-post-process)
899 "Track mouse drags by highlighting area between point and cursor.
900 The region will be defined with mark and point.
901 DO-MOUSE-DRAG-REGION-POST-PROCESS should only be used by
902 `mouse-drag-region'."
903 (mouse-minibuffer-check start-event)
904 (setq mouse-selection-click-count-buffer (current-buffer))
906 (let* ((original-window (selected-window))
907 ;; We've recorded what we needed from the current buffer and
908 ;; window, now let's jump to the place of the event, where things
910 (_ (mouse-set-point start-event))
912 (start-posn (event-start start-event))
913 (start-point (posn-point start-posn))
914 (start-window (posn-window start-posn))
915 (start-window-start (window-start start-window))
916 (start-hscroll (window-hscroll start-window))
917 (bounds (window-edges start-window))
918 (make-cursor-line-fully-visible nil)
920 (bottom (if (window-minibuffer-p start-window)
922 ;; Don't count the mode line.
923 (1- (nth 3 bounds))))
924 (on-link (and mouse-1-click-follows-link
925 (or mouse-1-click-in-non-selected-windows
926 (eq start-window original-window))
927 ;; Use start-point before the intangibility
928 ;; treatment, in case we click on a link inside an
930 (mouse-on-link-p start-posn)))
931 (click-count (1- (event-click-count start-event)))
932 (remap-double-click (and on-link
933 (eq mouse-1-click-follows-link 'double)
935 ;; Suppress automatic hscrolling, because that is a nuisance
936 ;; when setting point near the right fringe (but see below).
937 (automatic-hscrolling-saved automatic-hscrolling)
938 (automatic-hscrolling nil)
941 (setq mouse-selection-click-count click-count)
942 ;; In case the down click is in the middle of some intangible text,
943 ;; use the end of that text, and put it in START-POINT.
944 (if (< (point) start-point)
945 (goto-char start-point))
946 (setq start-point (point))
947 (if remap-double-click
948 (setq click-count 0))
950 ;; Activate the region, using `mouse-start-end' to determine where
951 ;; to put point and mark (e.g., double-click will select a word).
952 (setq transient-mark-mode
953 (if (eq transient-mark-mode 'lambda)
955 (cons 'only transient-mark-mode)))
956 (let ((range (mouse-start-end start-point start-point click-count)))
957 (goto-char (nth 0 range))
959 (goto-char (nth 1 range)))
961 ;; Track the mouse until we get a non-movement event.
964 (setq event (read-event))
965 (or (mouse-movement-p event)
966 (memq (car-safe event) '(switch-frame select-window))))
967 (unless (memq (car-safe event) '(switch-frame select-window))
968 ;; Automatic hscrolling did not occur during the call to
969 ;; `read-event'; but if the user subsequently drags the
970 ;; mouse, go ahead and hscroll.
971 (let ((automatic-hscrolling automatic-hscrolling-saved))
973 (setq end (event-end event)
974 end-point (posn-point end))
975 (if (and (eq (posn-window end) start-window)
976 (integer-or-marker-p end-point))
977 ;; If moving in the original window, move point by going
978 ;; to start first, so that if end is in intangible text,
979 ;; point jumps away from start. Don't do it if
980 ;; start=end, or a single click would select a region if
981 ;; it's on intangible text.
982 (unless (= start-point end-point)
983 (goto-char start-point)
984 (goto-char end-point))
985 (let ((mouse-row (cdr (cdr (mouse-position)))))
989 (mouse-scroll-subr start-window (- mouse-row top)
991 ((>= mouse-row bottom)
992 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
993 nil start-point))))))))
995 ;; Handle the terminating event if possible.
997 ;; Ensure that point is on the end of the last event.
998 (when (and (setq end-point (posn-point (event-end event)))
999 (eq (posn-window end) start-window)
1000 (integer-or-marker-p end-point)
1001 (/= start-point end-point))
1002 (goto-char start-point)
1003 (goto-char end-point))
1004 ;; Find its binding.
1005 (let* ((fun (key-binding (vector (car event))))
1006 (do-multi-click (and (> (event-click-count event) 0)
1008 (not (memq fun '(mouse-set-point
1009 mouse-set-region))))))
1010 (if (and (/= (mark) (point))
1011 (not do-multi-click))
1013 ;; If point has moved, finish the drag.
1014 (let* (last-command this-command)
1015 (and mouse-drag-copy-region
1016 do-mouse-drag-region-post-process
1017 (let (deactivate-mark)
1018 (copy-region-as-kill (mark) (point)))))
1020 ;; If point hasn't moved, run the binding of the
1021 ;; terminating up-event.
1023 (goto-char start-point)
1025 (when (and (functionp fun)
1026 (= start-hscroll (window-hscroll start-window))
1027 ;; Don't run the up-event handler if the window
1028 ;; start changed in a redisplay after the
1029 ;; mouse-set-point for the down-mouse event at
1030 ;; the beginning of this function. When the
1031 ;; window start has changed, the up-mouse event
1032 ;; contains a different position due to the new
1033 ;; window contents, and point is set again.
1035 (= (window-start start-window)
1036 start-window-start)))
1038 (= start-point (point))
1039 (mouse--remap-link-click-p start-event event))
1040 ;; If we rebind to mouse-2, reselect previous selected
1041 ;; window, so that the mouse-2 event runs in the same
1042 ;; situation as if user had clicked it directly. Fixes
1043 ;; the bug reported by juri@jurta.org on 2005-12-27.
1044 (if (or (vectorp on-link) (stringp on-link))
1045 (setq event (aref on-link 0))
1046 (select-window original-window)
1047 (setcar event 'mouse-2)
1048 ;; If this mouse click has never been done by the
1049 ;; user, it doesn't have the necessary property to be
1050 ;; interpreted correctly.
1051 (put 'mouse-2 'event-kind 'mouse-click)))
1052 (push event unread-command-events)))))))
1054 (defun mouse--remap-link-click-p (start-event end-event)
1055 (or (and (eq mouse-1-click-follows-link 'double)
1056 (= (event-click-count start-event) 2))
1058 (not (eq mouse-1-click-follows-link 'double))
1059 (= (event-click-count start-event) 1)
1060 (= (event-click-count end-event) 1)
1061 (or (not (integerp mouse-1-click-follows-link))
1062 (let ((t0 (posn-timestamp (event-start start-event)))
1063 (t1 (posn-timestamp (event-end end-event))))
1064 (and (integerp t0) (integerp t1)
1065 (if (> mouse-1-click-follows-link 0)
1066 (<= (- t1 t0) mouse-1-click-follows-link)
1067 (< (- t0 t1) mouse-1-click-follows-link))))))))
1070 ;; Commands to handle xterm-style multiple clicks.
1071 (defun mouse-skip-word (dir)
1072 "Skip over word, over whitespace, or over identical punctuation.
1073 If DIR is positive skip forward; if negative, skip backward."
1074 (let* ((char (following-char))
1075 (syntax (char-to-string (char-syntax char))))
1076 (cond ((string= syntax "w")
1077 ;; Here, we can't use skip-syntax-forward/backward because
1078 ;; they don't pay attention to word-separating-categories,
1079 ;; and thus they will skip over a true word boundary. So,
1080 ;; we simulate the original behavior by using forward-word.
1082 (if (not (looking-at "\\<"))
1084 (if (or (looking-at "\\<") (not (looking-at "\\>")))
1086 ((string= syntax " ")
1088 (skip-syntax-backward syntax)
1089 (skip-syntax-forward syntax)))
1090 ((string= syntax "_")
1092 (skip-syntax-backward "w_")
1093 (skip-syntax-forward "w_")))
1095 (while (and (not (bobp)) (= (preceding-char) char))
1098 (while (and (not (eobp)) (= (following-char) char))
1099 (forward-char 1))))))
1101 (defun mouse-start-end (start end mode)
1102 "Return a list of region bounds based on START and END according to MODE.
1103 If MODE is 0 then set point to (min START END), mark to (max START END).
1104 If MODE is 1 then set point to start of word at (min START END),
1105 mark to end of word at (max START END).
1106 If MODE is 2 then do the same for lines."
1111 (setq mode (mod mode 3))
1117 (= (char-syntax (char-after start)) ?\())
1126 (= (char-syntax (char-after start)) ?\)))
1127 (list (save-excursion
1128 (goto-char (1+ start))
1135 (= (char-syntax (char-after start)) ?\"))
1136 (let ((open (or (eq start (point-min))
1138 (goto-char (- start 1))
1139 (looking-at "\\s(\\|\\s \\|\\s>")))))
1149 (list (save-excursion
1152 (goto-char (1+ start))
1158 (list (save-excursion
1160 (mouse-skip-word -1)
1167 (list (save-excursion
1169 (beginning-of-line 1)
1176 ;; Subroutine: set the mark where CLICK happened,
1177 ;; but don't do anything else.
1178 (defun mouse-set-mark-fast (click)
1179 (mouse-minibuffer-check click)
1180 (let ((posn (event-start click)))
1181 (select-window (posn-window posn))
1182 (if (numberp (posn-point posn))
1183 (push-mark (posn-point posn) t t))))
1185 (defun mouse-undouble-last-event (events)
1186 (let* ((index (1- (length events)))
1187 (last (nthcdr index events))
1189 (basic (event-basic-type event))
1190 (old-modifiers (event-modifiers event))
1191 (modifiers (delq 'double (delq 'triple (copy-sequence old-modifiers))))
1194 ;; Use reverse, not nreverse, since event-modifiers
1195 ;; does not copy the list it returns.
1196 (cons (event-convert-list (reverse (cons basic modifiers)))
1200 (if (and (not (equal modifiers old-modifiers))
1201 (key-binding (apply 'vector events)))
1206 ;; Momentarily show where the mark is, if highlighting doesn't show it.
1208 (defun mouse-set-mark (click)
1209 "Set mark at the position clicked on with the mouse.
1210 Display cursor at that position for a second.
1211 This must be bound to a mouse click."
1213 (mouse-minibuffer-check click)
1214 (select-window (posn-window (event-start click)))
1215 ;; We don't use save-excursion because that preserves the mark too.
1216 (let ((point-save (point)))
1218 (progn (mouse-set-point click)
1220 (or transient-mark-mode
1222 (goto-char point-save))))
1224 (defun mouse-kill (click)
1225 "Kill the region between point and the mouse click.
1226 The text is saved in the kill ring, as with \\[kill-region]."
1228 (mouse-minibuffer-check click)
1229 (let* ((posn (event-start click))
1230 (click-posn (posn-point posn)))
1231 (select-window (posn-window posn))
1232 (if (numberp click-posn)
1233 (kill-region (min (point) click-posn)
1234 (max (point) click-posn)))))
1236 (defun mouse-yank-at-click (click arg)
1237 "Insert the last stretch of killed text at the position clicked on.
1238 Also move point to one end of the text thus inserted (normally the end),
1239 and set mark at the beginning.
1240 Prefix arguments are interpreted as with \\[yank].
1241 If `mouse-yank-at-point' is non-nil, insert at point
1242 regardless of where you click."
1243 (interactive "e\nP")
1244 ;; Give temporary modes such as isearch a chance to turn off.
1245 (run-hooks 'mouse-leave-buffer-hook)
1246 (when select-active-regions
1247 ;; Without this, confusing things happen upon e.g. inserting into
1248 ;; the middle of an active region.
1250 (or mouse-yank-at-point (mouse-set-point click))
1251 (setq this-command 'yank)
1252 (setq mouse-selection-click-count 0)
1255 (defun mouse-yank-primary (click)
1256 "Insert the primary selection at the position clicked on.
1257 Move point to the end of the inserted text.
1258 If `mouse-yank-at-point' is non-nil, insert at point
1259 regardless of where you click."
1261 ;; Give temporary modes such as isearch a chance to turn off.
1262 (run-hooks 'mouse-leave-buffer-hook)
1263 (when select-active-regions
1264 ;; Without this, confusing things happen upon e.g. inserting into
1265 ;; the middle of an active region.
1267 (or mouse-yank-at-point (mouse-set-point click))
1268 (let ((primary (x-get-selection 'PRIMARY)))
1271 (error "No primary selection"))))
1273 (defun mouse-kill-ring-save (click)
1274 "Copy the region between point and the mouse click in the kill ring.
1275 This does not delete the region; it acts like \\[kill-ring-save]."
1277 (mouse-set-mark-fast click)
1278 (let (this-command last-command)
1279 (kill-ring-save (point) (mark t))))
1281 ;; This function used to delete the text between point and the mouse
1282 ;; whenever it was equal to the front of the kill ring, but some
1283 ;; people found that confusing.
1285 ;; A list (TEXT START END), describing the text and position of the last
1286 ;; invocation of mouse-save-then-kill.
1287 (defvar mouse-save-then-kill-posn nil)
1289 (defun mouse-save-then-kill-delete-region (beg end)
1290 ;; We must make our own undo boundaries
1291 ;; because they happen automatically only for the current buffer.
1293 (if (or (= beg end) (eq buffer-undo-list t))
1294 ;; If we have no undo list in this buffer,
1296 (delete-region beg end)
1297 ;; Delete, but make the undo-list entry share with the kill ring.
1298 ;; First, delete just one char, so in case buffer is being modified
1299 ;; for the first time, the undo list records that fact.
1300 (let (before-change-functions after-change-functions)
1302 (+ beg (if (> end beg) 1 -1))))
1303 (let ((buffer-undo-list buffer-undo-list))
1304 ;; Undo that deletion--but don't change the undo list!
1305 (let (before-change-functions after-change-functions)
1306 (primitive-undo 1 buffer-undo-list))
1307 ;; Now delete the rest of the specified region,
1308 ;; but don't record it.
1309 (setq buffer-undo-list t)
1310 (if (/= (length (car kill-ring)) (- (max end beg) (min end beg)))
1311 (error "Lossage in mouse-save-then-kill-delete-region"))
1312 (delete-region beg end))
1313 (let ((tail buffer-undo-list))
1314 ;; Search back in buffer-undo-list for the string
1315 ;; that came from deleting one character.
1316 (while (and tail (not (stringp (car (car tail)))))
1317 (setq tail (cdr tail)))
1318 ;; Replace it with an entry for the entire deleted text.
1320 (setcar tail (cons (car kill-ring) (min beg end))))))
1323 (defun mouse-save-then-kill (click)
1324 "Set the region according to CLICK; the second time, kill the region.
1325 Assuming this command is bound to a mouse button, CLICK is the
1326 corresponding input event.
1328 If the region is already active, adjust it. Normally, this
1329 happens by moving either point or mark, whichever is closer, to
1330 the position of CLICK. But if you have selected words or lines,
1331 the region is adjusted by moving point or mark to the word or
1332 line boundary closest to CLICK.
1334 If the region is inactive, activate it temporarily; set mark at
1335 the original point, and move click to the position of CLICK.
1337 However, if this command is being called a second time (i.e. the
1338 value of `last-command' is `mouse-save-then-kill'), kill the
1339 region instead. If the text in the region is the same as the
1340 text in the front of the kill ring, just delete it."
1342 (let ((before-scroll
1343 (with-current-buffer (window-buffer (posn-window (event-start click)))
1344 point-before-scroll)))
1345 (mouse-minibuffer-check click)
1346 (let ((click-posn (posn-point (event-start click)))
1347 ;; Don't let a subsequent kill command append to this one:
1348 ;; prevent setting this-command to kill-region.
1349 (this-command this-command))
1350 (if (and (with-current-buffer
1351 (window-buffer (posn-window (event-start click)))
1353 (> (mod mouse-selection-click-count 3) 0)
1354 ;; Don't be fooled by a recent click in some other buffer.
1355 (eq mouse-selection-click-count-buffer
1356 (current-buffer)))))
1357 (if (and (eq last-command 'mouse-save-then-kill)
1358 (equal click-posn (nth 2 mouse-save-then-kill-posn)))
1359 ;; If we click this button again without moving it, kill.
1361 ;; Call `deactivate-mark' to save the primary selection.
1363 (mouse-save-then-kill-delete-region (mark) (point))
1364 (setq mouse-selection-click-count 0)
1365 (setq mouse-save-then-kill-posn nil))
1366 ;; Find both ends of the object selected by this click.
1368 (mouse-start-end click-posn click-posn
1369 mouse-selection-click-count)))
1370 ;; Move whichever end is closer to the click.
1371 ;; That's what xterm does, and it seems reasonable.
1372 (if (< (abs (- click-posn (mark t)))
1373 (abs (- click-posn (point))))
1374 (set-mark (car range))
1375 (goto-char (nth 1 range)))
1376 ;; We have already put the old region in the kill ring.
1377 ;; Replace it with the extended region.
1378 ;; (It would be annoying to make a separate entry.)
1379 (kill-new (buffer-substring (point) (mark t)) t)
1380 (mouse-set-region-1)
1381 ;; Arrange for a repeated mouse-3 to kill this region.
1382 (setq mouse-save-then-kill-posn
1383 (list (car kill-ring) (point) click-posn))))
1385 (if (and (eq last-command 'mouse-save-then-kill)
1386 mouse-save-then-kill-posn
1387 (eq (car mouse-save-then-kill-posn) (car kill-ring))
1388 (equal (cdr mouse-save-then-kill-posn)
1389 (list (point) click-posn)))
1390 ;; If this is the second time we've called
1391 ;; mouse-save-then-kill, delete the text from the buffer.
1393 ;; Call `deactivate-mark' to save the primary selection.
1395 (mouse-save-then-kill-delete-region (point) (mark t))
1396 ;; After we kill, another click counts as "the first time".
1397 (setq mouse-save-then-kill-posn nil))
1398 ;; This is not a repetition.
1399 ;; We are adjusting an old selection or creating a new one.
1400 (if (or (and (eq last-command 'mouse-save-then-kill)
1401 mouse-save-then-kill-posn)
1402 (and mark-active transient-mark-mode)
1403 (and (memq last-command
1404 '(mouse-drag-region mouse-set-region))
1405 (or mark-even-if-inactive
1406 (not transient-mark-mode))))
1407 ;; We have a selection or suitable region, so adjust it.
1408 (let* ((posn (event-start click))
1409 (new (posn-point posn)))
1410 (select-window (posn-window posn))
1413 ;; Move whichever end of the region is closer to the click.
1414 ;; That is what xterm does, and it seems reasonable.
1415 (if (<= (abs (- new (point))) (abs (- new (mark t))))
1418 (setq deactivate-mark nil)))
1419 (kill-new (buffer-substring (point) (mark t)) t))
1420 ;; Set the mark where point is, then move where clicked.
1421 (mouse-set-mark-fast click)
1423 (goto-char before-scroll))
1424 (exchange-point-and-mark) ;Why??? --Stef
1425 (kill-new (buffer-substring (point) (mark t))))
1426 (mouse-set-region-1)
1427 (setq mouse-save-then-kill-posn
1428 (list (car kill-ring) (point) click-posn)))))))
1430 (global-set-key [M-mouse-1] 'mouse-start-secondary)
1431 (global-set-key [M-drag-mouse-1] 'mouse-set-secondary)
1432 (global-set-key [M-down-mouse-1] 'mouse-drag-secondary)
1433 (global-set-key [M-mouse-3] 'mouse-secondary-save-then-kill)
1434 (global-set-key [M-mouse-2] 'mouse-yank-secondary)
1436 (defconst mouse-secondary-overlay
1437 (let ((ol (make-overlay (point-min) (point-min))))
1439 (overlay-put ol 'face 'secondary-selection)
1441 "An overlay which records the current secondary selection.
1442 It is deleted when there is no secondary selection.")
1444 (defvar mouse-secondary-click-count 0)
1446 ;; A marker which records the specified first end for a secondary selection.
1448 (defvar mouse-secondary-start nil)
1450 (defun mouse-start-secondary (click)
1451 "Set one end of the secondary selection to the position clicked on.
1452 Use \\[mouse-secondary-save-then-kill] to set the other end
1453 and complete the secondary selection."
1455 (mouse-minibuffer-check click)
1456 (let ((posn (event-start click)))
1457 (with-current-buffer (window-buffer (posn-window posn))
1458 ;; Cancel any preexisting secondary selection.
1459 (delete-overlay mouse-secondary-overlay)
1460 (if (numberp (posn-point posn))
1462 (or mouse-secondary-start
1463 (setq mouse-secondary-start (make-marker)))
1464 (move-marker mouse-secondary-start (posn-point posn)))))))
1466 (defun mouse-set-secondary (click)
1467 "Set the secondary selection to the text that the mouse is dragged over.
1468 This must be bound to a mouse drag event."
1470 (mouse-minibuffer-check click)
1471 (let ((posn (event-start click))
1473 (end (event-end click)))
1474 (with-current-buffer (window-buffer (posn-window posn))
1475 (if (numberp (posn-point posn))
1476 (setq beg (posn-point posn)))
1477 (move-overlay mouse-secondary-overlay beg (posn-point end))
1480 (buffer-substring (overlay-start mouse-secondary-overlay)
1481 (overlay-end mouse-secondary-overlay))))))
1483 (defun mouse-drag-secondary (start-event)
1484 "Set the secondary selection to the text that the mouse is dragged over.
1485 Highlight the drag area as you move the mouse.
1486 This must be bound to a button-down mouse event.
1487 The function returns a non-nil value if it creates a secondary selection."
1489 (mouse-minibuffer-check start-event)
1490 (let* ((echo-keystrokes 0)
1491 (start-posn (event-start start-event))
1492 (start-point (posn-point start-posn))
1493 (start-window (posn-window start-posn))
1494 (bounds (window-edges start-window))
1495 (top (nth 1 bounds))
1496 (bottom (if (window-minibuffer-p start-window)
1498 ;; Don't count the mode line.
1499 (1- (nth 3 bounds))))
1500 (click-count (1- (event-click-count start-event))))
1501 (with-current-buffer (window-buffer start-window)
1502 (setq mouse-secondary-click-count click-count)
1503 (if (> (mod click-count 3) 0)
1504 ;; Double or triple press: make an initial selection
1505 ;; of one word or line.
1506 (let ((range (mouse-start-end start-point start-point click-count)))
1507 (set-marker mouse-secondary-start nil)
1508 ;; Why the double move? --Stef
1509 ;; (move-overlay mouse-secondary-overlay 1 1
1510 ;; (window-buffer start-window))
1511 (move-overlay mouse-secondary-overlay (car range) (nth 1 range)
1512 (window-buffer start-window)))
1513 ;; Single-press: cancel any preexisting secondary selection.
1514 (or mouse-secondary-start
1515 (setq mouse-secondary-start (make-marker)))
1516 (set-marker mouse-secondary-start start-point)
1517 (delete-overlay mouse-secondary-overlay))
1518 (let (event end end-point)
1521 (setq event (read-event))
1522 (or (mouse-movement-p event)
1523 (memq (car-safe event) '(switch-frame select-window))))
1525 (if (memq (car-safe event) '(switch-frame select-window))
1527 (setq end (event-end event)
1528 end-point (posn-point end))
1530 ;; Are we moving within the original window?
1531 ((and (eq (posn-window end) start-window)
1532 (integer-or-marker-p end-point))
1533 (let ((range (mouse-start-end start-point end-point
1535 (if (or (/= start-point end-point)
1536 (null (marker-position mouse-secondary-start)))
1538 (set-marker mouse-secondary-start nil)
1539 (move-overlay mouse-secondary-overlay
1540 (car range) (nth 1 range))))))
1542 (let ((mouse-row (cdr (cdr (mouse-position)))))
1546 (mouse-scroll-subr start-window (- mouse-row top)
1547 mouse-secondary-overlay start-point))
1548 ((>= mouse-row bottom)
1549 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
1550 mouse-secondary-overlay start-point)))))))))
1553 (if (marker-position mouse-secondary-start)
1554 (save-window-excursion
1555 (delete-overlay mouse-secondary-overlay)
1556 (x-set-selection 'SECONDARY nil)
1557 (select-window start-window)
1559 (goto-char mouse-secondary-start)
1564 (buffer-substring (overlay-start mouse-secondary-overlay)
1565 (overlay-end mouse-secondary-overlay)))))))))
1567 (defun mouse-yank-secondary (click)
1568 "Insert the secondary selection at the position clicked on.
1569 Move point to the end of the inserted text.
1570 If `mouse-yank-at-point' is non-nil, insert at point
1571 regardless of where you click."
1573 ;; Give temporary modes such as isearch a chance to turn off.
1574 (run-hooks 'mouse-leave-buffer-hook)
1575 (or mouse-yank-at-point (mouse-set-point click))
1576 (let ((secondary (x-get-selection 'SECONDARY)))
1579 (error "No secondary selection"))))
1581 (defun mouse-kill-secondary ()
1582 "Kill the text in the secondary selection.
1583 This is intended more as a keyboard command than as a mouse command
1584 but it can work as either one.
1586 The current buffer (in case of keyboard use), or the buffer clicked on,
1587 must be the one that the secondary selection is in. This requirement
1588 is to prevent accidents."
1590 (let* ((keys (this-command-keys))
1591 (click (elt keys (1- (length keys)))))
1592 (or (eq (overlay-buffer mouse-secondary-overlay)
1594 (window-buffer (posn-window (event-start click)))
1596 (error "Select or click on the buffer where the secondary selection is")))
1598 (with-current-buffer (overlay-buffer mouse-secondary-overlay)
1599 (kill-region (overlay-start mouse-secondary-overlay)
1600 (overlay-end mouse-secondary-overlay))))
1601 (delete-overlay mouse-secondary-overlay))
1603 (defun mouse-secondary-save-then-kill (click)
1604 "Save text to point in kill ring; the second time, kill the text.
1605 You must use this in a buffer where you have recently done \\[mouse-start-secondary].
1606 If the text between where you did \\[mouse-start-secondary] and where
1607 you use this command matches the text at the front of the kill ring,
1608 this command deletes the text.
1609 Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
1610 which prepares for a second click with this command to delete the text.
1612 If you have already made a secondary selection in that buffer,
1613 this command extends or retracts the selection to where you click.
1614 If you do this again in a different position, it extends or retracts
1615 again. If you do this twice in the same position, it kills the selection."
1617 (mouse-minibuffer-check click)
1618 (let ((posn (event-start click))
1619 (click-posn (posn-point (event-start click)))
1620 ;; Don't let a subsequent kill command append to this one:
1621 ;; prevent setting this-command to kill-region.
1622 (this-command this-command))
1623 (or (eq (window-buffer (posn-window posn))
1624 (or (overlay-buffer mouse-secondary-overlay)
1625 (if mouse-secondary-start
1626 (marker-buffer mouse-secondary-start))))
1627 (error "Wrong buffer"))
1628 (with-current-buffer (window-buffer (posn-window posn))
1629 (if (> (mod mouse-secondary-click-count 3) 0)
1630 (if (not (and (eq last-command 'mouse-secondary-save-then-kill)
1632 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
1633 ;; Find both ends of the object selected by this click.
1635 (mouse-start-end click-posn click-posn
1636 mouse-secondary-click-count)))
1637 ;; Move whichever end is closer to the click.
1638 ;; That's what xterm does, and it seems reasonable.
1639 (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay)))
1640 (abs (- click-posn (overlay-end mouse-secondary-overlay))))
1641 (move-overlay mouse-secondary-overlay (car range)
1642 (overlay-end mouse-secondary-overlay))
1643 (move-overlay mouse-secondary-overlay
1644 (overlay-start mouse-secondary-overlay)
1646 ;; We have already put the old region in the kill ring.
1647 ;; Replace it with the extended region.
1648 ;; (It would be annoying to make a separate entry.)
1649 (kill-new (buffer-substring
1650 (overlay-start mouse-secondary-overlay)
1651 (overlay-end mouse-secondary-overlay)) t)
1652 ;; Arrange for a repeated mouse-3 to kill this region.
1653 (setq mouse-save-then-kill-posn
1654 (list (car kill-ring) (point) click-posn)))
1655 ;; If we click this button again without moving it,
1658 (mouse-save-then-kill-delete-region
1659 (overlay-start mouse-secondary-overlay)
1660 (overlay-end mouse-secondary-overlay))
1661 (setq mouse-save-then-kill-posn nil)
1662 (setq mouse-secondary-click-count 0)
1663 (delete-overlay mouse-secondary-overlay)))
1664 (if (and (eq last-command 'mouse-secondary-save-then-kill)
1665 mouse-save-then-kill-posn
1666 (eq (car mouse-save-then-kill-posn) (car kill-ring))
1667 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
1668 ;; If this is the second time we've called
1669 ;; mouse-secondary-save-then-kill, delete the text from the buffer.
1671 (mouse-save-then-kill-delete-region
1672 (overlay-start mouse-secondary-overlay)
1673 (overlay-end mouse-secondary-overlay))
1674 (setq mouse-save-then-kill-posn nil)
1675 (delete-overlay mouse-secondary-overlay))
1676 (if (overlay-start mouse-secondary-overlay)
1677 ;; We have a selection, so adjust it.
1679 (if (numberp click-posn)
1681 ;; Move whichever end of the region is closer to the click.
1682 ;; That is what xterm does, and it seems reasonable.
1683 (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay)))
1684 (abs (- click-posn (overlay-end mouse-secondary-overlay))))
1685 (move-overlay mouse-secondary-overlay click-posn
1686 (overlay-end mouse-secondary-overlay))
1687 (move-overlay mouse-secondary-overlay
1688 (overlay-start mouse-secondary-overlay)
1690 (setq deactivate-mark nil)))
1691 (if (eq last-command 'mouse-secondary-save-then-kill)
1692 ;; If the front of the kill ring comes from
1693 ;; an immediately previous use of this command,
1694 ;; replace it with the extended region.
1695 ;; (It would be annoying to make a separate entry.)
1696 (kill-new (buffer-substring
1697 (overlay-start mouse-secondary-overlay)
1698 (overlay-end mouse-secondary-overlay)) t)
1699 (let (deactivate-mark)
1700 (copy-region-as-kill (overlay-start mouse-secondary-overlay)
1701 (overlay-end mouse-secondary-overlay)))))
1702 (if mouse-secondary-start
1703 ;; All we have is one end of a selection,
1704 ;; so put the other end here.
1705 (let ((start (+ 0 mouse-secondary-start)))
1706 (kill-ring-save start click-posn)
1707 (move-overlay mouse-secondary-overlay start click-posn))))
1708 (setq mouse-save-then-kill-posn
1709 (list (car kill-ring) (point) click-posn))))
1710 (if (overlay-buffer mouse-secondary-overlay)
1711 (x-set-selection 'SECONDARY
1713 (overlay-start mouse-secondary-overlay)
1714 (overlay-end mouse-secondary-overlay)))))))
1716 (defcustom mouse-buffer-menu-maxlen 20
1717 "Number of buffers in one pane (submenu) of the buffer menu.
1718 If we have lots of buffers, divide them into groups of
1719 `mouse-buffer-menu-maxlen' and make a pane (or submenu) for each one."
1723 (defcustom mouse-buffer-menu-mode-mult 4
1724 "Group the buffers by the major mode groups on \\[mouse-buffer-menu]?
1725 This number which determines (in a hairy way) whether \\[mouse-buffer-menu]
1726 will split the buffer menu by the major modes (see
1727 `mouse-buffer-menu-mode-groups') or just by menu length.
1728 Set to 1 (or even 0!) if you want to group by major mode always, and to
1729 a large number if you prefer a mixed multitude. The default is 4."
1734 (defvar mouse-buffer-menu-mode-groups
1735 (mapcar (lambda (arg) (cons (purecopy (car arg)) (purecopy (cdr arg))))
1736 '(("Info\\|Help\\|Apropos\\|Man" . "Help")
1737 ("\\bVM\\b\\|\\bMH\\b\\|Message\\|Mail\\|Group\\|Score\\|Summary\\|Article"
1742 ("Outline" . "Text")
1743 ("\\(HT\\|SG\\|X\\|XHT\\)ML" . "SGML")
1744 ("log\\|diff\\|vc\\|cvs\\|Annotate" . "Version Control") ; "Change Management"?
1746 "How to group various major modes together in \\[mouse-buffer-menu].
1747 Each element has the form (REGEXP . GROUPNAME).
1748 If the major mode's name string matches REGEXP, use GROUPNAME instead.")
1750 (defun mouse-buffer-menu (event)
1751 "Pop up a menu of buffers for selection with the mouse.
1752 This switches buffers in the window that you clicked on,
1753 and selects that window."
1755 (mouse-minibuffer-check event)
1756 (let ((buffers (buffer-list)) alist menu split-by-major-mode sum-of-squares)
1757 ;; Make an alist of elements that look like (MENU-ITEM . BUFFER).
1758 (dolist (buf buffers)
1759 ;; Divide all buffers into buckets for various major modes.
1760 ;; Each bucket looks like (MODE NAMESTRING BUFFERS...).
1761 (with-current-buffer buf
1762 (let* ((adjusted-major-mode major-mode) elt)
1763 (dolist (group mouse-buffer-menu-mode-groups)
1764 (when (string-match (car group) (format-mode-line mode-name))
1765 (setq adjusted-major-mode (cdr group))))
1766 (setq elt (assoc adjusted-major-mode split-by-major-mode))
1768 (setq elt (list adjusted-major-mode
1769 (if (stringp adjusted-major-mode)
1771 (format-mode-line mode-name nil nil buf)))
1772 split-by-major-mode (cons elt split-by-major-mode)))
1773 (or (memq buf (cdr (cdr elt)))
1774 (setcdr (cdr elt) (cons buf (cdr (cdr elt))))))))
1775 ;; Compute the sum of squares of sizes of the major-mode buckets.
1776 (let ((tail split-by-major-mode))
1777 (setq sum-of-squares 0)
1779 (setq sum-of-squares
1781 (let ((len (length (cdr (cdr (car tail)))))) (* len len))))
1782 (setq tail (cdr tail))))
1783 (if (< (* sum-of-squares mouse-buffer-menu-mode-mult)
1784 (* (length buffers) (length buffers)))
1785 ;; Subdividing by major modes really helps, so let's do it.
1786 (let (subdivided-menus (buffers-left (length buffers)))
1787 ;; Sort the list to put the most popular major modes first.
1788 (setq split-by-major-mode
1789 (sort split-by-major-mode
1790 (function (lambda (elt1 elt2)
1791 (> (length elt1) (length elt2))))))
1792 ;; Make a separate submenu for each major mode
1793 ;; that has more than one buffer,
1794 ;; unless all the remaining buffers are less than 1/10 of them.
1795 (while (and split-by-major-mode
1796 (and (> (length (car split-by-major-mode)) 3)
1797 (> (* buffers-left 10) (length buffers))))
1798 (let ((this-mode-list (mouse-buffer-menu-alist
1799 (cdr (cdr (car split-by-major-mode))))))
1801 (setq subdivided-menus
1803 (nth 1 (car split-by-major-mode))
1805 subdivided-menus))))
1807 (- buffers-left (length (cdr (car split-by-major-mode)))))
1808 (setq split-by-major-mode (cdr split-by-major-mode)))
1809 ;; If any major modes are left over,
1810 ;; make a single submenu for them.
1811 (if split-by-major-mode
1813 (mouse-buffer-menu-alist
1814 ;; we don't need split-by-major-mode any more,
1815 ;; so we can ditch it with nconc.
1816 (apply 'nconc (mapcar 'cddr split-by-major-mode)))))
1818 (setq subdivided-menus
1819 (cons (cons "Others" others-list)
1820 subdivided-menus)))))
1821 (setq menu (cons "Buffer Menu" (nreverse subdivided-menus))))
1823 (setq alist (mouse-buffer-menu-alist buffers))
1824 (setq menu (cons "Buffer Menu"
1825 (mouse-buffer-menu-split "Select Buffer" alist)))))
1826 (let ((buf (x-popup-menu event menu))
1827 (window (posn-window (event-start event))))
1830 (if (framep window) (frame-selected-window window)
1832 (switch-to-buffer buf)))))
1834 (defun mouse-buffer-menu-alist (buffers)
1840 (function (lambda (elt1 elt2)
1841 (string< (buffer-name elt1) (buffer-name elt2))))))
1844 (or (eq ?\s (aref (buffer-name (car tail)) 0))
1847 (length (buffer-name (car tail))))))
1848 (setq tail (cdr tail)))
1851 (let ((elt (car tail)))
1852 (if (/= (aref (buffer-name elt) 0) ?\s)
1857 (format "%%-%ds %%s%%s %%s" maxlen)
1859 (if (buffer-modified-p elt) "*" " ")
1860 (with-current-buffer elt
1861 (if buffer-read-only "%" " "))
1862 (or (buffer-file-name elt)
1863 (with-current-buffer elt
1864 (if list-buffers-directory
1866 list-buffers-directory)))
1870 (setq tail (cdr tail)))
1871 ;; Compensate for the reversal that the above loop does.
1874 (defun mouse-buffer-menu-split (title alist)
1875 ;; If we have lots of buffers, divide them into groups of 20
1876 ;; and make a pane (or submenu) for each one.
1877 (if (> (length alist) (/ (* mouse-buffer-menu-maxlen 3) 2))
1878 (let ((alist alist) sublists next
1881 ;; Pull off the next mouse-buffer-menu-maxlen buffers
1882 ;; and make them the next element of sublist.
1883 (setq next (nthcdr mouse-buffer-menu-maxlen alist))
1885 (setcdr (nthcdr (1- mouse-buffer-menu-maxlen) alist)
1887 (setq sublists (cons (cons (format "Buffers %d" i) alist)
1891 (nreverse sublists))
1892 ;; Few buffers--put them all in one pane.
1893 (list (cons title alist))))
1895 ;; These need to be rewritten for the new scroll bar implementation.
1897 ;;!! ;; Commands for the scroll bar.
1899 ;;!! (defun mouse-scroll-down (click)
1900 ;;!! (interactive "@e")
1901 ;;!! (scroll-down (1+ (cdr (mouse-coords click)))))
1903 ;;!! (defun mouse-scroll-up (click)
1904 ;;!! (interactive "@e")
1905 ;;!! (scroll-up (1+ (cdr (mouse-coords click)))))
1907 ;;!! (defun mouse-scroll-down-full ()
1908 ;;!! (interactive "@")
1909 ;;!! (scroll-down nil))
1911 ;;!! (defun mouse-scroll-up-full ()
1912 ;;!! (interactive "@")
1913 ;;!! (scroll-up nil))
1915 ;;!! (defun mouse-scroll-move-cursor (click)
1916 ;;!! (interactive "@e")
1917 ;;!! (move-to-window-line (1+ (cdr (mouse-coords click)))))
1919 ;;!! (defun mouse-scroll-absolute (event)
1920 ;;!! (interactive "@e")
1921 ;;!! (let* ((pos (car event))
1922 ;;!! (position (car pos))
1923 ;;!! (length (car (cdr pos))))
1924 ;;!! (if (<= length 0) (setq length 1))
1925 ;;!! (let* ((scale-factor (max 1 (/ length (/ 8000000 (buffer-size)))))
1926 ;;!! (newpos (* (/ (* (/ (buffer-size) scale-factor)
1929 ;;!! scale-factor)))
1930 ;;!! (goto-char newpos)
1931 ;;!! (recenter '(4)))))
1933 ;;!! (defun mouse-scroll-left (click)
1934 ;;!! (interactive "@e")
1935 ;;!! (scroll-left (1+ (car (mouse-coords click)))))
1937 ;;!! (defun mouse-scroll-right (click)
1938 ;;!! (interactive "@e")
1939 ;;!! (scroll-right (1+ (car (mouse-coords click)))))
1941 ;;!! (defun mouse-scroll-left-full ()
1942 ;;!! (interactive "@")
1943 ;;!! (scroll-left nil))
1945 ;;!! (defun mouse-scroll-right-full ()
1946 ;;!! (interactive "@")
1947 ;;!! (scroll-right nil))
1949 ;;!! (defun mouse-scroll-move-cursor-horizontally (click)
1950 ;;!! (interactive "@e")
1951 ;;!! (move-to-column (1+ (car (mouse-coords click)))))
1953 ;;!! (defun mouse-scroll-absolute-horizontally (event)
1954 ;;!! (interactive "@e")
1955 ;;!! (let* ((pos (car event))
1956 ;;!! (position (car pos))
1957 ;;!! (length (car (cdr pos))))
1958 ;;!! (set-window-hscroll (selected-window) 33)))
1960 ;;!! (global-set-key [scroll-bar mouse-1] 'mouse-scroll-up)
1961 ;;!! (global-set-key [scroll-bar mouse-2] 'mouse-scroll-absolute)
1962 ;;!! (global-set-key [scroll-bar mouse-3] 'mouse-scroll-down)
1964 ;;!! (global-set-key [vertical-slider mouse-1] 'mouse-scroll-move-cursor)
1965 ;;!! (global-set-key [vertical-slider mouse-2] 'mouse-scroll-move-cursor)
1966 ;;!! (global-set-key [vertical-slider mouse-3] 'mouse-scroll-move-cursor)
1968 ;;!! (global-set-key [thumbup mouse-1] 'mouse-scroll-up-full)
1969 ;;!! (global-set-key [thumbup mouse-2] 'mouse-scroll-up-full)
1970 ;;!! (global-set-key [thumbup mouse-3] 'mouse-scroll-up-full)
1972 ;;!! (global-set-key [thumbdown mouse-1] 'mouse-scroll-down-full)
1973 ;;!! (global-set-key [thumbdown mouse-2] 'mouse-scroll-down-full)
1974 ;;!! (global-set-key [thumbdown mouse-3] 'mouse-scroll-down-full)
1976 ;;!! (global-set-key [horizontal-scroll-bar mouse-1] 'mouse-scroll-left)
1977 ;;!! (global-set-key [horizontal-scroll-bar mouse-2]
1978 ;;!! 'mouse-scroll-absolute-horizontally)
1979 ;;!! (global-set-key [horizontal-scroll-bar mouse-3] 'mouse-scroll-right)
1981 ;;!! (global-set-key [horizontal-slider mouse-1]
1982 ;;!! 'mouse-scroll-move-cursor-horizontally)
1983 ;;!! (global-set-key [horizontal-slider mouse-2]
1984 ;;!! 'mouse-scroll-move-cursor-horizontally)
1985 ;;!! (global-set-key [horizontal-slider mouse-3]
1986 ;;!! 'mouse-scroll-move-cursor-horizontally)
1988 ;;!! (global-set-key [thumbleft mouse-1] 'mouse-scroll-left-full)
1989 ;;!! (global-set-key [thumbleft mouse-2] 'mouse-scroll-left-full)
1990 ;;!! (global-set-key [thumbleft mouse-3] 'mouse-scroll-left-full)
1992 ;;!! (global-set-key [thumbright mouse-1] 'mouse-scroll-right-full)
1993 ;;!! (global-set-key [thumbright mouse-2] 'mouse-scroll-right-full)
1994 ;;!! (global-set-key [thumbright mouse-3] 'mouse-scroll-right-full)
1996 ;;!! (global-set-key [horizontal-scroll-bar S-mouse-2]
1997 ;;!! 'mouse-split-window-horizontally)
1998 ;;!! (global-set-key [mode-line S-mouse-2]
1999 ;;!! 'mouse-split-window-horizontally)
2000 ;;!! (global-set-key [vertical-scroll-bar S-mouse-2]
2001 ;;!! 'mouse-split-window)
2004 ;;!! ;;;; Here are experimental things being tested. Mouse events
2005 ;;!! ;;;; are of the form:
2006 ;;!! ;;;; ((x y) window screen-part key-sequence timestamp)
2009 ;;!! ;;;; Dynamically track mouse coordinates
2012 ;;!! ;;(defun track-mouse (event)
2013 ;;!! ;; "Track the coordinates, absolute and relative, of the mouse."
2014 ;;!! ;; (interactive "@e")
2015 ;;!! ;; (while mouse-grabbed
2016 ;;!! ;; (let* ((pos (read-mouse-position (selected-screen)))
2017 ;;!! ;; (abs-x (car pos))
2018 ;;!! ;; (abs-y (cdr pos))
2019 ;;!! ;; (relative-coordinate (coordinates-in-window-p
2020 ;;!! ;; (list (car pos) (cdr pos))
2021 ;;!! ;; (selected-window))))
2022 ;;!! ;; (if (consp relative-coordinate)
2023 ;;!! ;; (message "mouse: [%d %d], (%d %d)" abs-x abs-y
2024 ;;!! ;; (car relative-coordinate)
2025 ;;!! ;; (car (cdr relative-coordinate)))
2026 ;;!! ;; (message "mouse: [%d %d]" abs-x abs-y)))))
2029 ;;!! ;; Dynamically put a box around the line indicated by point
2032 ;;!! ;;(require 'backquote)
2034 ;;!! ;;(defun mouse-select-buffer-line (event)
2035 ;;!! ;; (interactive "@e")
2036 ;;!! ;; (let ((relative-coordinate
2037 ;;!! ;; (coordinates-in-window-p (car event) (selected-window)))
2038 ;;!! ;; (abs-y (car (cdr (car event)))))
2039 ;;!! ;; (if (consp relative-coordinate)
2041 ;;!! ;; (save-excursion
2042 ;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
2043 ;;!! ;; (x-draw-rectangle
2044 ;;!! ;; (selected-screen)
2046 ;;!! ;; (save-excursion
2047 ;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
2048 ;;!! ;; (end-of-line)
2049 ;;!! ;; (push-mark nil t)
2050 ;;!! ;; (beginning-of-line)
2051 ;;!! ;; (- (region-end) (region-beginning))) 1))
2053 ;;!! ;; (x-erase-rectangle (selected-screen))))))
2055 ;;!! ;;(defvar last-line-drawn nil)
2056 ;;!! ;;(defvar begin-delim "[^ \t]")
2057 ;;!! ;;(defvar end-delim "[^ \t]")
2059 ;;!! ;;(defun mouse-boxing (event)
2060 ;;!! ;; (interactive "@e")
2061 ;;!! ;; (save-excursion
2062 ;;!! ;; (let ((screen (selected-screen)))
2063 ;;!! ;; (while (= (x-mouse-events) 0)
2064 ;;!! ;; (let* ((pos (read-mouse-position screen))
2065 ;;!! ;; (abs-x (car pos))
2066 ;;!! ;; (abs-y (cdr pos))
2067 ;;!! ;; (relative-coordinate
2068 ;;!! ;; (coordinates-in-window-p `(,abs-x ,abs-y)
2069 ;;!! ;; (selected-window)))
2070 ;;!! ;; (begin-reg nil)
2071 ;;!! ;; (end-reg nil)
2072 ;;!! ;; (end-column nil)
2073 ;;!! ;; (begin-column nil))
2074 ;;!! ;; (if (and (consp relative-coordinate)
2075 ;;!! ;; (or (not last-line-drawn)
2076 ;;!! ;; (not (= last-line-drawn abs-y))))
2078 ;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
2079 ;;!! ;; (if (= (following-char) 10)
2082 ;;!! ;; (setq begin-reg (1- (re-search-forward end-delim)))
2083 ;;!! ;; (setq begin-column (1- (current-column)))
2084 ;;!! ;; (end-of-line)
2085 ;;!! ;; (setq end-reg (1+ (re-search-backward begin-delim)))
2086 ;;!! ;; (setq end-column (1+ (current-column)))
2087 ;;!! ;; (message "%s" (buffer-substring begin-reg end-reg))
2088 ;;!! ;; (x-draw-rectangle screen
2089 ;;!! ;; (setq last-line-drawn abs-y)
2090 ;;!! ;; begin-column
2091 ;;!! ;; (- end-column begin-column) 1))))))))))
2093 ;;!! ;;(defun mouse-erase-box ()
2094 ;;!! ;; (interactive)
2095 ;;!! ;; (if last-line-drawn
2097 ;;!! ;; (x-erase-rectangle (selected-screen))
2098 ;;!! ;; (setq last-line-drawn nil))))
2100 ;;!! ;;; (defun test-x-rectangle ()
2101 ;;!! ;;; (use-local-mouse-map (setq rectangle-test-map (make-sparse-keymap)))
2102 ;;!! ;;; (define-key rectangle-test-map mouse-motion-button-left 'mouse-boxing)
2103 ;;!! ;;; (define-key rectangle-test-map mouse-button-left-up 'mouse-erase-box))
2106 ;;!! ;; Here is how to do double clicking in lisp. About to change.
2109 ;;!! (defvar double-start nil)
2110 ;;!! (defconst double-click-interval 300
2111 ;;!! "Max ticks between clicks")
2113 ;;!! (defun double-down (event)
2114 ;;!! (interactive "@e")
2115 ;;!! (if double-start
2116 ;;!! (let ((interval (- (nth 4 event) double-start)))
2117 ;;!! (if (< interval double-click-interval)
2119 ;;!! (backward-up-list 1)
2120 ;;!! ;; (message "Interval %d" interval)
2121 ;;!! (sleep-for 1)))
2122 ;;!! (setq double-start nil))
2123 ;;!! (setq double-start (nth 4 event))))
2125 ;;!! (defun double-up (event)
2126 ;;!! (interactive "@e")
2127 ;;!! (and double-start
2128 ;;!! (> (- (nth 4 event ) double-start) double-click-interval)
2129 ;;!! (setq double-start nil)))
2131 ;;!! ;;; (defun x-test-doubleclick ()
2132 ;;!! ;;; (use-local-mouse-map (setq doubleclick-test-map (make-sparse-keymap)))
2133 ;;!! ;;; (define-key doubleclick-test-map mouse-button-left 'double-down)
2134 ;;!! ;;; (define-key doubleclick-test-map mouse-button-left-up 'double-up))
2137 ;;!! ;; This scrolls while button is depressed. Use preferable in scroll bar.
2140 ;;!! (defvar scrolled-lines 0)
2141 ;;!! (defconst scroll-speed 1)
2143 ;;!! (defun incr-scroll-down (event)
2144 ;;!! (interactive "@e")
2145 ;;!! (setq scrolled-lines 0)
2146 ;;!! (incremental-scroll scroll-speed))
2148 ;;!! (defun incr-scroll-up (event)
2149 ;;!! (interactive "@e")
2150 ;;!! (setq scrolled-lines 0)
2151 ;;!! (incremental-scroll (- scroll-speed)))
2153 ;;!! (defun incremental-scroll (n)
2154 ;;!! (while (= (x-mouse-events) 0)
2155 ;;!! (setq scrolled-lines (1+ (* scroll-speed scrolled-lines)))
2156 ;;!! (scroll-down n)
2157 ;;!! (sit-for 300 t)))
2159 ;;!! (defun incr-scroll-stop (event)
2160 ;;!! (interactive "@e")
2161 ;;!! (message "Scrolled %d lines" scrolled-lines)
2162 ;;!! (setq scrolled-lines 0)
2165 ;;!! ;;; (defun x-testing-scroll ()
2166 ;;!! ;;; (let ((scrolling-map (function mouse-vertical-scroll-bar-prefix)))
2167 ;;!! ;;; (define-key scrolling-map mouse-button-left 'incr-scroll-down)
2168 ;;!! ;;; (define-key scrolling-map mouse-button-right 'incr-scroll-up)
2169 ;;!! ;;; (define-key scrolling-map mouse-button-left-up 'incr-scroll-stop)
2170 ;;!! ;;; (define-key scrolling-map mouse-button-right-up 'incr-scroll-stop)))
2173 ;;!! ;; Some playthings suitable for picture mode? They need work.
2176 ;;!! (defun mouse-kill-rectangle (event)
2177 ;;!! "Kill the rectangle between point and the mouse cursor."
2178 ;;!! (interactive "@e")
2179 ;;!! (let ((point-save (point)))
2180 ;;!! (save-excursion
2181 ;;!! (mouse-set-point event)
2182 ;;!! (push-mark nil t)
2183 ;;!! (if (> point-save (point))
2184 ;;!! (kill-rectangle (point) point-save)
2185 ;;!! (kill-rectangle point-save (point))))))
2187 ;;!! (defun mouse-open-rectangle (event)
2188 ;;!! "Kill the rectangle between point and the mouse cursor."
2189 ;;!! (interactive "@e")
2190 ;;!! (let ((point-save (point)))
2191 ;;!! (save-excursion
2192 ;;!! (mouse-set-point event)
2193 ;;!! (push-mark nil t)
2194 ;;!! (if (> point-save (point))
2195 ;;!! (open-rectangle (point) point-save)
2196 ;;!! (open-rectangle point-save (point))))))
2198 ;;!! ;; Must be a better way to do this.
2200 ;;!! (defun mouse-multiple-insert (n char)
2203 ;;!! (setq n (1- n))))
2205 ;;!! ;; What this could do is not finalize until button was released.
2207 ;;!! (defun mouse-move-text (event)
2208 ;;!! "Move text from point to cursor position, inserting spaces."
2209 ;;!! (interactive "@e")
2210 ;;!! (let* ((relative-coordinate
2211 ;;!! (coordinates-in-window-p (car event) (selected-window))))
2212 ;;!! (if (consp relative-coordinate)
2213 ;;!! (cond ((> (current-column) (car relative-coordinate))
2215 ;;!! (- (car relative-coordinate) (current-column))))
2216 ;;!! ((< (current-column) (car relative-coordinate))
2217 ;;!! (mouse-multiple-insert
2218 ;;!! (- (car relative-coordinate) (current-column)) " "))
2219 ;;!! ((= (current-column) (car relative-coordinate)) (ding))))))
2221 (define-obsolete-function-alias
2222 'mouse-choose-completion 'choose-completion "23.2")
2226 (defun font-menu-add-default ()
2227 (let* ((default (cdr (assq 'font (frame-parameters (selected-frame)))))
2228 (font-alist x-fixed-font-alist)
2229 (elt (or (assoc "Misc" font-alist) (nth 1 font-alist))))
2230 (if (assoc "Default" elt)
2231 (delete (assoc "Default" elt) elt))
2233 (cons (list "Default" default)
2236 (defvar x-fixed-font-alist
2238 (purecopy "Font Menu")
2242 (lambda (arg) (cons (purecopy (car arg)) (purecopy (cdr arg))))
2243 ;; For these, we specify the pixel height and width.
2245 ("6x10" "-misc-fixed-medium-r-normal--10-*-*-*-c-60-iso8859-1" "6x10")
2247 "-misc-fixed-medium-r-semicondensed--12-*-*-*-c-60-iso8859-1" "6x12")
2249 "-misc-fixed-medium-r-semicondensed--13-*-*-*-c-60-iso8859-1" "6x13")
2250 ("7x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-70-iso8859-1" "7x13")
2251 ("7x14" "-misc-fixed-medium-r-normal--14-*-*-*-c-70-iso8859-1" "7x14")
2252 ("8x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-80-iso8859-1" "8x13")
2253 ("9x15" "-misc-fixed-medium-r-normal--15-*-*-*-c-90-iso8859-1" "9x15")
2254 ("10x20" "-misc-fixed-medium-r-normal--20-*-*-*-c-100-iso8859-1" "10x20")
2255 ("11x18" "-misc-fixed-medium-r-normal--18-*-*-*-c-110-iso8859-1" "11x18")
2256 ("12x24" "-misc-fixed-medium-r-normal--24-*-*-*-c-120-iso8859-1" "12x24")
2259 "-schumacher-clean-medium-r-normal--8-*-*-*-c-50-iso8859-1")
2261 "-schumacher-clean-medium-r-normal--8-*-*-*-c-60-iso8859-1")
2263 "-schumacher-clean-medium-r-normal--8-*-*-*-c-80-iso8859-1")
2265 "-schumacher-clean-medium-r-normal--10-*-*-*-c-80-iso8859-1")
2267 "-schumacher-clean-medium-r-normal--14-*-*-*-c-80-iso8859-1")
2269 "-schumacher-clean-medium-r-normal--16-*-*-*-c-80-iso8859-1")
2271 ("sony 8x16" "-sony-fixed-medium-r-normal--16-*-*-*-c-80-iso8859-1")
2272 ;; We don't seem to have these; who knows what they are.
2273 ;; ("fg-18" "fg-18")
2274 ;; ("fg-25" "fg-25")
2275 ("lucidasanstypewriter-12" "-b&h-lucidatypewriter-medium-r-normal-sans-*-120-*-*-*-*-iso8859-1")
2276 ("lucidasanstypewriter-bold-14" "-b&h-lucidatypewriter-bold-r-normal-sans-*-140-*-*-*-*-iso8859-1")
2277 ("lucidasanstypewriter-bold-24"
2278 "-b&h-lucidatypewriter-bold-r-normal-sans-*-240-*-*-*-*-iso8859-1")
2279 ;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
2280 ;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
2284 (purecopy "Courier")
2286 (lambda (arg) (cons (purecopy (car arg)) (purecopy (cdr arg))))
2287 ;; For these, we specify the point height.
2288 '(("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1")
2289 ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1")
2290 ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1")
2291 ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1")
2292 ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1")
2293 ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1")
2294 ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1")
2295 ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1")
2296 ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1")
2297 ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1")
2298 ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1")
2299 ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1")
2300 ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1")
2301 ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1")
2302 ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1")
2303 ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1")
2304 ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1")
2305 ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1")
2306 ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1")
2307 ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1")
2308 ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1")
2309 ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1")
2310 ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1")
2311 ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1")
2313 "X fonts suitable for use in Emacs.")
2315 (declare-function generate-fontset-menu "fontset" ())
2317 (defun mouse-select-font ()
2318 "Prompt for a font name, using `x-popup-menu', and return it."
2320 (unless (display-multi-font-p)
2321 (error "Cannot change fonts on this display"))
2324 (if (listp last-nonmenu-event)
2326 (list '(0 0) (selected-window)))
2327 (append x-fixed-font-alist
2328 (list (generate-fontset-menu))))))
2330 (declare-function text-scale-mode "face-remap")
2332 (defun mouse-set-font (&rest fonts)
2333 "Set the default font for the selected frame.
2334 The argument FONTS is a list of font names; the first valid font
2335 in this list is used.
2337 When called interactively, pop up a menu and allow the user to
2340 (progn (unless (display-multi-font-p)
2341 (error "Cannot change fonts on this display"))
2343 (if (listp last-nonmenu-event)
2345 (list '(0 0) (selected-window)))
2346 ;; Append list of fontsets currently defined.
2347 (append x-fixed-font-alist (list (generate-fontset-menu))))))
2353 (set-frame-font (car fonts))
2354 (setq font (car fonts))
2357 (setq fonts (cdr fonts)))))
2359 (error "Font not found")))))
2361 (defvar mouse-appearance-menu-map nil)
2362 (declare-function x-select-font "xfns.c" (&optional frame ignored)) ; USE_GTK
2363 (declare-function buffer-face-mode-invoke "face-remap"
2364 (face arg &optional interactive))
2365 (declare-function font-face-attributes "font.c" (font &optional frame))
2367 (defun mouse-appearance-menu (event)
2368 "Show a menu for changing the default face in the current buffer."
2370 (require 'face-remap)
2371 (when (display-multi-font-p)
2372 (with-selected-window (car (event-start event))
2373 (if mouse-appearance-menu-map
2374 nil ; regenerate new fonts
2375 ;; Initialize mouse-appearance-menu-map
2376 (setq mouse-appearance-menu-map
2377 (make-sparse-keymap "Change Default Buffer Face"))
2378 (define-key mouse-appearance-menu-map [face-remap-reset-base]
2379 '(menu-item "Reset to Default" face-remap-reset-base))
2380 (define-key mouse-appearance-menu-map [text-scale-decrease]
2381 '(menu-item "Decrease Buffer Text Size" text-scale-decrease))
2382 (define-key mouse-appearance-menu-map [text-scale-increase]
2383 '(menu-item "Increase Buffer Text Size" text-scale-increase))
2385 (if (functionp 'x-select-font)
2386 (define-key mouse-appearance-menu-map [x-select-font]
2387 '(menu-item "Change Buffer Font..." x-select-font))
2388 ;; If the select-font is unavailable, construct a menu.
2389 (let ((font-submenu (make-sparse-keymap "Change Text Font"))
2390 (font-alist (cdr (append x-fixed-font-alist
2391 (list (generate-fontset-menu))))))
2392 (dolist (family font-alist)
2393 (let* ((submenu-name (car family))
2394 (submenu-map (make-sparse-keymap submenu-name)))
2395 (dolist (font (cdr family))
2396 (let ((font-name (car font))
2398 (if (string= font-name "")
2399 (define-key submenu-map [space]
2401 (setq font-symbol (intern (cadr font)))
2402 (define-key submenu-map (vector font-symbol)
2403 (list 'menu-item (car font) font-symbol)))))
2404 (define-key font-submenu (vector (intern submenu-name))
2405 (list 'menu-item submenu-name submenu-map))))
2406 (define-key mouse-appearance-menu-map [font-submenu]
2407 (list 'menu-item "Change Text Font" font-submenu)))))
2408 (let ((choice (x-popup-menu event mouse-appearance-menu-map)))
2409 (setq choice (nth (1- (length choice)) choice))
2410 (cond ((eq choice 'text-scale-increase)
2411 (text-scale-increase 1))
2412 ((eq choice 'text-scale-decrease)
2413 (text-scale-increase -1))
2414 ((eq choice 'face-remap-reset-base)
2416 (buffer-face-mode 0))
2418 ;; Either choice == 'x-select-font, or choice is a
2419 ;; symbol whose name is a font.
2420 (buffer-face-mode-invoke (font-face-attributes
2421 (if (eq choice 'x-select-font)
2423 (symbol-name choice)))
2425 (called-interactively-p 'interactive))))))))
2428 ;;; Bindings for mouse commands.
2430 (define-key global-map [down-mouse-1] 'mouse-drag-region)
2431 (global-set-key [mouse-1] 'mouse-set-point)
2432 (global-set-key [drag-mouse-1] 'mouse-set-region)
2434 ;; These are tested for in mouse-drag-region.
2435 (global-set-key [double-mouse-1] 'mouse-set-point)
2436 (global-set-key [triple-mouse-1] 'mouse-set-point)
2438 ;; Clicking on the fringes causes hscrolling:
2439 (global-set-key [left-fringe mouse-1] 'mouse-set-point)
2440 (global-set-key [right-fringe mouse-1] 'mouse-set-point)
2442 (global-set-key [mouse-2] 'mouse-yank-primary)
2443 ;; Allow yanking also when the corresponding cursor is "in the fringe".
2444 (global-set-key [right-fringe mouse-2] 'mouse-yank-at-click)
2445 (global-set-key [left-fringe mouse-2] 'mouse-yank-at-click)
2446 (global-set-key [mouse-3] 'mouse-save-then-kill)
2447 (global-set-key [right-fringe mouse-3] 'mouse-save-then-kill)
2448 (global-set-key [left-fringe mouse-3] 'mouse-save-then-kill)
2450 ;; By binding these to down-going events, we let the user use the up-going
2451 ;; event to make the selection, saving a click.
2452 (global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
2453 (if (not (eq system-type 'ms-dos))
2454 (global-set-key [S-down-mouse-1] 'mouse-appearance-menu))
2455 ;; C-down-mouse-2 is bound in facemenu.el.
2456 (global-set-key [C-down-mouse-3]
2457 `(menu-item ,(purecopy "Menu Bar") ignore
2459 (if (zerop (or (frame-parameter nil 'menu-bar-lines) 0))
2460 (mouse-menu-bar-map)
2461 (mouse-menu-major-mode-map)))))
2464 ;; Replaced with dragging mouse-1
2465 ;; (global-set-key [S-mouse-1] 'mouse-set-mark)
2467 ;; Binding mouse-1 to mouse-select-window when on mode-, header-, or
2468 ;; vertical-line prevents Emacs from signaling an error when the mouse
2469 ;; button is released after dragging these lines, on non-toolkit
2471 (global-set-key [mode-line mouse-1] 'mouse-select-window)
2472 (global-set-key [mode-line drag-mouse-1] 'mouse-select-window)
2473 (global-set-key [mode-line down-mouse-1] 'mouse-drag-mode-line)
2474 (global-set-key [header-line down-mouse-1] 'mouse-drag-header-line)
2475 (global-set-key [header-line mouse-1] 'mouse-select-window)
2476 (global-set-key [mode-line mouse-2] 'mouse-delete-other-windows)
2477 (global-set-key [mode-line mouse-3] 'mouse-delete-window)
2478 (global-set-key [mode-line C-mouse-2] 'mouse-split-window-horizontally)
2479 (global-set-key [vertical-scroll-bar C-mouse-2] 'mouse-split-window-vertically)
2480 (global-set-key [vertical-line C-mouse-2] 'mouse-split-window-vertically)
2481 (global-set-key [vertical-line down-mouse-1] 'mouse-drag-vertical-line)
2482 (global-set-key [vertical-line mouse-1] 'mouse-select-window)
2486 ;; This file contains the functionality of the old mldrag.el.
2487 (defalias 'mldrag-drag-mode-line 'mouse-drag-mode-line)
2488 (defalias 'mldrag-drag-vertical-line 'mouse-drag-vertical-line)
2489 (make-obsolete 'mldrag-drag-mode-line 'mouse-drag-mode-line "21.1")
2490 (make-obsolete 'mldrag-drag-vertical-line 'mouse-drag-vertical-line "21.1")
2493 ;; arch-tag: 9a710ce1-914a-4923-9b81-697f7bf82ab3
2494 ;;; mouse.el ends here