1 ;;; mouse.el --- window system-independent mouse support
3 ;; Copyright (C) 1993, 1994, 1995, 1999, 2000, 2001, 2002, 2003,
4 ;; 2004, 2005, 2006, 2007 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 2, or (at your option)
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; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; This package provides various useful commands (including help
29 ;; system access) through the mouse. All this code assumes that mouse
30 ;; interpretation has been abstracted into Emacs input events.
32 ;; The code is rather X-dependent.
36 ;;; Utility functions.
38 ;;; Indent track-mouse like progn.
39 (put 'track-mouse
'lisp-indent-function
0)
41 (defcustom mouse-yank-at-point nil
42 "*If non-nil, mouse yank commands yank at point instead of at click."
46 (defcustom mouse-drag-copy-region t
47 "*If non-nil, mouse drag copies region to kill-ring."
52 (defcustom mouse-1-click-follows-link
450
53 "Non-nil means that clicking Mouse-1 on a link follows the link.
55 With the default setting, an ordinary Mouse-1 click on a link
56 performs the same action as Mouse-2 on that link, while a longer
57 Mouse-1 click \(hold down the Mouse-1 button for more than 450
58 milliseconds) performs the original Mouse-1 binding \(which
59 typically sets point where you click the mouse).
61 If value is an integer, the time elapsed between pressing and
62 releasing the mouse button determines whether to follow the link
63 or perform the normal Mouse-1 action (typically set point).
64 The absolute numeric value specifices the maximum duration of a
65 \"short click\" in milliseconds. A positive value means that a
66 short click follows the link, and a longer click performs the
67 normal action. A negative value gives the opposite behavior.
69 If value is `double', a double click follows the link.
71 Otherwise, a single Mouse-1 click unconditionally follows the link.
73 Note that dragging the mouse never follows the link.
75 This feature only works in modes that specifically identify
76 clickable text as links, so it may not work with some external
77 packages. See `mouse-on-link-p' for details."
79 :type
'(choice (const :tag
"Disabled" nil
)
80 (const :tag
"Double click" double
)
81 (number :tag
"Single click time limit" :value
450)
82 (other :tag
"Single click" t
))
85 (defcustom mouse-1-click-in-non-selected-windows t
86 "*If non-nil, a Mouse-1 click also follows links in non-selected windows.
88 If nil, a Mouse-1 click on a link in a non-selected window performs
89 the normal mouse-1 binding, typically selects the window and sets
90 point at the click position."
97 ;; Provide a mode-specific menu on a mouse button.
99 (defun popup-menu (menu &optional position prefix
)
100 "Popup the given menu and call the selected option.
101 MENU can be a keymap, an easymenu-style menu or a list of keymaps as for
103 POSITION can be a click event or ((XOFFSET YOFFSET) WINDOW) and defaults to
104 the current mouse position.
105 PREFIX is the prefix argument (if any) to pass to the command."
107 ((keymapp menu
) menu
)
108 ((and (listp menu
) (keymapp (car menu
))) menu
)
109 (t (let* ((map (easy-menu-create-menu (car menu
) (cdr menu
)))
110 (filter (when (symbolp map
)
111 (plist-get (get map
'menu-prop
) :filter
))))
112 (if filter
(funcall filter
(symbol-function map
)) map
)))))
115 (let ((mp (mouse-pixel-position)))
116 (setq position
(list (list (cadr mp
) (cddr mp
)) (car mp
)))))
117 ;; The looping behavior was taken from lmenu's popup-menu-popup
118 (while (and map
(setq event
119 ;; map could be a prefix key, in which case
120 ;; we need to get its function cell
122 (x-popup-menu position
(indirect-function map
))))
123 ;; Strangely x-popup-menu returns a list.
124 ;; mouse-major-mode-menu was using a weird:
125 ;; (key-binding (apply 'vector (append '(menu-bar) menu-prefix events)))
127 (if (and (not (keymapp map
)) (listp map
))
128 ;; We were given a list of keymaps. Search them all
129 ;; in sequence until a first binding is found.
130 (let ((mouse-click (apply 'vector event
))
132 (while (and map
(null binding
))
133 (setq binding
(lookup-key (car map
) mouse-click
))
134 (if (numberp binding
) ; `too long'
136 (setq map
(cdr map
)))
138 ;; We were given a single keymap.
139 (lookup-key map
(apply 'vector event
))))
140 ;; Clear out echoing, which perhaps shows a prefix arg.
142 ;; Maybe try again but with the submap.
143 (setq map
(if (keymapp cmd
) cmd
)))
144 ;; If the user did not cancel by refusing to select,
145 ;; and if the result is a command, run it.
146 (when (and (null map
) (commandp cmd
))
147 (setq prefix-arg prefix
)
148 ;; `setup-specified-language-environment', for instance,
149 ;; expects this to be set from a menu keymap.
150 (setq last-command-event
(car (last event
)))
151 ;; mouse-major-mode-menu was using `command-execute' instead.
152 (call-interactively cmd
))))
154 (defvar mouse-major-mode-menu-prefix
) ; dynamically bound
156 (defun mouse-major-mode-menu (event &optional prefix
)
157 "Pop up a mode-specific menu of mouse commands.
158 Default to the Edit menu if the major mode doesn't define a menu."
159 ;; Switch to the window clicked on, because otherwise
160 ;; the mode's commands may not make sense.
161 (interactive "@e\nP")
162 ;; Let the mode update its menus first.
163 (run-hooks 'activate-menubar-hook
'menu-bar-update-hook
)
164 (let* (;; This is where mouse-major-mode-menu-prefix
165 ;; returns the prefix we should use (after menu-bar).
166 ;; It is either nil or (SOME-SYMBOL).
167 (mouse-major-mode-menu-prefix nil
)
168 ;; Keymap from which to inherit; may be null.
169 (ancestor (mouse-major-mode-menu-1
170 (and (current-local-map)
171 (local-key-binding [menu-bar
]))))
172 ;; Make a keymap in which our last command leads to a menu or
173 ;; default to the edit menu.
175 (make-sparse-keymap (concat mode-name
" Mode"))
176 menu-bar-edit-menu
)))
178 ;; Make our menu inherit from the desired keymap which we want
179 ;; to display as the menu now.
180 (set-keymap-parent newmap ancestor
))
181 (popup-menu newmap event prefix
)))
184 ;; Compute and cache the equivalent keys in MENU and all its submenus.
185 ;;;(defun mouse-major-mode-menu-compute-equiv-keys (menu)
186 ;;; (and (eq (car menu) 'keymap)
187 ;;; (x-popup-menu nil menu))
189 ;;; (and (consp (car menu))
190 ;;; (consp (cdr (car menu)))
191 ;;; (let ((tail (cdr (car menu))))
192 ;;; (while (and (consp tail)
193 ;;; (not (eq (car tail) 'keymap)))
194 ;;; (setq tail (cdr tail)))
196 ;;; (mouse-major-mode-menu-compute-equiv-keys tail))))
197 ;;; (setq menu (cdr menu))))
199 ;; Given a mode's menu bar keymap,
200 ;; if it defines exactly one menu bar menu,
201 ;; return just that menu.
202 ;; Otherwise return a menu for all of them.
203 (defun mouse-major-mode-menu-1 (menubar)
208 (if (consp (car tail
))
211 (setq submap
(car tail
))))
212 (setq tail
(cdr tail
)))
215 (setq mouse-major-mode-menu-prefix
(list (car submap
)))
216 (lookup-key menubar
(vector (car submap
)))))))
218 (defun mouse-popup-menubar (event prefix
)
219 "Pop up a menu equivalent to the menu bar for keyboard EVENT with PREFIX.
220 The contents are the items that would be in the menu bar whether or
221 not it is actually displayed."
222 (interactive "@e \nP")
223 (run-hooks 'activate-menubar-hook
'menu-bar-update-hook
)
224 (let* ((local-menu (and (current-local-map)
225 (lookup-key (current-local-map) [menu-bar
])))
226 (global-menu (lookup-key global-map
[menu-bar
]))
227 ;; If a keymap doesn't have a prompt string (a lazy
228 ;; programmer didn't bother to provide one), create it and
229 ;; insert it into the keymap; each keymap gets its own
230 ;; prompt. This is required for non-toolkit versions to
231 ;; display non-empty menu pane names.
236 (let* ((minor-mode (car menu
))
238 (title-or-map (cadr menu
)))
239 (or (stringp title-or-map
)
243 (capitalize (subst-char-in-string
249 (minor-mode-key-binding [menu-bar
])))
250 (local-title-or-map (and local-menu
(cadr local-menu
)))
251 (global-title-or-map (cadr global-menu
)))
252 (or (null local-menu
)
253 (stringp local-title-or-map
)
254 (setq local-menu
(cons 'keymap
255 (cons (concat mode-name
" Mode Menu")
257 (or (stringp global-title-or-map
)
258 (setq global-menu
(cons 'keymap
260 (cdr global-menu
)))))
261 ;; Supplying the list is faster than making a new map.
262 (popup-menu (append (list global-menu
)
268 (defun mouse-popup-menubar-stuff (event prefix
)
269 "Popup a menu like either `mouse-major-mode-menu' or `mouse-popup-menubar'.
270 Use the former if the menu bar is showing, otherwise the latter."
271 (interactive "@e \nP")
272 (if (zerop (assoc-default 'menu-bar-lines
(frame-parameters) 'eq
0))
273 (mouse-popup-menubar event prefix
)
274 (mouse-major-mode-menu event prefix
)))
276 ;; Commands that operate on windows.
278 (defun mouse-minibuffer-check (event)
279 (let ((w (posn-window (event-start event
))))
280 (and (window-minibuffer-p w
)
281 (not (minibuffer-window-active-p w
))
282 (error "Minibuffer window is not active")))
283 ;; Give temporary modes such as isearch a chance to turn off.
284 (run-hooks 'mouse-leave-buffer-hook
))
286 (defun mouse-delete-window (click)
287 "Delete the window you click on.
288 Do nothing if the frame has just one window.
289 This command must be bound to a mouse click."
291 (unless (one-window-p t
)
292 (mouse-minibuffer-check click
)
293 (delete-window (posn-window (event-start click
)))))
295 (defun mouse-select-window (click)
296 "Select the window clicked on; don't move point."
298 (mouse-minibuffer-check click
)
299 (let ((oframe (selected-frame))
300 (frame (window-frame (posn-window (event-start click
)))))
301 (select-window (posn-window (event-start click
)))
304 (or (eq frame oframe
)
305 (set-mouse-position (selected-frame) (1- (frame-width)) 0))))
307 (defun mouse-tear-off-window (click)
308 "Delete the window clicked on, and create a new frame displaying its buffer."
310 (mouse-minibuffer-check click
)
311 (let* ((window (posn-window (event-start click
)))
312 (buf (window-buffer window
))
313 (frame (make-frame)))
315 (switch-to-buffer buf
)
316 (delete-window window
)))
318 (defun mouse-delete-other-windows ()
319 "Delete all windows except the one you click on."
321 (delete-other-windows))
323 (defun mouse-split-window-vertically (click)
324 "Select Emacs window mouse is on, then split it vertically in half.
325 The window is split at the line clicked on.
326 This command must be bound to a mouse click."
328 (mouse-minibuffer-check click
)
329 (let ((start (event-start click
)))
330 (select-window (posn-window start
))
331 (let ((new-height (1+ (cdr (posn-col-row (event-end click
)))))
332 (first-line window-min-height
)
333 (last-line (- (window-height) window-min-height
)))
334 (if (< last-line first-line
)
335 (error "Window too short to split")
336 (split-window-vertically
337 (min (max new-height first-line
) last-line
))))))
339 (defun mouse-split-window-horizontally (click)
340 "Select Emacs window mouse is on, then split it horizontally in half.
341 The window is split at the column clicked on.
342 This command must be bound to a mouse click."
344 (mouse-minibuffer-check click
)
345 (let ((start (event-start click
)))
346 (select-window (posn-window start
))
347 (let ((new-width (1+ (car (posn-col-row (event-end click
)))))
348 (first-col window-min-width
)
349 (last-col (- (window-width) window-min-width
)))
350 (if (< last-col first-col
)
351 (error "Window too narrow to split")
352 (split-window-horizontally
353 (min (max new-width first-col
) last-col
))))))
355 (defun mouse-drag-window-above (window)
356 "Return the (or a) window directly above WINDOW.
357 That means one whose bottom edge is at the same height as WINDOW's top edge."
358 (let ((start-top (nth 1 (window-edges window
)))
359 (start-left (nth 0 (window-edges window
)))
360 (start-right (nth 2 (window-edges window
)))
361 (start-window window
)
363 (setq window
(previous-window window
0))
364 (while (and (not above-window
) (not (eq window start-window
)))
365 (let ((left (nth 0 (window-edges window
)))
366 (right (nth 2 (window-edges window
))))
367 (when (and (= (+ (window-height window
) (nth 1 (window-edges window
)))
369 (or (and (<= left start-left
) (<= start-right right
))
370 (and (<= start-left left
) (<= left start-right
))
371 (and (<= start-left right
) (<= right start-right
))))
372 (setq above-window window
)))
373 (setq window
(previous-window window
)))
376 (defun mouse-drag-move-window-bottom (window growth
)
377 "Move the bottom of WINDOW up or down by GROWTH lines.
378 Move it down if GROWTH is positive, or up if GROWTH is negative.
379 If this would make WINDOW too short,
380 shrink the window or windows above it to make room."
382 (adjust-window-trailing-edge window growth nil
)
385 (defsubst mouse-drag-move-window-top
(window growth
)
386 "Move the top of WINDOW up or down by GROWTH lines.
387 Move it down if GROWTH is positive, or up if GROWTH is negative.
388 If this would make WINDOW too short, shrink the window or windows
389 above it to make room."
390 ;; Moving the top of WINDOW is actually moving the bottom of the
392 (let ((window-above (mouse-drag-window-above window
)))
394 (mouse-drag-move-window-bottom window-above
(- growth
)))))
396 (defun mouse-drag-mode-line-1 (start-event mode-line-p
)
397 "Change the height of a window by dragging on the mode or header line.
398 START-EVENT is the starting mouse-event of the drag action.
399 MODE-LINE-P non-nil means dragging a mode line; nil means a header line."
400 ;; Give temporary modes such as isearch a chance to turn off.
401 (run-hooks 'mouse-leave-buffer-hook
)
404 (start (event-start start-event
))
405 (start-event-window (posn-window start
))
406 (start-event-frame (window-frame start-event-window
))
407 (start-nwindows (count-windows t
))
408 (minibuffer (frame-parameter nil
'minibuffer
))
409 should-enlarge-minibuffer event mouse y top bot edges wconfig growth
)
412 ;; if this is the bottommost ordinary window, then to
413 ;; move its modeline the minibuffer must be enlarged.
414 (setq should-enlarge-minibuffer
417 (not (one-window-p t
))
418 (= (nth 1 (window-edges minibuffer
))
419 (nth 3 (window-edges start-event-window
)))))
421 ;; loop reading events and sampling the position of
424 (setq event
(read-event)
425 mouse
(mouse-position))
428 ;; - there is a switch-frame event.
429 ;; - the mouse isn't in the frame that we started in
430 ;; - the mouse isn't in any Emacs frame
432 ;; - there is a mouse-movement event
433 ;; - there is a scroll-bar-movement event
434 ;; (same as mouse movement for our purposes)
436 ;; - there is a keyboard event or some other unknown event.
437 (cond ((not (consp event
))
440 ((memq (car event
) '(switch-frame select-window
))
443 ((not (memq (car event
) '(mouse-movement scroll-bar-movement
)))
445 ;; Do not unread a drag-mouse-1 event since it will cause the
446 ;; selection of the window above when dragging the modeline
447 ;; above the selected window.
448 (unless (eq (car event
) 'drag-mouse-1
)
449 (push event unread-command-events
)))
452 ((not (eq (car mouse
) start-event-frame
))
455 ((null (car (cdr mouse
)))
459 (setq y
(cdr (cdr mouse
))
460 edges
(window-edges start-event-window
)
464 ;; compute size change needed
466 (setq growth
(- y bot -
1)))
468 (when (< (- bot y
) window-min-height
)
469 (setq y
(- bot window-min-height
)))
470 ;; The window's top includes the header line!
471 (setq growth
(- top y
))))
472 (setq wconfig
(current-window-configuration))
474 ;; Check for an error case.
475 (when (and (/= growth
0)
478 (error "Attempt to resize sole window"))
480 ;; grow/shrink minibuffer?
481 (if should-enlarge-minibuffer
482 (unless resize-mini-windows
483 (mouse-drag-move-window-bottom start-event-window growth
))
484 ;; no. grow/shrink the selected window
485 ;(message "growth = %d" growth)
487 (mouse-drag-move-window-bottom start-event-window growth
)
488 (mouse-drag-move-window-top start-event-window growth
)))
490 ;; if this window's growth caused another
491 ;; window to be deleted because it was too
492 ;; short, rescind the change.
494 ;; if size change caused space to be stolen
495 ;; from a window above this one, rescind the
496 ;; change, but only if we didn't grow/shrink
497 ;; the minibuffer. minibuffer size changes
498 ;; can cause all windows to shrink... no way
500 (when (or (/= start-nwindows
(count-windows t
))
501 (and (not should-enlarge-minibuffer
)
506 ;; Choose right window.
507 start-event-window
)))))
508 (set-window-configuration wconfig
)))))))))
510 (defun mouse-drag-mode-line (start-event)
511 "Change the height of a window by dragging on the mode line."
513 (mouse-drag-mode-line-1 start-event t
))
515 (defun mouse-drag-header-line (start-event)
516 "Change the height of a window by dragging on the header line.
517 Windows whose header-lines are at the top of the frame cannot be
518 resized by dragging their header-line."
520 ;; Changing the window's size by dragging its header-line when the
521 ;; header-line is at the top of the frame is somewhat strange,
522 ;; because the header-line doesn't move, so don't do it.
523 (let* ((start (event-start start-event
))
524 (window (posn-window start
))
525 (frame (window-frame window
))
526 (first-window (frame-first-window frame
)))
527 (unless (or (eq window first-window
)
528 (= (nth 1 (window-edges window
))
529 (nth 1 (window-edges first-window
))))
530 (mouse-drag-mode-line-1 start-event nil
))))
533 (defun mouse-drag-vertical-line-rightward-window (window)
534 "Return a window that is immediately to the right of WINDOW, or nil."
535 (let ((bottom (nth 3 (window-inside-edges window
)))
536 (left (nth 0 (window-inside-edges window
)))
538 (try (previous-window window
)))
539 (while (not (eq try window
))
540 (let ((try-top (nth 1 (window-inside-edges try
)))
541 (try-bottom (nth 3 (window-inside-edges try
)))
542 (try-right (nth 2 (window-inside-edges try
))))
543 (if (and (< try-top bottom
)
544 (>= try-bottom bottom
)
546 (or (null best-right
) (> try-right best-right
)))
547 (setq best-right try-right best try
)))
548 (setq try
(previous-window try
)))
551 (defun mouse-drag-vertical-line (start-event)
552 "Change the width of a window by dragging on the vertical line."
554 ;; Give temporary modes such as isearch a chance to turn off.
555 (run-hooks 'mouse-leave-buffer-hook
)
558 (start-event-frame (window-frame (car (car (cdr start-event
)))))
559 (start-event-window (car (car (cdr start-event
))))
560 event mouse x left right edges growth
562 (or (cdr (assq 'vertical-scroll-bars
(frame-parameters start-event-frame
)))
566 (error "Attempt to resize sole ordinary window"))
567 ((and (eq which-side
'right
)
568 (>= (nth 2 (window-inside-edges start-event-window
))
569 (frame-width start-event-frame
)))
570 (error "Attempt to drag rightmost scrollbar"))
571 ((and (eq which-side
'left
)
572 (= (nth 0 (window-inside-edges start-event-window
)) 0))
573 (error "Attempt to drag leftmost scrollbar")))
576 ;; loop reading events and sampling the position of
579 (setq event
(read-event)
580 mouse
(mouse-position))
582 ;; - there is a switch-frame event.
583 ;; - the mouse isn't in the frame that we started in
584 ;; - the mouse isn't in any Emacs frame
586 ;; - there is a mouse-movement event
587 ;; - there is a scroll-bar-movement event
588 ;; (same as mouse movement for our purposes)
590 ;; - there is a keyboard event or some other unknown event
592 (cond ((integerp event
)
594 ((memq (car event
) '(switch-frame select-window
))
596 ((not (memq (car event
)
597 '(mouse-movement scroll-bar-movement
)))
599 (setq unread-command-events
600 (cons event unread-command-events
)))
602 ((not (eq (car mouse
) start-event-frame
))
604 ((null (car (cdr mouse
)))
608 ;; If the scroll bar is on the window's left,
609 ;; adjust the window on the left.
610 (if (eq which-side
'right
)
612 (mouse-drag-vertical-line-rightward-window
613 start-event-window
))))
614 (setq x
(- (car (cdr mouse
))
615 (if (eq which-side
'right
) 0 2))
616 edges
(window-edges window
)
619 ;; scale back a move that would make the
621 (if (< (- x left -
1) window-min-width
)
622 (setq x
(+ left window-min-width -
1)))
623 ;; compute size change needed
624 (setq growth
(- x right -
1))
626 (adjust-window-trailing-edge window growth t
)
629 (defun mouse-set-point (event)
630 "Move point to the position clicked on with the mouse.
631 This should be bound to a mouse click event type."
633 (mouse-minibuffer-check event
)
634 ;; Use event-end in case called from mouse-drag-region.
635 ;; If EVENT is a click, event-end and event-start give same value.
636 (posn-set-point (event-end event
)))
638 (defvar mouse-last-region-beg nil
)
639 (defvar mouse-last-region-end nil
)
640 (defvar mouse-last-region-tick nil
)
642 (defun mouse-region-match ()
643 "Return non-nil if there's an active region that was set with the mouse."
644 (and (mark t
) mark-active
645 (eq mouse-last-region-beg
(region-beginning))
646 (eq mouse-last-region-end
(region-end))
647 (eq mouse-last-region-tick
(buffer-modified-tick))))
649 (defun mouse-set-region (click)
650 "Set the region to the text dragged over, and copy to kill ring.
651 This should be bound to a mouse drag event."
653 (mouse-minibuffer-check click
)
654 (let ((posn (event-start click
))
655 (end (event-end click
)))
656 (select-window (posn-window posn
))
657 (if (numberp (posn-point posn
))
658 (goto-char (posn-point posn
)))
659 ;; If mark is highlighted, no need to bounce the cursor.
660 ;; On X, we highlight while dragging, thus once again no need to bounce.
661 (or transient-mark-mode
662 (memq (framep (selected-frame)) '(x pc w32 mac
))
666 (if (numberp (posn-point end
))
667 (goto-char (posn-point end
)))
668 ;; Don't set this-command to kill-region, so that a following
669 ;; C-w will not double the text in the kill ring.
670 ;; Ignore last-command so we don't append to a preceding kill.
671 (when mouse-drag-copy-region
672 (let (this-command last-command deactivate-mark
)
673 (copy-region-as-kill (mark) (point))))
674 (mouse-set-region-1)))
676 (defun mouse-set-region-1 ()
677 ;; Set transient-mark-mode for a little while.
678 (if (memq transient-mark-mode
'(nil identity
))
679 (setq transient-mark-mode
'only
))
680 (setq mouse-last-region-beg
(region-beginning))
681 (setq mouse-last-region-end
(region-end))
682 (setq mouse-last-region-tick
(buffer-modified-tick)))
684 (defcustom mouse-scroll-delay
0.25
685 "*The pause between scroll steps caused by mouse drags, in seconds.
686 If you drag the mouse beyond the edge of a window, Emacs scrolls the
687 window to bring the text beyond that edge into view, with a delay of
688 this many seconds between scroll steps. Scrolling stops when you move
689 the mouse back into the window, or release the button.
690 This variable's value may be non-integral.
691 Setting this to zero causes Emacs to scroll as fast as it can."
695 (defcustom mouse-scroll-min-lines
1
696 "*The minimum number of lines scrolled by dragging mouse out of window.
697 Moving the mouse out the top or bottom edge of the window begins
698 scrolling repeatedly. The number of lines scrolled per repetition
699 is normally equal to the number of lines beyond the window edge that
700 the mouse has moved. However, it always scrolls at least the number
701 of lines specified by this variable."
705 (defun mouse-scroll-subr (window jump
&optional overlay start
)
706 "Scroll the window WINDOW, JUMP lines at a time, until new input arrives.
707 If OVERLAY is an overlay, let it stretch from START to the far edge of
708 the newly visible text.
709 Upon exit, point is at the far edge of the newly visible text."
711 ((and (> jump
0) (< jump mouse-scroll-min-lines
))
712 (setq jump mouse-scroll-min-lines
))
713 ((and (< jump
0) (< (- jump
) mouse-scroll-min-lines
))
714 (setq jump
(- mouse-scroll-min-lines
))))
715 (let ((opoint (point)))
717 (goto-char (window-start window
))
718 (if (not (zerop (vertical-motion jump window
)))
720 (set-window-start window
(point))
722 (if (window-end window
)
724 (goto-char (window-end window
))
725 ;; window-end doesn't reflect the window's new
726 ;; start position until the next redisplay.
727 (vertical-motion (1- jump
) window
))
728 (vertical-motion (- (window-height window
) 2)))
729 (goto-char (window-start window
)))
731 (move-overlay overlay start
(point)))
732 ;; Now that we have scrolled WINDOW properly,
733 ;; put point back where it was for the redisplay
734 ;; so that we don't mess up the selected window.
735 (or (eq window
(selected-window))
737 (sit-for mouse-scroll-delay
)))))
738 (or (eq window
(selected-window))
739 (goto-char opoint
))))
741 ;; Create an overlay and immediately delete it, to get "overlay in no buffer".
742 (defconst mouse-drag-overlay
743 (let ((ol (make-overlay (point-min) (point-min))))
745 (overlay-put ol
'face
'region
)
748 (defvar mouse-selection-click-count
0)
750 (defvar mouse-selection-click-count-buffer nil
)
752 (defun mouse-drag-region (start-event)
753 "Set the region to the text that the mouse is dragged over.
754 Highlight the drag area as you move the mouse.
755 This must be bound to a button-down mouse event.
756 In Transient Mark mode, the highlighting remains as long as the mark
757 remains active. Otherwise, it remains until the next input event.
759 If the click is in the echo area, display the `*Messages*' buffer."
761 (let ((w (posn-window (event-start start-event
))))
762 (if (and (window-minibuffer-p w
)
763 (not (minibuffer-window-active-p w
)))
765 ;; Swallow the up-event.
767 (set-buffer (get-buffer-create "*Messages*"))
768 (goto-char (point-max))
769 (display-buffer (current-buffer)))
770 ;; Give temporary modes such as isearch a chance to turn off.
771 (run-hooks 'mouse-leave-buffer-hook
)
772 (mouse-drag-track start-event t
))))
775 (defun mouse-posn-property (pos property
)
776 "Look for a property at click position.
777 POS may be either a buffer position or a click position like
778 those returned from `event-start'. If the click position is on
779 a string, the text property PROPERTY is examined.
780 If this is nil or the click is not on a string, then
781 the corresponding buffer position is searched for PROPERTY.
782 If PROPERTY is encountered in one of those places,
783 its value is returned."
785 (let ((w (posn-window pos
)) (pt (posn-point pos
))
786 (str (posn-string pos
)))
788 (get-text-property (cdr str
) property
(car str
)))
790 (get-char-property pt property w
))))
791 (get-char-property pos property
)))
793 (defun mouse-on-link-p (pos)
794 "Return non-nil if POS is on a link in the current buffer.
795 POS must be a buffer position in the current buffer or a mouse
796 event location in the selected window (see `event-start').
797 However, if `mouse-1-click-in-non-selected-windows' is non-nil,
798 POS may be a mouse event location in any window.
800 A clickable link is identified by one of the following methods:
802 - If the character at POS has a non-nil `follow-link' text or
803 overlay property, the value of that property determines what to do.
805 - If there is a local key-binding or a keybinding at position POS
806 for the `follow-link' event, the binding of that event determines
809 The resulting value determine whether POS is inside a link:
811 - If the value is `mouse-face', POS is inside a link if there
812 is a non-nil `mouse-face' property at POS. Return t in this case.
814 - If the value is a function, FUNC, POS is inside a link if
815 the call \(FUNC POS) returns non-nil. Return the return value
816 from that call. Arg is \(posn-point POS) if POS is a mouse event.
818 - Otherwise, return the value itself.
820 The return value is interpreted as follows:
822 - If it is a string, the mouse-1 event is translated into the
823 first character of the string, i.e. the action of the mouse-1
824 click is the local or global binding of that character.
826 - If it is a vector, the mouse-1 event is translated into the
827 first element of that vector, i.e. the action of the mouse-1
828 click is the local or global binding of that event.
830 - Otherwise, the mouse-1 event is translated into a mouse-2 event
831 at the same position."
833 (and (or (not (consp pos
))
834 mouse-1-click-in-non-selected-windows
835 (eq (selected-window) (posn-window pos
)))
836 (or (mouse-posn-property pos
'follow-link
)
837 (key-binding [follow-link
] nil t pos
)))))
839 ((eq action
'mouse-face
)
840 (and (mouse-posn-property pos
'mouse-face
) t
))
842 ;; FIXME: This seems questionable if the click is not in a buffer.
843 ;; Should we instead decide that `action' takes a `posn'?
845 (with-current-buffer (window-buffer (posn-window pos
))
846 (funcall action
(posn-point pos
)))
847 (funcall action pos
)))
850 (defun mouse-fixup-help-message (msg)
851 "Fix help message MSG for `mouse-1-click-follows-link'."
853 (if (and mouse-1-click-follows-link
856 (string-match "^mouse-2" msg
))
857 (setq mp
(mouse-pixel-position))
858 (consp (setq pos
(cdr mp
)))
859 (car pos
) (>= (car pos
) 0)
860 (cdr pos
) (>= (cdr pos
) 0)
861 (setq pos
(posn-at-x-y (car pos
) (cdr pos
) (car mp
)))
862 (windowp (posn-window pos
)))
863 (with-current-buffer (window-buffer (posn-window pos
))
864 (if (mouse-on-link-p pos
)
867 ((eq mouse-1-click-follows-link
'double
) "double-")
868 ((and (integerp mouse-1-click-follows-link
)
869 (< mouse-1-click-follows-link
0)) "Long ")
871 "mouse-1" (substring msg
7)))))))
874 (defun mouse-move-drag-overlay (ol start end mode
)
875 (unless (= start end
)
876 ;; Go to START first, so that when we move to END, if it's in the middle
877 ;; of intangible text, point jumps in the direction away from START.
878 ;; Don't do it if START=END otherwise a single click risks selecting
879 ;; a region if it's on intangible text. This exception was originally
880 ;; only applied on entry to mouse-drag-region, which had the problem
881 ;; that a tiny move during a single-click would cause the intangible
882 ;; text to be selected.
886 (let ((range (mouse-start-end start end mode
)))
887 (move-overlay ol
(car range
) (nth 1 range
))))
889 (defun mouse-drag-track (start-event &optional
890 do-mouse-drag-region-post-process
)
891 "Track mouse drags by highlighting area between point and cursor.
892 The region will be defined with mark and point, and the overlay
893 will be deleted after return. DO-MOUSE-DRAG-REGION-POST-PROCESS
894 should only be used by mouse-drag-region."
895 (mouse-minibuffer-check start-event
)
896 (setq mouse-selection-click-count-buffer
(current-buffer))
897 (let* ((original-window (selected-window))
898 ;; We've recorded what we needed from the current buffer and
899 ;; window, now let's jump to the place of the event, where things
901 (_ (mouse-set-point start-event
))
903 (start-posn (event-start start-event
))
904 (start-point (posn-point start-posn
))
905 (start-window (posn-window start-posn
))
906 (start-window-start (window-start start-window
))
907 (start-hscroll (window-hscroll start-window
))
908 (bounds (window-edges start-window
))
909 (make-cursor-line-fully-visible nil
)
911 (bottom (if (window-minibuffer-p start-window
)
913 ;; Don't count the mode line.
914 (1- (nth 3 bounds
))))
915 (on-link (and mouse-1-click-follows-link
916 (or mouse-1-click-in-non-selected-windows
917 (eq start-window original-window
))
918 ;; Use start-point before the intangibility
919 ;; treatment, in case we click on a link inside an
921 (mouse-on-link-p start-posn
)))
922 (click-count (1- (event-click-count start-event
)))
923 (remap-double-click (and on-link
924 (eq mouse-1-click-follows-link
'double
)
926 ;; Suppress automatic hscrolling, because that is a nuisance
927 ;; when setting point near the right fringe (but see below).
928 (automatic-hscrolling-saved automatic-hscrolling
)
929 (automatic-hscrolling nil
))
930 (setq mouse-selection-click-count click-count
)
931 ;; In case the down click is in the middle of some intangible text,
932 ;; use the end of that text, and put it in START-POINT.
933 (if (< (point) start-point
)
934 (goto-char start-point
))
935 (setq start-point
(point))
936 (if remap-double-click
;; Don't expand mouse overlay in links
937 (setq click-count
0))
938 (mouse-move-drag-overlay mouse-drag-overlay start-point start-point
940 (overlay-put mouse-drag-overlay
'window start-window
)
942 (let (event end end-point last-end-point
)
945 (setq event
(read-event))
946 (or (mouse-movement-p event
)
947 (memq (car-safe event
) '(switch-frame select-window
))))
948 (if (memq (car-safe event
) '(switch-frame select-window
))
950 ;; Automatic hscrolling did not occur during the call to
951 ;; `read-event'; but if the user subsequently drags the
952 ;; mouse, go ahead and hscroll.
953 (let ((automatic-hscrolling automatic-hscrolling-saved
))
955 (setq end
(event-end event
)
956 end-point
(posn-point end
))
957 (if (numberp end-point
)
958 (setq last-end-point end-point
))
961 ;; Are we moving within the original window?
962 ((and (eq (posn-window end
) start-window
)
963 (integer-or-marker-p end-point
))
964 (mouse-move-drag-overlay mouse-drag-overlay start-point end-point click-count
))
967 (let ((mouse-row (cdr (cdr (mouse-position)))))
971 (mouse-scroll-subr start-window
(- mouse-row top
)
972 mouse-drag-overlay start-point
))
973 ((>= mouse-row bottom
)
974 (mouse-scroll-subr start-window
(1+ (- mouse-row bottom
))
975 mouse-drag-overlay start-point
)))))))))
977 ;; In case we did not get a mouse-motion event
978 ;; for the final move of the mouse before a drag event
979 ;; pretend that we did get one.
980 (when (and (memq 'drag
(event-modifiers (car-safe event
)))
981 (setq end
(event-end event
)
982 end-point
(posn-point end
))
983 (eq (posn-window end
) start-window
)
984 (integer-or-marker-p end-point
))
985 (mouse-move-drag-overlay mouse-drag-overlay start-point end-point click-count
))
987 ;; Handle the terminating event
989 (let* ((fun (key-binding (vector (car event
))))
990 (do-multi-click (and (> (event-click-count event
) 0)
994 mouse-set-region
))))))
995 ;; Run the binding of the terminating up-event, if possible.
996 (if (and (not (= (overlay-start mouse-drag-overlay
)
997 (overlay-end mouse-drag-overlay
)))
998 (not do-multi-click
))
1000 (if (numberp (posn-point (event-end event
)))
1001 (posn-point (event-end event
))
1003 ;; The end that comes from where we ended the drag.
1006 (if (and stop-point
(< stop-point start-point
))
1007 (overlay-start mouse-drag-overlay
)
1008 (overlay-end mouse-drag-overlay
)))
1009 ;; The end that comes from where we started the drag.
1011 (region-commencement
1012 (- (+ (overlay-end mouse-drag-overlay
)
1013 (overlay-start mouse-drag-overlay
))
1014 region-termination
))
1015 last-command this-command
)
1016 (push-mark region-commencement t t
)
1017 (goto-char region-termination
)
1018 (if (not do-mouse-drag-region-post-process
)
1019 ;; Skip all post-event handling, return immediately.
1020 (delete-overlay mouse-drag-overlay
)
1021 ;; Don't let copy-region-as-kill set deactivate-mark.
1022 (when mouse-drag-copy-region
1023 (let (deactivate-mark)
1024 (copy-region-as-kill (point) (mark t
))))
1025 (let ((buffer (current-buffer)))
1027 ;; mouse-show-mark can call read-event,
1028 ;; and that means the Emacs server could switch buffers
1029 ;; under us. If that happened,
1030 ;; avoid trying to use the region.
1031 (and (mark t
) mark-active
1032 (eq buffer
(current-buffer))
1033 (mouse-set-region-1)))))
1034 ;; Run the binding of the terminating up-event.
1035 ;; If a multiple click is not bound to mouse-set-point,
1036 ;; cancel the effects of mouse-move-drag-overlay to
1037 ;; avoid producing wrong results.
1038 (if do-multi-click
(goto-char start-point
))
1039 (delete-overlay mouse-drag-overlay
)
1040 (when (and (functionp fun
)
1041 (= start-hscroll
(window-hscroll start-window
))
1042 ;; Don't run the up-event handler if the
1043 ;; window start changed in a redisplay after
1044 ;; the mouse-set-point for the down-mouse
1045 ;; event at the beginning of this function.
1046 ;; When the window start has changed, the
1047 ;; up-mouse event will contain a different
1048 ;; position due to the new window contents,
1049 ;; and point is set again.
1051 (= (window-start start-window
)
1052 start-window-start
)))
1054 (or (not end-point
) (= end-point start-point
))
1056 (or remap-double-click
1058 (not (eq mouse-1-click-follows-link
'double
))
1060 (= (event-click-count 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 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
))))))))
1068 ;; If we rebind to mouse-2, reselect previous selected window,
1069 ;; so that the mouse-2 event runs in the same
1070 ;; situation as if user had clicked it directly.
1071 ;; Fixes the bug reported by juri@jurta.org on 2005-12-27.
1072 (if (or (vectorp on-link
) (stringp on-link
))
1073 (setq event
(aref on-link
0))
1074 (select-window original-window
)
1075 (setcar event
'mouse-2
)
1076 ;; If this mouse click has never been done by
1077 ;; the user, it doesn't have the necessary
1078 ;; property to be interpreted correctly.
1079 (put 'mouse-2
'event-kind
'mouse-click
)))
1080 (push event unread-command-events
))))
1082 ;; Case where the end-event is not a cons cell (it's just a boring
1084 (delete-overlay mouse-drag-overlay
)))))
1086 ;; Commands to handle xterm-style multiple clicks.
1087 (defun mouse-skip-word (dir)
1088 "Skip over word, over whitespace, or over identical punctuation.
1089 If DIR is positive skip forward; if negative, skip backward."
1090 (let* ((char (following-char))
1091 (syntax (char-to-string (char-syntax char
))))
1092 (cond ((string= syntax
"w")
1093 ;; Here, we can't use skip-syntax-forward/backward because
1094 ;; they don't pay attention to word-separating-categories,
1095 ;; and thus they will skip over a true word boundary. So,
1096 ;; we simularte the original behaviour by using
1099 (if (not (looking-at "\\<"))
1101 (if (or (looking-at "\\<") (not (looking-at "\\>")))
1103 ((string= syntax
" ")
1105 (skip-syntax-backward syntax
)
1106 (skip-syntax-forward syntax
)))
1107 ((string= syntax
"_")
1109 (skip-syntax-backward "w_")
1110 (skip-syntax-forward "w_")))
1112 (while (and (not (bobp)) (= (preceding-char) char
))
1115 (while (and (not (eobp)) (= (following-char) char
))
1116 (forward-char 1))))))
1118 (defun mouse-start-end (start end mode
)
1119 "Return a list of region bounds based on START and END according to MODE.
1120 If MODE is 0 then set point to (min START END), mark to (max START END).
1121 If MODE is 1 then set point to start of word at (min START END),
1122 mark to end of word at (max START END).
1123 If MODE is 2 then do the same for lines."
1128 (setq mode
(mod mode
3))
1134 (= (char-syntax (char-after start
)) ?\
())
1143 (= (char-syntax (char-after start
)) ?\
)))
1144 (list (save-excursion
1145 (goto-char (1+ start
))
1152 (= (char-syntax (char-after start
)) ?
\"))
1153 (let ((open (or (eq start
(point-min))
1155 (goto-char (- start
1))
1156 (looking-at "\\s(\\|\\s \\|\\s>")))))
1166 (list (save-excursion
1169 (goto-char (1+ start
))
1175 (list (save-excursion
1177 (mouse-skip-word -
1)
1184 (list (save-excursion
1186 (beginning-of-line 1)
1193 ;; Subroutine: set the mark where CLICK happened,
1194 ;; but don't do anything else.
1195 (defun mouse-set-mark-fast (click)
1196 (mouse-minibuffer-check click
)
1197 (let ((posn (event-start click
)))
1198 (select-window (posn-window posn
))
1199 (if (numberp (posn-point posn
))
1200 (push-mark (posn-point posn
) t t
))))
1202 (defun mouse-undouble-last-event (events)
1203 (let* ((index (1- (length events
)))
1204 (last (nthcdr index events
))
1206 (basic (event-basic-type event
))
1207 (old-modifiers (event-modifiers event
))
1208 (modifiers (delq 'double
(delq 'triple
(copy-sequence old-modifiers
))))
1211 ;; Use reverse, not nreverse, since event-modifiers
1212 ;; does not copy the list it returns.
1213 (cons (event-convert-list (reverse (cons basic modifiers
)))
1217 (if (and (not (equal modifiers old-modifiers
))
1218 (key-binding (apply 'vector events
)))
1223 ;; Momentarily show where the mark is, if highlighting doesn't show it.
1225 (defcustom mouse-region-delete-keys
'([delete] [deletechar] [backspace])
1226 "List of keys that should cause the mouse region to be deleted."
1228 :type '(repeat key-sequence))
1230 (defun mouse-show-mark ()
1231 (let ((inhibit-quit t)
1233 event events key ignore
1234 (x-lost-selection-functions
1235 (when (boundp 'x-lost-selection-functions)
1236 (copy-sequence x-lost-selection-functions))))
1237 (add-hook 'x-lost-selection-functions
1239 (when (eq seltype 'PRIMARY)
1241 (throw 'mouse-show-mark t))))
1242 (if transient-mark-mode
1243 (delete-overlay mouse-drag-overlay)
1244 (move-overlay mouse-drag-overlay (point) (mark t)))
1245 (catch 'mouse-show-mark
1246 ;; In this loop, execute scroll bar and switch-frame events.
1247 ;; Should we similarly handle `select-window' events? --Stef
1248 ;; Also ignore down-events that are undefined.
1249 (while (progn (setq event (read-event))
1250 (setq events (append events (list event)))
1251 (setq key (apply 'vector events))
1252 (or (and (consp event)
1253 (eq (car event) 'switch-frame))
1255 (eq (posn-point (event-end event))
1256 'vertical-scroll-bar))
1257 (and (memq 'down (event-modifiers event))
1258 (not (key-binding key))
1259 (not (mouse-undouble-last-event events))
1260 (not (member key mouse-region-delete-keys)))))
1262 (or (eq (car event) 'switch-frame)
1263 (eq (posn-point (event-end event))
1264 'vertical-scroll-bar))
1265 (let ((keys (vector 'vertical-scroll-bar event)))
1266 (and (key-binding keys)
1268 (call-interactively (key-binding keys)
1270 (setq events nil)))))))
1271 ;; If we lost the selection, just turn off the highlighting.
1273 ;; For certain special keys, delete the region.
1274 (if (member key mouse-region-delete-keys)
1276 ;; Since notionally this is a separate command,
1277 ;; run all the hooks that would be run if it were
1278 ;; executed separately.
1279 (run-hooks 'post-command-hook)
1280 (setq last-command this-command)
1281 (setq this-original-command 'delete-region)
1282 (setq this-command (or (command-remapping this-original-command)
1283 this-original-command))
1284 (run-hooks 'pre-command-hook)
1285 (call-interactively this-command))
1286 ;; Otherwise, unread the key so it gets executed normally.
1287 (setq unread-command-events
1288 (nconc events unread-command-events))))
1289 (setq quit-flag nil)
1290 (unless transient-mark-mode
1291 (delete-overlay mouse-drag-overlay))))
1293 (defun mouse-set-mark (click)
1294 "Set mark at the position clicked on with the mouse.
1295 Display cursor at that position for a second.
1296 This must be bound to a mouse click."
1298 (mouse-minibuffer-check click)
1299 (select-window (posn-window (event-start click)))
1300 ;; We don't use save-excursion because that preserves the mark too.
1301 (let ((point-save (point)))
1303 (progn (mouse-set-point click)
1305 (or transient-mark-mode
1307 (goto-char point-save))))
1309 (defun mouse-kill (click)
1310 "Kill the region between point and the mouse click.
1311 The text is saved in the kill ring, as with \\[kill-region]."
1313 (mouse-minibuffer-check click)
1314 (let* ((posn (event-start click))
1315 (click-posn (posn-point posn)))
1316 (select-window (posn-window posn))
1317 (if (numberp click-posn)
1318 (kill-region (min (point) click-posn)
1319 (max (point) click-posn)))))
1321 (defun mouse-yank-at-click (click arg)
1322 "Insert the last stretch of killed text at the position clicked on.
1323 Also move point to one end of the text thus inserted (normally the end),
1324 and set mark at the beginning.
1325 Prefix arguments are interpreted as with \\[yank].
1326 If `mouse-yank-at-point' is non-nil, insert at point
1327 regardless of where you click."
1328 (interactive "e\nP")
1329 ;; Give temporary modes such as isearch a chance to turn off.
1330 (run-hooks 'mouse-leave-buffer-hook)
1331 (or mouse-yank-at-point (mouse-set-point click))
1332 (setq this-command 'yank)
1333 (setq mouse-selection-click-count 0)
1336 (defun mouse-kill-ring-save (click)
1337 "Copy the region between point and the mouse click in the kill ring.
1338 This does not delete the region; it acts like \\[kill-ring-save]."
1340 (mouse-set-mark-fast click)
1341 (let (this-command last-command)
1342 (kill-ring-save (point) (mark t)))
1345 ;;; This function used to delete the text between point and the mouse
1346 ;;; whenever it was equal to the front of the kill ring, but some
1347 ;;; people found that confusing.
1349 ;;; A list (TEXT START END), describing the text and position of the last
1350 ;;; invocation of mouse-save-then-kill.
1351 (defvar mouse-save-then-kill-posn nil)
1353 (defun mouse-save-then-kill-delete-region (beg end)
1354 ;; We must make our own undo boundaries
1355 ;; because they happen automatically only for the current buffer.
1357 (if (or (= beg end) (eq buffer-undo-list t))
1358 ;; If we have no undo list in this buffer,
1360 (delete-region beg end)
1361 ;; Delete, but make the undo-list entry share with the kill ring.
1362 ;; First, delete just one char, so in case buffer is being modified
1363 ;; for the first time, the undo list records that fact.
1364 (let (before-change-functions after-change-functions)
1366 (+ beg (if (> end beg) 1 -1))))
1367 (let ((buffer-undo-list buffer-undo-list))
1368 ;; Undo that deletion--but don't change the undo list!
1369 (let (before-change-functions after-change-functions)
1370 (primitive-undo 1 buffer-undo-list))
1371 ;; Now delete the rest of the specified region,
1372 ;; but don't record it.
1373 (setq buffer-undo-list t)
1374 (if (/= (length (car kill-ring)) (- (max end beg) (min end beg)))
1375 (error "Lossage in mouse-save-then-kill-delete-region"))
1376 (delete-region beg end))
1377 (let ((tail buffer-undo-list))
1378 ;; Search back in buffer-undo-list for the string
1379 ;; that came from deleting one character.
1380 (while (and tail (not (stringp (car (car tail)))))
1381 (setq tail (cdr tail)))
1382 ;; Replace it with an entry for the entire deleted text.
1384 (setcar tail (cons (car kill-ring) (min beg end))))))
1387 (defun mouse-save-then-kill (click)
1388 "Save text to point in kill ring; the second time, kill the text.
1389 If the text between point and the mouse is the same as what's
1390 at the front of the kill ring, this deletes the text.
1391 Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
1392 which prepares for a second click to delete the text.
1394 If you have selected words or lines, this command extends the
1395 selection through the word or line clicked on. If you do this
1396 again in a different position, it extends the selection again.
1397 If you do this twice in the same position, the selection is killed."
1399 (let ((before-scroll
1400 (with-current-buffer (window-buffer (posn-window (event-start click)))
1401 point-before-scroll)))
1402 (mouse-minibuffer-check click)
1403 (let ((click-posn (posn-point (event-start click)))
1404 ;; Don't let a subsequent kill command append to this one:
1405 ;; prevent setting this-command to kill-region.
1406 (this-command this-command))
1407 (if (and (with-current-buffer
1408 (window-buffer (posn-window (event-start click)))
1409 (and (mark t) (> (mod mouse-selection-click-count 3) 0)
1410 ;; Don't be fooled by a recent click in some other buffer.
1411 (eq mouse-selection-click-count-buffer
1412 (current-buffer)))))
1413 (if (not (and (eq last-command 'mouse-save-then-kill)
1415 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
1416 ;; Find both ends of the object selected by this click.
1418 (mouse-start-end click-posn click-posn
1419 mouse-selection-click-count)))
1420 ;; Move whichever end is closer to the click.
1421 ;; That's what xterm does, and it seems reasonable.
1422 (if (< (abs (- click-posn (mark t)))
1423 (abs (- click-posn (point))))
1424 (set-mark (car range))
1425 (goto-char (nth 1 range)))
1426 ;; We have already put the old region in the kill ring.
1427 ;; Replace it with the extended region.
1428 ;; (It would be annoying to make a separate entry.)
1429 (kill-new (buffer-substring (point) (mark t)) t)
1430 (mouse-set-region-1)
1431 ;; Arrange for a repeated mouse-3 to kill this region.
1432 (setq mouse-save-then-kill-posn
1433 (list (car kill-ring) (point) click-posn))
1435 ;; If we click this button again without moving it,
1437 (mouse-save-then-kill-delete-region (mark) (point))
1438 (setq mouse-selection-click-count 0)
1439 (setq mouse-save-then-kill-posn nil))
1440 (if (and (eq last-command 'mouse-save-then-kill)
1441 mouse-save-then-kill-posn
1442 (eq (car mouse-save-then-kill-posn) (car kill-ring))
1443 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
1444 ;; If this is the second time we've called
1445 ;; mouse-save-then-kill, delete the text from the buffer.
1447 (mouse-save-then-kill-delete-region (point) (mark))
1448 ;; After we kill, another click counts as "the first time".
1449 (setq mouse-save-then-kill-posn nil))
1450 ;; This is not a repetition.
1451 ;; We are adjusting an old selection or creating a new one.
1452 (if (or (and (eq last-command 'mouse-save-then-kill)
1453 mouse-save-then-kill-posn)
1454 (and mark-active transient-mark-mode)
1455 (and (memq last-command
1456 '(mouse-drag-region mouse-set-region))
1457 (or mark-even-if-inactive
1458 (not transient-mark-mode))))
1459 ;; We have a selection or suitable region, so adjust it.
1460 (let* ((posn (event-start click))
1461 (new (posn-point posn)))
1462 (select-window (posn-window posn))
1465 ;; Move whichever end of the region is closer to the click.
1466 ;; That is what xterm does, and it seems reasonable.
1467 (if (<= (abs (- new (point))) (abs (- new (mark t))))
1470 (setq deactivate-mark nil)))
1471 (kill-new (buffer-substring (point) (mark t)) t))
1472 ;; Set the mark where point is, then move where clicked.
1473 (mouse-set-mark-fast click)
1475 (goto-char before-scroll))
1476 (exchange-point-and-mark) ;Why??? --Stef
1477 (kill-new (buffer-substring (point) (mark t))))
1479 (mouse-set-region-1)
1480 (setq mouse-save-then-kill-posn
1481 (list (car kill-ring) (point) click-posn)))))))
1483 (global-set-key [M-mouse-1] 'mouse-start-secondary)
1484 (global-set-key [M-drag-mouse-1] 'mouse-set-secondary)
1485 (global-set-key [M-down-mouse-1] 'mouse-drag-secondary)
1486 (global-set-key [M-mouse-3] 'mouse-secondary-save-then-kill)
1487 (global-set-key [M-mouse-2] 'mouse-yank-secondary)
1489 (defconst mouse-secondary-overlay
1490 (let ((ol (make-overlay (point-min) (point-min))))
1492 (overlay-put ol 'face 'secondary-selection)
1494 "An overlay which records the current secondary selection.
1495 It is deleted when there is no secondary selection.")
1497 (defvar mouse-secondary-click-count 0)
1499 ;; A marker which records the specified first end for a secondary selection.
1501 (defvar mouse-secondary-start nil)
1503 (defun mouse-start-secondary (click)
1504 "Set one end of the secondary selection to the position clicked on.
1505 Use \\[mouse-secondary-save-then-kill] to set the other end
1506 and complete the secondary selection."
1508 (mouse-minibuffer-check click)
1509 (let ((posn (event-start click)))
1510 (with-current-buffer (window-buffer (posn-window posn))
1511 ;; Cancel any preexisting secondary selection.
1512 (delete-overlay mouse-secondary-overlay)
1513 (if (numberp (posn-point posn))
1515 (or mouse-secondary-start
1516 (setq mouse-secondary-start (make-marker)))
1517 (move-marker mouse-secondary-start (posn-point posn)))))))
1519 (defun mouse-set-secondary (click)
1520 "Set the secondary selection to the text that the mouse is dragged over.
1521 This must be bound to a mouse drag event."
1523 (mouse-minibuffer-check click)
1524 (let ((posn (event-start click))
1526 (end (event-end click)))
1527 (with-current-buffer (window-buffer (posn-window posn))
1528 (if (numberp (posn-point posn))
1529 (setq beg (posn-point posn)))
1530 (move-overlay mouse-secondary-overlay beg (posn-point end))
1533 (buffer-substring (overlay-start mouse-secondary-overlay)
1534 (overlay-end mouse-secondary-overlay))))))
1536 (defun mouse-drag-secondary (start-event)
1537 "Set the secondary selection to the text that the mouse is dragged over.
1538 Highlight the drag area as you move the mouse.
1539 This must be bound to a button-down mouse event.
1540 The function returns a non-nil value if it creates a secondary selection."
1542 (mouse-minibuffer-check start-event)
1543 (let* ((echo-keystrokes 0)
1544 (start-posn (event-start start-event))
1545 (start-point (posn-point start-posn))
1546 (start-window (posn-window start-posn))
1547 (bounds (window-edges start-window))
1548 (top (nth 1 bounds))
1549 (bottom (if (window-minibuffer-p start-window)
1551 ;; Don't count the mode line.
1552 (1- (nth 3 bounds))))
1553 (click-count (1- (event-click-count start-event))))
1554 (with-current-buffer (window-buffer start-window)
1555 (setq mouse-secondary-click-count click-count)
1556 (if (> (mod click-count 3) 0)
1557 ;; Double or triple press: make an initial selection
1558 ;; of one word or line.
1559 (let ((range (mouse-start-end start-point start-point click-count)))
1560 (set-marker mouse-secondary-start nil)
1561 ;; Why the double move? --Stef
1562 ;; (move-overlay mouse-secondary-overlay 1 1
1563 ;; (window-buffer start-window))
1564 (move-overlay mouse-secondary-overlay (car range) (nth 1 range)
1565 (window-buffer start-window)))
1566 ;; Single-press: cancel any preexisting secondary selection.
1567 (or mouse-secondary-start
1568 (setq mouse-secondary-start (make-marker)))
1569 (set-marker mouse-secondary-start start-point)
1570 (delete-overlay mouse-secondary-overlay))
1571 (let (event end end-point)
1574 (setq event (read-event))
1575 (or (mouse-movement-p event)
1576 (memq (car-safe event) '(switch-frame select-window))))
1578 (if (memq (car-safe event) '(switch-frame select-window))
1580 (setq end (event-end event)
1581 end-point (posn-point end))
1583 ;; Are we moving within the original window?
1584 ((and (eq (posn-window end) start-window)
1585 (integer-or-marker-p end-point))
1586 (let ((range (mouse-start-end start-point end-point
1588 (if (or (/= start-point end-point)
1589 (null (marker-position mouse-secondary-start)))
1591 (set-marker mouse-secondary-start nil)
1592 (move-overlay mouse-secondary-overlay
1593 (car range) (nth 1 range))))))
1595 (let ((mouse-row (cdr (cdr (mouse-position)))))
1599 (mouse-scroll-subr start-window (- mouse-row top)
1600 mouse-secondary-overlay start-point))
1601 ((>= mouse-row bottom)
1602 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
1603 mouse-secondary-overlay start-point)))))))))
1606 (if (marker-position mouse-secondary-start)
1607 (save-window-excursion
1608 (delete-overlay mouse-secondary-overlay)
1609 (x-set-selection 'SECONDARY nil)
1610 (select-window start-window)
1612 (goto-char mouse-secondary-start)
1617 (buffer-substring (overlay-start mouse-secondary-overlay)
1618 (overlay-end mouse-secondary-overlay)))))))))
1620 (defun mouse-yank-secondary (click)
1621 "Insert the secondary selection at the position clicked on.
1622 Move point to the end of the inserted text.
1623 If `mouse-yank-at-point' is non-nil, insert at point
1624 regardless of where you click."
1626 ;; Give temporary modes such as isearch a chance to turn off.
1627 (run-hooks 'mouse-leave-buffer-hook)
1628 (or mouse-yank-at-point (mouse-set-point click))
1629 (insert (x-get-selection 'SECONDARY)))
1631 (defun mouse-kill-secondary ()
1632 "Kill the text in the secondary selection.
1633 This is intended more as a keyboard command than as a mouse command
1634 but it can work as either one.
1636 The current buffer (in case of keyboard use), or the buffer clicked on,
1637 must be the one that the secondary selection is in. This requirement
1638 is to prevent accidents."
1640 (let* ((keys (this-command-keys))
1641 (click (elt keys (1- (length keys)))))
1642 (or (eq (overlay-buffer mouse-secondary-overlay)
1644 (window-buffer (posn-window (event-start click)))
1646 (error "Select or click on the buffer where the secondary selection is")))
1648 (with-current-buffer (overlay-buffer mouse-secondary-overlay)
1649 (kill-region (overlay-start mouse-secondary-overlay)
1650 (overlay-end mouse-secondary-overlay))))
1651 (delete-overlay mouse-secondary-overlay)
1652 ;;; (x-set-selection 'SECONDARY nil)
1655 (defun mouse-secondary-save-then-kill (click)
1656 "Save text to point in kill ring; the second time, kill the text.
1657 You must use this in a buffer where you have recently done \\[mouse-start-secondary].
1658 If the text between where you did \\[mouse-start-secondary] and where
1659 you use this command matches the text at the front of the kill ring,
1660 this command deletes the text.
1661 Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
1662 which prepares for a second click with this command to delete the text.
1664 If you have already made a secondary selection in that buffer,
1665 this command extends or retracts the selection to where you click.
1666 If you do this again in a different position, it extends or retracts
1667 again. If you do this twice in the same position, it kills the selection."
1669 (mouse-minibuffer-check click)
1670 (let ((posn (event-start click))
1671 (click-posn (posn-point (event-start click)))
1672 ;; Don't let a subsequent kill command append to this one:
1673 ;; prevent setting this-command to kill-region.
1674 (this-command this-command))
1675 (or (eq (window-buffer (posn-window posn))
1676 (or (overlay-buffer mouse-secondary-overlay)
1677 (if mouse-secondary-start
1678 (marker-buffer mouse-secondary-start))))
1679 (error "Wrong buffer"))
1680 (with-current-buffer (window-buffer (posn-window posn))
1681 (if (> (mod mouse-secondary-click-count 3) 0)
1682 (if (not (and (eq last-command 'mouse-secondary-save-then-kill)
1684 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
1685 ;; Find both ends of the object selected by this click.
1687 (mouse-start-end click-posn click-posn
1688 mouse-secondary-click-count)))
1689 ;; Move whichever end is closer to the click.
1690 ;; That's what xterm does, and it seems reasonable.
1691 (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay)))
1692 (abs (- click-posn (overlay-end mouse-secondary-overlay))))
1693 (move-overlay mouse-secondary-overlay (car range)
1694 (overlay-end mouse-secondary-overlay))
1695 (move-overlay mouse-secondary-overlay
1696 (overlay-start mouse-secondary-overlay)
1698 ;; We have already put the old region in the kill ring.
1699 ;; Replace it with the extended region.
1700 ;; (It would be annoying to make a separate entry.)
1701 (kill-new (buffer-substring
1702 (overlay-start mouse-secondary-overlay)
1703 (overlay-end mouse-secondary-overlay)) t)
1704 ;; Arrange for a repeated mouse-3 to kill this region.
1705 (setq mouse-save-then-kill-posn
1706 (list (car kill-ring) (point) click-posn)))
1707 ;; If we click this button again without moving it,
1710 (mouse-save-then-kill-delete-region
1711 (overlay-start mouse-secondary-overlay)
1712 (overlay-end mouse-secondary-overlay))
1713 (setq mouse-save-then-kill-posn nil)
1714 (setq mouse-secondary-click-count 0)
1715 (delete-overlay mouse-secondary-overlay)))
1716 (if (and (eq last-command 'mouse-secondary-save-then-kill)
1717 mouse-save-then-kill-posn
1718 (eq (car mouse-save-then-kill-posn) (car kill-ring))
1719 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
1720 ;; If this is the second time we've called
1721 ;; mouse-secondary-save-then-kill, delete the text from the buffer.
1723 (mouse-save-then-kill-delete-region
1724 (overlay-start mouse-secondary-overlay)
1725 (overlay-end mouse-secondary-overlay))
1726 (setq mouse-save-then-kill-posn nil)
1727 (delete-overlay mouse-secondary-overlay))
1728 (if (overlay-start mouse-secondary-overlay)
1729 ;; We have a selection, so adjust it.
1731 (if (numberp click-posn)
1733 ;; Move whichever end of the region is closer to the click.
1734 ;; That is what xterm does, and it seems reasonable.
1735 (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay)))
1736 (abs (- click-posn (overlay-end mouse-secondary-overlay))))
1737 (move-overlay mouse-secondary-overlay click-posn
1738 (overlay-end mouse-secondary-overlay))
1739 (move-overlay mouse-secondary-overlay
1740 (overlay-start mouse-secondary-overlay)
1742 (setq deactivate-mark nil)))
1743 (if (eq last-command 'mouse-secondary-save-then-kill)
1744 ;; If the front of the kill ring comes from
1745 ;; an immediately previous use of this command,
1746 ;; replace it with the extended region.
1747 ;; (It would be annoying to make a separate entry.)
1748 (kill-new (buffer-substring
1749 (overlay-start mouse-secondary-overlay)
1750 (overlay-end mouse-secondary-overlay)) t)
1751 (let (deactivate-mark)
1752 (copy-region-as-kill (overlay-start mouse-secondary-overlay)
1753 (overlay-end mouse-secondary-overlay)))))
1754 (if mouse-secondary-start
1755 ;; All we have is one end of a selection,
1756 ;; so put the other end here.
1757 (let ((start (+ 0 mouse-secondary-start)))
1758 (kill-ring-save start click-posn)
1759 (move-overlay mouse-secondary-overlay start click-posn))))
1760 (setq mouse-save-then-kill-posn
1761 (list (car kill-ring) (point) click-posn))))
1762 (if (overlay-buffer mouse-secondary-overlay)
1763 (x-set-selection 'SECONDARY
1765 (overlay-start mouse-secondary-overlay)
1766 (overlay-end mouse-secondary-overlay)))))))
1768 (defcustom mouse-buffer-menu-maxlen 20
1769 "*Number of buffers in one pane (submenu) of the buffer menu.
1770 If we have lots of buffers, divide them into groups of
1771 `mouse-buffer-menu-maxlen' and make a pane (or submenu) for each one."
1775 (defcustom mouse-buffer-menu-mode-mult 4
1776 "*Group the buffers by the major mode groups on \\[mouse-buffer-menu]?
1777 This number which determines (in a hairy way) whether \\[mouse-buffer-menu]
1778 will split the buffer menu by the major modes (see
1779 `mouse-buffer-menu-mode-groups') or just by menu length.
1780 Set to 1 (or even 0!) if you want to group by major mode always, and to
1781 a large number if you prefer a mixed multitude. The default is 4."
1786 (defvar mouse-buffer-menu-mode-groups
1787 '(("Info\\|Help\\|Apropos\\|Man" . "Help")
1788 ("\\bVM\\b\\|\\bMH\\b\\|Message\\|Mail\\|Group\\|Score\\|Summary\\|Article"
1793 ("Outline" . "Text")
1794 ("\\(HT\\|SG\\|X\\|XHT\\)ML" . "SGML")
1795 ("log\\|diff\\|vc\\|cvs" . "Version Control") ; "Change Management"?
1797 "How to group various major modes together in \\[mouse-buffer-menu].
1798 Each element has the form (REGEXP . GROUPNAME).
1799 If the major mode's name string matches REGEXP, use GROUPNAME instead.")
1801 (defun mouse-buffer-menu (event)
1802 "Pop up a menu of buffers for selection with the mouse.
1803 This switches buffers in the window that you clicked on,
1804 and selects that window."
1806 (mouse-minibuffer-check event)
1807 (let ((buffers (buffer-list)) alist menu split-by-major-mode sum-of-squares)
1808 ;; Make an alist of elements that look like (MENU-ITEM . BUFFER).
1809 (let ((tail buffers))
1811 ;; Divide all buffers into buckets for various major modes.
1812 ;; Each bucket looks like (MODE NAMESTRING BUFFERS...).
1813 (with-current-buffer (car tail)
1814 (let* ((adjusted-major-mode major-mode) elt)
1815 (let ((tail mouse-buffer-menu-mode-groups))
1817 (if (string-match (car (car tail)) mode-name)
1818 (setq adjusted-major-mode (cdr (car tail))))
1819 (setq tail (cdr tail))))
1820 (setq elt (assoc adjusted-major-mode split-by-major-mode))
1822 (setq elt (list adjusted-major-mode
1823 (if (stringp adjusted-major-mode)
1826 split-by-major-mode (cons elt split-by-major-mode)))
1827 (or (memq (car tail) (cdr (cdr elt)))
1828 (setcdr (cdr elt) (cons (car tail) (cdr (cdr elt)))))))
1829 (setq tail (cdr tail))))
1830 ;; Compute the sum of squares of sizes of the major-mode buckets.
1831 (let ((tail split-by-major-mode))
1832 (setq sum-of-squares 0)
1834 (setq sum-of-squares
1836 (let ((len (length (cdr (cdr (car tail)))))) (* len len))))
1837 (setq tail (cdr tail))))
1838 (if (< (* sum-of-squares mouse-buffer-menu-mode-mult)
1839 (* (length buffers) (length buffers)))
1840 ;; Subdividing by major modes really helps, so let's do it.
1841 (let (subdivided-menus (buffers-left (length buffers)))
1842 ;; Sort the list to put the most popular major modes first.
1843 (setq split-by-major-mode
1844 (sort split-by-major-mode
1845 (function (lambda (elt1 elt2)
1846 (> (length elt1) (length elt2))))))
1847 ;; Make a separate submenu for each major mode
1848 ;; that has more than one buffer,
1849 ;; unless all the remaining buffers are less than 1/10 of them.
1850 (while (and split-by-major-mode
1851 (and (> (length (car split-by-major-mode)) 3)
1852 (> (* buffers-left 10) (length buffers))))
1853 (let ((this-mode-list (mouse-buffer-menu-alist
1854 (cdr (cdr (car split-by-major-mode))))))
1856 (setq subdivided-menus
1858 (nth 1 (car split-by-major-mode))
1860 subdivided-menus))))
1862 (- buffers-left (length (cdr (car split-by-major-mode)))))
1863 (setq split-by-major-mode (cdr split-by-major-mode)))
1864 ;; If any major modes are left over,
1865 ;; make a single submenu for them.
1866 (if split-by-major-mode
1868 (mouse-buffer-menu-alist
1869 ;; we don't need split-by-major-mode any more,
1870 ;; so we can ditch it with nconc.
1871 (apply 'nconc (mapcar 'cddr split-by-major-mode)))))
1873 (setq subdivided-menus
1874 (cons (cons "Others" others-list)
1875 subdivided-menus)))))
1876 (setq menu (cons "Buffer Menu" (nreverse subdivided-menus))))
1878 (setq alist (mouse-buffer-menu-alist buffers))
1879 (setq menu (cons "Buffer Menu"
1880 (mouse-buffer-menu-split "Select Buffer" alist)))))
1881 (let ((buf (x-popup-menu event menu))
1882 (window (posn-window (event-start event))))
1885 (if (framep window) (frame-selected-window window)
1887 (switch-to-buffer buf)))))
1889 (defun mouse-buffer-menu-alist (buffers)
1895 (function (lambda (elt1 elt2)
1896 (string< (buffer-name elt1) (buffer-name elt2))))))
1899 (or (eq ?\s (aref (buffer-name (car tail)) 0))
1902 (length (buffer-name (car tail))))))
1903 (setq tail (cdr tail)))
1906 (let ((elt (car tail)))
1907 (if (/= (aref (buffer-name elt) 0) ?\s)
1912 (format "%%%ds %%s%%s %%s" maxlen)
1914 (if (buffer-modified-p elt) "*" " ")
1917 (if buffer-read-only "%" " "))
1918 (or (buffer-file-name elt)
1921 (if list-buffers-directory
1923 list-buffers-directory)))
1927 (setq tail (cdr tail)))
1928 ;; Compensate for the reversal that the above loop does.
1931 (defun mouse-buffer-menu-split (title alist)
1932 ;; If we have lots of buffers, divide them into groups of 20
1933 ;; and make a pane (or submenu) for each one.
1934 (if (> (length alist) (/ (* mouse-buffer-menu-maxlen 3) 2))
1935 (let ((alist alist) sublists next
1938 ;; Pull off the next mouse-buffer-menu-maxlen buffers
1939 ;; and make them the next element of sublist.
1940 (setq next (nthcdr mouse-buffer-menu-maxlen alist))
1942 (setcdr (nthcdr (1- mouse-buffer-menu-maxlen) alist)
1944 (setq sublists (cons (cons (format "Buffers %d" i) alist)
1948 (nreverse sublists))
1949 ;; Few buffers--put them all in one pane.
1950 (list (cons title alist))))
1952 ;;; These need to be rewritten for the new scroll bar implementation.
1954 ;;;!! ;; Commands for the scroll bar.
1956 ;;;!! (defun mouse-scroll-down (click)
1957 ;;;!! (interactive "@e")
1958 ;;;!! (scroll-down (1+ (cdr (mouse-coords click)))))
1960 ;;;!! (defun mouse-scroll-up (click)
1961 ;;;!! (interactive "@e")
1962 ;;;!! (scroll-up (1+ (cdr (mouse-coords click)))))
1964 ;;;!! (defun mouse-scroll-down-full ()
1965 ;;;!! (interactive "@")
1966 ;;;!! (scroll-down nil))
1968 ;;;!! (defun mouse-scroll-up-full ()
1969 ;;;!! (interactive "@")
1970 ;;;!! (scroll-up nil))
1972 ;;;!! (defun mouse-scroll-move-cursor (click)
1973 ;;;!! (interactive "@e")
1974 ;;;!! (move-to-window-line (1+ (cdr (mouse-coords click)))))
1976 ;;;!! (defun mouse-scroll-absolute (event)
1977 ;;;!! (interactive "@e")
1978 ;;;!! (let* ((pos (car event))
1979 ;;;!! (position (car pos))
1980 ;;;!! (length (car (cdr pos))))
1981 ;;;!! (if (<= length 0) (setq length 1))
1982 ;;;!! (let* ((scale-factor (max 1 (/ length (/ 8000000 (buffer-size)))))
1983 ;;;!! (newpos (* (/ (* (/ (buffer-size) scale-factor)
1986 ;;;!! scale-factor)))
1987 ;;;!! (goto-char newpos)
1988 ;;;!! (recenter '(4)))))
1990 ;;;!! (defun mouse-scroll-left (click)
1991 ;;;!! (interactive "@e")
1992 ;;;!! (scroll-left (1+ (car (mouse-coords click)))))
1994 ;;;!! (defun mouse-scroll-right (click)
1995 ;;;!! (interactive "@e")
1996 ;;;!! (scroll-right (1+ (car (mouse-coords click)))))
1998 ;;;!! (defun mouse-scroll-left-full ()
1999 ;;;!! (interactive "@")
2000 ;;;!! (scroll-left nil))
2002 ;;;!! (defun mouse-scroll-right-full ()
2003 ;;;!! (interactive "@")
2004 ;;;!! (scroll-right nil))
2006 ;;;!! (defun mouse-scroll-move-cursor-horizontally (click)
2007 ;;;!! (interactive "@e")
2008 ;;;!! (move-to-column (1+ (car (mouse-coords click)))))
2010 ;;;!! (defun mouse-scroll-absolute-horizontally (event)
2011 ;;;!! (interactive "@e")
2012 ;;;!! (let* ((pos (car event))
2013 ;;;!! (position (car pos))
2014 ;;;!! (length (car (cdr pos))))
2015 ;;;!! (set-window-hscroll (selected-window) 33)))
2017 ;;;!! (global-set-key [scroll-bar mouse-1] 'mouse-scroll-up)
2018 ;;;!! (global-set-key [scroll-bar mouse-2] 'mouse-scroll-absolute)
2019 ;;;!! (global-set-key [scroll-bar mouse-3] 'mouse-scroll-down)
2021 ;;;!! (global-set-key [vertical-slider mouse-1] 'mouse-scroll-move-cursor)
2022 ;;;!! (global-set-key [vertical-slider mouse-2] 'mouse-scroll-move-cursor)
2023 ;;;!! (global-set-key [vertical-slider mouse-3] 'mouse-scroll-move-cursor)
2025 ;;;!! (global-set-key [thumbup mouse-1] 'mouse-scroll-up-full)
2026 ;;;!! (global-set-key [thumbup mouse-2] 'mouse-scroll-up-full)
2027 ;;;!! (global-set-key [thumbup mouse-3] 'mouse-scroll-up-full)
2029 ;;;!! (global-set-key [thumbdown mouse-1] 'mouse-scroll-down-full)
2030 ;;;!! (global-set-key [thumbdown mouse-2] 'mouse-scroll-down-full)
2031 ;;;!! (global-set-key [thumbdown mouse-3] 'mouse-scroll-down-full)
2033 ;;;!! (global-set-key [horizontal-scroll-bar mouse-1] 'mouse-scroll-left)
2034 ;;;!! (global-set-key [horizontal-scroll-bar mouse-2]
2035 ;;;!! 'mouse-scroll-absolute-horizontally)
2036 ;;;!! (global-set-key [horizontal-scroll-bar mouse-3] 'mouse-scroll-right)
2038 ;;;!! (global-set-key [horizontal-slider mouse-1]
2039 ;;;!! 'mouse-scroll-move-cursor-horizontally)
2040 ;;;!! (global-set-key [horizontal-slider mouse-2]
2041 ;;;!! 'mouse-scroll-move-cursor-horizontally)
2042 ;;;!! (global-set-key [horizontal-slider mouse-3]
2043 ;;;!! 'mouse-scroll-move-cursor-horizontally)
2045 ;;;!! (global-set-key [thumbleft mouse-1] 'mouse-scroll-left-full)
2046 ;;;!! (global-set-key [thumbleft mouse-2] 'mouse-scroll-left-full)
2047 ;;;!! (global-set-key [thumbleft mouse-3] 'mouse-scroll-left-full)
2049 ;;;!! (global-set-key [thumbright mouse-1] 'mouse-scroll-right-full)
2050 ;;;!! (global-set-key [thumbright mouse-2] 'mouse-scroll-right-full)
2051 ;;;!! (global-set-key [thumbright mouse-3] 'mouse-scroll-right-full)
2053 ;;;!! (global-set-key [horizontal-scroll-bar S-mouse-2]
2054 ;;;!! 'mouse-split-window-horizontally)
2055 ;;;!! (global-set-key [mode-line S-mouse-2]
2056 ;;;!! 'mouse-split-window-horizontally)
2057 ;;;!! (global-set-key [vertical-scroll-bar S-mouse-2]
2058 ;;;!! 'mouse-split-window)
2061 ;;;!! ;;;; Here are experimental things being tested. Mouse events
2062 ;;;!! ;;;; are of the form:
2063 ;;;!! ;;;; ((x y) window screen-part key-sequence timestamp)
2066 ;;;!! ;;;; Dynamically track mouse coordinates
2069 ;;;!! ;;(defun track-mouse (event)
2070 ;;;!! ;; "Track the coordinates, absolute and relative, of the mouse."
2071 ;;;!! ;; (interactive "@e")
2072 ;;;!! ;; (while mouse-grabbed
2073 ;;;!! ;; (let* ((pos (read-mouse-position (selected-screen)))
2074 ;;;!! ;; (abs-x (car pos))
2075 ;;;!! ;; (abs-y (cdr pos))
2076 ;;;!! ;; (relative-coordinate (coordinates-in-window-p
2077 ;;;!! ;; (list (car pos) (cdr pos))
2078 ;;;!! ;; (selected-window))))
2079 ;;;!! ;; (if (consp relative-coordinate)
2080 ;;;!! ;; (message "mouse: [%d %d], (%d %d)" abs-x abs-y
2081 ;;;!! ;; (car relative-coordinate)
2082 ;;;!! ;; (car (cdr relative-coordinate)))
2083 ;;;!! ;; (message "mouse: [%d %d]" abs-x abs-y)))))
2086 ;;;!! ;; Dynamically put a box around the line indicated by point
2089 ;;;!! ;;(require 'backquote)
2091 ;;;!! ;;(defun mouse-select-buffer-line (event)
2092 ;;;!! ;; (interactive "@e")
2093 ;;;!! ;; (let ((relative-coordinate
2094 ;;;!! ;; (coordinates-in-window-p (car event) (selected-window)))
2095 ;;;!! ;; (abs-y (car (cdr (car event)))))
2096 ;;;!! ;; (if (consp relative-coordinate)
2098 ;;;!! ;; (save-excursion
2099 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
2100 ;;;!! ;; (x-draw-rectangle
2101 ;;;!! ;; (selected-screen)
2103 ;;;!! ;; (save-excursion
2104 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
2105 ;;;!! ;; (end-of-line)
2106 ;;;!! ;; (push-mark nil t)
2107 ;;;!! ;; (beginning-of-line)
2108 ;;;!! ;; (- (region-end) (region-beginning))) 1))
2109 ;;;!! ;; (sit-for 1)
2110 ;;;!! ;; (x-erase-rectangle (selected-screen))))))
2112 ;;;!! ;;(defvar last-line-drawn nil)
2113 ;;;!! ;;(defvar begin-delim "[^ \t]")
2114 ;;;!! ;;(defvar end-delim "[^ \t]")
2116 ;;;!! ;;(defun mouse-boxing (event)
2117 ;;;!! ;; (interactive "@e")
2118 ;;;!! ;; (save-excursion
2119 ;;;!! ;; (let ((screen (selected-screen)))
2120 ;;;!! ;; (while (= (x-mouse-events) 0)
2121 ;;;!! ;; (let* ((pos (read-mouse-position screen))
2122 ;;;!! ;; (abs-x (car pos))
2123 ;;;!! ;; (abs-y (cdr pos))
2124 ;;;!! ;; (relative-coordinate
2125 ;;;!! ;; (coordinates-in-window-p `(,abs-x ,abs-y)
2126 ;;;!! ;; (selected-window)))
2127 ;;;!! ;; (begin-reg nil)
2128 ;;;!! ;; (end-reg nil)
2129 ;;;!! ;; (end-column nil)
2130 ;;;!! ;; (begin-column nil))
2131 ;;;!! ;; (if (and (consp relative-coordinate)
2132 ;;;!! ;; (or (not last-line-drawn)
2133 ;;;!! ;; (not (= last-line-drawn abs-y))))
2135 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
2136 ;;;!! ;; (if (= (following-char) 10)
2139 ;;;!! ;; (setq begin-reg (1- (re-search-forward end-delim)))
2140 ;;;!! ;; (setq begin-column (1- (current-column)))
2141 ;;;!! ;; (end-of-line)
2142 ;;;!! ;; (setq end-reg (1+ (re-search-backward begin-delim)))
2143 ;;;!! ;; (setq end-column (1+ (current-column)))
2144 ;;;!! ;; (message "%s" (buffer-substring begin-reg end-reg))
2145 ;;;!! ;; (x-draw-rectangle screen
2146 ;;;!! ;; (setq last-line-drawn abs-y)
2147 ;;;!! ;; begin-column
2148 ;;;!! ;; (- end-column begin-column) 1))))))))))
2150 ;;;!! ;;(defun mouse-erase-box ()
2151 ;;;!! ;; (interactive)
2152 ;;;!! ;; (if last-line-drawn
2154 ;;;!! ;; (x-erase-rectangle (selected-screen))
2155 ;;;!! ;; (setq last-line-drawn nil))))
2157 ;;;!! ;;; (defun test-x-rectangle ()
2158 ;;;!! ;;; (use-local-mouse-map (setq rectangle-test-map (make-sparse-keymap)))
2159 ;;;!! ;;; (define-key rectangle-test-map mouse-motion-button-left 'mouse-boxing)
2160 ;;;!! ;;; (define-key rectangle-test-map mouse-button-left-up 'mouse-erase-box))
2163 ;;;!! ;; Here is how to do double clicking in lisp. About to change.
2166 ;;;!! (defvar double-start nil)
2167 ;;;!! (defconst double-click-interval 300
2168 ;;;!! "Max ticks between clicks")
2170 ;;;!! (defun double-down (event)
2171 ;;;!! (interactive "@e")
2172 ;;;!! (if double-start
2173 ;;;!! (let ((interval (- (nth 4 event) double-start)))
2174 ;;;!! (if (< interval double-click-interval)
2176 ;;;!! (backward-up-list 1)
2177 ;;;!! ;; (message "Interval %d" interval)
2178 ;;;!! (sleep-for 1)))
2179 ;;;!! (setq double-start nil))
2180 ;;;!! (setq double-start (nth 4 event))))
2182 ;;;!! (defun double-up (event)
2183 ;;;!! (interactive "@e")
2184 ;;;!! (and double-start
2185 ;;;!! (> (- (nth 4 event ) double-start) double-click-interval)
2186 ;;;!! (setq double-start nil)))
2188 ;;;!! ;;; (defun x-test-doubleclick ()
2189 ;;;!! ;;; (use-local-mouse-map (setq doubleclick-test-map (make-sparse-keymap)))
2190 ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left 'double-down)
2191 ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left-up 'double-up))
2194 ;;;!! ;; This scrolls while button is depressed. Use preferable in scroll bar.
2197 ;;;!! (defvar scrolled-lines 0)
2198 ;;;!! (defconst scroll-speed 1)
2200 ;;;!! (defun incr-scroll-down (event)
2201 ;;;!! (interactive "@e")
2202 ;;;!! (setq scrolled-lines 0)
2203 ;;;!! (incremental-scroll scroll-speed))
2205 ;;;!! (defun incr-scroll-up (event)
2206 ;;;!! (interactive "@e")
2207 ;;;!! (setq scrolled-lines 0)
2208 ;;;!! (incremental-scroll (- scroll-speed)))
2210 ;;;!! (defun incremental-scroll (n)
2211 ;;;!! (while (= (x-mouse-events) 0)
2212 ;;;!! (setq scrolled-lines (1+ (* scroll-speed scrolled-lines)))
2213 ;;;!! (scroll-down n)
2214 ;;;!! (sit-for 300 t)))
2216 ;;;!! (defun incr-scroll-stop (event)
2217 ;;;!! (interactive "@e")
2218 ;;;!! (message "Scrolled %d lines" scrolled-lines)
2219 ;;;!! (setq scrolled-lines 0)
2220 ;;;!! (sleep-for 1))
2222 ;;;!! ;;; (defun x-testing-scroll ()
2223 ;;;!! ;;; (let ((scrolling-map (function mouse-vertical-scroll-bar-prefix)))
2224 ;;;!! ;;; (define-key scrolling-map mouse-button-left 'incr-scroll-down)
2225 ;;;!! ;;; (define-key scrolling-map mouse-button-right 'incr-scroll-up)
2226 ;;;!! ;;; (define-key scrolling-map mouse-button-left-up 'incr-scroll-stop)
2227 ;;;!! ;;; (define-key scrolling-map mouse-button-right-up 'incr-scroll-stop)))
2230 ;;;!! ;; Some playthings suitable for picture mode? They need work.
2233 ;;;!! (defun mouse-kill-rectangle (event)
2234 ;;;!! "Kill the rectangle between point and the mouse cursor."
2235 ;;;!! (interactive "@e")
2236 ;;;!! (let ((point-save (point)))
2237 ;;;!! (save-excursion
2238 ;;;!! (mouse-set-point event)
2239 ;;;!! (push-mark nil t)
2240 ;;;!! (if (> point-save (point))
2241 ;;;!! (kill-rectangle (point) point-save)
2242 ;;;!! (kill-rectangle point-save (point))))))
2244 ;;;!! (defun mouse-open-rectangle (event)
2245 ;;;!! "Kill the rectangle between point and the mouse cursor."
2246 ;;;!! (interactive "@e")
2247 ;;;!! (let ((point-save (point)))
2248 ;;;!! (save-excursion
2249 ;;;!! (mouse-set-point event)
2250 ;;;!! (push-mark nil t)
2251 ;;;!! (if (> point-save (point))
2252 ;;;!! (open-rectangle (point) point-save)
2253 ;;;!! (open-rectangle point-save (point))))))
2255 ;;;!! ;; Must be a better way to do this.
2257 ;;;!! (defun mouse-multiple-insert (n char)
2258 ;;;!! (while (> n 0)
2260 ;;;!! (setq n (1- n))))
2262 ;;;!! ;; What this could do is not finalize until button was released.
2264 ;;;!! (defun mouse-move-text (event)
2265 ;;;!! "Move text from point to cursor position, inserting spaces."
2266 ;;;!! (interactive "@e")
2267 ;;;!! (let* ((relative-coordinate
2268 ;;;!! (coordinates-in-window-p (car event) (selected-window))))
2269 ;;;!! (if (consp relative-coordinate)
2270 ;;;!! (cond ((> (current-column) (car relative-coordinate))
2272 ;;;!! (- (car relative-coordinate) (current-column))))
2273 ;;;!! ((< (current-column) (car relative-coordinate))
2274 ;;;!! (mouse-multiple-insert
2275 ;;;!! (- (car relative-coordinate) (current-column)) " "))
2276 ;;;!! ((= (current-column) (car relative-coordinate)) (ding))))))
2278 ;; Choose a completion with the mouse.
2280 (defun mouse-choose-completion (event)
2281 "Click on an alternative in the `*Completions*' buffer to choose it."
2283 ;; Give temporary modes such as isearch a chance to turn off.
2284 (run-hooks 'mouse-leave-buffer-hook)
2285 (let ((buffer (window-buffer))
2289 (set-buffer (window-buffer (posn-window (event-start event))))
2290 (if completion-reference-buffer
2291 (setq buffer completion-reference-buffer))
2292 (setq base-size completion-base-size)
2294 (goto-char (posn-point (event-start event)))
2296 (if (and (not (eobp)) (get-text-property (point) 'mouse-face))
2297 (setq end (point) beg (1+ (point))))
2299 (error "No completion here"))
2300 (setq beg (previous-single-property-change beg 'mouse-face))
2301 (setq end (or (next-single-property-change end 'mouse-face)
2303 (setq choice (buffer-substring-no-properties beg end)))))
2304 (let ((owindow (selected-window)))
2305 (select-window (posn-window (event-start event)))
2306 (if (and (one-window-p t 'selected-frame)
2307 (window-dedicated-p (selected-window)))
2308 ;; This is a special buffer's frame
2309 (iconify-frame (selected-frame))
2310 (or (window-dedicated-p (selected-window))
2312 (select-window owindow))
2313 (choose-completion-string choice buffer base-size)))
2317 (defun font-menu-add-default ()
2318 (let* ((default (cdr (assq 'font (frame-parameters (selected-frame)))))
2319 (font-alist x-fixed-font-alist)
2320 (elt (or (assoc "Misc" font-alist) (nth 1 font-alist))))
2321 (if (assoc "Default" elt)
2322 (delete (assoc "Default" elt) elt))
2324 (cons (list "Default" default)
2327 (defvar x-fixed-font-alist
2330 ;; For these, we specify the pixel height and width.
2332 ("6x10" "-misc-fixed-medium-r-normal--10-*-*-*-c-60-iso8859-1" "6x10")
2334 "-misc-fixed-medium-r-semicondensed--12-*-*-*-c-60-iso8859-1" "6x12")
2336 "-misc-fixed-medium-r-semicondensed--13-*-*-*-c-60-iso8859-1" "6x13")
2337 ("7x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-70-iso8859-1" "7x13")
2338 ("7x14" "-misc-fixed-medium-r-normal--14-*-*-*-c-70-iso8859-1" "7x14")
2339 ("8x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-80-iso8859-1" "8x13")
2340 ("9x15" "-misc-fixed-medium-r-normal--15-*-*-*-c-90-iso8859-1" "9x15")
2341 ("10x20" "-misc-fixed-medium-r-normal--20-*-*-*-c-100-iso8859-1" "10x20")
2342 ("11x18" "-misc-fixed-medium-r-normal--18-*-*-*-c-110-iso8859-1" "11x18")
2343 ("12x24" "-misc-fixed-medium-r-normal--24-*-*-*-c-120-iso8859-1" "12x24")
2346 "-schumacher-clean-medium-r-normal--8-*-*-*-c-50-iso8859-1")
2348 "-schumacher-clean-medium-r-normal--8-*-*-*-c-60-iso8859-1")
2350 "-schumacher-clean-medium-r-normal--8-*-*-*-c-80-iso8859-1")
2352 "-schumacher-clean-medium-r-normal--10-*-*-*-c-80-iso8859-1")
2354 "-schumacher-clean-medium-r-normal--14-*-*-*-c-80-iso8859-1")
2356 "-schumacher-clean-medium-r-normal--16-*-*-*-c-80-iso8859-1")
2358 ("sony 8x16" "-sony-fixed-medium-r-normal--16-*-*-*-c-80-iso8859-1")
2359 ;;; We don't seem to have these; who knows what they are.
2360 ;;; ("fg-18" "fg-18")
2361 ;;; ("fg-25" "fg-25")
2362 ("lucidasanstypewriter-12" "-b&h-lucidatypewriter-medium-r-normal-sans-*-120-*-*-*-*-iso8859-1")
2363 ("lucidasanstypewriter-bold-14" "-b&h-lucidatypewriter-bold-r-normal-sans-*-140-*-*-*-*-iso8859-1")
2364 ("lucidasanstypewriter-bold-24"
2365 "-b&h-lucidatypewriter-bold-r-normal-sans-*-240-*-*-*-*-iso8859-1")
2366 ;;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
2367 ;;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
2370 ;; For these, we specify the point height.
2371 ("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1")
2372 ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1")
2373 ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1")
2374 ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1")
2375 ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1")
2376 ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1")
2377 ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1")
2378 ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1")
2379 ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1")
2380 ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1")
2381 ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1")
2382 ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1")
2383 ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1")
2384 ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1")
2385 ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1")
2386 ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1")
2387 ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1")
2388 ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1")
2389 ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1")
2390 ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1")
2391 ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1")
2392 ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1")
2393 ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1")
2394 ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1"))
2396 "X fonts suitable for use in Emacs.")
2398 (defun mouse-set-font (&rest fonts)
2399 "Select an Emacs font from a list of known good fonts and fontsets."
2401 (progn (unless (display-multi-font-p)
2402 (error "Cannot change fonts on this display"))
2404 (if (listp last-nonmenu-event)
2406 (list '(0 0) (selected-window)))
2407 ;; Append list of fontsets currently defined.
2408 (append x-fixed-font-alist (list (generate-fontset-menu))))))
2414 (set-default-font (car fonts))
2415 (setq font (car fonts))
2418 (setq fonts (cdr fonts)))))
2420 (error "Font not found")))))
2422 ;;; Bindings for mouse commands.
2424 (define-key global-map [down-mouse-1] 'mouse-drag-region)
2425 (global-set-key [mouse-1] 'mouse-set-point)
2426 (global-set-key [drag-mouse-1] 'mouse-set-region)
2428 ;; These are tested for in mouse-drag-region.
2429 (global-set-key [double-mouse-1] 'mouse-set-point)
2430 (global-set-key [triple-mouse-1] 'mouse-set-point)
2432 ;; Clicking on the fringes causes hscrolling:
2433 (global-set-key [left-fringe mouse-1] 'mouse-set-point)
2434 (global-set-key [right-fringe mouse-1] 'mouse-set-point)
2436 (global-set-key [mouse-2] 'mouse-yank-at-click)
2437 ;; Allow yanking also when the corresponding cursor is "in the fringe".
2438 (global-set-key [right-fringe mouse-2] 'mouse-yank-at-click)
2439 (global-set-key [left-fringe mouse-2] 'mouse-yank-at-click)
2440 (global-set-key [mouse-3] 'mouse-save-then-kill)
2441 (global-set-key [right-fringe mouse-3] 'mouse-save-then-kill)
2442 (global-set-key [left-fringe mouse-3] 'mouse-save-then-kill)
2444 ;; By binding these to down-going events, we let the user use the up-going
2445 ;; event to make the selection, saving a click.
2446 (global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
2447 (if (not (eq system-type 'ms-dos))
2448 (global-set-key [S-down-mouse-1] 'mouse-set-font))
2449 ;; C-down-mouse-2 is bound in facemenu.el.
2450 (global-set-key [C-down-mouse-3] 'mouse-popup-menubar-stuff)
2453 ;; Replaced with dragging mouse-1
2454 ;; (global-set-key [S-mouse-1] 'mouse-set-mark)
2456 ;; Binding mouse-1 to mouse-select-window when on mode-, header-, or
2457 ;; vertical-line prevents Emacs from signaling an error when the mouse
2458 ;; button is released after dragging these lines, on non-toolkit
2460 (global-set-key [mode-line mouse-1] 'mouse-select-window)
2461 (global-set-key [mode-line drag-mouse-1] 'mouse-select-window)
2462 (global-set-key [mode-line down-mouse-1] 'mouse-drag-mode-line)
2463 (global-set-key [header-line down-mouse-1] 'mouse-drag-header-line)
2464 (global-set-key [header-line mouse-1] 'mouse-select-window)
2465 (global-set-key [mode-line mouse-2] 'mouse-delete-other-windows)
2466 (global-set-key [mode-line mouse-3] 'mouse-delete-window)
2467 (global-set-key [mode-line C-mouse-2] 'mouse-split-window-horizontally)
2468 (global-set-key [vertical-scroll-bar C-mouse-2] 'mouse-split-window-vertically)
2469 (global-set-key [vertical-line C-mouse-2] 'mouse-split-window-vertically)
2470 (global-set-key [vertical-line down-mouse-1] 'mouse-drag-vertical-line)
2471 (global-set-key [vertical-line mouse-1] 'mouse-select-window)
2475 ;; This file contains the functionality of the old mldrag.el.
2476 (defalias 'mldrag-drag-mode-line 'mouse-drag-mode-line)
2477 (defalias 'mldrag-drag-vertical-line 'mouse-drag-vertical-line)
2478 (make-obsolete 'mldrag-drag-mode-line 'mouse-drag-mode-line "21.1")
2479 (make-obsolete 'mldrag-drag-vertical-line 'mouse-drag-vertical-line "21.1")
2482 ;; arch-tag: 9a710ce1-914a-4923-9b81-697f7bf82ab3
2483 ;;; mouse.el ends here