(diff-default-read-only): Change default.
[emacs.git] / lisp / mouse.el
blob9b80ccc0cf5062b51a0e5449cb09f6d4d11b3465
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 ;; 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 (let ((posn (event-end event)))
581 (if (not (windowp (posn-window posn)))
582 (error "Cursor not in text area of window"))
583 (select-window (posn-window posn))
584 (if (numberp (posn-point posn))
585 (goto-char (posn-point posn)))))
587 (defvar mouse-last-region-beg nil)
588 (defvar mouse-last-region-end nil)
589 (defvar mouse-last-region-tick nil)
591 (defun mouse-region-match ()
592 "Return non-nil if there's an active region that was set with the mouse."
593 (and (mark t) mark-active
594 (eq mouse-last-region-beg (region-beginning))
595 (eq mouse-last-region-end (region-end))
596 (eq mouse-last-region-tick (buffer-modified-tick))))
598 (defun mouse-set-region (click)
599 "Set the region to the text dragged over, and copy to kill ring.
600 This should be bound to a mouse drag event."
601 (interactive "e")
602 (mouse-minibuffer-check click)
603 (let ((posn (event-start click))
604 (end (event-end click)))
605 (select-window (posn-window posn))
606 (if (numberp (posn-point posn))
607 (goto-char (posn-point posn)))
608 ;; If mark is highlighted, no need to bounce the cursor.
609 ;; On X, we highlight while dragging, thus once again no need to bounce.
610 (or transient-mark-mode
611 (memq (framep (selected-frame)) '(x pc w32))
612 (sit-for 1))
613 (push-mark)
614 (set-mark (point))
615 (if (numberp (posn-point end))
616 (goto-char (posn-point end)))
617 ;; Don't set this-command to kill-region, so that a following
618 ;; C-w will not double the text in the kill ring.
619 ;; Ignore last-command so we don't append to a preceding kill.
620 (let (this-command last-command deactivate-mark)
621 (copy-region-as-kill (mark) (point)))
622 (mouse-set-region-1)))
624 (defun mouse-set-region-1 ()
625 (setq mouse-last-region-beg (region-beginning))
626 (setq mouse-last-region-end (region-end))
627 (setq mouse-last-region-tick (buffer-modified-tick)))
629 (defcustom mouse-scroll-delay 0.25
630 "*The pause between scroll steps caused by mouse drags, in seconds.
631 If you drag the mouse beyond the edge of a window, Emacs scrolls the
632 window to bring the text beyond that edge into view, with a delay of
633 this many seconds between scroll steps. Scrolling stops when you move
634 the mouse back into the window, or release the button.
635 This variable's value may be non-integral.
636 Setting this to zero causes Emacs to scroll as fast as it can."
637 :type 'number
638 :group 'mouse)
640 (defcustom mouse-scroll-min-lines 1
641 "*The minimum number of lines scrolled by dragging mouse out of window.
642 Moving the mouse out the top or bottom edge of the window begins
643 scrolling repeatedly. The number of lines scrolled per repetition
644 is normally equal to the number of lines beyond the window edge that
645 the mouse has moved. However, it always scrolls at least the number
646 of lines specified by this variable."
647 :type 'integer
648 :group 'mouse)
650 (defun mouse-scroll-subr (window jump &optional overlay start)
651 "Scroll the window WINDOW, JUMP lines at a time, until new input arrives.
652 If OVERLAY is an overlay, let it stretch from START to the far edge of
653 the newly visible text.
654 Upon exit, point is at the far edge of the newly visible text."
655 (cond
656 ((and (> jump 0) (< jump mouse-scroll-min-lines))
657 (setq jump mouse-scroll-min-lines))
658 ((and (< jump 0) (< (- jump) mouse-scroll-min-lines))
659 (setq jump (- mouse-scroll-min-lines))))
660 (let ((opoint (point)))
661 (while (progn
662 (goto-char (window-start window))
663 (if (not (zerop (vertical-motion jump window)))
664 (progn
665 (set-window-start window (point))
666 (if (natnump jump)
667 (if (window-end window)
668 (progn
669 (goto-char (window-end window))
670 ;; window-end doesn't reflect the window's new
671 ;; start position until the next redisplay.
672 (vertical-motion (1- jump) window))
673 (vertical-motion (- (window-height window) 2)))
674 (goto-char (window-start window)))
675 (if overlay
676 (move-overlay overlay start (point)))
677 ;; Now that we have scrolled WINDOW properly,
678 ;; put point back where it was for the redisplay
679 ;; so that we don't mess up the selected window.
680 (or (eq window (selected-window))
681 (goto-char opoint))
682 (sit-for mouse-scroll-delay)))))
683 (or (eq window (selected-window))
684 (goto-char opoint))))
686 ;; Create an overlay and immediately delete it, to get "overlay in no buffer".
687 (defvar mouse-drag-overlay (make-overlay 1 1))
688 (delete-overlay mouse-drag-overlay)
689 (overlay-put mouse-drag-overlay 'face 'region)
691 (defvar mouse-selection-click-count 0)
693 (defvar mouse-selection-click-count-buffer nil)
695 (defun mouse-drag-region (start-event)
696 "Set the region to the text that the mouse is dragged over.
697 Highlight the drag area as you move the mouse.
698 This must be bound to a button-down mouse event.
699 In Transient Mark mode, the highlighting remains as long as the mark
700 remains active. Otherwise, it remains until the next input event.
702 If the click is in the echo area, display the `*Messages*' buffer."
703 (interactive "e")
704 (let ((w (posn-window (event-start start-event))))
705 (if (not (or (not (window-minibuffer-p w))
706 (minibuffer-window-active-p w)))
707 (save-excursion
708 (read-event)
709 (set-buffer "*Messages*")
710 (goto-char (point-max))
711 (display-buffer (current-buffer)))
712 ;; Give temporary modes such as isearch a chance to turn off.
713 (run-hooks 'mouse-leave-buffer-hook)
714 (mouse-drag-region-1 start-event))))
716 (defun mouse-drag-region-1 (start-event)
717 (mouse-minibuffer-check start-event)
718 (let* ((echo-keystrokes 0)
719 (start-posn (event-start start-event))
720 (start-point (posn-point start-posn))
721 (start-window (posn-window start-posn))
722 (start-window-start (window-start start-window))
723 (start-frame (window-frame start-window))
724 (start-hscroll (window-hscroll start-window))
725 (bounds (window-edges start-window))
726 (top (nth 1 bounds))
727 (bottom (if (window-minibuffer-p start-window)
728 (nth 3 bounds)
729 ;; Don't count the mode line.
730 (1- (nth 3 bounds))))
731 (click-count (1- (event-click-count start-event))))
732 (setq mouse-selection-click-count click-count)
733 (setq mouse-selection-click-count-buffer (current-buffer))
734 (mouse-set-point start-event)
735 ;; In case the down click is in the middle of some intangible text,
736 ;; use the end of that text, and put it in START-POINT.
737 (if (< (point) start-point)
738 (goto-char start-point))
739 (setq start-point (point))
740 (let ((range (mouse-start-end start-point start-point click-count)))
741 (move-overlay mouse-drag-overlay (car range) (nth 1 range)
742 (window-buffer start-window))
743 (overlay-put mouse-drag-overlay 'window (selected-window)))
744 (deactivate-mark)
745 ;; end-of-range is used only in the single-click case.
746 ;; It is the place where the drag has reached so far
747 ;; (but not outside the window where the drag started).
748 (let (event end end-point last-end-point (end-of-range (point)))
749 (track-mouse
750 (while (progn
751 (setq event (read-event))
752 (or (mouse-movement-p event)
753 (eq (car-safe event) 'switch-frame)))
754 (if (eq (car-safe event) 'switch-frame)
756 (setq end (event-end event)
757 end-point (posn-point end))
758 (if (numberp end-point)
759 (setq last-end-point end-point))
761 (cond
762 ;; Are we moving within the original window?
763 ((and (eq (posn-window end) start-window)
764 (integer-or-marker-p end-point))
765 ;; Go to START-POINT first, so that when we move to END-POINT,
766 ;; if it's in the middle of intangible text,
767 ;; point jumps in the direction away from START-POINT.
768 (goto-char start-point)
769 (goto-char end-point)
770 (if (zerop (% click-count 3))
771 (setq end-of-range (point)))
772 (let ((range (mouse-start-end start-point (point) click-count)))
773 (move-overlay mouse-drag-overlay (car range) (nth 1 range))))
776 (let ((mouse-row (cdr (cdr (mouse-position)))))
777 (cond
778 ((null mouse-row))
779 ((< mouse-row top)
780 (mouse-scroll-subr start-window (- mouse-row top)
781 mouse-drag-overlay start-point)
782 ;; Without this, point tends to jump back to the starting
783 ;; position where the mouse button was pressed down.
784 (setq end-of-range (overlay-start mouse-drag-overlay)))
785 ((>= mouse-row bottom)
786 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
787 mouse-drag-overlay start-point)
788 (setq end-of-range (overlay-end mouse-drag-overlay))))))))))
790 ;; In case we did not get a mouse-motion event
791 ;; for the final move of the mouse before a drag event
792 ;; pretend that we did get one.
793 (when (and (memq 'drag (event-modifiers (car-safe event)))
794 (setq end (event-end event)
795 end-point (posn-point end))
796 (eq (posn-window end) start-window)
797 (integer-or-marker-p end-point))
798 ;; Go to START-POINT first, so that when we move to END-POINT,
799 ;; if it's in the middle of intangible text,
800 ;; point jumps in the direction away from START-POINT.
801 (goto-char start-point)
802 (goto-char end-point)
803 (if (zerop (% click-count 3))
804 (setq end-of-range (point)))
805 (let ((range (mouse-start-end start-point (point) click-count)))
806 (move-overlay mouse-drag-overlay (car range) (nth 1 range))))
808 (if (consp event)
809 (let ((fun (key-binding (vector (car event)))))
810 ;; Run the binding of the terminating up-event, if possible.
811 ;; In the case of a multiple click, it gives the wrong results,
812 ;; because it would fail to set up a region.
813 (if (not (= (overlay-start mouse-drag-overlay)
814 (overlay-end mouse-drag-overlay)))
815 (let* ((stop-point
816 (if (numberp (posn-point (event-end event)))
817 (posn-point (event-end event))
818 last-end-point))
819 ;; The end that comes from where we ended the drag.
820 ;; Point goes here.
821 (region-termination
822 (if (and stop-point (< stop-point start-point))
823 (overlay-start mouse-drag-overlay)
824 (overlay-end mouse-drag-overlay)))
825 ;; The end that comes from where we started the drag.
826 ;; Mark goes there.
827 (region-commencement
828 (- (+ (overlay-end mouse-drag-overlay)
829 (overlay-start mouse-drag-overlay))
830 region-termination))
831 last-command this-command)
832 (push-mark region-commencement t t)
833 (goto-char region-termination)
834 ;; Don't let copy-region-as-kill set deactivate-mark.
835 (let (deactivate-mark)
836 (copy-region-as-kill (point) (mark t)))
837 (let ((buffer (current-buffer)))
838 (mouse-show-mark)
839 ;; mouse-show-mark can call read-event,
840 ;; and that means the Emacs server could switch buffers
841 ;; under us. If that happened,
842 ;; avoid trying to use the region.
843 (and (mark t) mark-active
844 (eq buffer (current-buffer))
845 (mouse-set-region-1))))
846 (delete-overlay mouse-drag-overlay)
847 ;; Run the binding of the terminating up-event.
848 (when (and (functionp fun)
849 (= start-hscroll (window-hscroll start-window))
850 ;; Don't run the up-event handler if the
851 ;; window start changed in a redisplay after
852 ;; the mouse-set-point for the down-mouse
853 ;; event at the beginning of this function.
854 ;; When the window start has changed, the
855 ;; up-mouse event will contain a different
856 ;; position due to the new window contents,
857 ;; and point is set again.
858 (or end-point
859 (= (window-start start-window)
860 start-window-start)))
861 (setq unread-command-events
862 (cons event unread-command-events)))))
863 (delete-overlay mouse-drag-overlay)))))
865 ;; Commands to handle xterm-style multiple clicks.
867 (defun mouse-skip-word (dir)
868 "Skip over word, over whitespace, or over identical punctuation.
869 If DIR is positive skip forward; if negative, skip backward."
870 (let* ((char (following-char))
871 (syntax (char-to-string (char-syntax char))))
872 (cond ((string= syntax "w")
873 ;; Here, we can't use skip-syntax-forward/backward because
874 ;; they don't pay attention to word-separating-categories,
875 ;; and thus they will skip over a true word boundary. So,
876 ;; we simularte the original behaviour by using
877 ;; forward-word.
878 (if (< dir 0)
879 (if (not (looking-at "\\<"))
880 (forward-word -1))
881 (if (or (looking-at "\\<") (not (looking-at "\\>")))
882 (forward-word 1))))
883 ((string= syntax " ")
884 (if (< dir 0)
885 (skip-syntax-backward syntax)
886 (skip-syntax-forward syntax)))
887 ((string= syntax "_")
888 (if (< dir 0)
889 (skip-syntax-backward "w_")
890 (skip-syntax-forward "w_")))
891 ((< dir 0)
892 (while (and (not (bobp)) (= (preceding-char) char))
893 (forward-char -1)))
895 (while (and (not (eobp)) (= (following-char) char))
896 (forward-char 1))))))
898 (defun mouse-start-end (start end mode)
899 "Return a list of region bounds based on START and END according to MODE.
900 If MODE is 0 then set point to (min START END), mark to (max START END).
901 If MODE is 1 then set point to start of word at (min START END),
902 mark to end of word at (max START END).
903 If MODE is 2 then do the same for lines."
904 (if (> start end)
905 (let ((temp start))
906 (setq start end
907 end temp)))
908 (setq mode (mod mode 3))
909 (cond ((= mode 0)
910 (list start end))
911 ((and (= mode 1)
912 (= start end)
913 (char-after start)
914 (= (char-syntax (char-after start)) ?\())
915 (list start
916 (save-excursion
917 (goto-char start)
918 (forward-sexp 1)
919 (point))))
920 ((and (= mode 1)
921 (= start end)
922 (char-after start)
923 (= (char-syntax (char-after start)) ?\)))
924 (list (save-excursion
925 (goto-char (1+ start))
926 (backward-sexp 1)
927 (point))
928 (1+ start)))
929 ((and (= mode 1)
930 (= start end)
931 (char-after start)
932 (= (char-syntax (char-after start)) ?\"))
933 (let ((open (or (eq start (point-min))
934 (save-excursion
935 (goto-char (- start 1))
936 (looking-at "\\s(\\|\\s \\|\\s>")))))
937 (if open
938 (list start
939 (save-excursion
940 (condition-case nil
941 (progn
942 (goto-char start)
943 (forward-sexp 1)
944 (point))
945 (error end))))
946 (list (save-excursion
947 (condition-case nil
948 (progn
949 (goto-char (1+ start))
950 (backward-sexp 1)
951 (point))
952 (error end)))
953 (1+ start)))))
954 ((= mode 1)
955 (list (save-excursion
956 (goto-char start)
957 (mouse-skip-word -1)
958 (point))
959 (save-excursion
960 (goto-char end)
961 (mouse-skip-word 1)
962 (point))))
963 ((= mode 2)
964 (list (save-excursion
965 (goto-char start)
966 (beginning-of-line 1)
967 (point))
968 (save-excursion
969 (goto-char end)
970 (forward-line 1)
971 (point))))))
973 ;; Subroutine: set the mark where CLICK happened,
974 ;; but don't do anything else.
975 (defun mouse-set-mark-fast (click)
976 (mouse-minibuffer-check click)
977 (let ((posn (event-start click)))
978 (select-window (posn-window posn))
979 (if (numberp (posn-point posn))
980 (push-mark (posn-point posn) t t))))
982 (defun mouse-undouble-last-event (events)
983 (let* ((index (1- (length events)))
984 (last (nthcdr index events))
985 (event (car last))
986 (basic (event-basic-type event))
987 (old-modifiers (event-modifiers event))
988 (modifiers (delq 'double (delq 'triple (copy-sequence old-modifiers))))
989 (new
990 (if (consp event)
991 ;; Use reverse, not nreverse, since event-modifiers
992 ;; does not copy the list it returns.
993 (cons (event-convert-list (reverse (cons basic modifiers)))
994 (cdr event))
995 event)))
996 (setcar last new)
997 (if (and (not (equal modifiers old-modifiers))
998 (key-binding (apply 'vector events)))
1000 (setcar last event)
1001 nil)))
1003 ;; Momentarily show where the mark is, if highlighting doesn't show it.
1005 (defvar mouse-region-delete-keys '([delete] [deletechar])
1006 "List of keys which shall cause the mouse region to be deleted.")
1008 (defun mouse-show-mark ()
1009 (if transient-mark-mode
1010 (delete-overlay mouse-drag-overlay)
1011 (let ((inhibit-quit t)
1012 (echo-keystrokes 0)
1013 event events key ignore
1014 x-lost-selection-hooks)
1015 (add-hook 'x-lost-selection-hooks
1016 (lambda (seltype)
1017 (if (eq seltype 'PRIMARY)
1018 (progn (setq ignore t)
1019 (throw 'mouse-show-mark t)))))
1020 (move-overlay mouse-drag-overlay (point) (mark t))
1021 (catch 'mouse-show-mark
1022 ;; In this loop, execute scroll bar and switch-frame events.
1023 ;; Also ignore down-events that are undefined.
1024 (while (progn (setq event (read-event))
1025 (setq events (append events (list event)))
1026 (setq key (apply 'vector events))
1027 (or (and (consp event)
1028 (eq (car event) 'switch-frame))
1029 (and (consp event)
1030 (eq (posn-point (event-end event))
1031 'vertical-scroll-bar))
1032 (and (memq 'down (event-modifiers event))
1033 (not (key-binding key))
1034 (not (mouse-undouble-last-event events))
1035 (not (member key mouse-region-delete-keys)))))
1036 (and (consp event)
1037 (or (eq (car event) 'switch-frame)
1038 (eq (posn-point (event-end event))
1039 'vertical-scroll-bar))
1040 (let ((keys (vector 'vertical-scroll-bar event)))
1041 (and (key-binding keys)
1042 (progn
1043 (call-interactively (key-binding keys)
1044 nil keys)
1045 (setq events nil)))))))
1046 ;; If we lost the selection, just turn off the highlighting.
1047 (if ignore
1049 ;; For certain special keys, delete the region.
1050 (if (member key mouse-region-delete-keys)
1051 (delete-region (overlay-start mouse-drag-overlay)
1052 (overlay-end mouse-drag-overlay))
1053 ;; Otherwise, unread the key so it gets executed normally.
1054 (setq unread-command-events
1055 (nconc events unread-command-events))))
1056 (setq quit-flag nil)
1057 (delete-overlay mouse-drag-overlay))))
1059 (defun mouse-set-mark (click)
1060 "Set mark at the position clicked on with the mouse.
1061 Display cursor at that position for a second.
1062 This must be bound to a mouse click."
1063 (interactive "e")
1064 (mouse-minibuffer-check click)
1065 (select-window (posn-window (event-start click)))
1066 ;; We don't use save-excursion because that preserves the mark too.
1067 (let ((point-save (point)))
1068 (unwind-protect
1069 (progn (mouse-set-point click)
1070 (push-mark nil t t)
1071 (or transient-mark-mode
1072 (sit-for 1)))
1073 (goto-char point-save))))
1075 (defun mouse-kill (click)
1076 "Kill the region between point and the mouse click.
1077 The text is saved in the kill ring, as with \\[kill-region]."
1078 (interactive "e")
1079 (mouse-minibuffer-check click)
1080 (let* ((posn (event-start click))
1081 (click-posn (posn-point posn)))
1082 (select-window (posn-window posn))
1083 (if (numberp click-posn)
1084 (kill-region (min (point) click-posn)
1085 (max (point) click-posn)))))
1087 (defun mouse-yank-at-click (click arg)
1088 "Insert the last stretch of killed text at the position clicked on.
1089 Also move point to one end of the text thus inserted (normally the end),
1090 and set mark at the beginning.
1091 Prefix arguments are interpreted as with \\[yank].
1092 If `mouse-yank-at-point' is non-nil, insert at point
1093 regardless of where you click."
1094 (interactive "e\nP")
1095 ;; Give temporary modes such as isearch a chance to turn off.
1096 (run-hooks 'mouse-leave-buffer-hook)
1097 (or mouse-yank-at-point (mouse-set-point click))
1098 (setq this-command 'yank)
1099 (setq mouse-selection-click-count 0)
1100 (yank arg))
1102 (defun mouse-kill-ring-save (click)
1103 "Copy the region between point and the mouse click in the kill ring.
1104 This does not delete the region; it acts like \\[kill-ring-save]."
1105 (interactive "e")
1106 (mouse-set-mark-fast click)
1107 (let (this-command last-command)
1108 (kill-ring-save (point) (mark t)))
1109 (mouse-show-mark))
1111 ;;; This function used to delete the text between point and the mouse
1112 ;;; whenever it was equal to the front of the kill ring, but some
1113 ;;; people found that confusing.
1115 ;;; A list (TEXT START END), describing the text and position of the last
1116 ;;; invocation of mouse-save-then-kill.
1117 (defvar mouse-save-then-kill-posn nil)
1119 (defun mouse-save-then-kill-delete-region (beg end)
1120 ;; We must make our own undo boundaries
1121 ;; because they happen automatically only for the current buffer.
1122 (undo-boundary)
1123 (if (or (= beg end) (eq buffer-undo-list t))
1124 ;; If we have no undo list in this buffer,
1125 ;; just delete.
1126 (delete-region beg end)
1127 ;; Delete, but make the undo-list entry share with the kill ring.
1128 ;; First, delete just one char, so in case buffer is being modified
1129 ;; for the first time, the undo list records that fact.
1130 (let (before-change-functions after-change-functions)
1131 (delete-region beg
1132 (+ beg (if (> end beg) 1 -1))))
1133 (let ((buffer-undo-list buffer-undo-list))
1134 ;; Undo that deletion--but don't change the undo list!
1135 (let (before-change-functions after-change-functions)
1136 (primitive-undo 1 buffer-undo-list))
1137 ;; Now delete the rest of the specified region,
1138 ;; but don't record it.
1139 (setq buffer-undo-list t)
1140 (if (/= (length (car kill-ring)) (- (max end beg) (min end beg)))
1141 (error "Lossage in mouse-save-then-kill-delete-region"))
1142 (delete-region beg end))
1143 (let ((tail buffer-undo-list))
1144 ;; Search back in buffer-undo-list for the string
1145 ;; that came from deleting one character.
1146 (while (and tail (not (stringp (car (car tail)))))
1147 (setq tail (cdr tail)))
1148 ;; Replace it with an entry for the entire deleted text.
1149 (and tail
1150 (setcar tail (cons (car kill-ring) (min beg end))))))
1151 (undo-boundary))
1153 (defun mouse-save-then-kill (click)
1154 "Save text to point in kill ring; the second time, kill the text.
1155 If the text between point and the mouse is the same as what's
1156 at the front of the kill ring, this deletes the text.
1157 Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
1158 which prepares for a second click to delete the text.
1160 If you have selected words or lines, this command extends the
1161 selection through the word or line clicked on. If you do this
1162 again in a different position, it extends the selection again.
1163 If you do this twice in the same position, the selection is killed."
1164 (interactive "e")
1165 (let ((before-scroll
1166 (with-current-buffer (window-buffer (posn-window (event-start click)))
1167 point-before-scroll)))
1168 (mouse-minibuffer-check click)
1169 (let ((click-posn (posn-point (event-start click)))
1170 ;; Don't let a subsequent kill command append to this one:
1171 ;; prevent setting this-command to kill-region.
1172 (this-command this-command))
1173 (if (and (save-excursion
1174 (set-buffer (window-buffer (posn-window (event-start click))))
1175 (and (mark t) (> (mod mouse-selection-click-count 3) 0)
1176 ;; Don't be fooled by a recent click in some other buffer.
1177 (eq mouse-selection-click-count-buffer
1178 (current-buffer)))))
1179 (if (not (and (eq last-command 'mouse-save-then-kill)
1180 (equal click-posn
1181 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
1182 ;; Find both ends of the object selected by this click.
1183 (let* ((range
1184 (mouse-start-end click-posn click-posn
1185 mouse-selection-click-count)))
1186 ;; Move whichever end is closer to the click.
1187 ;; That's what xterm does, and it seems reasonable.
1188 (if (< (abs (- click-posn (mark t)))
1189 (abs (- click-posn (point))))
1190 (set-mark (car range))
1191 (goto-char (nth 1 range)))
1192 ;; We have already put the old region in the kill ring.
1193 ;; Replace it with the extended region.
1194 ;; (It would be annoying to make a separate entry.)
1195 (kill-new (buffer-substring (point) (mark t)) t)
1196 (mouse-set-region-1)
1197 ;; Arrange for a repeated mouse-3 to kill this region.
1198 (setq mouse-save-then-kill-posn
1199 (list (car kill-ring) (point) click-posn))
1200 (mouse-show-mark))
1201 ;; If we click this button again without moving it,
1202 ;; that time kill.
1203 (mouse-save-then-kill-delete-region (mark) (point))
1204 (setq mouse-selection-click-count 0)
1205 (setq mouse-save-then-kill-posn nil))
1206 (if (and (eq last-command 'mouse-save-then-kill)
1207 mouse-save-then-kill-posn
1208 (eq (car mouse-save-then-kill-posn) (car kill-ring))
1209 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
1210 ;; If this is the second time we've called
1211 ;; mouse-save-then-kill, delete the text from the buffer.
1212 (progn
1213 (mouse-save-then-kill-delete-region (point) (mark))
1214 ;; After we kill, another click counts as "the first time".
1215 (setq mouse-save-then-kill-posn nil))
1216 ;; This is not a repetition.
1217 ;; We are adjusting an old selection or creating a new one.
1218 (if (or (and (eq last-command 'mouse-save-then-kill)
1219 mouse-save-then-kill-posn)
1220 (and mark-active transient-mark-mode)
1221 (and (memq last-command
1222 '(mouse-drag-region mouse-set-region))
1223 (or mark-even-if-inactive
1224 (not transient-mark-mode))))
1225 ;; We have a selection or suitable region, so adjust it.
1226 (let* ((posn (event-start click))
1227 (new (posn-point posn)))
1228 (select-window (posn-window posn))
1229 (if (numberp new)
1230 (progn
1231 ;; Move whichever end of the region is closer to the click.
1232 ;; That is what xterm does, and it seems reasonable.
1233 (if (<= (abs (- new (point))) (abs (- new (mark t))))
1234 (goto-char new)
1235 (set-mark new))
1236 (setq deactivate-mark nil)))
1237 (kill-new (buffer-substring (point) (mark t)) t)
1238 (mouse-show-mark))
1239 ;; Set the mark where point is, then move where clicked.
1240 (mouse-set-mark-fast click)
1241 (if before-scroll
1242 (goto-char before-scroll))
1243 (exchange-point-and-mark)
1244 (kill-new (buffer-substring (point) (mark t)))
1245 (mouse-show-mark))
1246 (mouse-set-region-1)
1247 (setq mouse-save-then-kill-posn
1248 (list (car kill-ring) (point) click-posn)))))))
1250 (global-set-key [M-mouse-1] 'mouse-start-secondary)
1251 (global-set-key [M-drag-mouse-1] 'mouse-set-secondary)
1252 (global-set-key [M-down-mouse-1] 'mouse-drag-secondary)
1253 (global-set-key [M-mouse-3] 'mouse-secondary-save-then-kill)
1254 (global-set-key [M-mouse-2] 'mouse-yank-secondary)
1256 ;; An overlay which records the current secondary selection
1257 ;; or else is deleted when there is no secondary selection.
1258 ;; May be nil.
1259 (defvar mouse-secondary-overlay nil)
1261 (defvar mouse-secondary-click-count 0)
1263 ;; A marker which records the specified first end for a secondary selection.
1264 ;; May be nil.
1265 (defvar mouse-secondary-start nil)
1267 (defun mouse-start-secondary (click)
1268 "Set one end of the secondary selection to the position clicked on.
1269 Use \\[mouse-secondary-save-then-kill] to set the other end
1270 and complete the secondary selection."
1271 (interactive "e")
1272 (mouse-minibuffer-check click)
1273 (let ((posn (event-start click)))
1274 (save-excursion
1275 (set-buffer (window-buffer (posn-window posn)))
1276 ;; Cancel any preexisting secondary selection.
1277 (if mouse-secondary-overlay
1278 (delete-overlay mouse-secondary-overlay))
1279 (if (numberp (posn-point posn))
1280 (progn
1281 (or mouse-secondary-start
1282 (setq mouse-secondary-start (make-marker)))
1283 (move-marker mouse-secondary-start (posn-point posn)))))))
1285 (defun mouse-set-secondary (click)
1286 "Set the secondary selection to the text that the mouse is dragged over.
1287 This must be bound to a mouse drag event."
1288 (interactive "e")
1289 (mouse-minibuffer-check click)
1290 (let ((posn (event-start click))
1292 (end (event-end click)))
1293 (save-excursion
1294 (set-buffer (window-buffer (posn-window posn)))
1295 (if (numberp (posn-point posn))
1296 (setq beg (posn-point posn)))
1297 (if mouse-secondary-overlay
1298 (move-overlay mouse-secondary-overlay beg (posn-point end))
1299 (setq mouse-secondary-overlay (make-overlay beg (posn-point end))))
1300 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))))
1302 (defun mouse-drag-secondary (start-event)
1303 "Set the secondary selection to the text that the mouse is dragged over.
1304 Highlight the drag area as you move the mouse.
1305 This must be bound to a button-down mouse event.
1306 The function returns a non-nil value if it creates a secondary selection."
1307 (interactive "e")
1308 (mouse-minibuffer-check start-event)
1309 (let* ((echo-keystrokes 0)
1310 (start-posn (event-start start-event))
1311 (start-point (posn-point start-posn))
1312 (start-window (posn-window start-posn))
1313 (start-frame (window-frame start-window))
1314 (bounds (window-edges start-window))
1315 (top (nth 1 bounds))
1316 (bottom (if (window-minibuffer-p start-window)
1317 (nth 3 bounds)
1318 ;; Don't count the mode line.
1319 (1- (nth 3 bounds))))
1320 (click-count (1- (event-click-count start-event))))
1321 (save-excursion
1322 (set-buffer (window-buffer start-window))
1323 (setq mouse-secondary-click-count click-count)
1324 (or mouse-secondary-overlay
1325 (setq mouse-secondary-overlay
1326 (make-overlay (point) (point))))
1327 (overlay-put mouse-secondary-overlay 'face 'secondary-selection)
1328 (if (> (mod click-count 3) 0)
1329 ;; Double or triple press: make an initial selection
1330 ;; of one word or line.
1331 (let ((range (mouse-start-end start-point start-point click-count)))
1332 (set-marker mouse-secondary-start nil)
1333 (move-overlay mouse-secondary-overlay 1 1
1334 (window-buffer start-window))
1335 (move-overlay mouse-secondary-overlay (car range) (nth 1 range)
1336 (window-buffer start-window)))
1337 ;; Single-press: cancel any preexisting secondary selection.
1338 (or mouse-secondary-start
1339 (setq mouse-secondary-start (make-marker)))
1340 (set-marker mouse-secondary-start start-point)
1341 (delete-overlay mouse-secondary-overlay))
1342 (let (event end end-point)
1343 (track-mouse
1344 (while (progn
1345 (setq event (read-event))
1346 (or (mouse-movement-p event)
1347 (eq (car-safe event) 'switch-frame)))
1349 (if (eq (car-safe event) 'switch-frame)
1351 (setq end (event-end event)
1352 end-point (posn-point end))
1353 (cond
1354 ;; Are we moving within the original window?
1355 ((and (eq (posn-window end) start-window)
1356 (integer-or-marker-p end-point))
1357 (let ((range (mouse-start-end start-point end-point
1358 click-count)))
1359 (if (or (/= start-point end-point)
1360 (null (marker-position mouse-secondary-start)))
1361 (progn
1362 (set-marker mouse-secondary-start nil)
1363 (move-overlay mouse-secondary-overlay
1364 (car range) (nth 1 range))))))
1366 (let ((mouse-row (cdr (cdr (mouse-position)))))
1367 (cond
1368 ((null mouse-row))
1369 ((< mouse-row top)
1370 (mouse-scroll-subr start-window (- mouse-row top)
1371 mouse-secondary-overlay start-point))
1372 ((>= mouse-row bottom)
1373 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
1374 mouse-secondary-overlay start-point)))))))))
1376 (if (consp event)
1377 (if (marker-position mouse-secondary-start)
1378 (save-window-excursion
1379 (delete-overlay mouse-secondary-overlay)
1380 (x-set-selection 'SECONDARY nil)
1381 (select-window start-window)
1382 (save-excursion
1383 (goto-char mouse-secondary-start)
1384 (sit-for 1)
1385 nil))
1386 (x-set-selection
1387 'SECONDARY
1388 (buffer-substring (overlay-start mouse-secondary-overlay)
1389 (overlay-end mouse-secondary-overlay)))))))))
1391 (defun mouse-yank-secondary (click)
1392 "Insert the secondary selection at the position clicked on.
1393 Move point to the end of the inserted text.
1394 If `mouse-yank-at-point' is non-nil, insert at point
1395 regardless of where you click."
1396 (interactive "e")
1397 ;; Give temporary modes such as isearch a chance to turn off.
1398 (run-hooks 'mouse-leave-buffer-hook)
1399 (or mouse-yank-at-point (mouse-set-point click))
1400 (insert (x-get-selection 'SECONDARY)))
1402 (defun mouse-kill-secondary ()
1403 "Kill the text in the secondary selection.
1404 This is intended more as a keyboard command than as a mouse command
1405 but it can work as either one.
1407 The current buffer (in case of keyboard use), or the buffer clicked on,
1408 must be the one that the secondary selection is in. This requirement
1409 is to prevent accidents."
1410 (interactive)
1411 (let* ((keys (this-command-keys))
1412 (click (elt keys (1- (length keys)))))
1413 (or (eq (overlay-buffer mouse-secondary-overlay)
1414 (if (listp click)
1415 (window-buffer (posn-window (event-start click)))
1416 (current-buffer)))
1417 (error "Select or click on the buffer where the secondary selection is")))
1418 (let (this-command)
1419 (save-excursion
1420 (set-buffer (overlay-buffer mouse-secondary-overlay))
1421 (kill-region (overlay-start mouse-secondary-overlay)
1422 (overlay-end mouse-secondary-overlay))))
1423 (delete-overlay mouse-secondary-overlay)
1424 ;;; (x-set-selection 'SECONDARY nil)
1425 (setq mouse-secondary-overlay nil))
1427 (defun mouse-secondary-save-then-kill (click)
1428 "Save text to point in kill ring; the second time, kill the text.
1429 You must use this in a buffer where you have recently done \\[mouse-start-secondary].
1430 If the text between where you did \\[mouse-start-secondary] and where
1431 you use this command matches the text at the front of the kill ring,
1432 this command deletes the text.
1433 Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
1434 which prepares for a second click with this command to delete the text.
1436 If you have already made a secondary selection in that buffer,
1437 this command extends or retracts the selection to where you click.
1438 If you do this again in a different position, it extends or retracts
1439 again. If you do this twice in the same position, it kills the selection."
1440 (interactive "e")
1441 (mouse-minibuffer-check click)
1442 (let ((posn (event-start click))
1443 (click-posn (posn-point (event-start click)))
1444 ;; Don't let a subsequent kill command append to this one:
1445 ;; prevent setting this-command to kill-region.
1446 (this-command this-command))
1447 (or (eq (window-buffer (posn-window posn))
1448 (or (and mouse-secondary-overlay
1449 (overlay-buffer mouse-secondary-overlay))
1450 (if mouse-secondary-start
1451 (marker-buffer mouse-secondary-start))))
1452 (error "Wrong buffer"))
1453 (save-excursion
1454 (set-buffer (window-buffer (posn-window posn)))
1455 (if (> (mod mouse-secondary-click-count 3) 0)
1456 (if (not (and (eq last-command 'mouse-secondary-save-then-kill)
1457 (equal click-posn
1458 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
1459 ;; Find both ends of the object selected by this click.
1460 (let* ((range
1461 (mouse-start-end click-posn click-posn
1462 mouse-secondary-click-count)))
1463 ;; Move whichever end is closer to the click.
1464 ;; That's what xterm does, and it seems reasonable.
1465 (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay)))
1466 (abs (- click-posn (overlay-end mouse-secondary-overlay))))
1467 (move-overlay mouse-secondary-overlay (car range)
1468 (overlay-end mouse-secondary-overlay))
1469 (move-overlay mouse-secondary-overlay
1470 (overlay-start mouse-secondary-overlay)
1471 (nth 1 range)))
1472 ;; We have already put the old region in the kill ring.
1473 ;; Replace it with the extended region.
1474 ;; (It would be annoying to make a separate entry.)
1475 (kill-new (buffer-substring
1476 (overlay-start mouse-secondary-overlay)
1477 (overlay-end mouse-secondary-overlay)) t)
1478 ;; Arrange for a repeated mouse-3 to kill this region.
1479 (setq mouse-save-then-kill-posn
1480 (list (car kill-ring) (point) click-posn)))
1481 ;; If we click this button again without moving it,
1482 ;; that time kill.
1483 (progn
1484 (mouse-save-then-kill-delete-region
1485 (overlay-start mouse-secondary-overlay)
1486 (overlay-end mouse-secondary-overlay))
1487 (setq mouse-save-then-kill-posn nil)
1488 (setq mouse-secondary-click-count 0)
1489 (delete-overlay mouse-secondary-overlay)))
1490 (if (and (eq last-command 'mouse-secondary-save-then-kill)
1491 mouse-save-then-kill-posn
1492 (eq (car mouse-save-then-kill-posn) (car kill-ring))
1493 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
1494 ;; If this is the second time we've called
1495 ;; mouse-secondary-save-then-kill, delete the text from the buffer.
1496 (progn
1497 (mouse-save-then-kill-delete-region
1498 (overlay-start mouse-secondary-overlay)
1499 (overlay-end mouse-secondary-overlay))
1500 (setq mouse-save-then-kill-posn nil)
1501 (delete-overlay mouse-secondary-overlay))
1502 (if (overlay-start mouse-secondary-overlay)
1503 ;; We have a selection, so adjust it.
1504 (progn
1505 (if (numberp click-posn)
1506 (progn
1507 ;; Move whichever end of the region is closer to the click.
1508 ;; That is what xterm does, and it seems reasonable.
1509 (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay)))
1510 (abs (- click-posn (overlay-end mouse-secondary-overlay))))
1511 (move-overlay mouse-secondary-overlay click-posn
1512 (overlay-end mouse-secondary-overlay))
1513 (move-overlay mouse-secondary-overlay
1514 (overlay-start mouse-secondary-overlay)
1515 click-posn))
1516 (setq deactivate-mark nil)))
1517 (if (eq last-command 'mouse-secondary-save-then-kill)
1518 ;; If the front of the kill ring comes from
1519 ;; an immediately previous use of this command,
1520 ;; replace it with the extended region.
1521 ;; (It would be annoying to make a separate entry.)
1522 (kill-new (buffer-substring
1523 (overlay-start mouse-secondary-overlay)
1524 (overlay-end mouse-secondary-overlay)) t)
1525 (let (deactivate-mark)
1526 (copy-region-as-kill (overlay-start mouse-secondary-overlay)
1527 (overlay-end mouse-secondary-overlay)))))
1528 (if mouse-secondary-start
1529 ;; All we have is one end of a selection,
1530 ;; so put the other end here.
1531 (let ((start (+ 0 mouse-secondary-start)))
1532 (kill-ring-save start click-posn)
1533 (if mouse-secondary-overlay
1534 (move-overlay mouse-secondary-overlay start click-posn)
1535 (setq mouse-secondary-overlay (make-overlay start click-posn)))
1536 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))))
1537 (setq mouse-save-then-kill-posn
1538 (list (car kill-ring) (point) click-posn))))
1539 (if (overlay-buffer mouse-secondary-overlay)
1540 (x-set-selection 'SECONDARY
1541 (buffer-substring
1542 (overlay-start mouse-secondary-overlay)
1543 (overlay-end mouse-secondary-overlay)))))))
1545 (defcustom mouse-buffer-menu-maxlen 20
1546 "*Number of buffers in one pane (submenu) of the buffer menu.
1547 If we have lots of buffers, divide them into groups of
1548 `mouse-buffer-menu-maxlen' and make a pane (or submenu) for each one."
1549 :type 'integer
1550 :group 'mouse)
1552 (defcustom mouse-buffer-menu-mode-mult 4
1553 "*Group the buffers by the major mode groups on \\[mouse-buffer-menu]?
1554 This number which determines (in a hairy way) whether \\[mouse-buffer-menu]
1555 will split the buffer menu by the major modes (see
1556 `mouse-buffer-menu-mode-groups') or just by menu length.
1557 Set to 1 (or even 0!) if you want to group by major mode always, and to
1558 a large number if you prefer a mixed multitude. The default is 4."
1559 :type 'integer
1560 :group 'mouse
1561 :version "20.3")
1563 (defvar mouse-buffer-menu-mode-groups
1564 '(("Info\\|Help\\|Apropos\\|Man" . "Help")
1565 ("\\bVM\\b\\|\\bMH\\b\\|Message\\|Mail\\|Group\\|Score\\|Summary\\|Article"
1566 . "Mail/News")
1567 ("\\<C\\>" . "C")
1568 ("ObjC" . "C")
1569 ("Text" . "Text")
1570 ("Outline" . "Text")
1571 ("\\(HT\\|SG\\|X\\|XHT\\)ML" . "SGML")
1572 ("log\\|diff\\|vc\\|cvs" . "Version Control") ; "Change Management"?
1573 ("Lisp" . "Lisp"))
1574 "How to group various major modes together in \\[mouse-buffer-menu].
1575 Each element has the form (REGEXP . GROUPNAME).
1576 If the major mode's name string matches REGEXP, use GROUPNAME instead.")
1578 (defun mouse-buffer-menu (event)
1579 "Pop up a menu of buffers for selection with the mouse.
1580 This switches buffers in the window that you clicked on,
1581 and selects that window."
1582 (interactive "e")
1583 (mouse-minibuffer-check event)
1584 (let ((buffers (buffer-list)) alist menu split-by-major-mode sum-of-squares)
1585 ;; Make an alist of elements that look like (MENU-ITEM . BUFFER).
1586 (let ((tail buffers))
1587 (while tail
1588 ;; Divide all buffers into buckets for various major modes.
1589 ;; Each bucket looks like (MODE NAMESTRING BUFFERS...).
1590 (with-current-buffer (car tail)
1591 (let* ((adjusted-major-mode major-mode) elt)
1592 (let ((tail mouse-buffer-menu-mode-groups))
1593 (while tail
1594 (if (string-match (car (car tail)) mode-name)
1595 (setq adjusted-major-mode (cdr (car tail))))
1596 (setq tail (cdr tail))))
1597 (setq elt (assoc adjusted-major-mode split-by-major-mode))
1598 (if (null elt)
1599 (setq elt (list adjusted-major-mode
1600 (if (stringp adjusted-major-mode)
1601 adjusted-major-mode
1602 mode-name))
1603 split-by-major-mode (cons elt split-by-major-mode)))
1604 (or (memq (car tail) (cdr (cdr elt)))
1605 (setcdr (cdr elt) (cons (car tail) (cdr (cdr elt)))))))
1606 (setq tail (cdr tail))))
1607 ;; Compute the sum of squares of sizes of the major-mode buckets.
1608 (let ((tail split-by-major-mode))
1609 (setq sum-of-squares 0)
1610 (while tail
1611 (setq sum-of-squares
1612 (+ sum-of-squares
1613 (let ((len (length (cdr (cdr (car tail)))))) (* len len))))
1614 (setq tail (cdr tail))))
1615 (if (< (* sum-of-squares mouse-buffer-menu-mode-mult)
1616 (* (length buffers) (length buffers)))
1617 ;; Subdividing by major modes really helps, so let's do it.
1618 (let (subdivided-menus (buffers-left (length buffers)))
1619 ;; Sort the list to put the most popular major modes first.
1620 (setq split-by-major-mode
1621 (sort split-by-major-mode
1622 (function (lambda (elt1 elt2)
1623 (> (length elt1) (length elt2))))))
1624 ;; Make a separate submenu for each major mode
1625 ;; that has more than one buffer,
1626 ;; unless all the remaining buffers are less than 1/10 of them.
1627 (while (and split-by-major-mode
1628 (and (> (length (car split-by-major-mode)) 3)
1629 (> (* buffers-left 10) (length buffers))))
1630 (let ((this-mode-list (mouse-buffer-menu-alist
1631 (cdr (cdr (car split-by-major-mode))))))
1632 (and this-mode-list
1633 (setq subdivided-menus
1634 (cons (cons
1635 (nth 1 (car split-by-major-mode))
1636 this-mode-list)
1637 subdivided-menus))))
1638 (setq buffers-left
1639 (- buffers-left (length (cdr (car split-by-major-mode)))))
1640 (setq split-by-major-mode (cdr split-by-major-mode)))
1641 ;; If any major modes are left over,
1642 ;; make a single submenu for them.
1643 (if split-by-major-mode
1644 (let ((others-list
1645 (mouse-buffer-menu-alist
1646 ;; we don't need split-by-major-mode any more,
1647 ;; so we can ditch it with nconc.
1648 (apply 'nconc (mapcar 'cddr split-by-major-mode)))))
1649 (and others-list
1650 (setq subdivided-menus
1651 (cons (cons "Others" others-list)
1652 subdivided-menus)))))
1653 (setq menu (cons "Buffer Menu" (nreverse subdivided-menus))))
1654 (progn
1655 (setq alist (mouse-buffer-menu-alist buffers))
1656 (setq menu (cons "Buffer Menu"
1657 (mouse-buffer-menu-split "Select Buffer" alist)))))
1658 (let ((buf (x-popup-menu event menu))
1659 (window (posn-window (event-start event))))
1660 (when buf
1661 (select-window
1662 (if (framep window) (frame-selected-window window)
1663 window))
1664 (switch-to-buffer buf)))))
1666 (defun mouse-buffer-menu-alist (buffers)
1667 (let (tail
1668 (maxlen 0)
1669 head)
1670 (setq buffers
1671 (sort buffers
1672 (function (lambda (elt1 elt2)
1673 (string< (buffer-name elt1) (buffer-name elt2))))))
1674 (setq tail buffers)
1675 (while tail
1676 (or (eq ?\ (aref (buffer-name (car tail)) 0))
1677 (setq maxlen
1678 (max maxlen
1679 (length (buffer-name (car tail))))))
1680 (setq tail (cdr tail)))
1681 (setq tail buffers)
1682 (while tail
1683 (let ((elt (car tail)))
1684 (if (/= (aref (buffer-name elt) 0) ?\ )
1685 (setq head
1686 (cons
1687 (cons
1688 (format
1689 (format "%%%ds %%s%%s %%s" maxlen)
1690 (buffer-name elt)
1691 (if (buffer-modified-p elt) "*" " ")
1692 (save-excursion
1693 (set-buffer elt)
1694 (if buffer-read-only "%" " "))
1695 (or (buffer-file-name elt)
1696 (save-excursion
1697 (set-buffer elt)
1698 (if list-buffers-directory
1699 (expand-file-name
1700 list-buffers-directory)))
1701 ""))
1702 elt)
1703 head))))
1704 (setq tail (cdr tail)))
1705 ;; Compensate for the reversal that the above loop does.
1706 (nreverse head)))
1708 (defun mouse-buffer-menu-split (title alist)
1709 ;; If we have lots of buffers, divide them into groups of 20
1710 ;; and make a pane (or submenu) for each one.
1711 (if (> (length alist) (/ (* mouse-buffer-menu-maxlen 3) 2))
1712 (let ((alist alist) sublists next
1713 (i 1))
1714 (while alist
1715 ;; Pull off the next mouse-buffer-menu-maxlen buffers
1716 ;; and make them the next element of sublist.
1717 (setq next (nthcdr mouse-buffer-menu-maxlen alist))
1718 (if next
1719 (setcdr (nthcdr (1- mouse-buffer-menu-maxlen) alist)
1720 nil))
1721 (setq sublists (cons (cons (format "Buffers %d" i) alist)
1722 sublists))
1723 (setq i (1+ i))
1724 (setq alist next))
1725 (nreverse sublists))
1726 ;; Few buffers--put them all in one pane.
1727 (list (cons title alist))))
1729 ;;; These need to be rewritten for the new scroll bar implementation.
1731 ;;;!! ;; Commands for the scroll bar.
1732 ;;;!!
1733 ;;;!! (defun mouse-scroll-down (click)
1734 ;;;!! (interactive "@e")
1735 ;;;!! (scroll-down (1+ (cdr (mouse-coords click)))))
1736 ;;;!!
1737 ;;;!! (defun mouse-scroll-up (click)
1738 ;;;!! (interactive "@e")
1739 ;;;!! (scroll-up (1+ (cdr (mouse-coords click)))))
1740 ;;;!!
1741 ;;;!! (defun mouse-scroll-down-full ()
1742 ;;;!! (interactive "@")
1743 ;;;!! (scroll-down nil))
1744 ;;;!!
1745 ;;;!! (defun mouse-scroll-up-full ()
1746 ;;;!! (interactive "@")
1747 ;;;!! (scroll-up nil))
1748 ;;;!!
1749 ;;;!! (defun mouse-scroll-move-cursor (click)
1750 ;;;!! (interactive "@e")
1751 ;;;!! (move-to-window-line (1+ (cdr (mouse-coords click)))))
1752 ;;;!!
1753 ;;;!! (defun mouse-scroll-absolute (event)
1754 ;;;!! (interactive "@e")
1755 ;;;!! (let* ((pos (car event))
1756 ;;;!! (position (car pos))
1757 ;;;!! (length (car (cdr pos))))
1758 ;;;!! (if (<= length 0) (setq length 1))
1759 ;;;!! (let* ((scale-factor (max 1 (/ length (/ 8000000 (buffer-size)))))
1760 ;;;!! (newpos (* (/ (* (/ (buffer-size) scale-factor)
1761 ;;;!! position)
1762 ;;;!! length)
1763 ;;;!! scale-factor)))
1764 ;;;!! (goto-char newpos)
1765 ;;;!! (recenter '(4)))))
1766 ;;;!!
1767 ;;;!! (defun mouse-scroll-left (click)
1768 ;;;!! (interactive "@e")
1769 ;;;!! (scroll-left (1+ (car (mouse-coords click)))))
1770 ;;;!!
1771 ;;;!! (defun mouse-scroll-right (click)
1772 ;;;!! (interactive "@e")
1773 ;;;!! (scroll-right (1+ (car (mouse-coords click)))))
1774 ;;;!!
1775 ;;;!! (defun mouse-scroll-left-full ()
1776 ;;;!! (interactive "@")
1777 ;;;!! (scroll-left nil))
1778 ;;;!!
1779 ;;;!! (defun mouse-scroll-right-full ()
1780 ;;;!! (interactive "@")
1781 ;;;!! (scroll-right nil))
1782 ;;;!!
1783 ;;;!! (defun mouse-scroll-move-cursor-horizontally (click)
1784 ;;;!! (interactive "@e")
1785 ;;;!! (move-to-column (1+ (car (mouse-coords click)))))
1786 ;;;!!
1787 ;;;!! (defun mouse-scroll-absolute-horizontally (event)
1788 ;;;!! (interactive "@e")
1789 ;;;!! (let* ((pos (car event))
1790 ;;;!! (position (car pos))
1791 ;;;!! (length (car (cdr pos))))
1792 ;;;!! (set-window-hscroll (selected-window) 33)))
1793 ;;;!!
1794 ;;;!! (global-set-key [scroll-bar mouse-1] 'mouse-scroll-up)
1795 ;;;!! (global-set-key [scroll-bar mouse-2] 'mouse-scroll-absolute)
1796 ;;;!! (global-set-key [scroll-bar mouse-3] 'mouse-scroll-down)
1797 ;;;!!
1798 ;;;!! (global-set-key [vertical-slider mouse-1] 'mouse-scroll-move-cursor)
1799 ;;;!! (global-set-key [vertical-slider mouse-2] 'mouse-scroll-move-cursor)
1800 ;;;!! (global-set-key [vertical-slider mouse-3] 'mouse-scroll-move-cursor)
1801 ;;;!!
1802 ;;;!! (global-set-key [thumbup mouse-1] 'mouse-scroll-up-full)
1803 ;;;!! (global-set-key [thumbup mouse-2] 'mouse-scroll-up-full)
1804 ;;;!! (global-set-key [thumbup mouse-3] 'mouse-scroll-up-full)
1805 ;;;!!
1806 ;;;!! (global-set-key [thumbdown mouse-1] 'mouse-scroll-down-full)
1807 ;;;!! (global-set-key [thumbdown mouse-2] 'mouse-scroll-down-full)
1808 ;;;!! (global-set-key [thumbdown mouse-3] 'mouse-scroll-down-full)
1809 ;;;!!
1810 ;;;!! (global-set-key [horizontal-scroll-bar mouse-1] 'mouse-scroll-left)
1811 ;;;!! (global-set-key [horizontal-scroll-bar mouse-2]
1812 ;;;!! 'mouse-scroll-absolute-horizontally)
1813 ;;;!! (global-set-key [horizontal-scroll-bar mouse-3] 'mouse-scroll-right)
1814 ;;;!!
1815 ;;;!! (global-set-key [horizontal-slider mouse-1]
1816 ;;;!! 'mouse-scroll-move-cursor-horizontally)
1817 ;;;!! (global-set-key [horizontal-slider mouse-2]
1818 ;;;!! 'mouse-scroll-move-cursor-horizontally)
1819 ;;;!! (global-set-key [horizontal-slider mouse-3]
1820 ;;;!! 'mouse-scroll-move-cursor-horizontally)
1821 ;;;!!
1822 ;;;!! (global-set-key [thumbleft mouse-1] 'mouse-scroll-left-full)
1823 ;;;!! (global-set-key [thumbleft mouse-2] 'mouse-scroll-left-full)
1824 ;;;!! (global-set-key [thumbleft mouse-3] 'mouse-scroll-left-full)
1825 ;;;!!
1826 ;;;!! (global-set-key [thumbright mouse-1] 'mouse-scroll-right-full)
1827 ;;;!! (global-set-key [thumbright mouse-2] 'mouse-scroll-right-full)
1828 ;;;!! (global-set-key [thumbright mouse-3] 'mouse-scroll-right-full)
1829 ;;;!!
1830 ;;;!! (global-set-key [horizontal-scroll-bar S-mouse-2]
1831 ;;;!! 'mouse-split-window-horizontally)
1832 ;;;!! (global-set-key [mode-line S-mouse-2]
1833 ;;;!! 'mouse-split-window-horizontally)
1834 ;;;!! (global-set-key [vertical-scroll-bar S-mouse-2]
1835 ;;;!! 'mouse-split-window)
1837 ;;;!! ;;;;
1838 ;;;!! ;;;; Here are experimental things being tested. Mouse events
1839 ;;;!! ;;;; are of the form:
1840 ;;;!! ;;;; ((x y) window screen-part key-sequence timestamp)
1841 ;;;!! ;;
1842 ;;;!! ;;;;
1843 ;;;!! ;;;; Dynamically track mouse coordinates
1844 ;;;!! ;;;;
1845 ;;;!! ;;
1846 ;;;!! ;;(defun track-mouse (event)
1847 ;;;!! ;; "Track the coordinates, absolute and relative, of the mouse."
1848 ;;;!! ;; (interactive "@e")
1849 ;;;!! ;; (while mouse-grabbed
1850 ;;;!! ;; (let* ((pos (read-mouse-position (selected-screen)))
1851 ;;;!! ;; (abs-x (car pos))
1852 ;;;!! ;; (abs-y (cdr pos))
1853 ;;;!! ;; (relative-coordinate (coordinates-in-window-p
1854 ;;;!! ;; (list (car pos) (cdr pos))
1855 ;;;!! ;; (selected-window))))
1856 ;;;!! ;; (if (consp relative-coordinate)
1857 ;;;!! ;; (message "mouse: [%d %d], (%d %d)" abs-x abs-y
1858 ;;;!! ;; (car relative-coordinate)
1859 ;;;!! ;; (car (cdr relative-coordinate)))
1860 ;;;!! ;; (message "mouse: [%d %d]" abs-x abs-y)))))
1861 ;;;!!
1862 ;;;!! ;;
1863 ;;;!! ;; Dynamically put a box around the line indicated by point
1864 ;;;!! ;;
1865 ;;;!! ;;
1866 ;;;!! ;;(require 'backquote)
1867 ;;;!! ;;
1868 ;;;!! ;;(defun mouse-select-buffer-line (event)
1869 ;;;!! ;; (interactive "@e")
1870 ;;;!! ;; (let ((relative-coordinate
1871 ;;;!! ;; (coordinates-in-window-p (car event) (selected-window)))
1872 ;;;!! ;; (abs-y (car (cdr (car event)))))
1873 ;;;!! ;; (if (consp relative-coordinate)
1874 ;;;!! ;; (progn
1875 ;;;!! ;; (save-excursion
1876 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1877 ;;;!! ;; (x-draw-rectangle
1878 ;;;!! ;; (selected-screen)
1879 ;;;!! ;; abs-y 0
1880 ;;;!! ;; (save-excursion
1881 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1882 ;;;!! ;; (end-of-line)
1883 ;;;!! ;; (push-mark nil t)
1884 ;;;!! ;; (beginning-of-line)
1885 ;;;!! ;; (- (region-end) (region-beginning))) 1))
1886 ;;;!! ;; (sit-for 1)
1887 ;;;!! ;; (x-erase-rectangle (selected-screen))))))
1888 ;;;!! ;;
1889 ;;;!! ;;(defvar last-line-drawn nil)
1890 ;;;!! ;;(defvar begin-delim "[^ \t]")
1891 ;;;!! ;;(defvar end-delim "[^ \t]")
1892 ;;;!! ;;
1893 ;;;!! ;;(defun mouse-boxing (event)
1894 ;;;!! ;; (interactive "@e")
1895 ;;;!! ;; (save-excursion
1896 ;;;!! ;; (let ((screen (selected-screen)))
1897 ;;;!! ;; (while (= (x-mouse-events) 0)
1898 ;;;!! ;; (let* ((pos (read-mouse-position screen))
1899 ;;;!! ;; (abs-x (car pos))
1900 ;;;!! ;; (abs-y (cdr pos))
1901 ;;;!! ;; (relative-coordinate
1902 ;;;!! ;; (coordinates-in-window-p `(,abs-x ,abs-y)
1903 ;;;!! ;; (selected-window)))
1904 ;;;!! ;; (begin-reg nil)
1905 ;;;!! ;; (end-reg nil)
1906 ;;;!! ;; (end-column nil)
1907 ;;;!! ;; (begin-column nil))
1908 ;;;!! ;; (if (and (consp relative-coordinate)
1909 ;;;!! ;; (or (not last-line-drawn)
1910 ;;;!! ;; (not (= last-line-drawn abs-y))))
1911 ;;;!! ;; (progn
1912 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1913 ;;;!! ;; (if (= (following-char) 10)
1914 ;;;!! ;; ()
1915 ;;;!! ;; (progn
1916 ;;;!! ;; (setq begin-reg (1- (re-search-forward end-delim)))
1917 ;;;!! ;; (setq begin-column (1- (current-column)))
1918 ;;;!! ;; (end-of-line)
1919 ;;;!! ;; (setq end-reg (1+ (re-search-backward begin-delim)))
1920 ;;;!! ;; (setq end-column (1+ (current-column)))
1921 ;;;!! ;; (message "%s" (buffer-substring begin-reg end-reg))
1922 ;;;!! ;; (x-draw-rectangle screen
1923 ;;;!! ;; (setq last-line-drawn abs-y)
1924 ;;;!! ;; begin-column
1925 ;;;!! ;; (- end-column begin-column) 1))))))))))
1926 ;;;!! ;;
1927 ;;;!! ;;(defun mouse-erase-box ()
1928 ;;;!! ;; (interactive)
1929 ;;;!! ;; (if last-line-drawn
1930 ;;;!! ;; (progn
1931 ;;;!! ;; (x-erase-rectangle (selected-screen))
1932 ;;;!! ;; (setq last-line-drawn nil))))
1933 ;;;!!
1934 ;;;!! ;;; (defun test-x-rectangle ()
1935 ;;;!! ;;; (use-local-mouse-map (setq rectangle-test-map (make-sparse-keymap)))
1936 ;;;!! ;;; (define-key rectangle-test-map mouse-motion-button-left 'mouse-boxing)
1937 ;;;!! ;;; (define-key rectangle-test-map mouse-button-left-up 'mouse-erase-box))
1938 ;;;!!
1939 ;;;!! ;;
1940 ;;;!! ;; Here is how to do double clicking in lisp. About to change.
1941 ;;;!! ;;
1942 ;;;!!
1943 ;;;!! (defvar double-start nil)
1944 ;;;!! (defconst double-click-interval 300
1945 ;;;!! "Max ticks between clicks")
1946 ;;;!!
1947 ;;;!! (defun double-down (event)
1948 ;;;!! (interactive "@e")
1949 ;;;!! (if double-start
1950 ;;;!! (let ((interval (- (nth 4 event) double-start)))
1951 ;;;!! (if (< interval double-click-interval)
1952 ;;;!! (progn
1953 ;;;!! (backward-up-list 1)
1954 ;;;!! ;; (message "Interval %d" interval)
1955 ;;;!! (sleep-for 1)))
1956 ;;;!! (setq double-start nil))
1957 ;;;!! (setq double-start (nth 4 event))))
1958 ;;;!!
1959 ;;;!! (defun double-up (event)
1960 ;;;!! (interactive "@e")
1961 ;;;!! (and double-start
1962 ;;;!! (> (- (nth 4 event ) double-start) double-click-interval)
1963 ;;;!! (setq double-start nil)))
1964 ;;;!!
1965 ;;;!! ;;; (defun x-test-doubleclick ()
1966 ;;;!! ;;; (use-local-mouse-map (setq doubleclick-test-map (make-sparse-keymap)))
1967 ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left 'double-down)
1968 ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left-up 'double-up))
1969 ;;;!!
1970 ;;;!! ;;
1971 ;;;!! ;; This scrolls while button is depressed. Use preferable in scroll bar.
1972 ;;;!! ;;
1973 ;;;!!
1974 ;;;!! (defvar scrolled-lines 0)
1975 ;;;!! (defconst scroll-speed 1)
1976 ;;;!!
1977 ;;;!! (defun incr-scroll-down (event)
1978 ;;;!! (interactive "@e")
1979 ;;;!! (setq scrolled-lines 0)
1980 ;;;!! (incremental-scroll scroll-speed))
1981 ;;;!!
1982 ;;;!! (defun incr-scroll-up (event)
1983 ;;;!! (interactive "@e")
1984 ;;;!! (setq scrolled-lines 0)
1985 ;;;!! (incremental-scroll (- scroll-speed)))
1986 ;;;!!
1987 ;;;!! (defun incremental-scroll (n)
1988 ;;;!! (while (= (x-mouse-events) 0)
1989 ;;;!! (setq scrolled-lines (1+ (* scroll-speed scrolled-lines)))
1990 ;;;!! (scroll-down n)
1991 ;;;!! (sit-for 300 t)))
1992 ;;;!!
1993 ;;;!! (defun incr-scroll-stop (event)
1994 ;;;!! (interactive "@e")
1995 ;;;!! (message "Scrolled %d lines" scrolled-lines)
1996 ;;;!! (setq scrolled-lines 0)
1997 ;;;!! (sleep-for 1))
1998 ;;;!!
1999 ;;;!! ;;; (defun x-testing-scroll ()
2000 ;;;!! ;;; (let ((scrolling-map (function mouse-vertical-scroll-bar-prefix)))
2001 ;;;!! ;;; (define-key scrolling-map mouse-button-left 'incr-scroll-down)
2002 ;;;!! ;;; (define-key scrolling-map mouse-button-right 'incr-scroll-up)
2003 ;;;!! ;;; (define-key scrolling-map mouse-button-left-up 'incr-scroll-stop)
2004 ;;;!! ;;; (define-key scrolling-map mouse-button-right-up 'incr-scroll-stop)))
2005 ;;;!!
2006 ;;;!! ;;
2007 ;;;!! ;; Some playthings suitable for picture mode? They need work.
2008 ;;;!! ;;
2009 ;;;!!
2010 ;;;!! (defun mouse-kill-rectangle (event)
2011 ;;;!! "Kill the rectangle between point and the mouse cursor."
2012 ;;;!! (interactive "@e")
2013 ;;;!! (let ((point-save (point)))
2014 ;;;!! (save-excursion
2015 ;;;!! (mouse-set-point event)
2016 ;;;!! (push-mark nil t)
2017 ;;;!! (if (> point-save (point))
2018 ;;;!! (kill-rectangle (point) point-save)
2019 ;;;!! (kill-rectangle point-save (point))))))
2020 ;;;!!
2021 ;;;!! (defun mouse-open-rectangle (event)
2022 ;;;!! "Kill the rectangle between point and the mouse cursor."
2023 ;;;!! (interactive "@e")
2024 ;;;!! (let ((point-save (point)))
2025 ;;;!! (save-excursion
2026 ;;;!! (mouse-set-point event)
2027 ;;;!! (push-mark nil t)
2028 ;;;!! (if (> point-save (point))
2029 ;;;!! (open-rectangle (point) point-save)
2030 ;;;!! (open-rectangle point-save (point))))))
2031 ;;;!!
2032 ;;;!! ;; Must be a better way to do this.
2033 ;;;!!
2034 ;;;!! (defun mouse-multiple-insert (n char)
2035 ;;;!! (while (> n 0)
2036 ;;;!! (insert char)
2037 ;;;!! (setq n (1- n))))
2038 ;;;!!
2039 ;;;!! ;; What this could do is not finalize until button was released.
2040 ;;;!!
2041 ;;;!! (defun mouse-move-text (event)
2042 ;;;!! "Move text from point to cursor position, inserting spaces."
2043 ;;;!! (interactive "@e")
2044 ;;;!! (let* ((relative-coordinate
2045 ;;;!! (coordinates-in-window-p (car event) (selected-window))))
2046 ;;;!! (if (consp relative-coordinate)
2047 ;;;!! (cond ((> (current-column) (car relative-coordinate))
2048 ;;;!! (delete-char
2049 ;;;!! (- (car relative-coordinate) (current-column))))
2050 ;;;!! ((< (current-column) (car relative-coordinate))
2051 ;;;!! (mouse-multiple-insert
2052 ;;;!! (- (car relative-coordinate) (current-column)) " "))
2053 ;;;!! ((= (current-column) (car relative-coordinate)) (ding))))))
2055 ;; Choose a completion with the mouse.
2057 (defun mouse-choose-completion (event)
2058 "Click on an alternative in the `*Completions*' buffer to choose it."
2059 (interactive "e")
2060 ;; Give temporary modes such as isearch a chance to turn off.
2061 (run-hooks 'mouse-leave-buffer-hook)
2062 (let ((buffer (window-buffer))
2063 choice
2064 base-size)
2065 (save-excursion
2066 (set-buffer (window-buffer (posn-window (event-start event))))
2067 (if completion-reference-buffer
2068 (setq buffer completion-reference-buffer))
2069 (setq base-size completion-base-size)
2070 (save-excursion
2071 (goto-char (posn-point (event-start event)))
2072 (let (beg end)
2073 (if (and (not (eobp)) (get-text-property (point) 'mouse-face))
2074 (setq end (point) beg (1+ (point))))
2075 (if (null beg)
2076 (error "No completion here"))
2077 (setq beg (previous-single-property-change beg 'mouse-face))
2078 (setq end (or (next-single-property-change end 'mouse-face)
2079 (point-max)))
2080 (setq choice (buffer-substring beg end)))))
2081 (let ((owindow (selected-window)))
2082 (select-window (posn-window (event-start event)))
2083 (if (and (one-window-p t 'selected-frame)
2084 (window-dedicated-p (selected-window)))
2085 ;; This is a special buffer's frame
2086 (iconify-frame (selected-frame))
2087 (or (window-dedicated-p (selected-window))
2088 (bury-buffer)))
2089 (select-window owindow))
2090 (choose-completion-string choice buffer base-size)))
2092 ;; Font selection.
2094 (defun font-menu-add-default ()
2095 (let* ((default (cdr (assq 'font (frame-parameters (selected-frame)))))
2096 (font-alist x-fixed-font-alist)
2097 (elt (or (assoc "Misc" font-alist) (nth 1 font-alist))))
2098 (if (assoc "Default" elt)
2099 (delete (assoc "Default" elt) elt))
2100 (setcdr elt
2101 (cons (list "Default" default)
2102 (cdr elt)))))
2104 (defvar x-fixed-font-alist
2105 '("Font menu"
2106 ("Misc"
2107 ;; For these, we specify the pixel height and width.
2108 ("fixed" "fixed")
2109 ("6x10" "-misc-fixed-medium-r-normal--10-*-*-*-c-60-iso8859-1" "6x10")
2110 ("6x12"
2111 "-misc-fixed-medium-r-semicondensed--12-*-*-*-c-60-iso8859-1" "6x12")
2112 ("6x13"
2113 "-misc-fixed-medium-r-semicondensed--13-*-*-*-c-60-iso8859-1" "6x13")
2114 ("7x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-70-iso8859-1" "7x13")
2115 ("7x14" "-misc-fixed-medium-r-normal--14-*-*-*-c-70-iso8859-1" "7x14")
2116 ("8x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-80-iso8859-1" "8x13")
2117 ("9x15" "-misc-fixed-medium-r-normal--15-*-*-*-c-90-iso8859-1" "9x15")
2118 ("10x20" "-misc-fixed-medium-r-normal--20-*-*-*-c-100-iso8859-1" "10x20")
2119 ("11x18" "-misc-fixed-medium-r-normal--18-*-*-*-c-110-iso8859-1" "11x18")
2120 ("12x24" "-misc-fixed-medium-r-normal--24-*-*-*-c-120-iso8859-1" "12x24")
2121 ("")
2122 ("clean 5x8"
2123 "-schumacher-clean-medium-r-normal--8-*-*-*-c-50-iso8859-1")
2124 ("clean 6x8"
2125 "-schumacher-clean-medium-r-normal--8-*-*-*-c-60-iso8859-1")
2126 ("clean 8x8"
2127 "-schumacher-clean-medium-r-normal--8-*-*-*-c-80-iso8859-1")
2128 ("clean 8x10"
2129 "-schumacher-clean-medium-r-normal--10-*-*-*-c-80-iso8859-1")
2130 ("clean 8x14"
2131 "-schumacher-clean-medium-r-normal--14-*-*-*-c-80-iso8859-1")
2132 ("clean 8x16"
2133 "-schumacher-clean-medium-r-normal--16-*-*-*-c-80-iso8859-1")
2134 ("")
2135 ("sony 8x16" "-sony-fixed-medium-r-normal--16-*-*-*-c-80-iso8859-1")
2136 ;;; We don't seem to have these; who knows what they are.
2137 ;;; ("fg-18" "fg-18")
2138 ;;; ("fg-25" "fg-25")
2139 ("lucidasanstypewriter-12" "-b&h-lucidatypewriter-medium-r-normal-sans-*-120-*-*-*-*-iso8859-1")
2140 ("lucidasanstypewriter-bold-14" "-b&h-lucidatypewriter-bold-r-normal-sans-*-140-*-*-*-*-iso8859-1")
2141 ("lucidasanstypewriter-bold-24"
2142 "-b&h-lucidatypewriter-bold-r-normal-sans-*-240-*-*-*-*-iso8859-1")
2143 ;;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
2144 ;;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
2146 ("Courier"
2147 ;; For these, we specify the point height.
2148 ("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1")
2149 ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1")
2150 ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1")
2151 ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1")
2152 ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1")
2153 ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1")
2154 ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1")
2155 ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1")
2156 ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1")
2157 ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1")
2158 ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1")
2159 ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1")
2160 ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1")
2161 ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1")
2162 ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1")
2163 ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1")
2164 ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1")
2165 ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1")
2166 ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1")
2167 ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1")
2168 ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1")
2169 ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1")
2170 ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1")
2171 ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1"))
2173 "X fonts suitable for use in Emacs.")
2175 (defun mouse-set-font (&rest fonts)
2176 "Select an emacs font from a list of known good fonts and fontsets."
2177 (interactive
2178 (progn (unless (display-multi-font-p)
2179 (error "Cannot change fonts on this display"))
2180 (x-popup-menu
2181 last-nonmenu-event
2182 ;; Append list of fontsets currently defined.
2183 (append x-fixed-font-alist (list (generate-fontset-menu))))))
2184 (if fonts
2185 (let (font)
2186 (while fonts
2187 (condition-case nil
2188 (progn
2189 (set-default-font (car fonts))
2190 (setq font (car fonts))
2191 (setq fonts nil))
2192 (error
2193 (setq fonts (cdr fonts)))))
2194 (if (null font)
2195 (error "Font not found")))))
2197 ;;; Bindings for mouse commands.
2199 (define-key global-map [down-mouse-1] 'mouse-drag-region)
2200 (global-set-key [mouse-1] 'mouse-set-point)
2201 (global-set-key [drag-mouse-1] 'mouse-set-region)
2203 ;; These are tested for in mouse-drag-region.
2204 (global-set-key [double-mouse-1] 'mouse-set-point)
2205 (global-set-key [triple-mouse-1] 'mouse-set-point)
2207 ;; Clicking on the fringes causes hscrolling:
2208 (global-set-key [left-fringe mouse-1] 'mouse-set-point)
2209 (global-set-key [right-fringe mouse-1] 'mouse-set-point)
2211 (global-set-key [mouse-2] 'mouse-yank-at-click)
2212 (global-set-key [mouse-3] 'mouse-save-then-kill)
2214 ;; By binding these to down-going events, we let the user use the up-going
2215 ;; event to make the selection, saving a click.
2216 (global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
2217 (if (not (eq system-type 'ms-dos))
2218 (global-set-key [S-down-mouse-1] 'mouse-set-font))
2219 ;; C-down-mouse-2 is bound in facemenu.el.
2220 (global-set-key [C-down-mouse-3] 'mouse-popup-menubar-stuff)
2223 ;; Replaced with dragging mouse-1
2224 ;; (global-set-key [S-mouse-1] 'mouse-set-mark)
2226 ;; Binding mouse-1 to mouse-select-window when on mode-, header-, or
2227 ;; vertical-line prevents Emacs from signaling an error when the mouse
2228 ;; button is released after dragging these lines, on non-toolkit
2229 ;; versions.
2230 (global-set-key [mode-line mouse-1] 'mouse-select-window)
2231 (global-set-key [mode-line drag-mouse-1] 'mouse-select-window)
2232 (global-set-key [mode-line down-mouse-1] 'mouse-drag-mode-line)
2233 (global-set-key [header-line down-mouse-1] 'mouse-drag-header-line)
2234 (global-set-key [header-line mouse-1] 'mouse-select-window)
2235 (global-set-key [mode-line mouse-2] 'mouse-delete-other-windows)
2236 (global-set-key [mode-line mouse-3] 'mouse-delete-window)
2237 (global-set-key [mode-line C-mouse-2] 'mouse-split-window-horizontally)
2238 (global-set-key [vertical-scroll-bar C-mouse-2] 'mouse-split-window-vertically)
2239 (global-set-key [vertical-line C-mouse-2] 'mouse-split-window-vertically)
2240 (global-set-key [vertical-line down-mouse-1] 'mouse-drag-vertical-line)
2241 (global-set-key [vertical-line mouse-1] 'mouse-select-window)
2243 (provide 'mouse)
2245 ;; This file contains the functionality of the old mldrag.el.
2246 (defalias 'mldrag-drag-mode-line 'mouse-drag-mode-line)
2247 (defalias 'mldrag-drag-vertical-line 'mouse-drag-vertical-line)
2248 (make-obsolete 'mldrag-drag-mode-line 'mouse-drag-mode-line "21.1")
2249 (make-obsolete 'mldrag-drag-vertical-line 'mouse-drag-vertical-line "21.1")
2250 (provide 'mldrag)
2252 ;;; arch-tag: 9a710ce1-914a-4923-9b81-697f7bf82ab3
2253 ;;; mouse.el ends here