1 ;;; mouse.el --- window system-independent mouse support
3 ;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; This package provides various useful commands (including help
28 ;; system access) through the mouse. All this code assumes that mouse
29 ;; interpretation has been abstracted into Emacs input events.
31 ;; The code is rather X-dependent.
35 ;;; Utility functions.
37 ;;; Indent track-mouse like progn.
38 (put 'track-mouse
'lisp-indent-function
0)
40 (defvar mouse-yank-at-point nil
41 "*If non-nil, mouse yank commands yank at point instead of at click.")
43 ;; Provide a mode-specific menu on a mouse button.
45 (defun mouse-major-mode-menu (event prefix
)
46 "Pop up a mode-specific menu of mouse commands."
47 ;; Switch to the window clicked on, because otherwise
48 ;; the mode's commands may not make sense.
50 (let (;; This is where mouse-major-mode-menu-prefix
51 ;; returns the prefix we should use (after menu-bar).
52 ;; It is either nil or (SOME-SYMBOL).
53 (mouse-major-mode-menu-prefix nil
)
54 ;; Make a keymap in which our last command leads to a menu
55 (newmap (make-sparse-keymap (concat mode-name
" Mode")))
57 ;; Make our menu inherit from the desired keymap
58 ;; which we want to display as the menu now.
59 (set-keymap-parent newmap
60 (mouse-major-mode-menu-1
61 (and (current-local-map)
62 (lookup-key (current-local-map) [menu-bar
]))))
63 (setq result
(x-popup-menu t
(list newmap
)))
65 (let ((command (key-binding
66 (apply 'vector
(append '(menu-bar)
67 mouse-major-mode-menu-prefix
69 ;; Clear out echoing, which perhaps shows a prefix arg.
73 (setq prefix-arg prefix
)
74 (command-execute command
)))))))
76 ;; Compute and cache the equivalent keys in MENU and all its submenus.
77 ;;;(defun mouse-major-mode-menu-compute-equiv-keys (menu)
78 ;;; (and (eq (car menu) 'keymap)
79 ;;; (x-popup-menu nil menu))
81 ;;; (and (consp (car menu))
82 ;;; (consp (cdr (car menu)))
83 ;;; (let ((tail (cdr (car menu))))
84 ;;; (while (and (consp tail)
85 ;;; (not (eq (car tail) 'keymap)))
86 ;;; (setq tail (cdr tail)))
88 ;;; (mouse-major-mode-menu-compute-equiv-keys tail))))
89 ;;; (setq menu (cdr menu))))
91 ;; Given a mode's menu bar keymap,
92 ;; if it defines exactly one menu bar menu,
93 ;; return just that menu.
94 ;; Otherwise return a menu for all of them.
95 (defun mouse-major-mode-menu-1 (menubar)
100 (if (consp (car tail
))
103 (setq submap
(car tail
))))
104 (setq tail
(cdr tail
)))
107 (setq mouse-major-mode-menu-prefix
(list (car submap
)))
108 (cdr (cdr submap
))))))
110 ;; Commands that operate on windows.
112 (defun mouse-minibuffer-check (event)
113 (let ((w (posn-window (event-start event
))))
114 (and (window-minibuffer-p w
)
115 (not (minibuffer-window-active-p w
))
116 (error "Minibuffer window is not active")))
117 ;; Give temporary modes such as isearch a chance to turn off.
118 (run-hooks 'mouse-leave-buffer-hook
))
120 (defun mouse-delete-window (click)
121 "Delete the window you click on.
122 This must be bound to a mouse click."
124 (mouse-minibuffer-check click
)
125 (delete-window (posn-window (event-start click
))))
127 (defun mouse-select-window (click)
128 "Select the window clicked on; don't move point."
130 (mouse-minibuffer-check click
)
131 (let ((oframe (selected-frame))
132 (frame (window-frame (posn-window (event-start click
)))))
133 (select-window (posn-window (event-start click
)))
136 (or (eq frame oframe
)
137 (set-mouse-position (selected-frame) (1- (frame-width)) 0))))
139 (defun mouse-tear-off-window (click)
140 "Delete the window clicked on, and create a new frame displaying its buffer."
142 (mouse-minibuffer-check click
)
143 (let* ((window (posn-window (event-start click
)))
144 (buf (window-buffer window
))
145 (frame (make-frame)))
147 (switch-to-buffer buf
)
148 (delete-window window
)))
150 (defun mouse-delete-other-windows ()
151 "Delete all window except the one you click on."
153 (delete-other-windows))
155 (defun mouse-split-window-vertically (click)
156 "Select Emacs window mouse is on, then split it vertically in half.
157 The window is split at the line clicked on.
158 This command must be bound to a mouse click."
160 (mouse-minibuffer-check click
)
161 (let ((start (event-start click
)))
162 (select-window (posn-window start
))
163 (let ((new-height (1+ (cdr (posn-col-row (event-end click
)))))
164 (first-line window-min-height
)
165 (last-line (- (window-height) window-min-height
)))
166 (if (< last-line first-line
)
167 (error "Window too short to split")
168 (split-window-vertically
169 (min (max new-height first-line
) last-line
))))))
171 (defun mouse-split-window-horizontally (click)
172 "Select Emacs window mouse is on, then split it horizontally in half.
173 The window is split at the column clicked on.
174 This command must be bound to a mouse click."
176 (mouse-minibuffer-check click
)
177 (let ((start (event-start click
)))
178 (select-window (posn-window start
))
179 (let ((new-width (1+ (car (posn-col-row (event-end click
)))))
180 (first-col window-min-width
)
181 (last-col (- (window-width) window-min-width
)))
182 (if (< last-col first-col
)
183 (error "Window too narrow to split")
184 (split-window-horizontally
185 (min (max new-width first-col
) last-col
))))))
187 (defun mouse-drag-mode-line (start-event)
188 "Change the height of a window by dragging on the mode line."
190 ;; Give temporary modes such as isearch a chance to turn off.
191 (run-hooks 'mouse-leave-buffer-hook
)
194 (start-event-frame (window-frame (car (car (cdr start-event
)))))
195 (start-event-window (car (car (cdr start-event
))))
196 (start-nwindows (count-windows t
))
197 (old-selected-window (selected-window))
198 should-enlarge-minibuffer
199 event mouse minibuffer y top bot edges wconfig params growth
)
200 (setq params
(frame-parameters))
201 (setq minibuffer
(cdr (assq 'minibuffer params
)))
204 ;; enlarge-window only works on the selected window, so
205 ;; we must select the window where the start event originated.
206 ;; unwind-protect will restore the old selected window later.
207 (select-window start-event-window
)
208 ;; if this is the bottommost ordinary window, then to
209 ;; move its modeline the minibuffer must be enlarged.
210 (setq should-enlarge-minibuffer
212 (not (one-window-p t
))
213 (= (nth 1 (window-edges minibuffer
))
214 (nth 3 (window-edges)))))
215 ;; loop reading events and sampling the position of
218 (setq event
(read-event)
219 mouse
(mouse-position))
221 ;; - there is a switch-frame event.
222 ;; - the mouse isn't in the frame that we started in
223 ;; - the mouse isn't in any Emacs frame
225 ;; - there is a mouse-movement event
226 ;; - there is a scroll-bar-movement event
227 ;; (same as mouse movement for our purposes)
229 ;; - there is a keyboard event or some other unknown event
231 (cond ((integerp event
)
233 ((eq (car event
) 'switch-frame
)
235 ((not (memq (car event
)
236 '(mouse-movement scroll-bar-movement
)))
238 (setq unread-command-events
239 (cons event unread-command-events
)))
241 ((not (eq (car mouse
) start-event-frame
))
243 ((null (car (cdr mouse
)))
246 (setq y
(cdr (cdr mouse
))
250 ;; scale back a move that would make the
252 (cond ((< (- y top -
1) window-min-height
)
253 (setq y
(+ top window-min-height -
1))))
254 ;; compute size change needed
255 (setq growth
(- y bot -
1)
256 wconfig
(current-window-configuration))
257 ;; Check for an error case.
258 (if (and (/= growth
0)
261 (error "Attempt to resize sole window"))
262 ;; grow/shrink minibuffer?
263 (if should-enlarge-minibuffer
265 ;; yes. briefly select minibuffer so
266 ;; enlarge-window will affect the
268 (select-window minibuffer
)
269 ;; scale back shrinkage if it would
270 ;; make the minibuffer less than 1
272 (if (and (> growth
0)
273 (< (- (window-height minibuffer
)
276 (setq growth
(1- (window-height minibuffer
))))
277 (enlarge-window (- growth
))
278 (select-window start-event-window
))
279 ;; no. grow/shrink the selected window
280 (enlarge-window growth
))
281 ;; if this window's growth caused another
282 ;; window to be deleted because it was too
283 ;; short, rescind the change.
285 ;; if size change caused space to be stolen
286 ;; from a window above this one, rescind the
287 ;; change, but only if we didn't grow/srhink
288 ;; the minibuffer. minibuffer size changes
289 ;; can cause all windows to shrink... no way
291 (if (or (/= start-nwindows
(count-windows t
))
292 (and (not should-enlarge-minibuffer
)
293 (/= top
(nth 1 (window-edges)))))
294 (set-window-configuration wconfig
)))))))))
296 (defun mouse-drag-vertical-line (start-event)
297 "Change the width of a window by dragging on the vertical line."
299 ;; Give temporary modes such as isearch a chance to turn off.
300 (run-hooks 'mouse-leave-buffer-hook
)
303 (start-event-frame (window-frame (car (car (cdr start-event
)))))
304 (start-event-window (car (car (cdr start-event
))))
305 (start-nwindows (count-windows t
))
306 (old-selected-window (selected-window))
307 event mouse x left right edges wconfig growth
)
309 (error "Attempt to resize sole ordinary window"))
310 (if (= (nth 2 (window-edges start-event-window
))
311 (frame-width start-event-frame
))
312 (error "Attempt to drag rightmost scrollbar"))
315 ;; enlarge-window only works on the selected window, so
316 ;; we must select the window where the start event originated.
317 ;; unwind-protect will restore the old selected window later.
318 (select-window start-event-window
)
319 ;; loop reading events and sampling the position of
322 (setq event
(read-event)
323 mouse
(mouse-position))
325 ;; - there is a switch-frame event.
326 ;; - the mouse isn't in the frame that we started in
327 ;; - the mouse isn't in any Emacs frame
329 ;; - there is a mouse-movement event
330 ;; - there is a scroll-bar-movement event
331 ;; (same as mouse movement for our purposes)
333 ;; - there is a keyboard event or some other unknown event
335 (cond ((integerp event
)
337 ((eq (car event
) 'switch-frame
)
339 ((not (memq (car event
)
340 '(mouse-movement scroll-bar-movement
)))
342 (setq unread-command-events
343 (cons event unread-command-events
)))
345 ((not (eq (car mouse
) start-event-frame
))
347 ((null (car (cdr mouse
)))
350 (setq x
(car (cdr mouse
))
354 ;; scale back a move that would make the
356 (cond ((< (- x left -
1) window-min-width
)
357 (setq x
(+ left window-min-width -
1))))
358 ;; compute size change needed
359 (setq growth
(- x right -
1)
360 wconfig
(current-window-configuration))
361 (enlarge-window growth t
)
362 ;; if this window's growth caused another
363 ;; window to be deleted because it was too
364 ;; thin, rescind the change.
366 ;; if size change caused space to be stolen
367 ;; from a window to the left of this one,
368 ;; rescind the change.
369 (if (or (/= start-nwindows
(count-windows t
))
370 (/= left
(nth 0 (window-edges))))
371 (set-window-configuration wconfig
)))))))))
373 (defun mouse-set-point (event)
374 "Move point to the position clicked on with the mouse.
375 This should be bound to a mouse click event type."
377 (mouse-minibuffer-check event
)
378 ;; Use event-end in case called from mouse-drag-region.
379 ;; If EVENT is a click, event-end and event-start give same value.
380 (let ((posn (event-end event
)))
381 (if (not (windowp (posn-window posn
)))
382 (error "Cursor not in text area of window"))
383 (select-window (posn-window posn
))
384 (if (numberp (posn-point posn
))
385 (goto-char (posn-point posn
)))))
387 (defvar mouse-last-region-beg nil
)
388 (defvar mouse-last-region-end nil
)
389 (defvar mouse-last-region-tick nil
)
391 (defun mouse-region-match ()
392 "Return non-nil if there's an active region that was set with the mouse."
393 (and (mark t
) mark-active
394 (eq mouse-last-region-beg
(region-beginning))
395 (eq mouse-last-region-end
(region-end))
396 (eq mouse-last-region-tick
(buffer-modified-tick))))
398 (defun mouse-set-region (click)
399 "Set the region to the text dragged over, and copy to kill ring.
400 This should be bound to a mouse drag event."
402 (mouse-minibuffer-check click
)
403 (let ((posn (event-start click
))
404 (end (event-end click
)))
405 (select-window (posn-window posn
))
406 (if (numberp (posn-point posn
))
407 (goto-char (posn-point posn
)))
408 ;; If mark is highlighted, no need to bounce the cursor.
409 ;; On X, we highlight while dragging, thus once again no need to bounce.
410 (or transient-mark-mode
411 (memq (framep (selected-frame)) '(x pc w32
))
415 (if (numberp (posn-point end
))
416 (goto-char (posn-point end
)))
417 ;; Don't set this-command to kill-region, so that a following
418 ;; C-w will not double the text in the kill ring.
419 ;; Ignore last-command so we don't append to a preceding kill.
420 (let (this-command last-command
)
421 (copy-region-as-kill (mark) (point)))
422 (mouse-set-region-1)))
424 (defun mouse-set-region-1 ()
425 (setq mouse-last-region-beg
(region-beginning))
426 (setq mouse-last-region-end
(region-end))
427 (setq mouse-last-region-tick
(buffer-modified-tick)))
429 (defvar mouse-scroll-delay
0.25
430 "*The pause between scroll steps caused by mouse drags, in seconds.
431 If you drag the mouse beyond the edge of a window, Emacs scrolls the
432 window to bring the text beyond that edge into view, with a delay of
433 this many seconds between scroll steps. Scrolling stops when you move
434 the mouse back into the window, or release the button.
435 This variable's value may be non-integral.
436 Setting this to zero causes Emacs to scroll as fast as it can.")
438 (defvar mouse-scroll-min-lines
1
439 "*The minimum number of lines scrolled by dragging mouse out of window.
440 Moving the mouse out the top or bottom edge of the window begins
441 scrolling repeatedly. The number of lines scrolled per repetition
442 is normally equal to the number of lines beyond the window edge that
443 the mouse has moved. However, it always scrolls at least the number
444 of lines specified by this variable.")
446 (defun mouse-scroll-subr (window jump
&optional overlay start
)
447 "Scroll the window WINDOW, JUMP lines at a time, until new input arrives.
448 If OVERLAY is an overlay, let it stretch from START to the far edge of
449 the newly visible text.
450 Upon exit, point is at the far edge of the newly visible text."
452 ((and (> jump
0) (< jump mouse-scroll-min-lines
))
453 (setq jump mouse-scroll-min-lines
))
454 ((and (< jump
0) (< (- jump
) mouse-scroll-min-lines
))
455 (setq jump
(- mouse-scroll-min-lines
))))
456 (let ((opoint (point)))
458 (goto-char (window-start window
))
459 (if (not (zerop (vertical-motion jump window
)))
461 (set-window-start window
(point))
464 (goto-char (window-end window
))
465 ;; window-end doesn't reflect the window's new
466 ;; start position until the next redisplay. Hurrah.
467 (vertical-motion (1- jump
) window
))
468 (goto-char (window-start window
)))
470 (move-overlay overlay start
(point)))
471 ;; Now that we have scrolled WINDOW properly,
472 ;; put point back where it was for the redisplay
473 ;; so that we don't mess up the selected window.
474 (or (eq window
(selected-window))
476 (sit-for mouse-scroll-delay
)))))
477 (or (eq window
(selected-window))
478 (goto-char opoint
))))
480 ;; Create an overlay and immediately delete it, to get "overlay in no buffer".
481 (defvar mouse-drag-overlay
(make-overlay 1 1))
482 (delete-overlay mouse-drag-overlay
)
483 (overlay-put mouse-drag-overlay
'face
'region
)
485 (defvar mouse-selection-click-count
0)
487 (defvar mouse-selection-click-count-buffer nil
)
489 (defun mouse-drag-region (start-event)
490 "Set the region to the text that the mouse is dragged over.
491 Highlight the drag area as you move the mouse.
492 This must be bound to a button-down mouse event.
493 In Transient Mark mode, the highlighting remains as long as the mark
494 remains active. Otherwise, it remains until the next input event."
496 (mouse-minibuffer-check start-event
)
497 (let* ((echo-keystrokes 0)
498 (start-posn (event-start start-event
))
499 (start-point (posn-point start-posn
))
500 (start-window (posn-window start-posn
))
501 (start-frame (window-frame start-window
))
502 (bounds (window-edges start-window
))
504 (bottom (if (window-minibuffer-p start-window
)
506 ;; Don't count the mode line.
507 (1- (nth 3 bounds
))))
508 (click-count (1- (event-click-count start-event
))))
509 (setq mouse-selection-click-count click-count
)
510 (setq mouse-selection-click-count-buffer
(current-buffer))
511 (mouse-set-point start-event
)
512 ;; In case the down click is in the middle of some intangible text,
513 ;; use the end of that text, and put it in START-POINT.
514 (if (< (point) start-point
)
515 (goto-char start-point
))
516 (setq start-point
(point))
517 (let ((range (mouse-start-end start-point start-point click-count
)))
518 (move-overlay mouse-drag-overlay
(car range
) (nth 1 range
)
519 (window-buffer start-window
)))
521 ;; end-of-range is used only in the single-click case.
522 ;; It is the place where the drag has reached so far
523 ;; (but not outside the window where the drag started).
524 (let (event end end-point last-end-point
(end-of-range (point)))
527 (setq event
(read-event))
528 (or (mouse-movement-p event
)
529 (eq (car-safe event
) 'switch-frame
)))
530 (if (eq (car-safe event
) 'switch-frame
)
532 (setq end
(event-end event
)
533 end-point
(posn-point end
))
534 (if (numberp end-point
)
535 (setq last-end-point end-point
))
538 ;; Are we moving within the original window?
539 ((and (eq (posn-window end
) start-window
)
540 (integer-or-marker-p end-point
))
541 ;; Go to START-POINT first, so that when we move to END-POINT,
542 ;; if it's in the middle of intangible text,
543 ;; point jumps in the direction away from START-POINT.
544 (goto-char start-point
)
545 (goto-char end-point
)
546 (if (zerop (% click-count
3))
547 (setq end-of-range
(point)))
548 (let ((range (mouse-start-end start-point
(point) click-count
)))
549 (move-overlay mouse-drag-overlay
(car range
) (nth 1 range
))))
552 (let ((mouse-row (cdr (cdr (mouse-position)))))
556 (mouse-scroll-subr start-window
(- mouse-row top
)
557 mouse-drag-overlay start-point
)
558 ;; Without this, point tends to jump back to the starting
559 ;; position where the mouse button was pressed down.
560 (setq end-of-range
(overlay-start mouse-drag-overlay
)))
561 ((>= mouse-row bottom
)
562 (mouse-scroll-subr start-window
(1+ (- mouse-row bottom
))
563 mouse-drag-overlay start-point
)
564 (setq end-of-range
(overlay-end mouse-drag-overlay
))))))))))
566 (let ((fun (key-binding (vector (car event
)))))
567 ;; Run the binding of the terminating up-event, if possible.
568 ;; In the case of a multiple click, it gives the wrong results,
569 ;; because it would fail to set up a region.
570 (if nil
;; (and (= (mod mouse-selection-click-count 3) 0) (fboundp fun))
571 ;; In this case, we can just let the up-event execute normally.
572 (let ((end (event-end event
)))
573 ;; Set the position in the event before we replay it,
574 ;; because otherwise it may have a position in the wrong
576 (setcar (cdr end
) end-of-range
)
577 ;; Delete the overlay before calling the function,
578 ;; because delete-overlay increases buffer-modified-tick.
579 (delete-overlay mouse-drag-overlay
)
580 (setq unread-command-events
581 (cons event unread-command-events
)))
582 (if (not (= (overlay-start mouse-drag-overlay
)
583 (overlay-end mouse-drag-overlay
)))
585 (if (numberp (posn-point (event-end event
)))
586 (posn-point (event-end event
))
588 ;; The end that comes from where we ended the drag.
591 (if (and stop-point
(< stop-point start-point
))
592 (overlay-start mouse-drag-overlay
)
593 (overlay-end mouse-drag-overlay
)))
594 ;; The end that comes from where we started the drag.
597 (- (+ (overlay-end mouse-drag-overlay
)
598 (overlay-start mouse-drag-overlay
))
600 last-command this-command
)
601 (push-mark region-commencement t t
)
602 (goto-char region-termination
)
603 (copy-region-as-kill (point) (mark t
))
604 (let ((buffer (current-buffer)))
606 ;; mouse-show-mark can call read-event,
607 ;; and that means the Emacs server could switch buffers
608 ;; under us. If that happened,
609 ;; avoid trying to use the region.
610 (and (mark t
) mark-active
611 (eq buffer
(current-buffer))
612 (mouse-set-region-1))))
613 (goto-char (overlay-end mouse-drag-overlay
))
614 (setq this-command
'mouse-set-point
)
615 (delete-overlay mouse-drag-overlay
))))
616 (delete-overlay mouse-drag-overlay
)))))
618 ;; Commands to handle xterm-style multiple clicks.
620 (defun mouse-skip-word (dir)
621 "Skip over word, over whitespace, or over identical punctuation.
622 If DIR is positive skip forward; if negative, skip backward."
623 (let* ((char (following-char))
624 (syntax (char-to-string (char-syntax char
))))
625 (cond ((or (string= syntax
"w") (string= syntax
" "))
627 (skip-syntax-backward syntax
)
628 (skip-syntax-forward syntax
)))
629 ((string= syntax
"_")
631 (skip-syntax-backward "w_")
632 (skip-syntax-forward "w_")))
634 (while (and (not (bobp)) (= (preceding-char) char
))
637 (while (and (not (eobp)) (= (following-char) char
))
638 (forward-char 1))))))
640 ;; Return a list of region bounds based on START and END according to MODE.
641 ;; If MODE is 0 then set point to (min START END), mark to (max START END).
642 ;; If MODE is 1 then set point to start of word at (min START END),
643 ;; mark to end of word at (max START END).
644 ;; If MODE is 2 then do the same for lines.
645 (defun mouse-start-end (start end mode
)
650 (setq mode
(mod mode
3))
656 (= (char-syntax (char-after start
)) ?\
())
665 (= (char-syntax (char-after start
)) ?\
)))
666 (list (save-excursion
667 (goto-char (1+ start
))
674 (= (char-syntax (char-after start
)) ?
\"))
675 (let ((open (or (eq start
(point-min))
677 (goto-char (- start
1))
678 (looking-at "\\s(\\|\\s \\|\\s>")))))
688 (list (save-excursion
691 (goto-char (1+ start
))
697 (list (save-excursion
706 (list (save-excursion
708 (beginning-of-line 1)
715 ;; Subroutine: set the mark where CLICK happened,
716 ;; but don't do anything else.
717 (defun mouse-set-mark-fast (click)
718 (mouse-minibuffer-check click
)
719 (let ((posn (event-start click
)))
720 (select-window (posn-window posn
))
721 (if (numberp (posn-point posn
))
722 (push-mark (posn-point posn
) t t
))))
724 (defun mouse-undouble-last-event (events)
725 (let* ((index (1- (length events
)))
726 (last (nthcdr index events
))
728 (basic (event-basic-type event
))
729 (modifiers (delq 'double
(delq 'triple
(copy-sequence (event-modifiers event
)))))
732 (cons (event-convert-list (nreverse (cons basic modifiers
)))
736 (if (key-binding (apply 'vector events
))
741 ;; Momentarily show where the mark is, if highlighting doesn't show it.
743 (defvar mouse-region-delete-keys
'([delete])
744 "List of keys which shall cause the mouse region to be deleted.")
746 (defun mouse-show-mark ()
747 (if transient-mark-mode
749 (delete-overlay mouse-drag-overlay))
751 (let ((inhibit-quit t)
753 event events key ignore
754 x-lost-selection-hooks)
755 (add-hook 'x-lost-selection-hooks
757 (if (eq seltype 'PRIMARY)
758 (progn (setq ignore t)
759 (throw 'mouse-show-mark t)))))
760 (move-overlay mouse-drag-overlay (point) (mark t))
761 (catch 'mouse-show-mark
762 (while (progn (setq event (read-event))
763 (setq events (append events (list event)))
764 (setq key (apply 'vector events))
765 (and (memq 'down (event-modifiers event))
766 (not (key-binding key))
767 (not (member key mouse-region-delete-keys))
768 (not (mouse-undouble-last-event events))))))
769 ;; If we lost the selection, just turn off the highlighting.
772 ;; For certain special keys, delete the region.
773 (if (member key mouse-region-delete-keys)
774 (delete-region (overlay-start mouse-drag-overlay)
775 (overlay-end mouse-drag-overlay))
776 ;; Otherwise, unread the key so it gets executed normally.
777 (setq unread-command-events
778 (nconc events unread-command-events))))
780 (delete-overlay mouse-drag-overlay))
785 (defun mouse-set-mark (click)
786 "Set mark at the position clicked on with the mouse.
787 Display cursor at that position for a second.
788 This must be bound to a mouse click."
790 (mouse-minibuffer-check click)
791 (select-window (posn-window (event-start click)))
792 ;; We don't use save-excursion because that preserves the mark too.
793 (let ((point-save (point)))
795 (progn (mouse-set-point click)
797 (or transient-mark-mode
799 (goto-char point-save))))
801 (defun mouse-kill (click)
802 "Kill the region between point and the mouse click.
803 The text is saved in the kill ring, as with \\[kill-region]."
805 (mouse-minibuffer-check click)
806 (let* ((posn (event-start click))
807 (click-posn (posn-point posn)))
808 (select-window (posn-window posn))
809 (if (numberp click-posn)
810 (kill-region (min (point) click-posn)
811 (max (point) click-posn)))))
813 (defun mouse-yank-at-click (click arg)
814 "Insert the last stretch of killed text at the position clicked on.
815 Also move point to one end of the text thus inserted (normally the end).
816 Prefix arguments are interpreted as with \\[yank].
817 If `mouse-yank-at-point' is non-nil, insert at point
818 regardless of where you click."
820 ;; Give temporary modes such as isearch a chance to turn off.
821 (run-hooks 'mouse-leave-buffer-hook)
822 (or mouse-yank-at-point (mouse-set-point click))
823 (setq this-command 'yank)
824 (setq mouse-selection-click-count 0)
827 (defun mouse-kill-ring-save (click)
828 "Copy the region between point and the mouse click in the kill ring.
829 This does not delete the region; it acts like \\[kill-ring-save]."
831 (mouse-set-mark-fast click)
832 (let (this-command last-command)
833 (kill-ring-save (point) (mark t)))
836 ;;; This function used to delete the text between point and the mouse
837 ;;; whenever it was equal to the front of the kill ring, but some
838 ;;; people found that confusing.
840 ;;; A list (TEXT START END), describing the text and position of the last
841 ;;; invocation of mouse-save-then-kill.
842 (defvar mouse-save-then-kill-posn nil)
844 (defun mouse-save-then-kill-delete-region (beg end)
845 ;; We must make our own undo boundaries
846 ;; because they happen automatically only for the current buffer.
848 (if (or (= beg end) (eq buffer-undo-list t))
849 ;; If we have no undo list in this buffer,
851 (delete-region beg end)
852 ;; Delete, but make the undo-list entry share with the kill ring.
853 ;; First, delete just one char, so in case buffer is being modified
854 ;; for the first time, the undo list records that fact.
855 (let (before-change-function after-change-function
856 before-change-functions after-change-functions)
858 (+ beg (if (> end beg) 1 -1))))
859 (let ((buffer-undo-list buffer-undo-list))
860 ;; Undo that deletion--but don't change the undo list!
861 (let (before-change-function after-change-function
862 before-change-functions after-change-functions)
863 (primitive-undo 1 buffer-undo-list))
864 ;; Now delete the rest of the specified region,
865 ;; but don't record it.
866 (setq buffer-undo-list t)
867 (if (/= (length (car kill-ring)) (- (max end beg) (min end beg)))
868 (error "Lossage in mouse-save-then-kill-delete-region"))
869 (delete-region beg end))
870 (let ((tail buffer-undo-list))
871 ;; Search back in buffer-undo-list for the string
872 ;; that came from deleting one character.
873 (while (and tail (not (stringp (car (car tail)))))
874 (setq tail (cdr tail)))
875 ;; Replace it with an entry for the entire deleted text.
877 (setcar tail (cons (car kill-ring) (min beg end))))))
880 (defun mouse-save-then-kill (click)
881 "Save text to point in kill ring; the second time, kill the text.
882 If the text between point and the mouse is the same as what's
883 at the front of the kill ring, this deletes the text.
884 Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
885 which prepares for a second click to delete the text.
887 If you have selected words or lines, this command extends the
888 selection through the word or line clicked on. If you do this
889 again in a different position, it extends the selection again.
890 If you do this twice in the same position, the selection is killed."
892 (let ((before-scroll point-before-scroll))
893 (mouse-minibuffer-check click)
894 (let ((click-posn (posn-point (event-start click)))
895 ;; Don't let a subsequent kill command append to this one:
896 ;; prevent setting this-command to kill-region.
897 (this-command this-command))
898 (if (and (save-excursion
899 (set-buffer (window-buffer (posn-window (event-start click))))
900 (and (mark t) (> (mod mouse-selection-click-count 3) 0)
901 ;; Don't be fooled by a recent click in some other buffer.
902 (eq mouse-selection-click-count-buffer
904 (if (not (and (eq last-command 'mouse-save-then-kill)
906 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
907 ;; Find both ends of the object selected by this click.
909 (mouse-start-end click-posn click-posn
910 mouse-selection-click-count)))
911 ;; Move whichever end is closer to the click.
912 ;; That's what xterm does, and it seems reasonable.
913 (if (< (abs (- click-posn (mark t)))
914 (abs (- click-posn (point))))
915 (set-mark (car range))
916 (goto-char (nth 1 range)))
917 ;; We have already put the old region in the kill ring.
918 ;; Replace it with the extended region.
919 ;; (It would be annoying to make a separate entry.)
920 (kill-new (buffer-substring (point) (mark t)) t)
922 ;; Arrange for a repeated mouse-3 to kill this region.
923 (setq mouse-save-then-kill-posn
924 (list (car kill-ring) (point) click-posn))
926 ;; If we click this button again without moving it,
928 (mouse-save-then-kill-delete-region (mark) (point))
929 (setq mouse-selection-click-count 0)
930 (setq mouse-save-then-kill-posn nil))
931 (if (and (eq last-command 'mouse-save-then-kill)
932 mouse-save-then-kill-posn
933 (eq (car mouse-save-then-kill-posn) (car kill-ring))
934 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
935 ;; If this is the second time we've called
936 ;; mouse-save-then-kill, delete the text from the buffer.
938 (mouse-save-then-kill-delete-region (point) (mark))
939 ;; After we kill, another click counts as "the first time".
940 (setq mouse-save-then-kill-posn nil))
941 ;; This is not a repetition.
942 ;; We are adjusting an old selection or creating a new one.
943 (if (or (and (eq last-command 'mouse-save-then-kill)
944 mouse-save-then-kill-posn)
945 (and mark-active transient-mark-mode)
946 (and (memq last-command
947 '(mouse-drag-region mouse-set-region))
948 (or mark-even-if-inactive
949 (not transient-mark-mode))))
950 ;; We have a selection or suitable region, so adjust it.
951 (let* ((posn (event-start click))
952 (new (posn-point posn)))
953 (select-window (posn-window posn))
956 ;; Move whichever end of the region is closer to the click.
957 ;; That is what xterm does, and it seems reasonable.
958 (if (< (abs (- new (point))) (abs (- new (mark t))))
961 (setq deactivate-mark nil)))
962 (kill-new (buffer-substring (point) (mark t)) t)
964 ;; Set the mark where point is, then move where clicked.
965 (mouse-set-mark-fast click)
967 (goto-char before-scroll))
968 (exchange-point-and-mark)
969 (kill-new (buffer-substring (point) (mark t)))
973 (setq mouse-save-then-kill-posn
974 (list (car kill-ring) (point) click-posn)))))))
976 (global-set-key [M-mouse-1] 'mouse-start-secondary)
977 (global-set-key [M-drag-mouse-1] 'mouse-set-secondary)
978 (global-set-key [M-down-mouse-1] 'mouse-drag-secondary)
979 (global-set-key [M-mouse-3] 'mouse-secondary-save-then-kill)
980 (global-set-key [M-mouse-2] 'mouse-yank-secondary)
982 ;; An overlay which records the current secondary selection
983 ;; or else is deleted when there is no secondary selection.
985 (defvar mouse-secondary-overlay nil)
987 (defvar mouse-secondary-click-count 0)
989 ;; A marker which records the specified first end for a secondary selection.
991 (defvar mouse-secondary-start nil)
993 (defun mouse-start-secondary (click)
994 "Set one end of the secondary selection to the position clicked on.
995 Use \\[mouse-secondary-save-then-kill] to set the other end
996 and complete the secondary selection."
998 (mouse-minibuffer-check click)
999 (let ((posn (event-start click)))
1001 (set-buffer (window-buffer (posn-window posn)))
1002 ;; Cancel any preexisting secondary selection.
1003 (if mouse-secondary-overlay
1004 (delete-overlay mouse-secondary-overlay))
1005 (if (numberp (posn-point posn))
1007 (or mouse-secondary-start
1008 (setq mouse-secondary-start (make-marker)))
1009 (move-marker mouse-secondary-start (posn-point posn)))))))
1011 (defun mouse-set-secondary (click)
1012 "Set the secondary selection to the text that the mouse is dragged over.
1013 This must be bound to a mouse drag event."
1015 (mouse-minibuffer-check click)
1016 (let ((posn (event-start click))
1018 (end (event-end click)))
1020 (set-buffer (window-buffer (posn-window posn)))
1021 (if (numberp (posn-point posn))
1022 (setq beg (posn-point posn)))
1023 (if mouse-secondary-overlay
1024 (move-overlay mouse-secondary-overlay beg (posn-point end))
1025 (setq mouse-secondary-overlay (make-overlay beg (posn-point end))))
1026 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))))
1028 (defun mouse-drag-secondary (start-event)
1029 "Set the secondary selection to the text that the mouse is dragged over.
1030 Highlight the drag area as you move the mouse.
1031 This must be bound to a button-down mouse event.
1032 The function returns a non-nil value if it creates a secondary selection."
1034 (mouse-minibuffer-check start-event)
1035 (let* ((echo-keystrokes 0)
1036 (start-posn (event-start start-event))
1037 (start-point (posn-point start-posn))
1038 (start-window (posn-window start-posn))
1039 (start-frame (window-frame start-window))
1040 (bounds (window-edges start-window))
1041 (top (nth 1 bounds))
1042 (bottom (if (window-minibuffer-p start-window)
1044 ;; Don't count the mode line.
1045 (1- (nth 3 bounds))))
1046 (click-count (1- (event-click-count start-event))))
1048 (set-buffer (window-buffer start-window))
1049 (setq mouse-secondary-click-count click-count)
1050 (or mouse-secondary-overlay
1051 (setq mouse-secondary-overlay
1052 (make-overlay (point) (point))))
1053 (overlay-put mouse-secondary-overlay 'face 'secondary-selection)
1054 (if (> (mod click-count 3) 0)
1055 ;; Double or triple press: make an initial selection
1056 ;; of one word or line.
1057 (let ((range (mouse-start-end start-point start-point click-count)))
1058 (set-marker mouse-secondary-start nil)
1059 (move-overlay mouse-secondary-overlay 1 1
1060 (window-buffer start-window))
1061 (move-overlay mouse-secondary-overlay (car range) (nth 1 range)
1062 (window-buffer start-window)))
1063 ;; Single-press: cancel any preexisting secondary selection.
1064 (or mouse-secondary-start
1065 (setq mouse-secondary-start (make-marker)))
1066 (set-marker mouse-secondary-start start-point)
1067 (delete-overlay mouse-secondary-overlay))
1068 (let (event end end-point)
1071 (setq event (read-event))
1072 (or (mouse-movement-p event)
1073 (eq (car-safe event) 'switch-frame)))
1075 (if (eq (car-safe event) 'switch-frame)
1077 (setq end (event-end event)
1078 end-point (posn-point end))
1080 ;; Are we moving within the original window?
1081 ((and (eq (posn-window end) start-window)
1082 (integer-or-marker-p end-point))
1083 (let ((range (mouse-start-end start-point end-point
1085 (if (or (/= start-point end-point)
1086 (null (marker-position mouse-secondary-start)))
1088 (set-marker mouse-secondary-start nil)
1089 (move-overlay mouse-secondary-overlay
1090 (car range) (nth 1 range))))))
1092 (let ((mouse-row (cdr (cdr (mouse-position)))))
1096 (mouse-scroll-subr start-window (- mouse-row top)
1097 mouse-secondary-overlay start-point))
1098 ((>= mouse-row bottom)
1099 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
1100 mouse-secondary-overlay start-point)))))))))
1103 (if (marker-position mouse-secondary-start)
1104 (save-window-excursion
1105 (delete-overlay mouse-secondary-overlay)
1106 (x-set-selection 'SECONDARY nil)
1107 (select-window start-window)
1109 (goto-char mouse-secondary-start)
1114 (buffer-substring (overlay-start mouse-secondary-overlay)
1115 (overlay-end mouse-secondary-overlay)))))))))
1117 (defun mouse-yank-secondary (click)
1118 "Insert the secondary selection at the position clicked on.
1119 Move point to the end of the inserted text.
1120 If `mouse-yank-at-point' is non-nil, insert at point
1121 regardless of where you click."
1123 ;; Give temporary modes such as isearch a chance to turn off.
1124 (run-hooks 'mouse-leave-buffer-hook)
1125 (or mouse-yank-at-point (mouse-set-point click))
1126 (insert (x-get-selection 'SECONDARY)))
1128 (defun mouse-kill-secondary ()
1129 "Kill the text in the secondary selection.
1130 This is intended more as a keyboard command than as a mouse command
1131 but it can work as either one.
1133 The current buffer (in case of keyboard use), or the buffer clicked on,
1134 must be the one that the secondary selection is in. This requirement
1135 is to prevent accidents."
1137 (let* ((keys (this-command-keys))
1138 (click (elt keys (1- (length keys)))))
1139 (or (eq (overlay-buffer mouse-secondary-overlay)
1141 (window-buffer (posn-window (event-start click)))
1143 (error "Select or click on the buffer where the secondary selection is")))
1146 (set-buffer (overlay-buffer mouse-secondary-overlay))
1147 (kill-region (overlay-start mouse-secondary-overlay)
1148 (overlay-end mouse-secondary-overlay))))
1149 (delete-overlay mouse-secondary-overlay)
1150 ;;; (x-set-selection 'SECONDARY nil)
1151 (setq mouse-secondary-overlay nil))
1153 (defun mouse-secondary-save-then-kill (click)
1154 "Save text to point in kill ring; the second time, kill the text.
1155 You must use this in a buffer where you have recently done \\[mouse-start-secondary].
1156 If the text between where you did \\[mouse-start-secondary] and where
1157 you use this command matches the text at the front of the kill ring,
1158 this command deletes the text.
1159 Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
1160 which prepares for a second click with this command to delete the text.
1162 If you have already made a secondary selection in that buffer,
1163 this command extends or retracts the selection to where you click.
1164 If you do this again in a different position, it extends or retracts
1165 again. If you do this twice in the same position, it kills the selection."
1167 (mouse-minibuffer-check click)
1168 (let ((posn (event-start click))
1169 (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 (or (eq (window-buffer (posn-window posn))
1174 (or (and mouse-secondary-overlay
1175 (overlay-buffer mouse-secondary-overlay))
1176 (if mouse-secondary-start
1177 (marker-buffer mouse-secondary-start))))
1178 (error "Wrong buffer"))
1180 (set-buffer (window-buffer (posn-window posn)))
1181 (if (> (mod mouse-secondary-click-count 3) 0)
1182 (if (not (and (eq last-command 'mouse-secondary-save-then-kill)
1184 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
1185 ;; Find both ends of the object selected by this click.
1187 (mouse-start-end click-posn click-posn
1188 mouse-secondary-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 (overlay-start mouse-secondary-overlay)))
1192 (abs (- click-posn (overlay-end mouse-secondary-overlay))))
1193 (move-overlay mouse-secondary-overlay (car range)
1194 (overlay-end mouse-secondary-overlay))
1195 (move-overlay mouse-secondary-overlay
1196 (overlay-start mouse-secondary-overlay)
1198 ;; We have already put the old region in the kill ring.
1199 ;; Replace it with the extended region.
1200 ;; (It would be annoying to make a separate entry.)
1201 (kill-new (buffer-substring
1202 (overlay-start mouse-secondary-overlay)
1203 (overlay-end mouse-secondary-overlay)) t)
1204 ;; Arrange for a repeated mouse-3 to kill this region.
1205 (setq mouse-save-then-kill-posn
1206 (list (car kill-ring) (point) click-posn)))
1207 ;; If we click this button again without moving it,
1210 (mouse-save-then-kill-delete-region
1211 (overlay-start mouse-secondary-overlay)
1212 (overlay-end mouse-secondary-overlay))
1213 (setq mouse-save-then-kill-posn nil)
1214 (setq mouse-secondary-click-count 0)
1215 (delete-overlay mouse-secondary-overlay)))
1216 (if (and (eq last-command 'mouse-secondary-save-then-kill)
1217 mouse-save-then-kill-posn
1218 (eq (car mouse-save-then-kill-posn) (car kill-ring))
1219 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
1220 ;; If this is the second time we've called
1221 ;; mouse-secondary-save-then-kill, delete the text from the buffer.
1223 (mouse-save-then-kill-delete-region
1224 (overlay-start mouse-secondary-overlay)
1225 (overlay-end mouse-secondary-overlay))
1226 (setq mouse-save-then-kill-posn nil)
1227 (delete-overlay mouse-secondary-overlay))
1228 (if (overlay-start mouse-secondary-overlay)
1229 ;; We have a selection, so adjust it.
1231 (if (numberp click-posn)
1233 ;; Move whichever end of the region is closer to the click.
1234 ;; That is what xterm does, and it seems reasonable.
1235 (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay)))
1236 (abs (- click-posn (overlay-end mouse-secondary-overlay))))
1237 (move-overlay mouse-secondary-overlay click-posn
1238 (overlay-end mouse-secondary-overlay))
1239 (move-overlay mouse-secondary-overlay
1240 (overlay-start mouse-secondary-overlay)
1242 (setq deactivate-mark nil)))
1243 (if (eq last-command 'mouse-secondary-save-then-kill)
1244 ;; If the front of the kill ring comes from
1245 ;; an immediately previous use of this command,
1246 ;; replace it with the extended region.
1247 ;; (It would be annoying to make a separate entry.)
1248 (kill-new (buffer-substring
1249 (overlay-start mouse-secondary-overlay)
1250 (overlay-end mouse-secondary-overlay)) t)
1251 (copy-region-as-kill (overlay-start mouse-secondary-overlay)
1252 (overlay-end mouse-secondary-overlay))))
1253 (if mouse-secondary-start
1254 ;; All we have is one end of a selection,
1255 ;; so put the other end here.
1256 (let ((start (+ 0 mouse-secondary-start)))
1257 (kill-ring-save start click-posn)
1258 (if mouse-secondary-overlay
1259 (move-overlay mouse-secondary-overlay start click-posn)
1260 (setq mouse-secondary-overlay (make-overlay start click-posn)))
1261 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))))
1262 (setq mouse-save-then-kill-posn
1263 (list (car kill-ring) (point) click-posn))))
1264 (if (overlay-buffer mouse-secondary-overlay)
1265 (x-set-selection 'SECONDARY
1267 (overlay-start mouse-secondary-overlay)
1268 (overlay-end mouse-secondary-overlay)))))))
1270 (defvar mouse-menu-buffer-maxlen 20
1271 "*Number of buffers in one pane (submenu) of the buffer menu.
1272 If we have lots of buffers, divide them into groups of
1273 `mouse-menu-buffer-maxlen' and make a pane (or submenu) for each one.")
1275 (defvar mouse-buffer-menu-mode-groups
1276 '(("Info\\|Help\\|Apropos\\|Man" . "Help")
1277 ("\\bVM\\b\\|\\bMH\\b\\|Message\\|Mail\\|Group\\|Score\\|Summary\\|Article"
1282 ("Outline" . "Text")
1284 "How to group various major modes together in \\[mouse-buffer-menu].
1285 Each element has the form (REGEXP . GROUPNAME).
1286 If the major mode's name string matches REGEXP, use GROUPNAME instead.")
1288 (defun mouse-buffer-menu (event)
1289 "Pop up a menu of buffers for selection with the mouse.
1290 This switches buffers in the window that you clicked on,
1291 and selects that window."
1293 (mouse-minibuffer-check event)
1294 (let (buffers alist menu split-by-major-mode sum-of-squares)
1295 (setq buffers (buffer-list))
1296 ;; Make an alist of elements that look like (MENU-ITEM . BUFFER).
1297 (let ((tail buffers))
1299 ;; Divide all buffers into buckets for various major modes.
1300 ;; Each bucket looks like (MODE NAMESTRING BUFFERS...).
1301 (with-current-buffer (car tail)
1302 (let* ((adjusted-major-mode major-mode) elt)
1303 (let ((tail mouse-buffer-menu-mode-groups))
1305 (if (string-match (car (car tail)) mode-name)
1306 (setq adjusted-major-mode (cdr (car tail))))
1307 (setq tail (cdr tail))))
1308 (setq elt (assoc adjusted-major-mode split-by-major-mode))
1310 (setq elt (list adjusted-major-mode
1311 (if (stringp adjusted-major-mode)
1314 split-by-major-mode (cons elt split-by-major-mode)))
1315 (or (memq (car tail) (cdr (cdr elt)))
1316 (setcdr (cdr elt) (cons (car tail) (cdr (cdr elt)))))))
1317 (setq tail (cdr tail))))
1318 ;; Compute the sum of squares of sizes of the major-mode buckets.
1319 (let ((tail split-by-major-mode))
1320 (setq sum-of-squares 0)
1322 (setq sum-of-squares
1324 (* (length (cdr (cdr (car tail))))
1325 (length (cdr (cdr (car tail)))))))
1326 (setq tail (cdr tail))))
1327 (if (< (* sum-of-squares 4) (* (length buffers) (length buffers)))
1328 ;; Subdividing by major modes really helps, so let's do it.
1329 (let (subdivided-menus (buffers-left (length buffers)))
1330 ;; Sort the list to put the most popular major modes first.
1331 (setq split-by-major-mode
1332 (sort split-by-major-mode
1333 (function (lambda (elt1 elt2)
1334 (> (length elt1) (length elt2))))))
1335 ;; Make a separate submenu for each major mode
1336 ;; that has more than one buffer,
1337 ;; unless all the remaining buffers are less than 1/10 of them.
1338 (while (and split-by-major-mode
1339 (and (> (length (car split-by-major-mode)) 3)
1340 (> (* buffers-left 10) (length buffers))))
1341 (setq subdivided-menus
1343 (nth 1 (car split-by-major-mode))
1344 (mouse-buffer-menu-alist
1345 (cdr (cdr (car split-by-major-mode)))))
1348 (- buffers-left (length (cdr (car split-by-major-mode)))))
1349 (setq split-by-major-mode (cdr split-by-major-mode)))
1350 ;; If any major modes are left over,
1351 ;; make a single submenu for them.
1352 (if split-by-major-mode
1353 (setq subdivided-menus
1356 (mouse-buffer-menu-alist
1359 (mapcar 'cdr split-by-major-mode)))))
1361 (setq subdivided-menus
1362 (nreverse subdivided-menus))
1363 (setq menu (cons "Buffer Menu" subdivided-menus)))
1365 (setq alist (mouse-buffer-menu-alist buffers))
1366 (setq menu (cons "Buffer Menu"
1367 (mouse-buffer-menu-split "Select Buffer" alist)))))
1368 (let ((buf (x-popup-menu event menu))
1369 (window (posn-window (event-start event))))
1372 (or (framep window) (select-window window))
1373 (switch-to-buffer buf))))))
1375 (defun mouse-buffer-menu-alist (buffers)
1381 (function (lambda (elt1 elt2)
1382 (string< (buffer-name elt1) (buffer-name elt2))))))
1385 (or (eq ?\ (aref (buffer-name (car tail)) 0))
1388 (length (buffer-name (car tail))))))
1389 (setq tail (cdr tail)))
1392 (let ((elt (car tail)))
1393 (if (/= (aref (buffer-name elt) 0) ?\ )
1398 (format "%%%ds %%s%%s %%s" maxlen)
1400 (if (buffer-modified-p elt) "*" " ")
1403 (if buffer-read-only "%" " "))
1404 (or (buffer-file-name elt)
1407 (if list-buffers-directory
1409 list-buffers-directory)))
1413 (setq tail (cdr tail)))
1414 ;; Compensate for the reversal that the above loop does.
1417 (defun mouse-buffer-menu-split (title alist)
1418 ;; If we have lots of buffers, divide them into groups of 20
1419 ;; and make a pane (or submenu) for each one.
1420 (if (> (length alist) (/ (* mouse-menu-buffer-maxlen 3) 2))
1421 (let ((alist alist) sublists next
1424 ;; Pull off the next mouse-menu-buffer-maxlen buffers
1425 ;; and make them the next element of sublist.
1426 (setq next (nthcdr mouse-menu-buffer-maxlen alist))
1428 (setcdr (nthcdr (1- mouse-menu-buffer-maxlen) alist)
1430 (setq sublists (cons (cons (format "Buffers %d" i) alist)
1434 (nreverse sublists))
1435 ;; Few buffers--put them all in one pane.
1436 (list (cons title alist))))
1438 ;;; These need to be rewritten for the new scroll bar implementation.
1440 ;;;!! ;; Commands for the scroll bar.
1442 ;;;!! (defun mouse-scroll-down (click)
1443 ;;;!! (interactive "@e")
1444 ;;;!! (scroll-down (1+ (cdr (mouse-coords click)))))
1446 ;;;!! (defun mouse-scroll-up (click)
1447 ;;;!! (interactive "@e")
1448 ;;;!! (scroll-up (1+ (cdr (mouse-coords click)))))
1450 ;;;!! (defun mouse-scroll-down-full ()
1451 ;;;!! (interactive "@")
1452 ;;;!! (scroll-down nil))
1454 ;;;!! (defun mouse-scroll-up-full ()
1455 ;;;!! (interactive "@")
1456 ;;;!! (scroll-up nil))
1458 ;;;!! (defun mouse-scroll-move-cursor (click)
1459 ;;;!! (interactive "@e")
1460 ;;;!! (move-to-window-line (1+ (cdr (mouse-coords click)))))
1462 ;;;!! (defun mouse-scroll-absolute (event)
1463 ;;;!! (interactive "@e")
1464 ;;;!! (let* ((pos (car event))
1465 ;;;!! (position (car pos))
1466 ;;;!! (length (car (cdr pos))))
1467 ;;;!! (if (<= length 0) (setq length 1))
1468 ;;;!! (let* ((scale-factor (max 1 (/ length (/ 8000000 (buffer-size)))))
1469 ;;;!! (newpos (* (/ (* (/ (buffer-size) scale-factor)
1472 ;;;!! scale-factor)))
1473 ;;;!! (goto-char newpos)
1474 ;;;!! (recenter '(4)))))
1476 ;;;!! (defun mouse-scroll-left (click)
1477 ;;;!! (interactive "@e")
1478 ;;;!! (scroll-left (1+ (car (mouse-coords click)))))
1480 ;;;!! (defun mouse-scroll-right (click)
1481 ;;;!! (interactive "@e")
1482 ;;;!! (scroll-right (1+ (car (mouse-coords click)))))
1484 ;;;!! (defun mouse-scroll-left-full ()
1485 ;;;!! (interactive "@")
1486 ;;;!! (scroll-left nil))
1488 ;;;!! (defun mouse-scroll-right-full ()
1489 ;;;!! (interactive "@")
1490 ;;;!! (scroll-right nil))
1492 ;;;!! (defun mouse-scroll-move-cursor-horizontally (click)
1493 ;;;!! (interactive "@e")
1494 ;;;!! (move-to-column (1+ (car (mouse-coords click)))))
1496 ;;;!! (defun mouse-scroll-absolute-horizontally (event)
1497 ;;;!! (interactive "@e")
1498 ;;;!! (let* ((pos (car event))
1499 ;;;!! (position (car pos))
1500 ;;;!! (length (car (cdr pos))))
1501 ;;;!! (set-window-hscroll (selected-window) 33)))
1503 ;;;!! (global-set-key [scroll-bar mouse-1] 'mouse-scroll-up)
1504 ;;;!! (global-set-key [scroll-bar mouse-2] 'mouse-scroll-absolute)
1505 ;;;!! (global-set-key [scroll-bar mouse-3] 'mouse-scroll-down)
1507 ;;;!! (global-set-key [vertical-slider mouse-1] 'mouse-scroll-move-cursor)
1508 ;;;!! (global-set-key [vertical-slider mouse-2] 'mouse-scroll-move-cursor)
1509 ;;;!! (global-set-key [vertical-slider mouse-3] 'mouse-scroll-move-cursor)
1511 ;;;!! (global-set-key [thumbup mouse-1] 'mouse-scroll-up-full)
1512 ;;;!! (global-set-key [thumbup mouse-2] 'mouse-scroll-up-full)
1513 ;;;!! (global-set-key [thumbup mouse-3] 'mouse-scroll-up-full)
1515 ;;;!! (global-set-key [thumbdown mouse-1] 'mouse-scroll-down-full)
1516 ;;;!! (global-set-key [thumbdown mouse-2] 'mouse-scroll-down-full)
1517 ;;;!! (global-set-key [thumbdown mouse-3] 'mouse-scroll-down-full)
1519 ;;;!! (global-set-key [horizontal-scroll-bar mouse-1] 'mouse-scroll-left)
1520 ;;;!! (global-set-key [horizontal-scroll-bar mouse-2]
1521 ;;;!! 'mouse-scroll-absolute-horizontally)
1522 ;;;!! (global-set-key [horizontal-scroll-bar mouse-3] 'mouse-scroll-right)
1524 ;;;!! (global-set-key [horizontal-slider mouse-1]
1525 ;;;!! 'mouse-scroll-move-cursor-horizontally)
1526 ;;;!! (global-set-key [horizontal-slider mouse-2]
1527 ;;;!! 'mouse-scroll-move-cursor-horizontally)
1528 ;;;!! (global-set-key [horizontal-slider mouse-3]
1529 ;;;!! 'mouse-scroll-move-cursor-horizontally)
1531 ;;;!! (global-set-key [thumbleft mouse-1] 'mouse-scroll-left-full)
1532 ;;;!! (global-set-key [thumbleft mouse-2] 'mouse-scroll-left-full)
1533 ;;;!! (global-set-key [thumbleft mouse-3] 'mouse-scroll-left-full)
1535 ;;;!! (global-set-key [thumbright mouse-1] 'mouse-scroll-right-full)
1536 ;;;!! (global-set-key [thumbright mouse-2] 'mouse-scroll-right-full)
1537 ;;;!! (global-set-key [thumbright mouse-3] 'mouse-scroll-right-full)
1539 ;;;!! (global-set-key [horizontal-scroll-bar S-mouse-2]
1540 ;;;!! 'mouse-split-window-horizontally)
1541 ;;;!! (global-set-key [mode-line S-mouse-2]
1542 ;;;!! 'mouse-split-window-horizontally)
1543 ;;;!! (global-set-key [vertical-scroll-bar S-mouse-2]
1544 ;;;!! 'mouse-split-window)
1547 ;;;!! ;;;; Here are experimental things being tested. Mouse events
1548 ;;;!! ;;;; are of the form:
1549 ;;;!! ;;;; ((x y) window screen-part key-sequence timestamp)
1552 ;;;!! ;;;; Dynamically track mouse coordinates
1555 ;;;!! ;;(defun track-mouse (event)
1556 ;;;!! ;; "Track the coordinates, absolute and relative, of the mouse."
1557 ;;;!! ;; (interactive "@e")
1558 ;;;!! ;; (while mouse-grabbed
1559 ;;;!! ;; (let* ((pos (read-mouse-position (selected-screen)))
1560 ;;;!! ;; (abs-x (car pos))
1561 ;;;!! ;; (abs-y (cdr pos))
1562 ;;;!! ;; (relative-coordinate (coordinates-in-window-p
1563 ;;;!! ;; (list (car pos) (cdr pos))
1564 ;;;!! ;; (selected-window))))
1565 ;;;!! ;; (if (consp relative-coordinate)
1566 ;;;!! ;; (message "mouse: [%d %d], (%d %d)" abs-x abs-y
1567 ;;;!! ;; (car relative-coordinate)
1568 ;;;!! ;; (car (cdr relative-coordinate)))
1569 ;;;!! ;; (message "mouse: [%d %d]" abs-x abs-y)))))
1572 ;;;!! ;; Dynamically put a box around the line indicated by point
1575 ;;;!! ;;(require 'backquote)
1577 ;;;!! ;;(defun mouse-select-buffer-line (event)
1578 ;;;!! ;; (interactive "@e")
1579 ;;;!! ;; (let ((relative-coordinate
1580 ;;;!! ;; (coordinates-in-window-p (car event) (selected-window)))
1581 ;;;!! ;; (abs-y (car (cdr (car event)))))
1582 ;;;!! ;; (if (consp relative-coordinate)
1584 ;;;!! ;; (save-excursion
1585 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1586 ;;;!! ;; (x-draw-rectangle
1587 ;;;!! ;; (selected-screen)
1589 ;;;!! ;; (save-excursion
1590 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1591 ;;;!! ;; (end-of-line)
1592 ;;;!! ;; (push-mark nil t)
1593 ;;;!! ;; (beginning-of-line)
1594 ;;;!! ;; (- (region-end) (region-beginning))) 1))
1595 ;;;!! ;; (sit-for 1)
1596 ;;;!! ;; (x-erase-rectangle (selected-screen))))))
1598 ;;;!! ;;(defvar last-line-drawn nil)
1599 ;;;!! ;;(defvar begin-delim "[^ \t]")
1600 ;;;!! ;;(defvar end-delim "[^ \t]")
1602 ;;;!! ;;(defun mouse-boxing (event)
1603 ;;;!! ;; (interactive "@e")
1604 ;;;!! ;; (save-excursion
1605 ;;;!! ;; (let ((screen (selected-screen)))
1606 ;;;!! ;; (while (= (x-mouse-events) 0)
1607 ;;;!! ;; (let* ((pos (read-mouse-position screen))
1608 ;;;!! ;; (abs-x (car pos))
1609 ;;;!! ;; (abs-y (cdr pos))
1610 ;;;!! ;; (relative-coordinate
1611 ;;;!! ;; (coordinates-in-window-p (` ((, abs-x) (, abs-y)))
1612 ;;;!! ;; (selected-window)))
1613 ;;;!! ;; (begin-reg nil)
1614 ;;;!! ;; (end-reg nil)
1615 ;;;!! ;; (end-column nil)
1616 ;;;!! ;; (begin-column nil))
1617 ;;;!! ;; (if (and (consp relative-coordinate)
1618 ;;;!! ;; (or (not last-line-drawn)
1619 ;;;!! ;; (not (= last-line-drawn abs-y))))
1621 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1622 ;;;!! ;; (if (= (following-char) 10)
1625 ;;;!! ;; (setq begin-reg (1- (re-search-forward end-delim)))
1626 ;;;!! ;; (setq begin-column (1- (current-column)))
1627 ;;;!! ;; (end-of-line)
1628 ;;;!! ;; (setq end-reg (1+ (re-search-backward begin-delim)))
1629 ;;;!! ;; (setq end-column (1+ (current-column)))
1630 ;;;!! ;; (message "%s" (buffer-substring begin-reg end-reg))
1631 ;;;!! ;; (x-draw-rectangle screen
1632 ;;;!! ;; (setq last-line-drawn abs-y)
1633 ;;;!! ;; begin-column
1634 ;;;!! ;; (- end-column begin-column) 1))))))))))
1636 ;;;!! ;;(defun mouse-erase-box ()
1637 ;;;!! ;; (interactive)
1638 ;;;!! ;; (if last-line-drawn
1640 ;;;!! ;; (x-erase-rectangle (selected-screen))
1641 ;;;!! ;; (setq last-line-drawn nil))))
1643 ;;;!! ;;; (defun test-x-rectangle ()
1644 ;;;!! ;;; (use-local-mouse-map (setq rectangle-test-map (make-sparse-keymap)))
1645 ;;;!! ;;; (define-key rectangle-test-map mouse-motion-button-left 'mouse-boxing)
1646 ;;;!! ;;; (define-key rectangle-test-map mouse-button-left-up 'mouse-erase-box))
1649 ;;;!! ;; Here is how to do double clicking in lisp. About to change.
1652 ;;;!! (defvar double-start nil)
1653 ;;;!! (defconst double-click-interval 300
1654 ;;;!! "Max ticks between clicks")
1656 ;;;!! (defun double-down (event)
1657 ;;;!! (interactive "@e")
1658 ;;;!! (if double-start
1659 ;;;!! (let ((interval (- (nth 4 event) double-start)))
1660 ;;;!! (if (< interval double-click-interval)
1662 ;;;!! (backward-up-list 1)
1663 ;;;!! ;; (message "Interval %d" interval)
1664 ;;;!! (sleep-for 1)))
1665 ;;;!! (setq double-start nil))
1666 ;;;!! (setq double-start (nth 4 event))))
1668 ;;;!! (defun double-up (event)
1669 ;;;!! (interactive "@e")
1670 ;;;!! (and double-start
1671 ;;;!! (> (- (nth 4 event ) double-start) double-click-interval)
1672 ;;;!! (setq double-start nil)))
1674 ;;;!! ;;; (defun x-test-doubleclick ()
1675 ;;;!! ;;; (use-local-mouse-map (setq doubleclick-test-map (make-sparse-keymap)))
1676 ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left 'double-down)
1677 ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left-up 'double-up))
1680 ;;;!! ;; This scrolls while button is depressed. Use preferable in scroll bar.
1683 ;;;!! (defvar scrolled-lines 0)
1684 ;;;!! (defconst scroll-speed 1)
1686 ;;;!! (defun incr-scroll-down (event)
1687 ;;;!! (interactive "@e")
1688 ;;;!! (setq scrolled-lines 0)
1689 ;;;!! (incremental-scroll scroll-speed))
1691 ;;;!! (defun incr-scroll-up (event)
1692 ;;;!! (interactive "@e")
1693 ;;;!! (setq scrolled-lines 0)
1694 ;;;!! (incremental-scroll (- scroll-speed)))
1696 ;;;!! (defun incremental-scroll (n)
1697 ;;;!! (while (= (x-mouse-events) 0)
1698 ;;;!! (setq scrolled-lines (1+ (* scroll-speed scrolled-lines)))
1699 ;;;!! (scroll-down n)
1700 ;;;!! (sit-for 300 t)))
1702 ;;;!! (defun incr-scroll-stop (event)
1703 ;;;!! (interactive "@e")
1704 ;;;!! (message "Scrolled %d lines" scrolled-lines)
1705 ;;;!! (setq scrolled-lines 0)
1706 ;;;!! (sleep-for 1))
1708 ;;;!! ;;; (defun x-testing-scroll ()
1709 ;;;!! ;;; (let ((scrolling-map (function mouse-vertical-scroll-bar-prefix)))
1710 ;;;!! ;;; (define-key scrolling-map mouse-button-left 'incr-scroll-down)
1711 ;;;!! ;;; (define-key scrolling-map mouse-button-right 'incr-scroll-up)
1712 ;;;!! ;;; (define-key scrolling-map mouse-button-left-up 'incr-scroll-stop)
1713 ;;;!! ;;; (define-key scrolling-map mouse-button-right-up 'incr-scroll-stop)))
1716 ;;;!! ;; Some playthings suitable for picture mode? They need work.
1719 ;;;!! (defun mouse-kill-rectangle (event)
1720 ;;;!! "Kill the rectangle between point and the mouse cursor."
1721 ;;;!! (interactive "@e")
1722 ;;;!! (let ((point-save (point)))
1723 ;;;!! (save-excursion
1724 ;;;!! (mouse-set-point event)
1725 ;;;!! (push-mark nil t)
1726 ;;;!! (if (> point-save (point))
1727 ;;;!! (kill-rectangle (point) point-save)
1728 ;;;!! (kill-rectangle point-save (point))))))
1730 ;;;!! (defun mouse-open-rectangle (event)
1731 ;;;!! "Kill the rectangle between point and the mouse cursor."
1732 ;;;!! (interactive "@e")
1733 ;;;!! (let ((point-save (point)))
1734 ;;;!! (save-excursion
1735 ;;;!! (mouse-set-point event)
1736 ;;;!! (push-mark nil t)
1737 ;;;!! (if (> point-save (point))
1738 ;;;!! (open-rectangle (point) point-save)
1739 ;;;!! (open-rectangle point-save (point))))))
1741 ;;;!! ;; Must be a better way to do this.
1743 ;;;!! (defun mouse-multiple-insert (n char)
1744 ;;;!! (while (> n 0)
1746 ;;;!! (setq n (1- n))))
1748 ;;;!! ;; What this could do is not finalize until button was released.
1750 ;;;!! (defun mouse-move-text (event)
1751 ;;;!! "Move text from point to cursor position, inserting spaces."
1752 ;;;!! (interactive "@e")
1753 ;;;!! (let* ((relative-coordinate
1754 ;;;!! (coordinates-in-window-p (car event) (selected-window))))
1755 ;;;!! (if (consp relative-coordinate)
1756 ;;;!! (cond ((> (current-column) (car relative-coordinate))
1758 ;;;!! (- (car relative-coordinate) (current-column))))
1759 ;;;!! ((< (current-column) (car relative-coordinate))
1760 ;;;!! (mouse-multiple-insert
1761 ;;;!! (- (car relative-coordinate) (current-column)) " "))
1762 ;;;!! ((= (current-column) (car relative-coordinate)) (ding))))))
1764 ;; Choose a completion with the mouse.
1766 (defun mouse-choose-completion (event)
1767 "Click on an alternative in the `*Completions*' buffer to choose it."
1769 ;; Give temporary modes such as isearch a chance to turn off.
1770 (run-hooks 'mouse-leave-buffer-hook)
1771 (let ((buffer (window-buffer))
1775 (set-buffer (window-buffer (posn-window (event-start event))))
1776 (if completion-reference-buffer
1777 (setq buffer completion-reference-buffer))
1778 (setq base-size completion-base-size)
1780 (goto-char (posn-point (event-start event)))
1782 (if (and (not (eobp)) (get-text-property (point) 'mouse-face))
1783 (setq end (point) beg (1+ (point))))
1785 (error "No completion here"))
1786 (setq beg (previous-single-property-change beg 'mouse-face))
1787 (setq end (or (next-single-property-change end 'mouse-face)
1789 (setq choice (buffer-substring beg end)))))
1790 (let ((owindow (selected-window)))
1791 (select-window (posn-window (event-start event)))
1792 (if (and (one-window-p t 'selected-frame)
1793 (window-dedicated-p (selected-window)))
1794 ;; This is a special buffer's frame
1795 (iconify-frame (selected-frame))
1796 (or (window-dedicated-p (selected-window))
1798 (select-window owindow))
1799 (choose-completion-string choice buffer base-size)))
1803 (defun font-menu-add-default ()
1804 (let* ((default (cdr (assq 'font (frame-parameters (selected-frame)))))
1805 (font-alist x-fixed-font-alist)
1806 (elt (or (assoc "Misc" font-alist) (nth 1 font-alist))))
1807 (if (assoc "Default" elt)
1808 (delete (assoc "Default" elt) elt))
1810 (cons (list "Default"
1811 (cdr (assq 'font (frame-parameters (selected-frame)))))
1814 (defvar x-fixed-font-alist
1817 ;; For these, we specify the pixel height and width.
1819 ("6x10" "-misc-fixed-medium-r-normal--10-*-*-*-c-60-iso8859-1" "6x10")
1821 "-misc-fixed-medium-r-semicondensed--12-*-*-*-c-60-iso8859-1" "6x12")
1823 "-misc-fixed-medium-r-semicondensed--13-*-*-*-c-60-iso8859-1" "6x13")
1824 ("7x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-70-iso8859-1" "7x13")
1825 ("7x14" "-misc-fixed-medium-r-normal--14-*-*-*-c-70-iso8859-1" "7x14")
1826 ("8x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-80-iso8859-1" "8x13")
1827 ("9x15" "-misc-fixed-medium-r-normal--15-*-*-*-c-90-iso8859-1" "9x15")
1828 ("10x20" "-misc-fixed-medium-r-normal--20-*-*-*-c-100-iso8859-1" "10x20")
1829 ("11x18" "-misc-fixed-medium-r-normal--18-*-*-*-c-110-iso8859-1" "11x18")
1830 ("12x24" "-misc-fixed-medium-r-normal--24-*-*-*-c-120-iso8859-1" "12x24")
1833 "-schumacher-clean-medium-r-normal--8-*-*-*-c-50-iso8859-1")
1835 "-schumacher-clean-medium-r-normal--8-*-*-*-c-60-iso8859-1")
1837 "-schumacher-clean-medium-r-normal--8-*-*-*-c-80-iso8859-1")
1839 "-schumacher-clean-medium-r-normal--10-*-*-*-c-80-iso8859-1")
1841 "-schumacher-clean-medium-r-normal--14-*-*-*-c-80-iso8859-1")
1843 "-schumacher-clean-medium-r-normal--16-*-*-*-c-80-iso8859-1")
1845 ("sony 8x16" "-sony-fixed-medium-r-normal--16-*-*-*-c-80-iso8859-1"))
1846 ;;; We don't seem to have these; who knows what they are.
1847 ;;; ("fg-18" "fg-18")
1848 ;;; ("fg-25" "fg-25")
1849 ;;; ("lucidasanstypewriter-12" "lucidasanstypewriter-12")
1850 ;;; ("lucidasanstypewriter-bold-14" "lucidasanstypewriter-bold-14")
1851 ;;; ("lucidasanstypewriter-bold-24" "lucidasanstypewriter-bold-24")
1852 ;;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
1853 ;;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
1855 ;; For these, we specify the point height.
1856 ("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1")
1857 ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1")
1858 ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1")
1859 ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1")
1860 ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1")
1861 ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1")
1862 ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1")
1863 ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1")
1864 ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1")
1865 ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1")
1866 ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1")
1867 ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1")
1868 ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1")
1869 ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1")
1870 ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1")
1871 ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1")
1872 ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1")
1873 ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1")
1874 ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1")
1875 ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1")
1876 ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1")
1877 ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1")
1878 ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1")
1879 ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1"))
1881 "X fonts suitable for use in Emacs.")
1883 (defun mouse-set-font (&rest fonts)
1884 "Select an emacs font from a list of known good fonts and fontsets."
1888 ;; Append list of fontsets currently defined.
1889 (append x-fixed-font-alist (list (generate-fontset-menu)))))
1895 (set-default-font (car fonts))
1896 (setq font (car fonts))
1899 (setq fonts (cdr fonts)))))
1901 (error "Font not found")))))
1903 ;;; Bindings for mouse commands.
1905 (define-key global-map [down-mouse-1] 'mouse-drag-region)
1906 (global-set-key [mouse-1] 'mouse-set-point)
1907 (global-set-key [drag-mouse-1] 'mouse-set-region)
1909 ;; These are tested for in mouse-drag-region.
1910 (global-set-key [double-mouse-1] 'mouse-set-point)
1911 (global-set-key [triple-mouse-1] 'mouse-set-point)
1913 (global-set-key [mouse-2] 'mouse-yank-at-click)
1914 (global-set-key [mouse-3] 'mouse-save-then-kill)
1916 ;; By binding these to down-going events, we let the user use the up-going
1917 ;; event to make the selection, saving a click.
1918 (global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
1919 (if (not (eq system-type 'ms-dos))
1920 (global-set-key [S-down-mouse-1] 'mouse-set-font))
1921 ;; C-down-mouse-2 is bound in facemenu.el.
1922 (global-set-key [C-down-mouse-3] 'mouse-major-mode-menu)
1925 ;; Replaced with dragging mouse-1
1926 ;; (global-set-key [S-mouse-1] 'mouse-set-mark)
1928 (global-set-key [mode-line mouse-1] 'mouse-select-window)
1929 (global-set-key [mode-line drag-mouse-1] 'mouse-select-window)
1930 (global-set-key [mode-line down-mouse-1] 'mouse-drag-mode-line)
1931 (global-set-key [mode-line mouse-2] 'mouse-delete-other-windows)
1932 (global-set-key [mode-line mouse-3] 'mouse-delete-window)
1933 (global-set-key [mode-line C-mouse-2] 'mouse-split-window-horizontally)
1934 (global-set-key [vertical-scroll-bar C-mouse-2] 'mouse-split-window-vertically)
1935 (global-set-key [vertical-line C-mouse-2] 'mouse-split-window-vertically)
1936 (global-set-key [vertical-line down-mouse-1] 'mouse-drag-vertical-line)
1937 (global-set-key [vertical-line mouse-1] 'mouse-select-window)
1941 ;;; mouse.el ends here