Some fixes to follow coding conventions in files maintained by FSF.
[emacs.git] / lisp / mouse.el
blob66d0a924b85bd1b175e4ddd8a0b8408dd07019c0
1 ;;; mouse.el --- window system-independent mouse support
3 ;; Copyright (C) 1993, 1994, 1995, 1999, 2000, 2001
4 ;; Free Software Foundation, Inc.
6 ;; Maintainer: FSF
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)
14 ;; 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; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
26 ;;; Commentary:
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.
34 ;;; Code:
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."
43 :type 'boolean
44 :group 'mouse)
46 ;; Provide a mode-specific menu on a mouse button.
48 (defun popup-menu (menu &optional position prefix)
49 "Popup the given menu and call the selected option.
50 MENU can be a keymap, an easymenu-style menu or a list of keymaps as for
51 `x-popup-menu'.
52 POSITION can be a click event or ((XOFFSET YOFFSET) WINDOW) and defaults to
53 the current mouse position.
54 PREFIX is the prefix argument (if any) to pass to the command."
55 (let* ((map (cond
56 ((keymapp menu) menu)
57 ((and (listp menu) (keymapp (car menu))) menu)
58 (t (let* ((map (easy-menu-create-menu (car menu) (cdr menu)))
59 (filter (when (symbolp map)
60 (plist-get (get map 'menu-prop) :filter))))
61 (if filter (funcall filter (symbol-function map)) map)))))
62 event cmd)
63 (unless position
64 (let ((mp (mouse-pixel-position)))
65 (setq position (list (list (cadr mp) (cddr mp)) (car mp)))))
66 ;; The looping behavior was taken from lmenu's popup-menu-popup
67 (while (and map (setq event
68 ;; map could be a prefix key, in which case
69 ;; we need to get its function cell
70 ;; definition.
71 (x-popup-menu position (indirect-function map))))
72 ;; Strangely x-popup-menu returns a list.
73 ;; mouse-major-mode-menu was using a weird:
74 ;; (key-binding (apply 'vector (append '(menu-bar) menu-prefix events)))
75 (setq cmd
76 (if (and (not (keymapp map)) (listp map))
77 ;; We were given a list of keymaps. Search them all
78 ;; in sequence until a first binding is found.
79 (let ((mouse-click (apply 'vector event))
80 binding)
81 (while (and map (null binding))
82 (setq binding (lookup-key (car map) mouse-click))
83 (if (numberp binding) ; `too long'
84 (setq binding nil))
85 (setq map (cdr map)))
86 binding)
87 ;; We were given a single keymap.
88 (lookup-key map (apply 'vector event))))
89 ;; Clear out echoing, which perhaps shows a prefix arg.
90 (message "")
91 ;; Maybe try again but with the submap.
92 (setq map (if (keymapp cmd) cmd)))
93 (when (functionp cmd)
94 (setq prefix-arg prefix)
95 ;; `setup-specified-language-environment', for instance,
96 ;; expects this to be set from a menu keymap.
97 (setq last-command-event (car (last event)))
98 ;; mouse-major-mode-menu was using `command-execute' instead.
99 (call-interactively cmd))))
101 (defvar mouse-major-mode-menu-prefix) ; dynamically bound
103 (defun mouse-major-mode-menu (event prefix)
104 "Pop up a mode-specific menu of mouse commands.
105 Default to the Edit menu if the major mode doesn't define a menu."
106 ;; Switch to the window clicked on, because otherwise
107 ;; the mode's commands may not make sense.
108 (interactive "@e\nP")
109 ;; Let the mode update its menus first.
110 (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
111 (let* (;; This is where mouse-major-mode-menu-prefix
112 ;; returns the prefix we should use (after menu-bar).
113 ;; It is either nil or (SOME-SYMBOL).
114 (mouse-major-mode-menu-prefix nil)
115 ;; Keymap from which to inherit; may be null.
116 (ancestor (mouse-major-mode-menu-1
117 (and (current-local-map)
118 (local-key-binding [menu-bar]))))
119 ;; Make a keymap in which our last command leads to a menu or
120 ;; default to the edit menu.
121 (newmap (if ancestor
122 (make-sparse-keymap (concat mode-name " Mode"))
123 menu-bar-edit-menu))
124 result)
125 (if ancestor
126 ;; Make our menu inherit from the desired keymap which we want
127 ;; to display as the menu now.
128 (set-keymap-parent newmap ancestor))
129 (popup-menu newmap event prefix)))
132 ;; Compute and cache the equivalent keys in MENU and all its submenus.
133 ;;;(defun mouse-major-mode-menu-compute-equiv-keys (menu)
134 ;;; (and (eq (car menu) 'keymap)
135 ;;; (x-popup-menu nil menu))
136 ;;; (while menu
137 ;;; (and (consp (car menu))
138 ;;; (consp (cdr (car menu)))
139 ;;; (let ((tail (cdr (car menu))))
140 ;;; (while (and (consp tail)
141 ;;; (not (eq (car tail) 'keymap)))
142 ;;; (setq tail (cdr tail)))
143 ;;; (if (consp tail)
144 ;;; (mouse-major-mode-menu-compute-equiv-keys tail))))
145 ;;; (setq menu (cdr menu))))
147 ;; Given a mode's menu bar keymap,
148 ;; if it defines exactly one menu bar menu,
149 ;; return just that menu.
150 ;; Otherwise return a menu for all of them.
151 (defun mouse-major-mode-menu-1 (menubar)
152 (if menubar
153 (let ((tail menubar)
154 submap)
155 (while tail
156 (if (consp (car tail))
157 (if submap
158 (setq submap t)
159 (setq submap (car tail))))
160 (setq tail (cdr tail)))
161 (if (eq submap t)
162 menubar
163 (setq mouse-major-mode-menu-prefix (list (car submap)))
164 (lookup-key menubar (vector (car submap)))))))
166 (defun mouse-popup-menubar (event prefix)
167 "Pops up a menu equiavlent to the menu bar a keyboard EVENT with PREFIX.
168 The contents are the items that would be in the menu bar whether or
169 not it is actually displayed."
170 (interactive "@e \nP")
171 (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
172 (let* ((local-menu (and (current-local-map)
173 (lookup-key (current-local-map) [menu-bar])))
174 (global-menu (lookup-key global-map [menu-bar]))
175 ;; If a keymap doesn't have a prompt string (a lazy
176 ;; programmer didn't bother to provide one), create it and
177 ;; insert it into the keymap; each keymap gets its own
178 ;; prompt. This is required for non-toolkit versions to
179 ;; display non-empty menu pane names.
180 (minor-mode-menus
181 (mapcar
182 (function
183 (lambda (menu)
184 (let* ((minor-mode (car menu))
185 (menu (cdr menu))
186 (title-or-map (cadr menu)))
187 (or (stringp title-or-map)
188 (setq menu
189 (cons 'keymap
190 (cons (concat
191 (capitalize (subst-char-in-string
192 ?- ?\ (symbol-name
193 minor-mode)))
194 " Menu")
195 (cdr menu)))))
196 menu)))
197 (minor-mode-key-binding [menu-bar])))
198 (local-title-or-map (and local-menu (cadr local-menu)))
199 (global-title-or-map (cadr global-menu)))
200 (or (null local-menu)
201 (stringp local-title-or-map)
202 (setq local-menu (cons 'keymap
203 (cons (concat mode-name " Mode Menu")
204 (cdr local-menu)))))
205 (or (stringp global-title-or-map)
206 (setq global-menu (cons 'keymap
207 (cons "Global Menu"
208 (cdr global-menu)))))
209 ;; Supplying the list is faster than making a new map.
210 (popup-menu (append (list global-menu)
211 (if local-menu
212 (list local-menu))
213 minor-mode-menus)
214 event prefix)))
216 (defun mouse-popup-menubar-stuff (event prefix)
217 "Popup a menu like either `mouse-major-mode-menu' or `mouse-popup-menubar'.
218 Use the former if the menu bar is showing, otherwise the latter."
219 (interactive "@e \nP")
220 (if (zerop (assoc-default 'menu-bar-lines (frame-parameters) 'eq 0))
221 (mouse-popup-menubar event prefix)
222 (mouse-major-mode-menu event prefix)))
224 ;; Commands that operate on windows.
226 (defun mouse-minibuffer-check (event)
227 (let ((w (posn-window (event-start event))))
228 (and (window-minibuffer-p w)
229 (not (minibuffer-window-active-p w))
230 (error "Minibuffer window is not active")))
231 ;; Give temporary modes such as isearch a chance to turn off.
232 (run-hooks 'mouse-leave-buffer-hook))
234 (defun mouse-delete-window (click)
235 "Delete the window you click on.
236 If the frame has just one window, bury the current buffer instead.
237 This command must be bound to a mouse click."
238 (interactive "e")
239 (if (one-window-p t)
240 (bury-buffer)
241 (mouse-minibuffer-check click)
242 (delete-window (posn-window (event-start click)))))
244 (defun mouse-select-window (click)
245 "Select the window clicked on; don't move point."
246 (interactive "e")
247 (mouse-minibuffer-check click)
248 (let ((oframe (selected-frame))
249 (frame (window-frame (posn-window (event-start click)))))
250 (select-window (posn-window (event-start click)))
251 (raise-frame frame)
252 (select-frame frame)
253 (or (eq frame oframe)
254 (set-mouse-position (selected-frame) (1- (frame-width)) 0))))
256 (defun mouse-tear-off-window (click)
257 "Delete the window clicked on, and create a new frame displaying its buffer."
258 (interactive "e")
259 (mouse-minibuffer-check click)
260 (let* ((window (posn-window (event-start click)))
261 (buf (window-buffer window))
262 (frame (make-frame)))
263 (select-frame frame)
264 (switch-to-buffer buf)
265 (delete-window window)))
267 (defun mouse-delete-other-windows ()
268 "Delete all windows except the one you click on."
269 (interactive "@")
270 (delete-other-windows))
272 (defun mouse-split-window-vertically (click)
273 "Select Emacs window mouse is on, then split it vertically in half.
274 The window is split at the line clicked on.
275 This command must be bound to a mouse click."
276 (interactive "@e")
277 (mouse-minibuffer-check click)
278 (let ((start (event-start click)))
279 (select-window (posn-window start))
280 (let ((new-height (1+ (cdr (posn-col-row (event-end click)))))
281 (first-line window-min-height)
282 (last-line (- (window-height) window-min-height)))
283 (if (< last-line first-line)
284 (error "Window too short to split")
285 (split-window-vertically
286 (min (max new-height first-line) last-line))))))
288 (defun mouse-split-window-horizontally (click)
289 "Select Emacs window mouse is on, then split it horizontally in half.
290 The window is split at the column clicked on.
291 This command must be bound to a mouse click."
292 (interactive "@e")
293 (mouse-minibuffer-check click)
294 (let ((start (event-start click)))
295 (select-window (posn-window start))
296 (let ((new-width (1+ (car (posn-col-row (event-end click)))))
297 (first-col window-min-width)
298 (last-col (- (window-width) window-min-width)))
299 (if (< last-col first-col)
300 (error "Window too narrow to split")
301 (split-window-horizontally
302 (min (max new-width first-col) last-col))))))
304 (defun mouse-drag-mode-line-1 (start-event mode-line-p)
305 "Change the height of a window by dragging on the mode or header line.
306 START-EVENT is the starting mouse-event of the drag action.
307 MODE-LINE-P non-nil means a mode line is dragged."
308 ;; Give temporary modes such as isearch a chance to turn off.
309 (run-hooks 'mouse-leave-buffer-hook)
310 (let* ((done nil)
311 (echo-keystrokes 0)
312 (start (event-start start-event))
313 (start-event-window (posn-window start))
314 (start-event-frame (window-frame start-event-window))
315 (start-nwindows (count-windows t))
316 (old-selected-window (selected-window))
317 (minibuffer (frame-parameter nil 'minibuffer))
318 should-enlarge-minibuffer event mouse y top bot edges wconfig growth)
319 (track-mouse
320 (progn
321 ;; enlarge-window only works on the selected window, so
322 ;; we must select the window where the start event originated.
323 ;; unwind-protect will restore the old selected window later.
324 (select-window start-event-window)
326 ;; if this is the bottommost ordinary window, then to
327 ;; move its modeline the minibuffer must be enlarged.
328 (setq should-enlarge-minibuffer
329 (and minibuffer
330 mode-line-p
331 (not (one-window-p t))
332 (= (nth 1 (window-edges minibuffer))
333 (nth 3 (window-edges)))))
335 ;; loop reading events and sampling the position of
336 ;; the mouse.
337 (while (not done)
338 (setq event (read-event)
339 mouse (mouse-position))
341 ;; do nothing if
342 ;; - there is a switch-frame event.
343 ;; - the mouse isn't in the frame that we started in
344 ;; - the mouse isn't in any Emacs frame
345 ;; drag if
346 ;; - there is a mouse-movement event
347 ;; - there is a scroll-bar-movement event
348 ;; (same as mouse movement for our purposes)
349 ;; quit if
350 ;; - there is a keyboard event or some other unknown event
351 ;; unknown event.
352 (cond ((integerp event)
353 (setq done t))
355 ((eq (car event) 'switch-frame)
356 nil)
358 ((not (memq (car event) '(mouse-movement scroll-bar-movement)))
359 (when (consp event)
360 (push event unread-command-events))
361 (setq done t))
363 ((not (eq (car mouse) start-event-frame))
364 nil)
366 ((null (car (cdr mouse)))
367 nil)
370 (setq y (cdr (cdr mouse))
371 edges (window-edges)
372 top (nth 1 edges)
373 bot (nth 3 edges))
375 ;; compute size change needed
376 (cond (mode-line-p
377 ;; Scale back a move that would make the
378 ;; window too short.
379 (when (< (- y top -1) window-min-height)
380 (setq y (+ top window-min-height -1)))
381 (setq growth (- y bot -1)))
382 (t ; header line
383 (when (< (- bot y) window-min-height)
384 (setq y (- bot window-min-height)))
385 ;; The window's top includes the header line!
386 (setq growth (- top y))))
387 (setq wconfig (current-window-configuration))
389 ;; Check for an error case.
390 (when (and (/= growth 0)
391 (not minibuffer)
392 (one-window-p t))
393 (error "Attempt to resize sole window"))
395 ;; grow/shrink minibuffer?
396 (if should-enlarge-minibuffer
397 (progn
398 ;; yes. briefly select minibuffer so
399 ;; enlarge-window will affect the
400 ;; correct window.
401 (select-window minibuffer)
402 ;; scale back shrinkage if it would
403 ;; make the minibuffer less than 1
404 ;; line tall.
405 (if (and (> growth 0)
406 (< (- (window-height minibuffer)
407 growth)
409 (setq growth (1- (window-height minibuffer))))
410 (enlarge-window (- growth))
411 (select-window start-event-window))
412 ;; no. grow/shrink the selected window
413 ;(message "growth = %d" growth)
414 (enlarge-window growth))
416 ;; if this window's growth caused another
417 ;; window to be deleted because it was too
418 ;; short, rescind the change.
420 ;; if size change caused space to be stolen
421 ;; from a window above this one, rescind the
422 ;; change, but only if we didn't grow/shrink
423 ;; the minibuffer. minibuffer size changes
424 ;; can cause all windows to shrink... no way
425 ;; around it.
426 (when (or (/= start-nwindows (count-windows t))
427 (and (not should-enlarge-minibuffer)
428 mode-line-p
429 (/= top (nth 1 (window-edges)))))
430 (set-window-configuration wconfig)))))))))
432 (defun mouse-drag-mode-line (start-event)
433 "Change the height of a window by dragging on the mode line."
434 (interactive "e")
435 (mouse-drag-mode-line-1 start-event t))
437 (defun mouse-drag-header-line (start-event)
438 "Change the height of a window by dragging on the header line.
439 Windows whose header-lines are at the top of the frame cannot be
440 resized by dragging their header-line."
441 (interactive "e")
442 ;; Changing the window's size by dragging its header-line when the
443 ;; header-line is at the top of the frame is somewhat strange,
444 ;; because the header-line doesn't move, so don't do it.
445 (let* ((start (event-start start-event))
446 (window (posn-window start))
447 (frame (window-frame window))
448 (first-window (frame-first-window frame)))
449 (when (or (eq window first-window)
450 (= (nth 1 (window-edges window))
451 (nth 1 (window-edges first-window))))
452 (error "Cannot move header-line at the top of the frame"))
453 (mouse-drag-mode-line-1 start-event nil)))
456 (defun mouse-drag-vertical-line (start-event)
457 "Change the width of a window by dragging on the vertical line."
458 (interactive "e")
459 ;; Give temporary modes such as isearch a chance to turn off.
460 (run-hooks 'mouse-leave-buffer-hook)
461 (let* ((done nil)
462 (echo-keystrokes 0)
463 (start-event-frame (window-frame (car (car (cdr start-event)))))
464 (start-event-window (car (car (cdr start-event))))
465 (start-nwindows (count-windows t))
466 (old-selected-window (selected-window))
467 event mouse x left right edges wconfig growth
468 (which-side
469 (or (cdr (assq 'vertical-scroll-bars (frame-parameters start-event-frame)))
470 'right)))
471 (if (one-window-p t)
472 (error "Attempt to resize sole ordinary window"))
473 (if (eq which-side 'right)
474 (if (= (nth 2 (window-edges start-event-window))
475 (frame-width start-event-frame))
476 (error "Attempt to drag rightmost scrollbar"))
477 (if (= (nth 0 (window-edges start-event-window)) 0)
478 (error "Attempt to drag leftmost scrollbar")))
479 (track-mouse
480 (progn
481 ;; enlarge-window only works on the selected window, so
482 ;; we must select the window where the start event originated.
483 ;; unwind-protect will restore the old selected window later.
484 (select-window start-event-window)
485 ;; loop reading events and sampling the position of
486 ;; the mouse.
487 (while (not done)
488 (setq event (read-event)
489 mouse (mouse-position))
490 ;; do nothing if
491 ;; - there is a switch-frame event.
492 ;; - the mouse isn't in the frame that we started in
493 ;; - the mouse isn't in any Emacs frame
494 ;; drag if
495 ;; - there is a mouse-movement event
496 ;; - there is a scroll-bar-movement event
497 ;; (same as mouse movement for our purposes)
498 ;; quit if
499 ;; - there is a keyboard event or some other unknown event
500 ;; unknown event.
501 (cond ((integerp event)
502 (setq done t))
503 ((eq (car event) 'switch-frame)
504 nil)
505 ((not (memq (car event)
506 '(mouse-movement scroll-bar-movement)))
507 (if (consp event)
508 (setq unread-command-events
509 (cons event unread-command-events)))
510 (setq done t))
511 ((not (eq (car mouse) start-event-frame))
512 nil)
513 ((null (car (cdr mouse)))
514 nil)
516 (save-selected-window
517 ;; If the scroll bar is on the window's left,
518 ;; adjust the window on the left.
519 (unless (eq which-side 'right)
520 (select-window (previous-window)))
521 (setq x (- (car (cdr mouse))
522 (if (eq which-side 'right) 0 2))
523 edges (window-edges)
524 left (nth 0 edges)
525 right (nth 2 edges))
526 ;; scale back a move that would make the
527 ;; window too thin.
528 (if (< (- x left -1) window-min-width)
529 (setq x (+ left window-min-width -1)))
530 ;; compute size change needed
531 (setq growth (- x right -1)
532 wconfig (current-window-configuration))
533 (enlarge-window growth t)
534 ;; if this window's growth caused another
535 ;; window to be deleted because it was too
536 ;; thin, rescind the change.
538 ;; if size change caused space to be stolen
539 ;; from a window to the left of this one,
540 ;; rescind the change.
541 (if (or (/= start-nwindows (count-windows t))
542 (/= left (nth 0 (window-edges))))
543 (set-window-configuration wconfig))))))))))
545 (defun mouse-set-point (event)
546 "Move point to the position clicked on with the mouse.
547 This should be bound to a mouse click event type."
548 (interactive "e")
549 (mouse-minibuffer-check event)
550 ;; Use event-end in case called from mouse-drag-region.
551 ;; If EVENT is a click, event-end and event-start give same value.
552 (let ((posn (event-end event)))
553 (if (not (windowp (posn-window posn)))
554 (error "Cursor not in text area of window"))
555 (select-window (posn-window posn))
556 (if (numberp (posn-point posn))
557 (goto-char (posn-point posn)))))
559 (defvar mouse-last-region-beg nil)
560 (defvar mouse-last-region-end nil)
561 (defvar mouse-last-region-tick nil)
563 (defun mouse-region-match ()
564 "Return non-nil if there's an active region that was set with the mouse."
565 (and (mark t) mark-active
566 (eq mouse-last-region-beg (region-beginning))
567 (eq mouse-last-region-end (region-end))
568 (eq mouse-last-region-tick (buffer-modified-tick))))
570 (defun mouse-set-region (click)
571 "Set the region to the text dragged over, and copy to kill ring.
572 This should be bound to a mouse drag event."
573 (interactive "e")
574 (mouse-minibuffer-check click)
575 (let ((posn (event-start click))
576 (end (event-end click)))
577 (select-window (posn-window posn))
578 (if (numberp (posn-point posn))
579 (goto-char (posn-point posn)))
580 ;; If mark is highlighted, no need to bounce the cursor.
581 ;; On X, we highlight while dragging, thus once again no need to bounce.
582 (or transient-mark-mode
583 (memq (framep (selected-frame)) '(x pc w32))
584 (sit-for 1))
585 (push-mark)
586 (set-mark (point))
587 (if (numberp (posn-point end))
588 (goto-char (posn-point end)))
589 ;; Don't set this-command to kill-region, so that a following
590 ;; C-w will not double the text in the kill ring.
591 ;; Ignore last-command so we don't append to a preceding kill.
592 (let (this-command last-command deactivate-mark)
593 (copy-region-as-kill (mark) (point)))
594 (mouse-set-region-1)))
596 (defun mouse-set-region-1 ()
597 (setq mouse-last-region-beg (region-beginning))
598 (setq mouse-last-region-end (region-end))
599 (setq mouse-last-region-tick (buffer-modified-tick)))
601 (defcustom mouse-scroll-delay 0.25
602 "*The pause between scroll steps caused by mouse drags, in seconds.
603 If you drag the mouse beyond the edge of a window, Emacs scrolls the
604 window to bring the text beyond that edge into view, with a delay of
605 this many seconds between scroll steps. Scrolling stops when you move
606 the mouse back into the window, or release the button.
607 This variable's value may be non-integral.
608 Setting this to zero causes Emacs to scroll as fast as it can."
609 :type 'number
610 :group 'mouse)
612 (defcustom mouse-scroll-min-lines 1
613 "*The minimum number of lines scrolled by dragging mouse out of window.
614 Moving the mouse out the top or bottom edge of the window begins
615 scrolling repeatedly. The number of lines scrolled per repetition
616 is normally equal to the number of lines beyond the window edge that
617 the mouse has moved. However, it always scrolls at least the number
618 of lines specified by this variable."
619 :type 'integer
620 :group 'mouse)
622 (defun mouse-scroll-subr (window jump &optional overlay start)
623 "Scroll the window WINDOW, JUMP lines at a time, until new input arrives.
624 If OVERLAY is an overlay, let it stretch from START to the far edge of
625 the newly visible text.
626 Upon exit, point is at the far edge of the newly visible text."
627 (cond
628 ((and (> jump 0) (< jump mouse-scroll-min-lines))
629 (setq jump mouse-scroll-min-lines))
630 ((and (< jump 0) (< (- jump) mouse-scroll-min-lines))
631 (setq jump (- mouse-scroll-min-lines))))
632 (let ((opoint (point)))
633 (while (progn
634 (goto-char (window-start window))
635 (if (not (zerop (vertical-motion jump window)))
636 (progn
637 (set-window-start window (point))
638 (if (natnump jump)
639 (if (window-end window)
640 (progn
641 (goto-char (window-end window))
642 ;; window-end doesn't reflect the window's new
643 ;; start position until the next redisplay.
644 (vertical-motion (1- jump) window))
645 (vertical-motion (- (window-height window) 2)))
646 (goto-char (window-start window)))
647 (if overlay
648 (move-overlay overlay start (point)))
649 ;; Now that we have scrolled WINDOW properly,
650 ;; put point back where it was for the redisplay
651 ;; so that we don't mess up the selected window.
652 (or (eq window (selected-window))
653 (goto-char opoint))
654 (sit-for mouse-scroll-delay)))))
655 (or (eq window (selected-window))
656 (goto-char opoint))))
658 ;; Create an overlay and immediately delete it, to get "overlay in no buffer".
659 (defvar mouse-drag-overlay (make-overlay 1 1))
660 (delete-overlay mouse-drag-overlay)
661 (overlay-put mouse-drag-overlay 'face 'region)
663 (defvar mouse-selection-click-count 0)
665 (defvar mouse-selection-click-count-buffer nil)
667 (defun mouse-drag-region (start-event)
668 "Set the region to the text that the mouse is dragged over.
669 Highlight the drag area as you move the mouse.
670 This must be bound to a button-down mouse event.
671 In Transient Mark mode, the highlighting remains as long as the mark
672 remains active. Otherwise, it remains until the next input event."
673 (interactive "e")
674 (mouse-minibuffer-check start-event)
675 (let* ((echo-keystrokes 0)
676 (start-posn (event-start start-event))
677 (start-point (posn-point start-posn))
678 (start-window (posn-window start-posn))
679 (start-frame (window-frame start-window))
680 (start-hscroll (window-hscroll start-window))
681 (bounds (window-edges start-window))
682 (top (nth 1 bounds))
683 (bottom (if (window-minibuffer-p start-window)
684 (nth 3 bounds)
685 ;; Don't count the mode line.
686 (1- (nth 3 bounds))))
687 (click-count (1- (event-click-count start-event))))
688 (setq mouse-selection-click-count click-count)
689 (setq mouse-selection-click-count-buffer (current-buffer))
690 (mouse-set-point start-event)
691 ;; In case the down click is in the middle of some intangible text,
692 ;; use the end of that text, and put it in START-POINT.
693 (if (< (point) start-point)
694 (goto-char start-point))
695 (setq start-point (point))
696 (let ((range (mouse-start-end start-point start-point click-count)))
697 (move-overlay mouse-drag-overlay (car range) (nth 1 range)
698 (window-buffer start-window)))
699 (deactivate-mark)
700 ;; end-of-range is used only in the single-click case.
701 ;; It is the place where the drag has reached so far
702 ;; (but not outside the window where the drag started).
703 (let (event end end-point last-end-point (end-of-range (point)))
704 (track-mouse
705 (while (progn
706 (setq event (read-event))
707 (or (mouse-movement-p event)
708 (eq (car-safe event) 'switch-frame)))
709 (if (eq (car-safe event) 'switch-frame)
711 (setq end (event-end event)
712 end-point (posn-point end))
713 (if (numberp end-point)
714 (setq last-end-point end-point))
716 (cond
717 ;; Are we moving within the original window?
718 ((and (eq (posn-window end) start-window)
719 (integer-or-marker-p end-point))
720 ;; Go to START-POINT first, so that when we move to END-POINT,
721 ;; if it's in the middle of intangible text,
722 ;; point jumps in the direction away from START-POINT.
723 (goto-char start-point)
724 (goto-char end-point)
725 (if (zerop (% click-count 3))
726 (setq end-of-range (point)))
727 (let ((range (mouse-start-end start-point (point) click-count)))
728 (move-overlay mouse-drag-overlay (car range) (nth 1 range))))
731 (let ((mouse-row (cdr (cdr (mouse-position)))))
732 (cond
733 ((null mouse-row))
734 ((< mouse-row top)
735 (mouse-scroll-subr start-window (- mouse-row top)
736 mouse-drag-overlay start-point)
737 ;; Without this, point tends to jump back to the starting
738 ;; position where the mouse button was pressed down.
739 (setq end-of-range (overlay-start mouse-drag-overlay)))
740 ((>= mouse-row bottom)
741 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
742 mouse-drag-overlay start-point)
743 (setq end-of-range (overlay-end mouse-drag-overlay))))))))))
744 ;; In case we did not get a mouse-motion event
745 ;; for the final move of the mouse before a drag event
746 ;; pretend that we did get one.
747 (when (and (memq 'drag (event-modifiers (car-safe event)))
748 (setq end (event-end event)
749 end-point (posn-point end))
750 (eq (posn-window end) start-window)
751 (integer-or-marker-p end-point))
753 ;; Go to START-POINT first, so that when we move to END-POINT,
754 ;; if it's in the middle of intangible text,
755 ;; point jumps in the direction away from START-POINT.
756 (goto-char start-point)
757 (goto-char end-point)
758 (if (zerop (% click-count 3))
759 (setq end-of-range (point)))
760 (let ((range (mouse-start-end start-point (point) click-count)))
761 (move-overlay mouse-drag-overlay (car range) (nth 1 range))))
763 (if (consp event)
764 (let ((fun (key-binding (vector (car event)))))
765 ;; Run the binding of the terminating up-event, if possible.
766 ;; In the case of a multiple click, it gives the wrong results,
767 ;; because it would fail to set up a region.
768 (if (not (= (overlay-start mouse-drag-overlay)
769 (overlay-end mouse-drag-overlay)))
770 (let* ((stop-point
771 (if (numberp (posn-point (event-end event)))
772 (posn-point (event-end event))
773 last-end-point))
774 ;; The end that comes from where we ended the drag.
775 ;; Point goes here.
776 (region-termination
777 (if (and stop-point (< stop-point start-point))
778 (overlay-start mouse-drag-overlay)
779 (overlay-end mouse-drag-overlay)))
780 ;; The end that comes from where we started the drag.
781 ;; Mark goes there.
782 (region-commencement
783 (- (+ (overlay-end mouse-drag-overlay)
784 (overlay-start mouse-drag-overlay))
785 region-termination))
786 last-command this-command)
787 (push-mark region-commencement t t)
788 (goto-char region-termination)
789 ;; Don't let copy-region-as-kill set deactivate-mark.
790 (let (deactivate-mark)
791 (copy-region-as-kill (point) (mark t)))
792 (let ((buffer (current-buffer)))
793 (mouse-show-mark)
794 ;; mouse-show-mark can call read-event,
795 ;; and that means the Emacs server could switch buffers
796 ;; under us. If that happened,
797 ;; avoid trying to use the region.
798 (and (mark t) mark-active
799 (eq buffer (current-buffer))
800 (mouse-set-region-1))))
801 (delete-overlay mouse-drag-overlay)
802 ;; Run the binding of the terminating up-event.
803 (when (and (functionp fun)
804 (= start-hscroll (window-hscroll start-window)))
805 (setq unread-command-events
806 (cons event unread-command-events)))))
807 (delete-overlay mouse-drag-overlay)))))
809 ;; Commands to handle xterm-style multiple clicks.
811 (defun mouse-skip-word (dir)
812 "Skip over word, over whitespace, or over identical punctuation.
813 If DIR is positive skip forward; if negative, skip backward."
814 (let* ((char (following-char))
815 (syntax (char-to-string (char-syntax char))))
816 (cond ((string= syntax "w")
817 ;; Here, we can't use skip-syntax-forward/backward because
818 ;; they don't pay attention to word-separating-categories,
819 ;; and thus they will skip over a true word boundary. So,
820 ;; we simularte the original behaviour by using
821 ;; forward-word.
822 (if (< dir 0)
823 (if (not (looking-at "\\<"))
824 (forward-word -1))
825 (if (or (looking-at "\\<") (not (looking-at "\\>")))
826 (forward-word 1))))
827 ((string= syntax " ")
828 (if (< dir 0)
829 (skip-syntax-backward syntax)
830 (skip-syntax-forward syntax)))
831 ((string= syntax "_")
832 (if (< dir 0)
833 (skip-syntax-backward "w_")
834 (skip-syntax-forward "w_")))
835 ((< dir 0)
836 (while (and (not (bobp)) (= (preceding-char) char))
837 (forward-char -1)))
839 (while (and (not (eobp)) (= (following-char) char))
840 (forward-char 1))))))
842 ;; Return a list of region bounds based on START and END according to MODE.
843 ;; If MODE is 0 then set point to (min START END), mark to (max START END).
844 ;; If MODE is 1 then set point to start of word at (min START END),
845 ;; mark to end of word at (max START END).
846 ;; If MODE is 2 then do the same for lines.
847 (defun mouse-start-end (start end mode)
848 (if (> start end)
849 (let ((temp start))
850 (setq start end
851 end temp)))
852 (setq mode (mod mode 3))
853 (cond ((= mode 0)
854 (list start end))
855 ((and (= mode 1)
856 (= start end)
857 (char-after start)
858 (= (char-syntax (char-after start)) ?\())
859 (list start
860 (save-excursion
861 (goto-char start)
862 (forward-sexp 1)
863 (point))))
864 ((and (= mode 1)
865 (= start end)
866 (char-after start)
867 (= (char-syntax (char-after start)) ?\)))
868 (list (save-excursion
869 (goto-char (1+ start))
870 (backward-sexp 1)
871 (point))
872 (1+ start)))
873 ((and (= mode 1)
874 (= start end)
875 (char-after start)
876 (= (char-syntax (char-after start)) ?\"))
877 (let ((open (or (eq start (point-min))
878 (save-excursion
879 (goto-char (- start 1))
880 (looking-at "\\s(\\|\\s \\|\\s>")))))
881 (if open
882 (list start
883 (save-excursion
884 (condition-case nil
885 (progn
886 (goto-char start)
887 (forward-sexp 1)
888 (point))
889 (error end))))
890 (list (save-excursion
891 (condition-case nil
892 (progn
893 (goto-char (1+ start))
894 (backward-sexp 1)
895 (point))
896 (error end)))
897 (1+ start)))))
898 ((= mode 1)
899 (list (save-excursion
900 (goto-char start)
901 (mouse-skip-word -1)
902 (point))
903 (save-excursion
904 (goto-char end)
905 (mouse-skip-word 1)
906 (point))))
907 ((= mode 2)
908 (list (save-excursion
909 (goto-char start)
910 (beginning-of-line 1)
911 (point))
912 (save-excursion
913 (goto-char end)
914 (forward-line 1)
915 (point))))))
917 ;; Subroutine: set the mark where CLICK happened,
918 ;; but don't do anything else.
919 (defun mouse-set-mark-fast (click)
920 (mouse-minibuffer-check click)
921 (let ((posn (event-start click)))
922 (select-window (posn-window posn))
923 (if (numberp (posn-point posn))
924 (push-mark (posn-point posn) t t))))
926 (defun mouse-undouble-last-event (events)
927 (let* ((index (1- (length events)))
928 (last (nthcdr index events))
929 (event (car last))
930 (basic (event-basic-type event))
931 (old-modifiers (event-modifiers event))
932 (modifiers (delq 'double (delq 'triple (copy-sequence old-modifiers))))
933 (new
934 (if (consp event)
935 ;; Use reverse, not nreverse, since event-modifiers
936 ;; does not copy the list it returns.
937 (cons (event-convert-list (reverse (cons basic modifiers)))
938 (cdr event))
939 event)))
940 (setcar last new)
941 (if (and (not (equal modifiers old-modifiers))
942 (key-binding (apply 'vector events)))
944 (setcar last event)
945 nil)))
947 ;; Momentarily show where the mark is, if highlighting doesn't show it.
949 (defvar mouse-region-delete-keys '([delete])
950 "List of keys which shall cause the mouse region to be deleted.")
952 (defun mouse-show-mark ()
953 (if transient-mark-mode
954 (delete-overlay mouse-drag-overlay)
955 (let ((inhibit-quit t)
956 (echo-keystrokes 0)
957 event events key ignore
958 x-lost-selection-hooks)
959 (add-hook 'x-lost-selection-hooks
960 (lambda (seltype)
961 (if (eq seltype 'PRIMARY)
962 (progn (setq ignore t)
963 (throw 'mouse-show-mark t)))))
964 (move-overlay mouse-drag-overlay (point) (mark t))
965 (catch 'mouse-show-mark
966 ;; In this loop, execute scroll bar and switch-frame events.
967 ;; Also ignore down-events that are undefined.
968 (while (progn (setq event (read-event))
969 (setq events (append events (list event)))
970 (setq key (apply 'vector events))
971 (or (and (consp event)
972 (eq (car event) 'switch-frame))
973 (and (consp event)
974 (eq (posn-point (event-end event))
975 'vertical-scroll-bar))
976 (and (memq 'down (event-modifiers event))
977 (not (key-binding key))
978 (not (mouse-undouble-last-event events))
979 (not (member key mouse-region-delete-keys)))))
980 (and (consp event)
981 (or (eq (car event) 'switch-frame)
982 (eq (posn-point (event-end event))
983 'vertical-scroll-bar))
984 (let ((keys (vector 'vertical-scroll-bar event)))
985 (and (key-binding keys)
986 (progn
987 (call-interactively (key-binding keys)
988 nil keys)
989 (setq events nil)))))))
990 ;; If we lost the selection, just turn off the highlighting.
991 (if ignore
993 ;; For certain special keys, delete the region.
994 (if (member key mouse-region-delete-keys)
995 (delete-region (overlay-start mouse-drag-overlay)
996 (overlay-end mouse-drag-overlay))
997 ;; Otherwise, unread the key so it gets executed normally.
998 (setq unread-command-events
999 (nconc events unread-command-events))))
1000 (setq quit-flag nil)
1001 (delete-overlay mouse-drag-overlay))
1002 (save-excursion
1003 (goto-char (mark t))
1004 (sit-for 1))))
1006 (defun mouse-set-mark (click)
1007 "Set mark at the position clicked on with the mouse.
1008 Display cursor at that position for a second.
1009 This must be bound to a mouse click."
1010 (interactive "e")
1011 (mouse-minibuffer-check click)
1012 (select-window (posn-window (event-start click)))
1013 ;; We don't use save-excursion because that preserves the mark too.
1014 (let ((point-save (point)))
1015 (unwind-protect
1016 (progn (mouse-set-point click)
1017 (push-mark nil t t)
1018 (or transient-mark-mode
1019 (sit-for 1)))
1020 (goto-char point-save))))
1022 (defun mouse-kill (click)
1023 "Kill the region between point and the mouse click.
1024 The text is saved in the kill ring, as with \\[kill-region]."
1025 (interactive "e")
1026 (mouse-minibuffer-check click)
1027 (let* ((posn (event-start click))
1028 (click-posn (posn-point posn)))
1029 (select-window (posn-window posn))
1030 (if (numberp click-posn)
1031 (kill-region (min (point) click-posn)
1032 (max (point) click-posn)))))
1034 (defun mouse-yank-at-click (click arg)
1035 "Insert the last stretch of killed text at the position clicked on.
1036 Also move point to one end of the text thus inserted (normally the end),
1037 and set mark at the beginning..
1038 Prefix arguments are interpreted as with \\[yank].
1039 If `mouse-yank-at-point' is non-nil, insert at point
1040 regardless of where you click."
1041 (interactive "e\nP")
1042 ;; Give temporary modes such as isearch a chance to turn off.
1043 (run-hooks 'mouse-leave-buffer-hook)
1044 (or mouse-yank-at-point (mouse-set-point click))
1045 (setq this-command 'yank)
1046 (setq mouse-selection-click-count 0)
1047 (yank arg))
1049 (defun mouse-kill-ring-save (click)
1050 "Copy the region between point and the mouse click in the kill ring.
1051 This does not delete the region; it acts like \\[kill-ring-save]."
1052 (interactive "e")
1053 (mouse-set-mark-fast click)
1054 (let (this-command last-command)
1055 (kill-ring-save (point) (mark t)))
1056 (mouse-show-mark))
1058 ;;; This function used to delete the text between point and the mouse
1059 ;;; whenever it was equal to the front of the kill ring, but some
1060 ;;; people found that confusing.
1062 ;;; A list (TEXT START END), describing the text and position of the last
1063 ;;; invocation of mouse-save-then-kill.
1064 (defvar mouse-save-then-kill-posn nil)
1066 (defun mouse-save-then-kill-delete-region (beg end)
1067 ;; We must make our own undo boundaries
1068 ;; because they happen automatically only for the current buffer.
1069 (undo-boundary)
1070 (if (or (= beg end) (eq buffer-undo-list t))
1071 ;; If we have no undo list in this buffer,
1072 ;; just delete.
1073 (delete-region beg end)
1074 ;; Delete, but make the undo-list entry share with the kill ring.
1075 ;; First, delete just one char, so in case buffer is being modified
1076 ;; for the first time, the undo list records that fact.
1077 (let (before-change-functions after-change-functions)
1078 (delete-region beg
1079 (+ beg (if (> end beg) 1 -1))))
1080 (let ((buffer-undo-list buffer-undo-list))
1081 ;; Undo that deletion--but don't change the undo list!
1082 (let (before-change-functions after-change-functions)
1083 (primitive-undo 1 buffer-undo-list))
1084 ;; Now delete the rest of the specified region,
1085 ;; but don't record it.
1086 (setq buffer-undo-list t)
1087 (if (/= (length (car kill-ring)) (- (max end beg) (min end beg)))
1088 (error "Lossage in mouse-save-then-kill-delete-region"))
1089 (delete-region beg end))
1090 (let ((tail buffer-undo-list))
1091 ;; Search back in buffer-undo-list for the string
1092 ;; that came from deleting one character.
1093 (while (and tail (not (stringp (car (car tail)))))
1094 (setq tail (cdr tail)))
1095 ;; Replace it with an entry for the entire deleted text.
1096 (and tail
1097 (setcar tail (cons (car kill-ring) (min beg end))))))
1098 (undo-boundary))
1100 (defun mouse-save-then-kill (click)
1101 "Save text to point in kill ring; the second time, kill the text.
1102 If the text between point and the mouse is the same as what's
1103 at the front of the kill ring, this deletes the text.
1104 Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
1105 which prepares for a second click to delete the text.
1107 If you have selected words or lines, this command extends the
1108 selection through the word or line clicked on. If you do this
1109 again in a different position, it extends the selection again.
1110 If you do this twice in the same position, the selection is killed."
1111 (interactive "e")
1112 (let ((before-scroll
1113 (with-current-buffer (window-buffer (posn-window (event-start click)))
1114 point-before-scroll)))
1115 (mouse-minibuffer-check click)
1116 (let ((click-posn (posn-point (event-start click)))
1117 ;; Don't let a subsequent kill command append to this one:
1118 ;; prevent setting this-command to kill-region.
1119 (this-command this-command))
1120 (if (and (save-excursion
1121 (set-buffer (window-buffer (posn-window (event-start click))))
1122 (and (mark t) (> (mod mouse-selection-click-count 3) 0)
1123 ;; Don't be fooled by a recent click in some other buffer.
1124 (eq mouse-selection-click-count-buffer
1125 (current-buffer)))))
1126 (if (not (and (eq last-command 'mouse-save-then-kill)
1127 (equal click-posn
1128 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
1129 ;; Find both ends of the object selected by this click.
1130 (let* ((range
1131 (mouse-start-end click-posn click-posn
1132 mouse-selection-click-count)))
1133 ;; Move whichever end is closer to the click.
1134 ;; That's what xterm does, and it seems reasonable.
1135 (if (< (abs (- click-posn (mark t)))
1136 (abs (- click-posn (point))))
1137 (set-mark (car range))
1138 (goto-char (nth 1 range)))
1139 ;; We have already put the old region in the kill ring.
1140 ;; Replace it with the extended region.
1141 ;; (It would be annoying to make a separate entry.)
1142 (kill-new (buffer-substring (point) (mark t)) t)
1143 (mouse-set-region-1)
1144 ;; Arrange for a repeated mouse-3 to kill this region.
1145 (setq mouse-save-then-kill-posn
1146 (list (car kill-ring) (point) click-posn))
1147 (mouse-show-mark))
1148 ;; If we click this button again without moving it,
1149 ;; that time kill.
1150 (mouse-save-then-kill-delete-region (mark) (point))
1151 (setq mouse-selection-click-count 0)
1152 (setq mouse-save-then-kill-posn nil))
1153 (if (and (eq last-command 'mouse-save-then-kill)
1154 mouse-save-then-kill-posn
1155 (eq (car mouse-save-then-kill-posn) (car kill-ring))
1156 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
1157 ;; If this is the second time we've called
1158 ;; mouse-save-then-kill, delete the text from the buffer.
1159 (progn
1160 (mouse-save-then-kill-delete-region (point) (mark))
1161 ;; After we kill, another click counts as "the first time".
1162 (setq mouse-save-then-kill-posn nil))
1163 ;; This is not a repetition.
1164 ;; We are adjusting an old selection or creating a new one.
1165 (if (or (and (eq last-command 'mouse-save-then-kill)
1166 mouse-save-then-kill-posn)
1167 (and mark-active transient-mark-mode)
1168 (and (memq last-command
1169 '(mouse-drag-region mouse-set-region))
1170 (or mark-even-if-inactive
1171 (not transient-mark-mode))))
1172 ;; We have a selection or suitable region, so adjust it.
1173 (let* ((posn (event-start click))
1174 (new (posn-point posn)))
1175 (select-window (posn-window posn))
1176 (if (numberp new)
1177 (progn
1178 ;; Move whichever end of the region is closer to the click.
1179 ;; That is what xterm does, and it seems reasonable.
1180 (if (<= (abs (- new (point))) (abs (- new (mark t))))
1181 (goto-char new)
1182 (set-mark new))
1183 (setq deactivate-mark nil)))
1184 (kill-new (buffer-substring (point) (mark t)) t)
1185 (mouse-show-mark))
1186 ;; Set the mark where point is, then move where clicked.
1187 (mouse-set-mark-fast click)
1188 (if before-scroll
1189 (goto-char before-scroll))
1190 (exchange-point-and-mark)
1191 (kill-new (buffer-substring (point) (mark t)))
1192 (mouse-show-mark))
1193 (mouse-set-region-1)
1194 (setq mouse-save-then-kill-posn
1195 (list (car kill-ring) (point) click-posn)))))))
1197 (global-set-key [M-mouse-1] 'mouse-start-secondary)
1198 (global-set-key [M-drag-mouse-1] 'mouse-set-secondary)
1199 (global-set-key [M-down-mouse-1] 'mouse-drag-secondary)
1200 (global-set-key [M-mouse-3] 'mouse-secondary-save-then-kill)
1201 (global-set-key [M-mouse-2] 'mouse-yank-secondary)
1203 ;; An overlay which records the current secondary selection
1204 ;; or else is deleted when there is no secondary selection.
1205 ;; May be nil.
1206 (defvar mouse-secondary-overlay nil)
1208 (defvar mouse-secondary-click-count 0)
1210 ;; A marker which records the specified first end for a secondary selection.
1211 ;; May be nil.
1212 (defvar mouse-secondary-start nil)
1214 (defun mouse-start-secondary (click)
1215 "Set one end of the secondary selection to the position clicked on.
1216 Use \\[mouse-secondary-save-then-kill] to set the other end
1217 and complete the secondary selection."
1218 (interactive "e")
1219 (mouse-minibuffer-check click)
1220 (let ((posn (event-start click)))
1221 (save-excursion
1222 (set-buffer (window-buffer (posn-window posn)))
1223 ;; Cancel any preexisting secondary selection.
1224 (if mouse-secondary-overlay
1225 (delete-overlay mouse-secondary-overlay))
1226 (if (numberp (posn-point posn))
1227 (progn
1228 (or mouse-secondary-start
1229 (setq mouse-secondary-start (make-marker)))
1230 (move-marker mouse-secondary-start (posn-point posn)))))))
1232 (defun mouse-set-secondary (click)
1233 "Set the secondary selection to the text that the mouse is dragged over.
1234 This must be bound to a mouse drag event."
1235 (interactive "e")
1236 (mouse-minibuffer-check click)
1237 (let ((posn (event-start click))
1239 (end (event-end click)))
1240 (save-excursion
1241 (set-buffer (window-buffer (posn-window posn)))
1242 (if (numberp (posn-point posn))
1243 (setq beg (posn-point posn)))
1244 (if mouse-secondary-overlay
1245 (move-overlay mouse-secondary-overlay beg (posn-point end))
1246 (setq mouse-secondary-overlay (make-overlay beg (posn-point end))))
1247 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))))
1249 (defun mouse-drag-secondary (start-event)
1250 "Set the secondary selection to the text that the mouse is dragged over.
1251 Highlight the drag area as you move the mouse.
1252 This must be bound to a button-down mouse event.
1253 The function returns a non-nil value if it creates a secondary selection."
1254 (interactive "e")
1255 (mouse-minibuffer-check start-event)
1256 (let* ((echo-keystrokes 0)
1257 (start-posn (event-start start-event))
1258 (start-point (posn-point start-posn))
1259 (start-window (posn-window start-posn))
1260 (start-frame (window-frame start-window))
1261 (bounds (window-edges start-window))
1262 (top (nth 1 bounds))
1263 (bottom (if (window-minibuffer-p start-window)
1264 (nth 3 bounds)
1265 ;; Don't count the mode line.
1266 (1- (nth 3 bounds))))
1267 (click-count (1- (event-click-count start-event))))
1268 (save-excursion
1269 (set-buffer (window-buffer start-window))
1270 (setq mouse-secondary-click-count click-count)
1271 (or mouse-secondary-overlay
1272 (setq mouse-secondary-overlay
1273 (make-overlay (point) (point))))
1274 (overlay-put mouse-secondary-overlay 'face 'secondary-selection)
1275 (if (> (mod click-count 3) 0)
1276 ;; Double or triple press: make an initial selection
1277 ;; of one word or line.
1278 (let ((range (mouse-start-end start-point start-point click-count)))
1279 (set-marker mouse-secondary-start nil)
1280 (move-overlay mouse-secondary-overlay 1 1
1281 (window-buffer start-window))
1282 (move-overlay mouse-secondary-overlay (car range) (nth 1 range)
1283 (window-buffer start-window)))
1284 ;; Single-press: cancel any preexisting secondary selection.
1285 (or mouse-secondary-start
1286 (setq mouse-secondary-start (make-marker)))
1287 (set-marker mouse-secondary-start start-point)
1288 (delete-overlay mouse-secondary-overlay))
1289 (let (event end end-point)
1290 (track-mouse
1291 (while (progn
1292 (setq event (read-event))
1293 (or (mouse-movement-p event)
1294 (eq (car-safe event) 'switch-frame)))
1296 (if (eq (car-safe event) 'switch-frame)
1298 (setq end (event-end event)
1299 end-point (posn-point end))
1300 (cond
1301 ;; Are we moving within the original window?
1302 ((and (eq (posn-window end) start-window)
1303 (integer-or-marker-p end-point))
1304 (let ((range (mouse-start-end start-point end-point
1305 click-count)))
1306 (if (or (/= start-point end-point)
1307 (null (marker-position mouse-secondary-start)))
1308 (progn
1309 (set-marker mouse-secondary-start nil)
1310 (move-overlay mouse-secondary-overlay
1311 (car range) (nth 1 range))))))
1313 (let ((mouse-row (cdr (cdr (mouse-position)))))
1314 (cond
1315 ((null mouse-row))
1316 ((< mouse-row top)
1317 (mouse-scroll-subr start-window (- mouse-row top)
1318 mouse-secondary-overlay start-point))
1319 ((>= mouse-row bottom)
1320 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
1321 mouse-secondary-overlay start-point)))))))))
1323 (if (consp event)
1324 (if (marker-position mouse-secondary-start)
1325 (save-window-excursion
1326 (delete-overlay mouse-secondary-overlay)
1327 (x-set-selection 'SECONDARY nil)
1328 (select-window start-window)
1329 (save-excursion
1330 (goto-char mouse-secondary-start)
1331 (sit-for 1)
1332 nil))
1333 (x-set-selection
1334 'SECONDARY
1335 (buffer-substring (overlay-start mouse-secondary-overlay)
1336 (overlay-end mouse-secondary-overlay)))))))))
1338 (defun mouse-yank-secondary (click)
1339 "Insert the secondary selection at the position clicked on.
1340 Move point to the end of the inserted text.
1341 If `mouse-yank-at-point' is non-nil, insert at point
1342 regardless of where you click."
1343 (interactive "e")
1344 ;; Give temporary modes such as isearch a chance to turn off.
1345 (run-hooks 'mouse-leave-buffer-hook)
1346 (or mouse-yank-at-point (mouse-set-point click))
1347 (insert (x-get-selection 'SECONDARY)))
1349 (defun mouse-kill-secondary ()
1350 "Kill the text in the secondary selection.
1351 This is intended more as a keyboard command than as a mouse command
1352 but it can work as either one.
1354 The current buffer (in case of keyboard use), or the buffer clicked on,
1355 must be the one that the secondary selection is in. This requirement
1356 is to prevent accidents."
1357 (interactive)
1358 (let* ((keys (this-command-keys))
1359 (click (elt keys (1- (length keys)))))
1360 (or (eq (overlay-buffer mouse-secondary-overlay)
1361 (if (listp click)
1362 (window-buffer (posn-window (event-start click)))
1363 (current-buffer)))
1364 (error "Select or click on the buffer where the secondary selection is")))
1365 (let (this-command)
1366 (save-excursion
1367 (set-buffer (overlay-buffer mouse-secondary-overlay))
1368 (kill-region (overlay-start mouse-secondary-overlay)
1369 (overlay-end mouse-secondary-overlay))))
1370 (delete-overlay mouse-secondary-overlay)
1371 ;;; (x-set-selection 'SECONDARY nil)
1372 (setq mouse-secondary-overlay nil))
1374 (defun mouse-secondary-save-then-kill (click)
1375 "Save text to point in kill ring; the second time, kill the text.
1376 You must use this in a buffer where you have recently done \\[mouse-start-secondary].
1377 If the text between where you did \\[mouse-start-secondary] and where
1378 you use this command matches the text at the front of the kill ring,
1379 this command deletes the text.
1380 Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
1381 which prepares for a second click with this command to delete the text.
1383 If you have already made a secondary selection in that buffer,
1384 this command extends or retracts the selection to where you click.
1385 If you do this again in a different position, it extends or retracts
1386 again. If you do this twice in the same position, it kills the selection."
1387 (interactive "e")
1388 (mouse-minibuffer-check click)
1389 (let ((posn (event-start click))
1390 (click-posn (posn-point (event-start click)))
1391 ;; Don't let a subsequent kill command append to this one:
1392 ;; prevent setting this-command to kill-region.
1393 (this-command this-command))
1394 (or (eq (window-buffer (posn-window posn))
1395 (or (and mouse-secondary-overlay
1396 (overlay-buffer mouse-secondary-overlay))
1397 (if mouse-secondary-start
1398 (marker-buffer mouse-secondary-start))))
1399 (error "Wrong buffer"))
1400 (save-excursion
1401 (set-buffer (window-buffer (posn-window posn)))
1402 (if (> (mod mouse-secondary-click-count 3) 0)
1403 (if (not (and (eq last-command 'mouse-secondary-save-then-kill)
1404 (equal click-posn
1405 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
1406 ;; Find both ends of the object selected by this click.
1407 (let* ((range
1408 (mouse-start-end click-posn click-posn
1409 mouse-secondary-click-count)))
1410 ;; Move whichever end is closer to the click.
1411 ;; That's what xterm does, and it seems reasonable.
1412 (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay)))
1413 (abs (- click-posn (overlay-end mouse-secondary-overlay))))
1414 (move-overlay mouse-secondary-overlay (car range)
1415 (overlay-end mouse-secondary-overlay))
1416 (move-overlay mouse-secondary-overlay
1417 (overlay-start mouse-secondary-overlay)
1418 (nth 1 range)))
1419 ;; We have already put the old region in the kill ring.
1420 ;; Replace it with the extended region.
1421 ;; (It would be annoying to make a separate entry.)
1422 (kill-new (buffer-substring
1423 (overlay-start mouse-secondary-overlay)
1424 (overlay-end mouse-secondary-overlay)) t)
1425 ;; Arrange for a repeated mouse-3 to kill this region.
1426 (setq mouse-save-then-kill-posn
1427 (list (car kill-ring) (point) click-posn)))
1428 ;; If we click this button again without moving it,
1429 ;; that time kill.
1430 (progn
1431 (mouse-save-then-kill-delete-region
1432 (overlay-start mouse-secondary-overlay)
1433 (overlay-end mouse-secondary-overlay))
1434 (setq mouse-save-then-kill-posn nil)
1435 (setq mouse-secondary-click-count 0)
1436 (delete-overlay mouse-secondary-overlay)))
1437 (if (and (eq last-command 'mouse-secondary-save-then-kill)
1438 mouse-save-then-kill-posn
1439 (eq (car mouse-save-then-kill-posn) (car kill-ring))
1440 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
1441 ;; If this is the second time we've called
1442 ;; mouse-secondary-save-then-kill, delete the text from the buffer.
1443 (progn
1444 (mouse-save-then-kill-delete-region
1445 (overlay-start mouse-secondary-overlay)
1446 (overlay-end mouse-secondary-overlay))
1447 (setq mouse-save-then-kill-posn nil)
1448 (delete-overlay mouse-secondary-overlay))
1449 (if (overlay-start mouse-secondary-overlay)
1450 ;; We have a selection, so adjust it.
1451 (progn
1452 (if (numberp click-posn)
1453 (progn
1454 ;; Move whichever end of the region is closer to the click.
1455 ;; That is what xterm does, and it seems reasonable.
1456 (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay)))
1457 (abs (- click-posn (overlay-end mouse-secondary-overlay))))
1458 (move-overlay mouse-secondary-overlay click-posn
1459 (overlay-end mouse-secondary-overlay))
1460 (move-overlay mouse-secondary-overlay
1461 (overlay-start mouse-secondary-overlay)
1462 click-posn))
1463 (setq deactivate-mark nil)))
1464 (if (eq last-command 'mouse-secondary-save-then-kill)
1465 ;; If the front of the kill ring comes from
1466 ;; an immediately previous use of this command,
1467 ;; replace it with the extended region.
1468 ;; (It would be annoying to make a separate entry.)
1469 (kill-new (buffer-substring
1470 (overlay-start mouse-secondary-overlay)
1471 (overlay-end mouse-secondary-overlay)) t)
1472 (let (deactivate-mark)
1473 (copy-region-as-kill (overlay-start mouse-secondary-overlay)
1474 (overlay-end mouse-secondary-overlay)))))
1475 (if mouse-secondary-start
1476 ;; All we have is one end of a selection,
1477 ;; so put the other end here.
1478 (let ((start (+ 0 mouse-secondary-start)))
1479 (kill-ring-save start click-posn)
1480 (if mouse-secondary-overlay
1481 (move-overlay mouse-secondary-overlay start click-posn)
1482 (setq mouse-secondary-overlay (make-overlay start click-posn)))
1483 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))))
1484 (setq mouse-save-then-kill-posn
1485 (list (car kill-ring) (point) click-posn))))
1486 (if (overlay-buffer mouse-secondary-overlay)
1487 (x-set-selection 'SECONDARY
1488 (buffer-substring
1489 (overlay-start mouse-secondary-overlay)
1490 (overlay-end mouse-secondary-overlay)))))))
1492 (defcustom mouse-buffer-menu-maxlen 20
1493 "*Number of buffers in one pane (submenu) of the buffer menu.
1494 If we have lots of buffers, divide them into groups of
1495 `mouse-buffer-menu-maxlen' and make a pane (or submenu) for each one."
1496 :type 'integer
1497 :group 'mouse)
1499 (defcustom mouse-buffer-menu-mode-mult 4
1500 "*Group the buffers by the major mode groups on \\[mouse-buffer-menu]?
1501 This number which determines (in a hairy way) whether \\[mouse-buffer-menu]
1502 will split the buffer menu by the major modes (see
1503 `mouse-buffer-menu-mode-groups') or just by menu length.
1504 Set to 1 (or even 0!) if you want to group by major mode always, and to
1505 a large number if you prefer a mixed multitude. The default is 4."
1506 :type 'integer
1507 :group 'mouse
1508 :version "20.3")
1510 (defvar mouse-buffer-menu-mode-groups
1511 '(("Info\\|Help\\|Apropos\\|Man" . "Help")
1512 ("\\bVM\\b\\|\\bMH\\b\\|Message\\|Mail\\|Group\\|Score\\|Summary\\|Article"
1513 . "Mail/News")
1514 ("\\<C\\>" . "C")
1515 ("ObjC" . "C")
1516 ("Text" . "Text")
1517 ("Outline" . "Text")
1518 ("Lisp" . "Lisp"))
1519 "How to group various major modes together in \\[mouse-buffer-menu].
1520 Each element has the form (REGEXP . GROUPNAME).
1521 If the major mode's name string matches REGEXP, use GROUPNAME instead.")
1523 (defun mouse-buffer-menu (event)
1524 "Pop up a menu of buffers for selection with the mouse.
1525 This switches buffers in the window that you clicked on,
1526 and selects that window."
1527 (interactive "e")
1528 (mouse-minibuffer-check event)
1529 (let ((buffers (buffer-list)) alist menu split-by-major-mode sum-of-squares)
1530 ;; Make an alist of elements that look like (MENU-ITEM . BUFFER).
1531 (let ((tail buffers))
1532 (while tail
1533 ;; Divide all buffers into buckets for various major modes.
1534 ;; Each bucket looks like (MODE NAMESTRING BUFFERS...).
1535 (with-current-buffer (car tail)
1536 (let* ((adjusted-major-mode major-mode) elt)
1537 (let ((tail mouse-buffer-menu-mode-groups))
1538 (while tail
1539 (if (string-match (car (car tail)) mode-name)
1540 (setq adjusted-major-mode (cdr (car tail))))
1541 (setq tail (cdr tail))))
1542 (setq elt (assoc adjusted-major-mode split-by-major-mode))
1543 (if (null elt)
1544 (setq elt (list adjusted-major-mode
1545 (if (stringp adjusted-major-mode)
1546 adjusted-major-mode
1547 mode-name))
1548 split-by-major-mode (cons elt split-by-major-mode)))
1549 (or (memq (car tail) (cdr (cdr elt)))
1550 (setcdr (cdr elt) (cons (car tail) (cdr (cdr elt)))))))
1551 (setq tail (cdr tail))))
1552 ;; Compute the sum of squares of sizes of the major-mode buckets.
1553 (let ((tail split-by-major-mode))
1554 (setq sum-of-squares 0)
1555 (while tail
1556 (setq sum-of-squares
1557 (+ sum-of-squares
1558 (let ((len (length (cdr (cdr (car tail)))))) (* len len))))
1559 (setq tail (cdr tail))))
1560 (if (< (* sum-of-squares mouse-buffer-menu-mode-mult)
1561 (* (length buffers) (length buffers)))
1562 ;; Subdividing by major modes really helps, so let's do it.
1563 (let (subdivided-menus (buffers-left (length buffers)))
1564 ;; Sort the list to put the most popular major modes first.
1565 (setq split-by-major-mode
1566 (sort split-by-major-mode
1567 (function (lambda (elt1 elt2)
1568 (> (length elt1) (length elt2))))))
1569 ;; Make a separate submenu for each major mode
1570 ;; that has more than one buffer,
1571 ;; unless all the remaining buffers are less than 1/10 of them.
1572 (while (and split-by-major-mode
1573 (and (> (length (car split-by-major-mode)) 3)
1574 (> (* buffers-left 10) (length buffers))))
1575 (setq subdivided-menus
1576 (cons (cons
1577 (nth 1 (car split-by-major-mode))
1578 (mouse-buffer-menu-alist
1579 (cdr (cdr (car split-by-major-mode)))))
1580 subdivided-menus))
1581 (setq buffers-left
1582 (- buffers-left (length (cdr (car split-by-major-mode)))))
1583 (setq split-by-major-mode (cdr split-by-major-mode)))
1584 ;; If any major modes are left over,
1585 ;; make a single submenu for them.
1586 (if split-by-major-mode
1587 (setq subdivided-menus
1588 (cons (cons
1589 "Others"
1590 (mouse-buffer-menu-alist
1591 ;; we don't need split-by-major-mode any
1592 ;; more, so we can ditch it with nconc.
1593 (apply 'nconc (mapcar 'cddr split-by-major-mode))))
1594 subdivided-menus)))
1595 (setq menu (cons "Buffer Menu" (nreverse subdivided-menus))))
1596 (progn
1597 (setq alist (mouse-buffer-menu-alist buffers))
1598 (setq menu (cons "Buffer Menu"
1599 (mouse-buffer-menu-split "Select Buffer" alist)))))
1600 (let ((buf (x-popup-menu event menu))
1601 (window (posn-window (event-start event))))
1602 (when buf
1603 (or (framep window) (select-window window))
1604 (switch-to-buffer buf)))))
1606 (defun mouse-buffer-menu-alist (buffers)
1607 (let (tail
1608 (maxlen 0)
1609 head)
1610 (setq buffers
1611 (sort buffers
1612 (function (lambda (elt1 elt2)
1613 (string< (buffer-name elt1) (buffer-name elt2))))))
1614 (setq tail buffers)
1615 (while tail
1616 (or (eq ?\ (aref (buffer-name (car tail)) 0))
1617 (setq maxlen
1618 (max maxlen
1619 (length (buffer-name (car tail))))))
1620 (setq tail (cdr tail)))
1621 (setq tail buffers)
1622 (while tail
1623 (let ((elt (car tail)))
1624 (if (/= (aref (buffer-name elt) 0) ?\ )
1625 (setq head
1626 (cons
1627 (cons
1628 (format
1629 (format "%%%ds %%s%%s %%s" maxlen)
1630 (buffer-name elt)
1631 (if (buffer-modified-p elt) "*" " ")
1632 (save-excursion
1633 (set-buffer elt)
1634 (if buffer-read-only "%" " "))
1635 (or (buffer-file-name elt)
1636 (save-excursion
1637 (set-buffer elt)
1638 (if list-buffers-directory
1639 (expand-file-name
1640 list-buffers-directory)))
1641 ""))
1642 elt)
1643 head))))
1644 (setq tail (cdr tail)))
1645 ;; Compensate for the reversal that the above loop does.
1646 (nreverse head)))
1648 (defun mouse-buffer-menu-split (title alist)
1649 ;; If we have lots of buffers, divide them into groups of 20
1650 ;; and make a pane (or submenu) for each one.
1651 (if (> (length alist) (/ (* mouse-buffer-menu-maxlen 3) 2))
1652 (let ((alist alist) sublists next
1653 (i 1))
1654 (while alist
1655 ;; Pull off the next mouse-buffer-menu-maxlen buffers
1656 ;; and make them the next element of sublist.
1657 (setq next (nthcdr mouse-buffer-menu-maxlen alist))
1658 (if next
1659 (setcdr (nthcdr (1- mouse-buffer-menu-maxlen) alist)
1660 nil))
1661 (setq sublists (cons (cons (format "Buffers %d" i) alist)
1662 sublists))
1663 (setq i (1+ i))
1664 (setq alist next))
1665 (nreverse sublists))
1666 ;; Few buffers--put them all in one pane.
1667 (list (cons title alist))))
1669 ;;; These need to be rewritten for the new scroll bar implementation.
1671 ;;;!! ;; Commands for the scroll bar.
1672 ;;;!!
1673 ;;;!! (defun mouse-scroll-down (click)
1674 ;;;!! (interactive "@e")
1675 ;;;!! (scroll-down (1+ (cdr (mouse-coords click)))))
1676 ;;;!!
1677 ;;;!! (defun mouse-scroll-up (click)
1678 ;;;!! (interactive "@e")
1679 ;;;!! (scroll-up (1+ (cdr (mouse-coords click)))))
1680 ;;;!!
1681 ;;;!! (defun mouse-scroll-down-full ()
1682 ;;;!! (interactive "@")
1683 ;;;!! (scroll-down nil))
1684 ;;;!!
1685 ;;;!! (defun mouse-scroll-up-full ()
1686 ;;;!! (interactive "@")
1687 ;;;!! (scroll-up nil))
1688 ;;;!!
1689 ;;;!! (defun mouse-scroll-move-cursor (click)
1690 ;;;!! (interactive "@e")
1691 ;;;!! (move-to-window-line (1+ (cdr (mouse-coords click)))))
1692 ;;;!!
1693 ;;;!! (defun mouse-scroll-absolute (event)
1694 ;;;!! (interactive "@e")
1695 ;;;!! (let* ((pos (car event))
1696 ;;;!! (position (car pos))
1697 ;;;!! (length (car (cdr pos))))
1698 ;;;!! (if (<= length 0) (setq length 1))
1699 ;;;!! (let* ((scale-factor (max 1 (/ length (/ 8000000 (buffer-size)))))
1700 ;;;!! (newpos (* (/ (* (/ (buffer-size) scale-factor)
1701 ;;;!! position)
1702 ;;;!! length)
1703 ;;;!! scale-factor)))
1704 ;;;!! (goto-char newpos)
1705 ;;;!! (recenter '(4)))))
1706 ;;;!!
1707 ;;;!! (defun mouse-scroll-left (click)
1708 ;;;!! (interactive "@e")
1709 ;;;!! (scroll-left (1+ (car (mouse-coords click)))))
1710 ;;;!!
1711 ;;;!! (defun mouse-scroll-right (click)
1712 ;;;!! (interactive "@e")
1713 ;;;!! (scroll-right (1+ (car (mouse-coords click)))))
1714 ;;;!!
1715 ;;;!! (defun mouse-scroll-left-full ()
1716 ;;;!! (interactive "@")
1717 ;;;!! (scroll-left nil))
1718 ;;;!!
1719 ;;;!! (defun mouse-scroll-right-full ()
1720 ;;;!! (interactive "@")
1721 ;;;!! (scroll-right nil))
1722 ;;;!!
1723 ;;;!! (defun mouse-scroll-move-cursor-horizontally (click)
1724 ;;;!! (interactive "@e")
1725 ;;;!! (move-to-column (1+ (car (mouse-coords click)))))
1726 ;;;!!
1727 ;;;!! (defun mouse-scroll-absolute-horizontally (event)
1728 ;;;!! (interactive "@e")
1729 ;;;!! (let* ((pos (car event))
1730 ;;;!! (position (car pos))
1731 ;;;!! (length (car (cdr pos))))
1732 ;;;!! (set-window-hscroll (selected-window) 33)))
1733 ;;;!!
1734 ;;;!! (global-set-key [scroll-bar mouse-1] 'mouse-scroll-up)
1735 ;;;!! (global-set-key [scroll-bar mouse-2] 'mouse-scroll-absolute)
1736 ;;;!! (global-set-key [scroll-bar mouse-3] 'mouse-scroll-down)
1737 ;;;!!
1738 ;;;!! (global-set-key [vertical-slider mouse-1] 'mouse-scroll-move-cursor)
1739 ;;;!! (global-set-key [vertical-slider mouse-2] 'mouse-scroll-move-cursor)
1740 ;;;!! (global-set-key [vertical-slider mouse-3] 'mouse-scroll-move-cursor)
1741 ;;;!!
1742 ;;;!! (global-set-key [thumbup mouse-1] 'mouse-scroll-up-full)
1743 ;;;!! (global-set-key [thumbup mouse-2] 'mouse-scroll-up-full)
1744 ;;;!! (global-set-key [thumbup mouse-3] 'mouse-scroll-up-full)
1745 ;;;!!
1746 ;;;!! (global-set-key [thumbdown mouse-1] 'mouse-scroll-down-full)
1747 ;;;!! (global-set-key [thumbdown mouse-2] 'mouse-scroll-down-full)
1748 ;;;!! (global-set-key [thumbdown mouse-3] 'mouse-scroll-down-full)
1749 ;;;!!
1750 ;;;!! (global-set-key [horizontal-scroll-bar mouse-1] 'mouse-scroll-left)
1751 ;;;!! (global-set-key [horizontal-scroll-bar mouse-2]
1752 ;;;!! 'mouse-scroll-absolute-horizontally)
1753 ;;;!! (global-set-key [horizontal-scroll-bar mouse-3] 'mouse-scroll-right)
1754 ;;;!!
1755 ;;;!! (global-set-key [horizontal-slider mouse-1]
1756 ;;;!! 'mouse-scroll-move-cursor-horizontally)
1757 ;;;!! (global-set-key [horizontal-slider mouse-2]
1758 ;;;!! 'mouse-scroll-move-cursor-horizontally)
1759 ;;;!! (global-set-key [horizontal-slider mouse-3]
1760 ;;;!! 'mouse-scroll-move-cursor-horizontally)
1761 ;;;!!
1762 ;;;!! (global-set-key [thumbleft mouse-1] 'mouse-scroll-left-full)
1763 ;;;!! (global-set-key [thumbleft mouse-2] 'mouse-scroll-left-full)
1764 ;;;!! (global-set-key [thumbleft mouse-3] 'mouse-scroll-left-full)
1765 ;;;!!
1766 ;;;!! (global-set-key [thumbright mouse-1] 'mouse-scroll-right-full)
1767 ;;;!! (global-set-key [thumbright mouse-2] 'mouse-scroll-right-full)
1768 ;;;!! (global-set-key [thumbright mouse-3] 'mouse-scroll-right-full)
1769 ;;;!!
1770 ;;;!! (global-set-key [horizontal-scroll-bar S-mouse-2]
1771 ;;;!! 'mouse-split-window-horizontally)
1772 ;;;!! (global-set-key [mode-line S-mouse-2]
1773 ;;;!! 'mouse-split-window-horizontally)
1774 ;;;!! (global-set-key [vertical-scroll-bar S-mouse-2]
1775 ;;;!! 'mouse-split-window)
1777 ;;;!! ;;;;
1778 ;;;!! ;;;; Here are experimental things being tested. Mouse events
1779 ;;;!! ;;;; are of the form:
1780 ;;;!! ;;;; ((x y) window screen-part key-sequence timestamp)
1781 ;;;!! ;;
1782 ;;;!! ;;;;
1783 ;;;!! ;;;; Dynamically track mouse coordinates
1784 ;;;!! ;;;;
1785 ;;;!! ;;
1786 ;;;!! ;;(defun track-mouse (event)
1787 ;;;!! ;; "Track the coordinates, absolute and relative, of the mouse."
1788 ;;;!! ;; (interactive "@e")
1789 ;;;!! ;; (while mouse-grabbed
1790 ;;;!! ;; (let* ((pos (read-mouse-position (selected-screen)))
1791 ;;;!! ;; (abs-x (car pos))
1792 ;;;!! ;; (abs-y (cdr pos))
1793 ;;;!! ;; (relative-coordinate (coordinates-in-window-p
1794 ;;;!! ;; (list (car pos) (cdr pos))
1795 ;;;!! ;; (selected-window))))
1796 ;;;!! ;; (if (consp relative-coordinate)
1797 ;;;!! ;; (message "mouse: [%d %d], (%d %d)" abs-x abs-y
1798 ;;;!! ;; (car relative-coordinate)
1799 ;;;!! ;; (car (cdr relative-coordinate)))
1800 ;;;!! ;; (message "mouse: [%d %d]" abs-x abs-y)))))
1801 ;;;!!
1802 ;;;!! ;;
1803 ;;;!! ;; Dynamically put a box around the line indicated by point
1804 ;;;!! ;;
1805 ;;;!! ;;
1806 ;;;!! ;;(require 'backquote)
1807 ;;;!! ;;
1808 ;;;!! ;;(defun mouse-select-buffer-line (event)
1809 ;;;!! ;; (interactive "@e")
1810 ;;;!! ;; (let ((relative-coordinate
1811 ;;;!! ;; (coordinates-in-window-p (car event) (selected-window)))
1812 ;;;!! ;; (abs-y (car (cdr (car event)))))
1813 ;;;!! ;; (if (consp relative-coordinate)
1814 ;;;!! ;; (progn
1815 ;;;!! ;; (save-excursion
1816 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1817 ;;;!! ;; (x-draw-rectangle
1818 ;;;!! ;; (selected-screen)
1819 ;;;!! ;; abs-y 0
1820 ;;;!! ;; (save-excursion
1821 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1822 ;;;!! ;; (end-of-line)
1823 ;;;!! ;; (push-mark nil t)
1824 ;;;!! ;; (beginning-of-line)
1825 ;;;!! ;; (- (region-end) (region-beginning))) 1))
1826 ;;;!! ;; (sit-for 1)
1827 ;;;!! ;; (x-erase-rectangle (selected-screen))))))
1828 ;;;!! ;;
1829 ;;;!! ;;(defvar last-line-drawn nil)
1830 ;;;!! ;;(defvar begin-delim "[^ \t]")
1831 ;;;!! ;;(defvar end-delim "[^ \t]")
1832 ;;;!! ;;
1833 ;;;!! ;;(defun mouse-boxing (event)
1834 ;;;!! ;; (interactive "@e")
1835 ;;;!! ;; (save-excursion
1836 ;;;!! ;; (let ((screen (selected-screen)))
1837 ;;;!! ;; (while (= (x-mouse-events) 0)
1838 ;;;!! ;; (let* ((pos (read-mouse-position screen))
1839 ;;;!! ;; (abs-x (car pos))
1840 ;;;!! ;; (abs-y (cdr pos))
1841 ;;;!! ;; (relative-coordinate
1842 ;;;!! ;; (coordinates-in-window-p (` ((, abs-x) (, abs-y)))
1843 ;;;!! ;; (selected-window)))
1844 ;;;!! ;; (begin-reg nil)
1845 ;;;!! ;; (end-reg nil)
1846 ;;;!! ;; (end-column nil)
1847 ;;;!! ;; (begin-column nil))
1848 ;;;!! ;; (if (and (consp relative-coordinate)
1849 ;;;!! ;; (or (not last-line-drawn)
1850 ;;;!! ;; (not (= last-line-drawn abs-y))))
1851 ;;;!! ;; (progn
1852 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1853 ;;;!! ;; (if (= (following-char) 10)
1854 ;;;!! ;; ()
1855 ;;;!! ;; (progn
1856 ;;;!! ;; (setq begin-reg (1- (re-search-forward end-delim)))
1857 ;;;!! ;; (setq begin-column (1- (current-column)))
1858 ;;;!! ;; (end-of-line)
1859 ;;;!! ;; (setq end-reg (1+ (re-search-backward begin-delim)))
1860 ;;;!! ;; (setq end-column (1+ (current-column)))
1861 ;;;!! ;; (message "%s" (buffer-substring begin-reg end-reg))
1862 ;;;!! ;; (x-draw-rectangle screen
1863 ;;;!! ;; (setq last-line-drawn abs-y)
1864 ;;;!! ;; begin-column
1865 ;;;!! ;; (- end-column begin-column) 1))))))))))
1866 ;;;!! ;;
1867 ;;;!! ;;(defun mouse-erase-box ()
1868 ;;;!! ;; (interactive)
1869 ;;;!! ;; (if last-line-drawn
1870 ;;;!! ;; (progn
1871 ;;;!! ;; (x-erase-rectangle (selected-screen))
1872 ;;;!! ;; (setq last-line-drawn nil))))
1873 ;;;!!
1874 ;;;!! ;;; (defun test-x-rectangle ()
1875 ;;;!! ;;; (use-local-mouse-map (setq rectangle-test-map (make-sparse-keymap)))
1876 ;;;!! ;;; (define-key rectangle-test-map mouse-motion-button-left 'mouse-boxing)
1877 ;;;!! ;;; (define-key rectangle-test-map mouse-button-left-up 'mouse-erase-box))
1878 ;;;!!
1879 ;;;!! ;;
1880 ;;;!! ;; Here is how to do double clicking in lisp. About to change.
1881 ;;;!! ;;
1882 ;;;!!
1883 ;;;!! (defvar double-start nil)
1884 ;;;!! (defconst double-click-interval 300
1885 ;;;!! "Max ticks between clicks")
1886 ;;;!!
1887 ;;;!! (defun double-down (event)
1888 ;;;!! (interactive "@e")
1889 ;;;!! (if double-start
1890 ;;;!! (let ((interval (- (nth 4 event) double-start)))
1891 ;;;!! (if (< interval double-click-interval)
1892 ;;;!! (progn
1893 ;;;!! (backward-up-list 1)
1894 ;;;!! ;; (message "Interval %d" interval)
1895 ;;;!! (sleep-for 1)))
1896 ;;;!! (setq double-start nil))
1897 ;;;!! (setq double-start (nth 4 event))))
1898 ;;;!!
1899 ;;;!! (defun double-up (event)
1900 ;;;!! (interactive "@e")
1901 ;;;!! (and double-start
1902 ;;;!! (> (- (nth 4 event ) double-start) double-click-interval)
1903 ;;;!! (setq double-start nil)))
1904 ;;;!!
1905 ;;;!! ;;; (defun x-test-doubleclick ()
1906 ;;;!! ;;; (use-local-mouse-map (setq doubleclick-test-map (make-sparse-keymap)))
1907 ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left 'double-down)
1908 ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left-up 'double-up))
1909 ;;;!!
1910 ;;;!! ;;
1911 ;;;!! ;; This scrolls while button is depressed. Use preferable in scroll bar.
1912 ;;;!! ;;
1913 ;;;!!
1914 ;;;!! (defvar scrolled-lines 0)
1915 ;;;!! (defconst scroll-speed 1)
1916 ;;;!!
1917 ;;;!! (defun incr-scroll-down (event)
1918 ;;;!! (interactive "@e")
1919 ;;;!! (setq scrolled-lines 0)
1920 ;;;!! (incremental-scroll scroll-speed))
1921 ;;;!!
1922 ;;;!! (defun incr-scroll-up (event)
1923 ;;;!! (interactive "@e")
1924 ;;;!! (setq scrolled-lines 0)
1925 ;;;!! (incremental-scroll (- scroll-speed)))
1926 ;;;!!
1927 ;;;!! (defun incremental-scroll (n)
1928 ;;;!! (while (= (x-mouse-events) 0)
1929 ;;;!! (setq scrolled-lines (1+ (* scroll-speed scrolled-lines)))
1930 ;;;!! (scroll-down n)
1931 ;;;!! (sit-for 300 t)))
1932 ;;;!!
1933 ;;;!! (defun incr-scroll-stop (event)
1934 ;;;!! (interactive "@e")
1935 ;;;!! (message "Scrolled %d lines" scrolled-lines)
1936 ;;;!! (setq scrolled-lines 0)
1937 ;;;!! (sleep-for 1))
1938 ;;;!!
1939 ;;;!! ;;; (defun x-testing-scroll ()
1940 ;;;!! ;;; (let ((scrolling-map (function mouse-vertical-scroll-bar-prefix)))
1941 ;;;!! ;;; (define-key scrolling-map mouse-button-left 'incr-scroll-down)
1942 ;;;!! ;;; (define-key scrolling-map mouse-button-right 'incr-scroll-up)
1943 ;;;!! ;;; (define-key scrolling-map mouse-button-left-up 'incr-scroll-stop)
1944 ;;;!! ;;; (define-key scrolling-map mouse-button-right-up 'incr-scroll-stop)))
1945 ;;;!!
1946 ;;;!! ;;
1947 ;;;!! ;; Some playthings suitable for picture mode? They need work.
1948 ;;;!! ;;
1949 ;;;!!
1950 ;;;!! (defun mouse-kill-rectangle (event)
1951 ;;;!! "Kill the rectangle between point and the mouse cursor."
1952 ;;;!! (interactive "@e")
1953 ;;;!! (let ((point-save (point)))
1954 ;;;!! (save-excursion
1955 ;;;!! (mouse-set-point event)
1956 ;;;!! (push-mark nil t)
1957 ;;;!! (if (> point-save (point))
1958 ;;;!! (kill-rectangle (point) point-save)
1959 ;;;!! (kill-rectangle point-save (point))))))
1960 ;;;!!
1961 ;;;!! (defun mouse-open-rectangle (event)
1962 ;;;!! "Kill the rectangle between point and the mouse cursor."
1963 ;;;!! (interactive "@e")
1964 ;;;!! (let ((point-save (point)))
1965 ;;;!! (save-excursion
1966 ;;;!! (mouse-set-point event)
1967 ;;;!! (push-mark nil t)
1968 ;;;!! (if (> point-save (point))
1969 ;;;!! (open-rectangle (point) point-save)
1970 ;;;!! (open-rectangle point-save (point))))))
1971 ;;;!!
1972 ;;;!! ;; Must be a better way to do this.
1973 ;;;!!
1974 ;;;!! (defun mouse-multiple-insert (n char)
1975 ;;;!! (while (> n 0)
1976 ;;;!! (insert char)
1977 ;;;!! (setq n (1- n))))
1978 ;;;!!
1979 ;;;!! ;; What this could do is not finalize until button was released.
1980 ;;;!!
1981 ;;;!! (defun mouse-move-text (event)
1982 ;;;!! "Move text from point to cursor position, inserting spaces."
1983 ;;;!! (interactive "@e")
1984 ;;;!! (let* ((relative-coordinate
1985 ;;;!! (coordinates-in-window-p (car event) (selected-window))))
1986 ;;;!! (if (consp relative-coordinate)
1987 ;;;!! (cond ((> (current-column) (car relative-coordinate))
1988 ;;;!! (delete-char
1989 ;;;!! (- (car relative-coordinate) (current-column))))
1990 ;;;!! ((< (current-column) (car relative-coordinate))
1991 ;;;!! (mouse-multiple-insert
1992 ;;;!! (- (car relative-coordinate) (current-column)) " "))
1993 ;;;!! ((= (current-column) (car relative-coordinate)) (ding))))))
1995 ;; Choose a completion with the mouse.
1997 (defun mouse-choose-completion (event)
1998 "Click on an alternative in the `*Completions*' buffer to choose it."
1999 (interactive "e")
2000 ;; Give temporary modes such as isearch a chance to turn off.
2001 (run-hooks 'mouse-leave-buffer-hook)
2002 (let ((buffer (window-buffer))
2003 choice
2004 base-size)
2005 (save-excursion
2006 (set-buffer (window-buffer (posn-window (event-start event))))
2007 (if completion-reference-buffer
2008 (setq buffer completion-reference-buffer))
2009 (setq base-size completion-base-size)
2010 (save-excursion
2011 (goto-char (posn-point (event-start event)))
2012 (let (beg end)
2013 (if (and (not (eobp)) (get-text-property (point) 'mouse-face))
2014 (setq end (point) beg (1+ (point))))
2015 (if (null beg)
2016 (error "No completion here"))
2017 (setq beg (previous-single-property-change beg 'mouse-face))
2018 (setq end (or (next-single-property-change end 'mouse-face)
2019 (point-max)))
2020 (setq choice (buffer-substring beg end)))))
2021 (let ((owindow (selected-window)))
2022 (select-window (posn-window (event-start event)))
2023 (if (and (one-window-p t 'selected-frame)
2024 (window-dedicated-p (selected-window)))
2025 ;; This is a special buffer's frame
2026 (iconify-frame (selected-frame))
2027 (or (window-dedicated-p (selected-window))
2028 (bury-buffer)))
2029 (select-window owindow))
2030 (choose-completion-string choice buffer base-size)))
2032 ;; Font selection.
2034 (defun font-menu-add-default ()
2035 (let* ((default (cdr (assq 'font (frame-parameters (selected-frame)))))
2036 (font-alist x-fixed-font-alist)
2037 (elt (or (assoc "Misc" font-alist) (nth 1 font-alist))))
2038 (if (assoc "Default" elt)
2039 (delete (assoc "Default" elt) elt))
2040 (setcdr elt
2041 (cons (list "Default" default)
2042 (cdr elt)))))
2044 (defvar x-fixed-font-alist
2045 '("Font menu"
2046 ("Misc"
2047 ;; For these, we specify the pixel height and width.
2048 ("fixed" "fixed")
2049 ("6x10" "-misc-fixed-medium-r-normal--10-*-*-*-c-60-iso8859-1" "6x10")
2050 ("6x12"
2051 "-misc-fixed-medium-r-semicondensed--12-*-*-*-c-60-iso8859-1" "6x12")
2052 ("6x13"
2053 "-misc-fixed-medium-r-semicondensed--13-*-*-*-c-60-iso8859-1" "6x13")
2054 ("7x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-70-iso8859-1" "7x13")
2055 ("7x14" "-misc-fixed-medium-r-normal--14-*-*-*-c-70-iso8859-1" "7x14")
2056 ("8x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-80-iso8859-1" "8x13")
2057 ("9x15" "-misc-fixed-medium-r-normal--15-*-*-*-c-90-iso8859-1" "9x15")
2058 ("10x20" "-misc-fixed-medium-r-normal--20-*-*-*-c-100-iso8859-1" "10x20")
2059 ("11x18" "-misc-fixed-medium-r-normal--18-*-*-*-c-110-iso8859-1" "11x18")
2060 ("12x24" "-misc-fixed-medium-r-normal--24-*-*-*-c-120-iso8859-1" "12x24")
2061 ("")
2062 ("clean 5x8"
2063 "-schumacher-clean-medium-r-normal--8-*-*-*-c-50-iso8859-1")
2064 ("clean 6x8"
2065 "-schumacher-clean-medium-r-normal--8-*-*-*-c-60-iso8859-1")
2066 ("clean 8x8"
2067 "-schumacher-clean-medium-r-normal--8-*-*-*-c-80-iso8859-1")
2068 ("clean 8x10"
2069 "-schumacher-clean-medium-r-normal--10-*-*-*-c-80-iso8859-1")
2070 ("clean 8x14"
2071 "-schumacher-clean-medium-r-normal--14-*-*-*-c-80-iso8859-1")
2072 ("clean 8x16"
2073 "-schumacher-clean-medium-r-normal--16-*-*-*-c-80-iso8859-1")
2074 ("")
2075 ("sony 8x16" "-sony-fixed-medium-r-normal--16-*-*-*-c-80-iso8859-1")
2076 ;;; We don't seem to have these; who knows what they are.
2077 ;;; ("fg-18" "fg-18")
2078 ;;; ("fg-25" "fg-25")
2079 ("lucidasanstypewriter-12" "-b&h-lucidatypewriter-medium-r-normal-sans-*-120-*-*-*-*-iso8859-1")
2080 ("lucidasanstypewriter-bold-14" "-b&h-lucidatypewriter-bold-r-normal-sans-*-140-*-*-*-*-iso8859-1")
2081 ("lucidasanstypewriter-bold-24"
2082 "-b&h-lucidatypewriter-bold-r-normal-sans-*-240-*-*-*-*-iso8859-1")
2083 ;;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
2084 ;;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
2086 ("Courier"
2087 ;; For these, we specify the point height.
2088 ("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1")
2089 ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1")
2090 ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1")
2091 ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1")
2092 ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1")
2093 ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1")
2094 ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1")
2095 ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1")
2096 ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1")
2097 ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1")
2098 ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1")
2099 ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1")
2100 ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1")
2101 ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1")
2102 ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1")
2103 ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1")
2104 ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1")
2105 ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1")
2106 ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1")
2107 ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1")
2108 ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1")
2109 ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1")
2110 ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1")
2111 ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1"))
2113 "X fonts suitable for use in Emacs.")
2115 (defun mouse-set-font (&rest fonts)
2116 "Select an emacs font from a list of known good fonts and fontsets."
2117 (interactive
2118 (x-popup-menu
2119 last-nonmenu-event
2120 ;; Append list of fontsets currently defined.
2121 (append x-fixed-font-alist (list (generate-fontset-menu)))))
2122 (if fonts
2123 (let (font)
2124 (while fonts
2125 (condition-case nil
2126 (progn
2127 (set-default-font (car fonts))
2128 (setq font (car fonts))
2129 (setq fonts nil))
2130 (error
2131 (setq fonts (cdr fonts)))))
2132 (if (null font)
2133 (error "Font not found")))))
2135 ;;; Bindings for mouse commands.
2137 (define-key global-map [down-mouse-1] 'mouse-drag-region)
2138 (global-set-key [mouse-1] 'mouse-set-point)
2139 (global-set-key [drag-mouse-1] 'mouse-set-region)
2141 ;; These are tested for in mouse-drag-region.
2142 (global-set-key [double-mouse-1] 'mouse-set-point)
2143 (global-set-key [triple-mouse-1] 'mouse-set-point)
2145 (global-set-key [mouse-2] 'mouse-yank-at-click)
2146 (global-set-key [mouse-3] 'mouse-save-then-kill)
2148 ;; By binding these to down-going events, we let the user use the up-going
2149 ;; event to make the selection, saving a click.
2150 (global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
2151 (if (not (eq system-type 'ms-dos))
2152 (global-set-key [S-down-mouse-1] 'mouse-set-font))
2153 ;; C-down-mouse-2 is bound in facemenu.el.
2154 (global-set-key [C-down-mouse-3] 'mouse-popup-menubar-stuff)
2157 ;; Replaced with dragging mouse-1
2158 ;; (global-set-key [S-mouse-1] 'mouse-set-mark)
2160 ;; Binding mouse-1 to mouse-select-window when on mode-, header-, or
2161 ;; vertical-line prevents Emacs from signaling an error when the mouse
2162 ;; button is released after dragging these lines, on non-toolkit
2163 ;; versions.
2164 (global-set-key [mode-line mouse-1] 'mouse-select-window)
2165 (global-set-key [mode-line drag-mouse-1] 'mouse-select-window)
2166 (global-set-key [mode-line down-mouse-1] 'mouse-drag-mode-line)
2167 (global-set-key [header-line down-mouse-1] 'mouse-drag-header-line)
2168 (global-set-key [header-line mouse-1] 'mouse-select-window)
2169 (global-set-key [mode-line mouse-2] 'mouse-delete-other-windows)
2170 (global-set-key [mode-line mouse-3] 'mouse-delete-window)
2171 (global-set-key [mode-line C-mouse-2] 'mouse-split-window-horizontally)
2172 (global-set-key [vertical-scroll-bar C-mouse-2] 'mouse-split-window-vertically)
2173 (global-set-key [vertical-line C-mouse-2] 'mouse-split-window-vertically)
2174 (global-set-key [vertical-line down-mouse-1] 'mouse-drag-vertical-line)
2175 (global-set-key [vertical-line mouse-1] 'mouse-select-window)
2177 (provide 'mouse)
2179 ;; This file contains the functionality of the old mldrag.el.
2180 (defalias 'mldrag-drag-mode-line 'mouse-drag-mode-line)
2181 (defalias 'mldrag-drag-vertical-line 'mouse-drag-vertical-line)
2182 (make-obsolete 'mldrag-drag-mode-line 'mouse-drag-mode-line "21.1")
2183 (make-obsolete 'mldrag-drag-vertical-line 'mouse-drag-vertical-line "21.1")
2184 (provide 'mldrag)
2186 ;;; mouse.el ends here