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