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