1 ;;; mouse.el --- window system-independent mouse support.
3 ;;; Copyright (C) 1993 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)
13 ;;; any later version.
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
22 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 ;; This package provides various useful commands (including help
27 ;; system access) through the mouse. All this code assumes that mouse
28 ;; interpretation has been abstracted into Emacs input events.
30 ;; The code is rather X-dependent.
34 ;;; Utility functions.
36 ;;; Indent track-mouse like progn.
37 (put 'track-mouse
'lisp-indent-function
0)
39 (defvar mouse-yank-at-point nil
40 "*If non-nil, mouse yank commands yank at point instead of at click.")
42 (defun mouse-delete-window (click)
43 "Delete the window you click on.
44 This must be bound to a mouse click."
46 (delete-window (posn-window (event-start click
))))
48 (defun mouse-tear-off-window (click)
49 "Delete the window clicked on, and create a new frame displaying its buffer."
51 (let* ((window (posn-window (event-start click
)))
52 (buf (window-buffer window
))
55 (switch-to-buffer buf
)
56 (delete-window window
)))
58 (defun mouse-delete-other-windows ()
59 "Delete all window except the one you click on."
61 (delete-other-windows))
63 (defun mouse-split-window-vertically (click)
64 "Select Emacs window mouse is on, then split it vertically in half.
65 The window is split at the line clicked on.
66 This command must be bound to a mouse click."
68 (let ((start (event-start click
)))
69 (select-window (posn-window start
))
70 (let ((new-height (if (eq (posn-point start
) 'vertical-scroll-bar
)
71 (scroll-bar-scale (posn-col-row start
)
73 (1+ (cdr (posn-col-row (event-end click
))))))
74 (first-line window-min-height
)
75 (last-line (- (window-height) window-min-height
)))
76 (if (< last-line first-line
)
77 (error "window too short to split")
78 (split-window-vertically
79 (min (max new-height first-line
) last-line
))))))
81 (defun mouse-split-window-horizontally (click)
82 "Select Emacs window mouse is on, then split it horizontally in half.
83 The window is split at the column clicked on.
84 This command must be bound to a mouse click."
86 (let ((start (event-start click
)))
87 (select-window (posn-window start
))
88 (let ((new-width (1+ (car (posn-col-row (event-end click
)))))
89 (first-col window-min-width
)
90 (last-col (- (window-width) window-min-width
)))
91 (if (< last-col first-col
)
92 (error "window too narrow to split")
93 (split-window-horizontally
94 (min (max new-width first-col
) last-col
))))))
96 (defun mouse-set-point (event)
97 "Move point to the position clicked on with the mouse.
98 This should be bound to a mouse click event type."
100 ;; Use event-end in case called from mouse-drag-region.
101 ;; If EVENT is a click, event-end and event-start give same value.
102 (let ((posn (event-end event
)))
103 (and (window-minibuffer-p (posn-window posn
))
104 (not (minibuffer-window-active-p (posn-window posn
)))
105 (error "Minibuffer window is not active"))
106 (select-window (posn-window posn
))
107 (if (numberp (posn-point posn
))
108 (goto-char (posn-point posn
)))))
110 (defun mouse-set-region (click)
111 "Set the region to the text dragged over, and copy to kill ring.
112 This should be bound to a mouse drag event."
114 (let ((posn (event-start click
))
115 (end (event-end click
)))
116 (select-window (posn-window posn
))
117 (if (numberp (posn-point posn
))
118 (goto-char (posn-point posn
)))
119 ;; If mark is highlighted, no need to bounce the cursor.
120 (or (and transient-mark-mode
121 (eq (framep (selected-frame)) 'x
))
125 (if (numberp (posn-point end
))
126 (goto-char (posn-point end
)))
127 ;; Don't set this-command to kill-region, so that a following
128 ;; C-w will not double the text in the kill ring.
130 (copy-region-as-kill (mark) (point)))))
132 (defvar mouse-scroll-delay
0.25
133 "*The pause between scroll steps caused by mouse drags, in seconds.
134 If you drag the mouse beyond the edge of a window, Emacs scrolls the
135 window to bring the text beyond that edge into view, with a delay of
136 this many seconds between scroll steps. Scrolling stops when you move
137 the mouse back into the window, or release the button.
138 This variable's value may be non-integral.
139 Setting this to zero causes Emacs to scroll as fast as it can.")
141 (defun mouse-scroll-subr (jump &optional overlay start
)
142 "Scroll the selected window JUMP lines at a time, until new input arrives.
143 If OVERLAY is an overlay, let it stretch from START to the far edge of
144 the newly visible text.
145 Upon exit, point is at the far edge of the newly visible text."
147 (goto-char (window-start))
148 (if (not (zerop (vertical-motion jump
)))
150 (set-window-start (selected-window) (point))
153 (goto-char (window-end (selected-window)))
154 ;; window-end doesn't reflect the window's new
155 ;; start position until the next redisplay. Hurrah.
156 (vertical-motion (1- jump
)))
157 (goto-char (window-start (selected-window))))
159 (move-overlay overlay start
(point)))
161 (sit-for mouse-scroll-delay
))))))
164 (defvar mouse-drag-overlay
(make-overlay 1 1))
165 (overlay-put mouse-drag-overlay
'face
'region
)
167 (defvar mouse-selection-click-count
0)
169 (defun mouse-drag-region (start-event)
170 "Set the region to the text that the mouse is dragged over.
171 Highlight the drag area as you move the mouse.
172 This must be bound to a button-down mouse event.
173 In Transient Mark mode, the highlighting remains once you
174 release the mouse button. Otherwise, it does not."
176 (let* ((start-posn (event-start start-event
))
177 (start-point (posn-point start-posn
))
178 (start-window (posn-window start-posn
))
179 (start-frame (window-frame start-window
))
180 (bounds (window-edges start-window
))
182 (bottom (if (window-minibuffer-p start-window
)
184 ;; Don't count the mode line.
185 (1- (nth 3 bounds
))))
186 (click-count (1- (event-click-count start-event
))))
187 (setq mouse-selection-click-count click-count
)
188 (mouse-set-point start-event
)
189 (let ((range (mouse-start-end start-point start-point click-count
)))
190 (move-overlay mouse-drag-overlay
(car range
) (nth 1 range
)
191 (window-buffer start-window
)))
193 (let (event end end-point
)
196 (setq event
(read-event))
197 (or (mouse-movement-p event
)
198 (eq (car-safe event
) 'switch-frame
)))
199 (if (eq (car-safe event
) 'switch-frame
)
201 (setq end
(event-end event
)
202 end-point
(posn-point end
))
206 ;; Ignore switch-frame events.
207 ((eq (car-safe event
) 'switch-frame
))
209 ;; Are we moving within the original window?
210 ((and (eq (posn-window end
) start-window
)
211 (integer-or-marker-p end-point
))
212 (goto-char end-point
)
213 (let ((range (mouse-start-end start-point
(point) click-count
)))
214 (move-overlay mouse-drag-overlay
(car range
) (nth 1 range
))))
216 ;; Are we moving on a different window on the same frame?
217 ((and (windowp (posn-window end
))
218 (eq (window-frame (posn-window end
)) start-frame
))
220 (+ (nth 1 (window-edges (posn-window end
)))
221 (cdr (posn-col-row end
)))))
225 (- mouse-row top
) mouse-drag-overlay start-point
))
227 (>= mouse-row bottom
))
228 (mouse-scroll-subr (1+ (- mouse-row bottom
))
229 mouse-drag-overlay start-point
)))))
232 (let ((mouse-y (cdr (cdr (mouse-position))))
233 (menu-bar-lines (or (cdr (assq 'menu-bar-lines
237 ;; Are we on the menu bar?
238 (and (integerp mouse-y
) (< mouse-y menu-bar-lines
)
239 (mouse-scroll-subr (- mouse-y menu-bar-lines
)
240 mouse-drag-overlay start-point
))))))))
242 (if (and (eq (get (event-basic-type event
) 'event-kind
) 'mouse-click
)
243 (eq (posn-window (event-end event
)) start-window
)
244 (numberp (posn-point (event-end event
))))
245 (let ((fun (key-binding (vector (car event
)))))
246 (if (memq fun
'(mouse-set-region mouse-set-point
))
247 (if (not (= (overlay-start mouse-drag-overlay
)
248 (overlay-end mouse-drag-overlay
)))
250 (push-mark (overlay-start mouse-drag-overlay
) t t
)
251 (goto-char (overlay-end mouse-drag-overlay
))
252 (copy-region-as-kill (point) (mark t
)))
253 (goto-char (overlay-end mouse-drag-overlay
))
254 (setq this-command
'mouse-set-point
))
256 (funcall fun event
)))))
257 (delete-overlay mouse-drag-overlay
))))
259 ;; Commands to handle xterm-style multiple clicks.
261 (defun mouse-skip-word (dir)
262 "Skip over word, over whitespace, or over identical punctuation.
263 If DIR is positive skip forward; if negative, skip backward."
264 (let* ((char (following-char))
265 (syntax (char-to-string (char-syntax char
))))
266 (if (or (string= syntax
"w") (string= syntax
" "))
268 (skip-syntax-backward syntax
)
269 (skip-syntax-forward syntax
))
271 (while (and (not (bobp)) (= (preceding-char) char
))
273 (while (and (not (eobp)) (= (following-char) char
))
274 (forward-char 1))))))
276 ;; Return a list of region bounds based on START and END according to MODE.
277 ;; If MODE is 0 then set point to (min START END), mark to (max START END).
278 ;; If MODE is 1 then set point to start of word at (min START END),
279 ;; mark to end of word at (max START END).
280 ;; If MODE is 2 then do the same for lines.
281 (defun mouse-start-end (start end mode
)
286 (setq mode
(mod mode
3))
292 (= (char-syntax (char-after start
)) ?\
())
293 (list start
(save-excursion (forward-sexp 1) (point))))
297 (= (char-syntax (char-after start
)) ?\
)))
298 (list (save-excursion
299 (goto-char (1+ start
))
304 (list (save-excursion
313 (list (save-excursion
315 (beginning-of-line 1)
322 ;; Subroutine: set the mark where CLICK happened,
323 ;; but don't do anything else.
324 (defun mouse-set-mark-fast (click)
325 (let ((posn (event-start click
)))
326 (select-window (posn-window posn
))
327 (if (numberp (posn-point posn
))
328 (push-mark (posn-point posn
) t t
))))
330 ;; Momentarily show where the mark is, if highlighting doesn't show it.
331 (defun mouse-show-mark ()
332 (or transient-mark-mode
337 (defun mouse-set-mark (click)
338 "Set mark at the position clicked on with the mouse.
339 Display cursor at that position for a second.
340 This must be bound to a mouse click."
342 (let ((point-save (point)))
344 (progn (mouse-set-point click
)
346 (or transient-mark-mode
348 (goto-char point-save
))))
350 (defun mouse-kill (click)
351 "Kill the region between point and the mouse click.
352 The text is saved in the kill ring, as with \\[kill-region]."
354 (let ((click-posn (posn-point (event-start click
))))
355 (if (numberp click-posn
)
356 (kill-region (min (point) click-posn
)
357 (max (point) click-posn
)))))
359 (defun mouse-yank-at-click (click arg
)
360 "Insert the last stretch of killed text at the position clicked on.
361 Also move point to one end of the text thus inserted (normally the end).
362 Prefix arguments are interpreted as with \\[yank].
363 If `mouse-yank-at-point' is non-nil, insert at point
364 regardless of where you click."
366 (or mouse-yank-at-point
(mouse-set-point click
))
367 (setq this-command
'yank
)
370 (defun mouse-kill-ring-save (click)
371 "Copy the region between point and the mouse click in the kill ring.
372 This does not delete the region; it acts like \\[kill-ring-save]."
374 (mouse-set-mark-fast click
)
375 (kill-ring-save (point) (mark t
))
378 ;;; This function used to delete the text between point and the mouse
379 ;;; whenever it was equal to the front of the kill ring, but some
380 ;;; people found that confusing.
382 ;;; A list (TEXT START END), describing the text and position of the last
383 ;;; invocation of mouse-save-then-kill.
384 (defvar mouse-save-then-kill-posn nil
)
386 (defun mouse-save-then-kill-delete-region (beg end
)
387 ;; We must make our own undo boundaries
388 ;; because they happen automatically only for the current buffer.
390 (if (or (= beg end
) (eq buffer-undo-list t
))
391 ;; If we have no undo list in this buffer,
393 (delete-region beg end
)
394 ;; Delete, but make the undo-list entry share with the kill ring.
395 ;; First, delete just one char, so in case buffer is being modified
396 ;; for the first time, the undo list records that fact.
398 (+ beg
(if (> end beg
) 1 -
1)))
399 (let ((buffer-undo-list buffer-undo-list
))
400 ;; Undo that deletion--but don't change the undo list!
401 (primitive-undo 1 buffer-undo-list
)
402 ;; Now delete the rest of the specified region,
403 ;; but don't record it.
404 (setq buffer-undo-list t
)
405 (if (/= (length (car kill-ring
)) (- (max end beg
) (min end beg
)))
406 (error "Lossage in mouse-save-then-kill-delete-region"))
407 (delete-region beg end
))
408 (let ((tail buffer-undo-list
))
409 ;; Search back in buffer-undo-list for the string
410 ;; that came from deleting one character.
411 (while (and tail
(not (stringp (car (car tail
)))))
412 (setq tail
(cdr tail
)))
413 ;; Replace it with an entry for the entire deleted text.
415 (setcar tail
(cons (car kill-ring
) (min beg end
))))))
418 (defun mouse-save-then-kill (click)
419 "Save text to point in kill ring; the second time, kill the text.
420 If the text between point and the mouse is the same as what's
421 at the front of the kill ring, this deletes the text.
422 Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
423 which prepares for a second click to delete the text.
425 If you have selected words or lines, this command extends the
426 selection through the word or line clicked on. If you do this
427 again in a different position, it extends the selection again.
428 If you do this twice in the same position, the selection is killed."
430 (let ((click-posn (posn-point (event-start click
)))
431 ;; Don't let a subsequent kill command append to this one:
432 ;; prevent setting this-command to kill-region.
433 (this-command this-command
))
434 (if (> (mod mouse-selection-click-count
3) 0)
435 (if (not (and (eq last-command
'mouse-save-then-kill
)
437 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn
))))))
438 ;; Find both ends of the object selected by this click.
440 (mouse-start-end click-posn click-posn
441 mouse-selection-click-count
)))
442 ;; Move whichever end is closer to the click.
443 ;; That's what xterm does, and it seems reasonable.
444 (if (< (abs (- click-posn
(mark t
)))
445 (abs (- click-posn
(point))))
446 (set-mark (car range
))
447 (goto-char (nth 1 range
)))
448 ;; We have already put the old region in the kill ring.
449 ;; Replace it with the extended region.
450 ;; (It would be annoying to make a separate entry.)
451 (setcar kill-ring
(buffer-substring (point) (mark t
)))
452 (if interprogram-cut-function
453 (funcall interprogram-cut-function
(car kill-ring
)))
454 ;; Arrange for a repeated mouse-3 to kill this region.
455 (setq mouse-save-then-kill-posn
456 (list (car kill-ring
) (point) click-posn
))
458 ;; If we click this button again without moving it,
460 (mouse-save-then-kill-delete-region (point) (mark))
461 (setq mouse-selection-click-count
0)
462 (setq mouse-save-then-kill-posn nil
))
463 (if (and (eq last-command
'mouse-save-then-kill
)
464 mouse-save-then-kill-posn
465 (eq (car mouse-save-then-kill-posn
) (car kill-ring
))
466 (equal (cdr mouse-save-then-kill-posn
) (list (point) click-posn
)))
467 ;; If this is the second time we've called
468 ;; mouse-save-then-kill, delete the text from the buffer.
470 (mouse-save-then-kill-delete-region (point) (mark))
471 ;; After we kill, another click counts as "the first time".
472 (setq mouse-save-then-kill-posn nil
))
473 (if (or (and (eq last-command
'mouse-save-then-kill
)
474 mouse-save-then-kill-posn
)
475 (and mark-active transient-mark-mode
)
476 (and (eq last-command
'mouse-drag-region
)
477 (or mark-even-if-inactive
478 (not transient-mark-mode
))))
479 ;; We have a selection or suitable region, so adjust it.
480 (let* ((posn (event-start click
))
481 (new (posn-point posn
)))
482 (select-window (posn-window posn
))
485 ;; Move whichever end of the region is closer to the click.
486 ;; That is what xterm does, and it seems reasonable.
487 (if (< (abs (- new
(point))) (abs (- new
(mark t
))))
490 (setq deactivate-mark nil
)))
491 (setcar kill-ring
(buffer-substring (point) (mark t
)))
492 (if interprogram-cut-function
493 (funcall interprogram-cut-function
(car kill-ring
))))
494 ;; We just have point, so set mark here.
495 (mouse-set-mark-fast click
)
496 (kill-ring-save (point) (mark t
))
498 (setq mouse-save-then-kill-posn
499 (list (car kill-ring
) (point) click-posn
))))))
501 (global-set-key [M-mouse-1
] 'mouse-start-secondary
)
502 (global-set-key [M-drag-mouse-1
] 'mouse-set-secondary
)
503 (global-set-key [M-down-mouse-1
] 'mouse-drag-secondary
)
504 (global-set-key [M-mouse-3
] 'mouse-secondary-save-then-kill
)
505 (global-set-key [M-mouse-2
] 'mouse-yank-secondary
)
507 ;; An overlay which records the current secondary selection
508 ;; or else is deleted when there is no secondary selection.
510 (defvar mouse-secondary-overlay nil
)
512 ;; A marker which records the specified first end for a secondary selection.
514 (defvar mouse-secondary-start nil
)
516 (defun mouse-start-secondary (click)
517 "Set one end of the secondary selection to the position clicked on.
518 Use \\[mouse-secondary-save-then-kill] to set the other end
519 and complete the secondary selection."
521 (let ((posn (event-start click
)))
523 (set-buffer (window-buffer (posn-window posn
)))
524 ;; Cancel any preexisting secondary selection.
525 (if mouse-secondary-overlay
526 (delete-overlay mouse-secondary-overlay
))
527 (if (numberp (posn-point posn
))
529 (or mouse-secondary-start
530 (setq mouse-secondary-start
(make-marker)))
531 (move-marker mouse-secondary-start
(posn-point posn
)))))))
533 (defun mouse-set-secondary (click)
534 "Set the secondary selection to the text that the mouse is dragged over.
535 This must be bound to a mouse drag event."
537 (let ((posn (event-start click
))
539 (end (event-end click
)))
541 (set-buffer (window-buffer (posn-window posn
)))
542 (if (numberp (posn-point posn
))
543 (setq beg
(posn-point posn
)))
544 (if mouse-secondary-overlay
545 (move-overlay mouse-secondary-overlay beg
(posn-point end
))
546 (setq mouse-secondary-overlay
(make-overlay beg
(posn-point end
))))
547 (overlay-put mouse-secondary-overlay
'face
'secondary-selection
))))
549 (defun mouse-drag-secondary (start-event)
550 "Set the secondary selection to the text that the mouse is dragged over.
551 Highlight the drag area as you move the mouse.
552 This must be bound to a button-down mouse event."
554 (let* ((start-posn (event-start start-event
))
555 (start-point (posn-point start-posn
))
556 (start-window (posn-window start-posn
))
557 (start-frame (window-frame start-window
))
558 (bounds (window-edges start-window
))
560 (bottom (if (window-minibuffer-p start-window
)
562 ;; Don't count the mode line.
563 (1- (nth 3 bounds
))))
564 (click-count (1- (event-click-count start-event
))))
566 (set-buffer (window-buffer start-window
))
567 (setq mouse-selection-click-count click-count
)
568 (or mouse-secondary-overlay
569 (setq mouse-secondary-overlay
570 (make-overlay (point) (point))))
571 (overlay-put mouse-secondary-overlay
'face
'secondary-selection
)
572 (if (> (mod click-count
3) 0)
573 ;; Double or triple press: make an initial selection
574 ;; of one word or line.
575 (let ((range (mouse-start-end start-point start-point click-count
)))
576 (set-marker mouse-secondary-start nil
)
577 (move-overlay mouse-secondary-overlay
1 1
578 (window-buffer start-window
))
579 (move-overlay mouse-secondary-overlay
(car range
) (nth 1 range
)
580 (window-buffer start-window
)))
581 ;; Single-press: cancel any preexisting secondary selection.
582 (or mouse-secondary-start
583 (setq mouse-secondary-start
(make-marker)))
584 (set-marker mouse-secondary-start start-point
)
585 (delete-overlay mouse-secondary-overlay
))
586 (let (event end end-point
)
589 (setq event
(read-event))
590 (or (mouse-movement-p event
)
591 (eq (car-safe event
) 'switch-frame
)))
593 (if (eq (car-safe event
) 'switch-frame
)
595 (setq end
(event-end event
)
596 end-point
(posn-point end
))
599 ;; Ignore switch-frame events.
600 ((eq (car-safe event
) 'switch-frame
))
602 ;; Are we moving within the original window?
603 ((and (eq (posn-window end
) start-window
)
604 (integer-or-marker-p end-point
))
605 (if (/= start-point end-point
)
606 (set-marker mouse-secondary-start nil
))
607 (let ((range (mouse-start-end start-point end-point
609 (move-overlay mouse-secondary-overlay
610 (car range
) (nth 1 range
))))
612 ;; Are we moving on a different window on the same frame?
613 ((and (windowp (posn-window end
))
614 (eq (window-frame (posn-window end
)) start-frame
))
616 (+ (nth 1 (window-edges (posn-window end
)))
617 (cdr (posn-col-row end
)))))
621 (- mouse-row top
) mouse-secondary-overlay start-point
))
623 (>= mouse-row bottom
))
624 (mouse-scroll-subr (1+ (- mouse-row bottom
))
625 mouse-drag-overlay start-point
)))))
628 (let ((mouse-y (cdr (cdr (mouse-position))))
629 (menu-bar-lines (or (cdr (assq 'menu-bar-lines
633 ;; Are we on the menu bar?
634 (and (integerp mouse-y
) (< mouse-y menu-bar-lines
)
635 (mouse-scroll-subr (- mouse-y menu-bar-lines
)
636 mouse-secondary-overlay start-point
))))))))
638 (if (and (eq (get (event-basic-type event
) 'event-kind
) 'mouse-click
)
639 (eq (posn-window (event-end event
)) start-window
)
640 (numberp (posn-point (event-end event
))))
641 (if (marker-position mouse-secondary-start
)
642 (save-window-excursion
643 (delete-overlay mouse-secondary-overlay
)
644 (x-set-selection 'SECONDARY nil
)
645 (select-window start-window
)
647 (goto-char mouse-secondary-start
)
651 (buffer-substring (overlay-start mouse-secondary-overlay
)
652 (overlay-end mouse-secondary-overlay
)))))))))
654 (defun mouse-yank-secondary (click)
655 "Insert the secondary selection at the position clicked on.
656 Move point to the end of the inserted text.
657 If `mouse-yank-at-point' is non-nil, insert at point
658 regardless of where you click."
660 (or mouse-yank-at-point
(mouse-set-point click
))
661 (insert (x-get-selection 'SECONDARY
)))
663 (defun mouse-kill-secondary ()
664 "Kill the text in the secondary selection.
665 This is intended more as a keyboard command than as a mouse command
666 but it can work as either one.
668 The current buffer (in case of keyboard use), or the buffer clicked on,
669 must be the one that the secondary selection is in. This requirement
670 is to prevent accidents."
672 (let* ((keys (this-command-keys))
673 (click (elt keys
(1- (length keys
)))))
674 (or (eq (overlay-buffer mouse-secondary-overlay
)
676 (window-buffer (posn-window (event-start click
)))
678 (error "Select or click on the buffer where the secondary selection is")))
680 (set-buffer (overlay-buffer mouse-secondary-overlay
))
681 (kill-region (overlay-start mouse-secondary-overlay
)
682 (overlay-end mouse-secondary-overlay
)))
683 (delete-overlay mouse-secondary-overlay
)
684 (x-set-selection 'SECONDARY nil
)
685 (setq mouse-secondary-overlay nil
))
687 (defun mouse-secondary-save-then-kill (click)
688 "Save text to point in kill ring; the second time, kill the text.
689 If the text between point and the mouse is the same as what's
690 at the front of the kill ring, this deletes the text.
691 Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
692 which prepares for a second click to delete the text.
694 If you have selected words or lines, this command extends the
695 selection through the word or line clicked on. If you do this
696 again in a different position, it extends the selection again.
697 If you do this twice in the same position, the selection is killed."
699 (let ((posn (event-start click
))
700 (click-posn (posn-point (event-start click
)))
701 ;; Don't let a subsequent kill command append to this one:
702 ;; prevent setting this-command to kill-region.
703 (this-command this-command
))
704 (or (eq (window-buffer (posn-window posn
))
705 (or (and mouse-secondary-overlay
706 (overlay-buffer mouse-secondary-overlay
))
707 (if mouse-secondary-start
708 (marker-buffer mouse-secondary-start
))))
709 (error "Wrong buffer"))
711 (set-buffer (window-buffer (posn-window posn
)))
712 (if (> (mod mouse-selection-click-count
3) 0)
713 (if (not (and (eq last-command
'mouse-secondary-save-then-kill
)
715 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn
))))))
716 ;; Find both ends of the object selected by this click.
718 (mouse-start-end click-posn click-posn
719 mouse-selection-click-count
)))
720 ;; Move whichever end is closer to the click.
721 ;; That's what xterm does, and it seems reasonable.
722 (if (< (abs (- click-posn
(overlay-start mouse-secondary-overlay
)))
723 (abs (- click-posn
(overlay-end mouse-secondary-overlay
))))
724 (move-overlay mouse-secondary-overlay
(car range
)
725 (overlay-end mouse-secondary-overlay
))
726 (move-overlay mouse-secondary-overlay
727 (overlay-start mouse-secondary-overlay
)
729 ;; We have already put the old region in the kill ring.
730 ;; Replace it with the extended region.
731 ;; (It would be annoying to make a separate entry.)
732 (setcar kill-ring
(buffer-substring
733 (overlay-start mouse-secondary-overlay
)
734 (overlay-end mouse-secondary-overlay
)))
735 (if interprogram-cut-function
736 (funcall interprogram-cut-function
(car kill-ring
)))
737 ;; Arrange for a repeated mouse-3 to kill this region.
738 (setq mouse-save-then-kill-posn
739 (list (car kill-ring
) (point) click-posn
)))
740 ;; If we click this button again without moving it,
743 (mouse-save-then-kill-delete-region
744 (overlay-start mouse-secondary-overlay
)
745 (overlay-end mouse-secondary-overlay
))
746 (setq mouse-save-then-kill-posn nil
)
747 (setq mouse-selection-click-count
0)
748 (delete-overlay mouse-secondary-overlay
)))
749 (if (and (eq last-command
'mouse-secondary-save-then-kill
)
750 mouse-save-then-kill-posn
751 (eq (car mouse-save-then-kill-posn
) (car kill-ring
))
752 (equal (cdr mouse-save-then-kill-posn
) (list (point) click-posn
)))
753 ;; If this is the second time we've called
754 ;; mouse-secondary-save-then-kill, delete the text from the buffer.
756 (mouse-save-then-kill-delete-region
757 (overlay-start mouse-secondary-overlay
)
758 (overlay-end mouse-secondary-overlay
))
759 (setq mouse-save-then-kill-posn nil
)
760 (delete-overlay mouse-secondary-overlay
))
761 (if (overlay-start mouse-secondary-overlay
)
762 ;; We have a selection, so adjust it.
764 (if (numberp click-posn
)
766 ;; Move whichever end of the region is closer to the click.
767 ;; That is what xterm does, and it seems reasonable.
768 (if (< (abs (- click-posn
(overlay-start mouse-secondary-overlay
)))
769 (abs (- click-posn
(overlay-end mouse-secondary-overlay
))))
770 (move-overlay mouse-secondary-overlay click-posn
771 (overlay-end mouse-secondary-overlay
))
772 (move-overlay mouse-secondary-overlay
773 (overlay-start mouse-secondary-overlay
)
775 (setq deactivate-mark nil
)))
776 (setcar kill-ring
(buffer-substring
777 (overlay-start mouse-secondary-overlay
)
778 (overlay-end mouse-secondary-overlay
)))
779 (if interprogram-cut-function
780 (funcall interprogram-cut-function
(car kill-ring
))))
781 (if mouse-secondary-start
782 ;; All we have is one end of a selection,
783 ;; so put the other end here.
784 (let ((start (+ 0 mouse-secondary-start
)))
785 (kill-ring-save start click-posn
)
786 (if mouse-secondary-overlay
787 (move-overlay mouse-secondary-overlay start click-posn
)
788 (setq mouse-secondary-overlay
(make-overlay start click-posn
)))
789 (overlay-put mouse-secondary-overlay
'face
'secondary-selection
))))
790 (setq mouse-save-then-kill-posn
791 (list (car kill-ring
) (point) click-posn
))))
792 (x-set-selection 'SECONDARY
793 (if (overlay-buffer mouse-secondary-overlay
)
795 (overlay-start mouse-secondary-overlay
)
796 (overlay-end mouse-secondary-overlay
)))))))
798 (defun mouse-buffer-menu (event)
799 "Pop up a menu of buffers for selection with the mouse.
800 This switches buffers in the window that you clicked on,
801 and selects that window."
805 (cons "Select Buffer"
806 (let ((tail (buffer-list))
810 (or (eq ?\
(aref (buffer-name (car tail
)) 0))
813 (length (buffer-name (car tail
))))))
814 (setq tail
(cdr tail
)))
815 (setq tail
(buffer-list))
817 (let ((elt (car tail
)))
818 (if (not (string-match "^ "
823 (format "%%%ds %%s%%s %%s"
826 (if (buffer-modified-p elt
)
830 (if buffer-read-only
"%" " "))
831 (or (buffer-file-name elt
) ""))
834 (setq tail
(cdr tail
)))
836 (let ((buf (x-popup-menu event menu
))
837 (window (posn-window (event-start event
))))
840 (or (framep window
) (select-window window
))
841 (switch-to-buffer buf
))))))
843 ;;; These need to be rewritten for the new scroll bar implementation.
845 ;;;!! ;; Commands for the scroll bar.
847 ;;;!! (defun mouse-scroll-down (click)
848 ;;;!! (interactive "@e")
849 ;;;!! (scroll-down (1+ (cdr (mouse-coords click)))))
851 ;;;!! (defun mouse-scroll-up (click)
852 ;;;!! (interactive "@e")
853 ;;;!! (scroll-up (1+ (cdr (mouse-coords click)))))
855 ;;;!! (defun mouse-scroll-down-full ()
856 ;;;!! (interactive "@")
857 ;;;!! (scroll-down nil))
859 ;;;!! (defun mouse-scroll-up-full ()
860 ;;;!! (interactive "@")
861 ;;;!! (scroll-up nil))
863 ;;;!! (defun mouse-scroll-move-cursor (click)
864 ;;;!! (interactive "@e")
865 ;;;!! (move-to-window-line (1+ (cdr (mouse-coords click)))))
867 ;;;!! (defun mouse-scroll-absolute (event)
868 ;;;!! (interactive "@e")
869 ;;;!! (let* ((pos (car event))
870 ;;;!! (position (car pos))
871 ;;;!! (length (car (cdr pos))))
872 ;;;!! (if (<= length 0) (setq length 1))
873 ;;;!! (let* ((scale-factor (max 1 (/ length (/ 8000000 (buffer-size)))))
874 ;;;!! (newpos (* (/ (* (/ (buffer-size) scale-factor)
877 ;;;!! scale-factor)))
878 ;;;!! (goto-char newpos)
879 ;;;!! (recenter '(4)))))
881 ;;;!! (defun mouse-scroll-left (click)
882 ;;;!! (interactive "@e")
883 ;;;!! (scroll-left (1+ (car (mouse-coords click)))))
885 ;;;!! (defun mouse-scroll-right (click)
886 ;;;!! (interactive "@e")
887 ;;;!! (scroll-right (1+ (car (mouse-coords click)))))
889 ;;;!! (defun mouse-scroll-left-full ()
890 ;;;!! (interactive "@")
891 ;;;!! (scroll-left nil))
893 ;;;!! (defun mouse-scroll-right-full ()
894 ;;;!! (interactive "@")
895 ;;;!! (scroll-right nil))
897 ;;;!! (defun mouse-scroll-move-cursor-horizontally (click)
898 ;;;!! (interactive "@e")
899 ;;;!! (move-to-column (1+ (car (mouse-coords click)))))
901 ;;;!! (defun mouse-scroll-absolute-horizontally (event)
902 ;;;!! (interactive "@e")
903 ;;;!! (let* ((pos (car event))
904 ;;;!! (position (car pos))
905 ;;;!! (length (car (cdr pos))))
906 ;;;!! (set-window-hscroll (selected-window) 33)))
908 ;;;!! (global-set-key [scroll-bar mouse-1] 'mouse-scroll-up)
909 ;;;!! (global-set-key [scroll-bar mouse-2] 'mouse-scroll-absolute)
910 ;;;!! (global-set-key [scroll-bar mouse-3] 'mouse-scroll-down)
912 ;;;!! (global-set-key [vertical-slider mouse-1] 'mouse-scroll-move-cursor)
913 ;;;!! (global-set-key [vertical-slider mouse-2] 'mouse-scroll-move-cursor)
914 ;;;!! (global-set-key [vertical-slider mouse-3] 'mouse-scroll-move-cursor)
916 ;;;!! (global-set-key [thumbup mouse-1] 'mouse-scroll-up-full)
917 ;;;!! (global-set-key [thumbup mouse-2] 'mouse-scroll-up-full)
918 ;;;!! (global-set-key [thumbup mouse-3] 'mouse-scroll-up-full)
920 ;;;!! (global-set-key [thumbdown mouse-1] 'mouse-scroll-down-full)
921 ;;;!! (global-set-key [thumbdown mouse-2] 'mouse-scroll-down-full)
922 ;;;!! (global-set-key [thumbdown mouse-3] 'mouse-scroll-down-full)
924 ;;;!! (global-set-key [horizontal-scroll-bar mouse-1] 'mouse-scroll-left)
925 ;;;!! (global-set-key [horizontal-scroll-bar mouse-2]
926 ;;;!! 'mouse-scroll-absolute-horizontally)
927 ;;;!! (global-set-key [horizontal-scroll-bar mouse-3] 'mouse-scroll-right)
929 ;;;!! (global-set-key [horizontal-slider mouse-1]
930 ;;;!! 'mouse-scroll-move-cursor-horizontally)
931 ;;;!! (global-set-key [horizontal-slider mouse-2]
932 ;;;!! 'mouse-scroll-move-cursor-horizontally)
933 ;;;!! (global-set-key [horizontal-slider mouse-3]
934 ;;;!! 'mouse-scroll-move-cursor-horizontally)
936 ;;;!! (global-set-key [thumbleft mouse-1] 'mouse-scroll-left-full)
937 ;;;!! (global-set-key [thumbleft mouse-2] 'mouse-scroll-left-full)
938 ;;;!! (global-set-key [thumbleft mouse-3] 'mouse-scroll-left-full)
940 ;;;!! (global-set-key [thumbright mouse-1] 'mouse-scroll-right-full)
941 ;;;!! (global-set-key [thumbright mouse-2] 'mouse-scroll-right-full)
942 ;;;!! (global-set-key [thumbright mouse-3] 'mouse-scroll-right-full)
944 ;;;!! (global-set-key [horizontal-scroll-bar S-mouse-2]
945 ;;;!! 'mouse-split-window-horizontally)
946 ;;;!! (global-set-key [mode-line S-mouse-2]
947 ;;;!! 'mouse-split-window-horizontally)
948 ;;;!! (global-set-key [vertical-scroll-bar S-mouse-2]
949 ;;;!! 'mouse-split-window)
952 ;;;!! ;;;; Here are experimental things being tested. Mouse events
953 ;;;!! ;;;; are of the form:
954 ;;;!! ;;;; ((x y) window screen-part key-sequence timestamp)
957 ;;;!! ;;;; Dynamically track mouse coordinates
960 ;;;!! ;;(defun track-mouse (event)
961 ;;;!! ;; "Track the coordinates, absolute and relative, of the mouse."
962 ;;;!! ;; (interactive "@e")
963 ;;;!! ;; (while mouse-grabbed
964 ;;;!! ;; (let* ((pos (read-mouse-position (selected-screen)))
965 ;;;!! ;; (abs-x (car pos))
966 ;;;!! ;; (abs-y (cdr pos))
967 ;;;!! ;; (relative-coordinate (coordinates-in-window-p
968 ;;;!! ;; (list (car pos) (cdr pos))
969 ;;;!! ;; (selected-window))))
970 ;;;!! ;; (if (consp relative-coordinate)
971 ;;;!! ;; (message "mouse: [%d %d], (%d %d)" abs-x abs-y
972 ;;;!! ;; (car relative-coordinate)
973 ;;;!! ;; (car (cdr relative-coordinate)))
974 ;;;!! ;; (message "mouse: [%d %d]" abs-x abs-y)))))
977 ;;;!! ;; Dynamically put a box around the line indicated by point
980 ;;;!! ;;(require 'backquote)
982 ;;;!! ;;(defun mouse-select-buffer-line (event)
983 ;;;!! ;; (interactive "@e")
984 ;;;!! ;; (let ((relative-coordinate
985 ;;;!! ;; (coordinates-in-window-p (car event) (selected-window)))
986 ;;;!! ;; (abs-y (car (cdr (car event)))))
987 ;;;!! ;; (if (consp relative-coordinate)
989 ;;;!! ;; (save-excursion
990 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
991 ;;;!! ;; (x-draw-rectangle
992 ;;;!! ;; (selected-screen)
994 ;;;!! ;; (save-excursion
995 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
996 ;;;!! ;; (end-of-line)
997 ;;;!! ;; (push-mark nil t)
998 ;;;!! ;; (beginning-of-line)
999 ;;;!! ;; (- (region-end) (region-beginning))) 1))
1000 ;;;!! ;; (sit-for 1)
1001 ;;;!! ;; (x-erase-rectangle (selected-screen))))))
1003 ;;;!! ;;(defvar last-line-drawn nil)
1004 ;;;!! ;;(defvar begin-delim "[^ \t]")
1005 ;;;!! ;;(defvar end-delim "[^ \t]")
1007 ;;;!! ;;(defun mouse-boxing (event)
1008 ;;;!! ;; (interactive "@e")
1009 ;;;!! ;; (save-excursion
1010 ;;;!! ;; (let ((screen (selected-screen)))
1011 ;;;!! ;; (while (= (x-mouse-events) 0)
1012 ;;;!! ;; (let* ((pos (read-mouse-position screen))
1013 ;;;!! ;; (abs-x (car pos))
1014 ;;;!! ;; (abs-y (cdr pos))
1015 ;;;!! ;; (relative-coordinate
1016 ;;;!! ;; (coordinates-in-window-p (` ((, abs-x) (, abs-y)))
1017 ;;;!! ;; (selected-window)))
1018 ;;;!! ;; (begin-reg nil)
1019 ;;;!! ;; (end-reg nil)
1020 ;;;!! ;; (end-column nil)
1021 ;;;!! ;; (begin-column nil))
1022 ;;;!! ;; (if (and (consp relative-coordinate)
1023 ;;;!! ;; (or (not last-line-drawn)
1024 ;;;!! ;; (not (= last-line-drawn abs-y))))
1026 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1027 ;;;!! ;; (if (= (following-char) 10)
1030 ;;;!! ;; (setq begin-reg (1- (re-search-forward end-delim)))
1031 ;;;!! ;; (setq begin-column (1- (current-column)))
1032 ;;;!! ;; (end-of-line)
1033 ;;;!! ;; (setq end-reg (1+ (re-search-backward begin-delim)))
1034 ;;;!! ;; (setq end-column (1+ (current-column)))
1035 ;;;!! ;; (message "%s" (buffer-substring begin-reg end-reg))
1036 ;;;!! ;; (x-draw-rectangle screen
1037 ;;;!! ;; (setq last-line-drawn abs-y)
1038 ;;;!! ;; begin-column
1039 ;;;!! ;; (- end-column begin-column) 1))))))))))
1041 ;;;!! ;;(defun mouse-erase-box ()
1042 ;;;!! ;; (interactive)
1043 ;;;!! ;; (if last-line-drawn
1045 ;;;!! ;; (x-erase-rectangle (selected-screen))
1046 ;;;!! ;; (setq last-line-drawn nil))))
1048 ;;;!! ;;; (defun test-x-rectangle ()
1049 ;;;!! ;;; (use-local-mouse-map (setq rectangle-test-map (make-sparse-keymap)))
1050 ;;;!! ;;; (define-key rectangle-test-map mouse-motion-button-left 'mouse-boxing)
1051 ;;;!! ;;; (define-key rectangle-test-map mouse-button-left-up 'mouse-erase-box))
1054 ;;;!! ;; Here is how to do double clicking in lisp. About to change.
1057 ;;;!! (defvar double-start nil)
1058 ;;;!! (defconst double-click-interval 300
1059 ;;;!! "Max ticks between clicks")
1061 ;;;!! (defun double-down (event)
1062 ;;;!! (interactive "@e")
1063 ;;;!! (if double-start
1064 ;;;!! (let ((interval (- (nth 4 event) double-start)))
1065 ;;;!! (if (< interval double-click-interval)
1067 ;;;!! (backward-up-list 1)
1068 ;;;!! ;; (message "Interval %d" interval)
1069 ;;;!! (sleep-for 1)))
1070 ;;;!! (setq double-start nil))
1071 ;;;!! (setq double-start (nth 4 event))))
1073 ;;;!! (defun double-up (event)
1074 ;;;!! (interactive "@e")
1075 ;;;!! (and double-start
1076 ;;;!! (> (- (nth 4 event ) double-start) double-click-interval)
1077 ;;;!! (setq double-start nil)))
1079 ;;;!! ;;; (defun x-test-doubleclick ()
1080 ;;;!! ;;; (use-local-mouse-map (setq doubleclick-test-map (make-sparse-keymap)))
1081 ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left 'double-down)
1082 ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left-up 'double-up))
1085 ;;;!! ;; This scrolls while button is depressed. Use preferable in scroll bar.
1088 ;;;!! (defvar scrolled-lines 0)
1089 ;;;!! (defconst scroll-speed 1)
1091 ;;;!! (defun incr-scroll-down (event)
1092 ;;;!! (interactive "@e")
1093 ;;;!! (setq scrolled-lines 0)
1094 ;;;!! (incremental-scroll scroll-speed))
1096 ;;;!! (defun incr-scroll-up (event)
1097 ;;;!! (interactive "@e")
1098 ;;;!! (setq scrolled-lines 0)
1099 ;;;!! (incremental-scroll (- scroll-speed)))
1101 ;;;!! (defun incremental-scroll (n)
1102 ;;;!! (while (= (x-mouse-events) 0)
1103 ;;;!! (setq scrolled-lines (1+ (* scroll-speed scrolled-lines)))
1104 ;;;!! (scroll-down n)
1105 ;;;!! (sit-for 300 t)))
1107 ;;;!! (defun incr-scroll-stop (event)
1108 ;;;!! (interactive "@e")
1109 ;;;!! (message "Scrolled %d lines" scrolled-lines)
1110 ;;;!! (setq scrolled-lines 0)
1111 ;;;!! (sleep-for 1))
1113 ;;;!! ;;; (defun x-testing-scroll ()
1114 ;;;!! ;;; (let ((scrolling-map (function mouse-vertical-scroll-bar-prefix)))
1115 ;;;!! ;;; (define-key scrolling-map mouse-button-left 'incr-scroll-down)
1116 ;;;!! ;;; (define-key scrolling-map mouse-button-right 'incr-scroll-up)
1117 ;;;!! ;;; (define-key scrolling-map mouse-button-left-up 'incr-scroll-stop)
1118 ;;;!! ;;; (define-key scrolling-map mouse-button-right-up 'incr-scroll-stop)))
1121 ;;;!! ;; Some playthings suitable for picture mode? They need work.
1124 ;;;!! (defun mouse-kill-rectangle (event)
1125 ;;;!! "Kill the rectangle between point and the mouse cursor."
1126 ;;;!! (interactive "@e")
1127 ;;;!! (let ((point-save (point)))
1128 ;;;!! (save-excursion
1129 ;;;!! (mouse-set-point event)
1130 ;;;!! (push-mark nil t)
1131 ;;;!! (if (> point-save (point))
1132 ;;;!! (kill-rectangle (point) point-save)
1133 ;;;!! (kill-rectangle point-save (point))))))
1135 ;;;!! (defun mouse-open-rectangle (event)
1136 ;;;!! "Kill the rectangle between point and the mouse cursor."
1137 ;;;!! (interactive "@e")
1138 ;;;!! (let ((point-save (point)))
1139 ;;;!! (save-excursion
1140 ;;;!! (mouse-set-point event)
1141 ;;;!! (push-mark nil t)
1142 ;;;!! (if (> point-save (point))
1143 ;;;!! (open-rectangle (point) point-save)
1144 ;;;!! (open-rectangle point-save (point))))))
1146 ;;;!! ;; Must be a better way to do this.
1148 ;;;!! (defun mouse-multiple-insert (n char)
1149 ;;;!! (while (> n 0)
1151 ;;;!! (setq n (1- n))))
1153 ;;;!! ;; What this could do is not finalize until button was released.
1155 ;;;!! (defun mouse-move-text (event)
1156 ;;;!! "Move text from point to cursor position, inserting spaces."
1157 ;;;!! (interactive "@e")
1158 ;;;!! (let* ((relative-coordinate
1159 ;;;!! (coordinates-in-window-p (car event) (selected-window))))
1160 ;;;!! (if (consp relative-coordinate)
1161 ;;;!! (cond ((> (current-column) (car relative-coordinate))
1163 ;;;!! (- (car relative-coordinate) (current-column))))
1164 ;;;!! ((< (current-column) (car relative-coordinate))
1165 ;;;!! (mouse-multiple-insert
1166 ;;;!! (- (car relative-coordinate) (current-column)) " "))
1167 ;;;!! ((= (current-column) (car relative-coordinate)) (ding))))))
1169 ;; Choose a completion with the mouse.
1171 ;; Delete the longest partial match for STRING
1172 ;; that can be found before POINT.
1173 (defun mouse-delete-max-match (string)
1174 (let ((len (min (length string
)
1175 (- (point-max) (point-min)))))
1176 (goto-char (max (point-min) (- (point) (length string
))))
1177 (while (and (> len
0)
1178 (let ((tail (buffer-substring (point)
1180 (not (string= tail
(substring string
0 len
)))))
1185 (defun mouse-choose-completion (event)
1186 "Click on an alternative in the `*Completions*' buffer to choose it."
1188 (let ((buffer (window-buffer))
1191 (set-buffer (window-buffer (posn-window (event-start event
))))
1193 (goto-char (posn-point (event-start event
)))
1194 (skip-chars-backward "^ \t\n")
1195 (let ((beg (point)))
1196 (skip-chars-forward "^ \t\n")
1197 (setq choice
(buffer-substring beg
(point))))))
1199 (mouse-delete-max-match choice
)
1201 (and (equal buffer
(window-buffer (minibuffer-window)))
1202 (minibuffer-complete-and-exit))))
1206 (defun font-menu-add-default ()
1207 (let* ((default (cdr (assq 'font
(frame-parameters (selected-frame)))))
1208 (font-alist x-fixed-font-alist
)
1209 (elt (or (assoc "Misc" font-alist
) (nth 1 font-alist
))))
1210 (if (assoc "Default" elt
)
1211 (delete (assoc "Default" elt
) elt
))
1213 (cons (list "Default"
1214 (cdr (assq 'font
(frame-parameters (selected-frame)))))
1217 (defvar x-fixed-font-alist
1220 ("6x10" "-misc-fixed-medium-r-normal--10-100-75-75-c-60-*-1")
1221 ("6x12" "-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-*-1")
1222 ("6x13" "-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-*-1")
1224 "-b&h-lucidatypewriter-medium-r-normal-sans-0-0-0-0-m-0-*-1")
1225 ("7x13" "-misc-fixed-medium-r-normal--13-120-75-75-c-70-*-1")
1226 ("7x14" "-misc-fixed-medium-r-normal--14-130-75-75-c-70-*-1")
1227 ("9x15" "-misc-fixed-medium-r-normal--15-140-*-*-c-*-*-1")
1229 ("clean 8x8" "-schumacher-clean-medium-r-normal--*-80-*-*-c-*-*-1")
1230 ("clean 8x14" "-schumacher-clean-medium-r-normal--*-140-*-*-c-*-*-1")
1231 ("clean 8x10" "-schumacher-clean-medium-r-normal--*-100-*-*-c-*-*-1")
1232 ("clean 8x16" "-schumacher-clean-medium-r-normal--*-160-*-*-c-*-*-1")
1234 ("sony 8x16" "-sony-fixed-medium-r-normal--16-120-100-100-c-80-*-1")
1240 ;;; We don't seem to have these; who knows what they are.
1241 ;;; ("fg-18" "fg-18")
1242 ;;; ("fg-25" "fg-25")
1243 ;;; ("lucidasanstypewriter-12" "lucidasanstypewriter-12")
1244 ;;; ("lucidasanstypewriter-bold-14" "lucidasanstypewriter-bold-14")
1245 ;;; ("lucidasanstypewriter-bold-24" "lucidasanstypewriter-bold-24")
1246 ;;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
1247 ;;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
1249 ("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1")
1250 ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1")
1251 ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1")
1252 ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1")
1253 ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1")
1254 ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1")
1255 ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1")
1256 ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1")
1257 ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1")
1258 ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1")
1259 ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1")
1260 ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1")
1261 ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1")
1262 ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1")
1263 ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1")
1264 ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1")
1265 ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1")
1266 ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1")
1267 ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1")
1268 ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1")
1269 ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1")
1270 ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1")
1271 ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1")
1272 ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1"))
1274 "X fonts suitable for use in Emacs.")
1276 (defun mouse-set-font (&optional font
)
1277 "Select an emacs font from a list of known good fonts"
1279 (x-popup-menu last-nonmenu-event x-fixed-font-alist
))
1281 (progn (modify-frame-parameters (selected-frame)
1282 (list (cons 'font font
)))
1283 ;; Update some standard faces too.
1284 (set-face-font 'bold nil
(selected-frame))
1285 (make-face-bold 'bold
(selected-frame) t
)
1286 (set-face-font 'italic nil
(selected-frame))
1287 (make-face-italic 'italic
(selected-frame) t
)
1288 (set-face-font 'bold-italic nil
(selected-frame))
1289 (make-face-bold-italic 'bold-italic
(selected-frame) t
)
1290 ;; Update any nonstandard faces whose definition is
1291 ;; "a bold/italic/bold&italic version of the frame's font".
1292 (let ((rest global-face-data
))
1295 (if (listp (face-font (cdr (car rest
))))
1296 (let ((bold (memq 'bold
(face-font (cdr (car rest
)))))
1297 (italic (memq 'italic
(face-font (cdr (car rest
))))))
1298 (if (and bold italic
)
1299 (make-face-bold-italic (car (car rest
)) (selected-frame))
1301 (make-face-bold (car (car rest
)) (selected-frame))
1303 (make-face-italic (car (car rest
)) (selected-frame)))))))
1305 (setq rest
(cdr rest
))))
1308 ;;; Bindings for mouse commands.
1310 (define-key global-map
[down-mouse-1
] 'mouse-drag-region
)
1311 (global-set-key [mouse-1
] 'mouse-set-point
)
1312 (global-set-key [drag-mouse-1
] 'mouse-set-region
)
1314 ;; These are tested for in mouse-drag-region.
1315 (global-set-key [double-mouse-1
] 'mouse-set-point
)
1316 (global-set-key [triple-mouse-1
] 'mouse-set-point
)
1318 (global-set-key [mouse-2
] 'mouse-yank-at-click
)
1319 (global-set-key [mouse-3
] 'mouse-save-then-kill
)
1321 ;; By binding these to down-going events, we let the user use the up-going
1322 ;; event to make the selection, saving a click.
1323 (global-set-key [C-down-mouse-1
] 'mouse-buffer-menu
)
1324 (global-set-key [C-down-mouse-3
] 'mouse-set-font
)
1326 ;; Replaced with dragging mouse-1
1327 ;; (global-set-key [S-mouse-1] 'mouse-set-mark)
1329 (global-set-key [mode-line mouse-1
] 'mouse-delete-other-windows
)
1330 (global-set-key [mode-line mouse-3
] 'mouse-delete-window
)
1331 (global-set-key [mode-line S-mouse-2
] 'mouse-split-window-horizontally
)
1333 ;; Define the mouse help menu tree.
1335 (defvar help-menu-map
'(keymap "Help"))
1336 (global-set-key [C-down-mouse-2
] help-menu-map
)
1338 (defvar help-apropos-map
(make-sparse-keymap "Is there a command that..."))
1339 (defvar help-keys-map
(make-sparse-keymap "Key Commands <==> Functions"))
1340 (defvar help-manual-map
(make-sparse-keymap "Manual and tutorial"))
1341 (defvar help-misc-map
(make-sparse-keymap "Odds and ends"))
1342 (defvar help-modes-map
(make-sparse-keymap "Modes"))
1343 (defvar help-admin-map
(make-sparse-keymap "Administrivia"))
1345 (define-key help-menu-map
[apropos]
1346 (cons "@Is there a command that..." help-apropos-map))
1347 (define-key help-menu-map [keys]
1348 (cons "@Key Commands <==> Functions" help-keys-map))
1349 (define-key help-menu-map [manuals]
1350 (cons "@Manual and tutorial" help-manual-map))
1351 (define-key help-menu-map [misc]
1352 (cons "@Odds and ends" help-misc-map))
1353 (define-key help-menu-map [modes]
1354 (cons "@Modes" help-modes-map))
1355 (define-key help-menu-map [admin]
1356 (cons "@Administrivia" help-admin-map))
1358 (define-key help-apropos-map "c" '("Command Apropos" . command-apropos))
1359 (define-key help-apropos-map "a" '("Apropos" . apropos))
1361 (define-key help-keys-map "b"
1362 '("List all keystroke commands" . describe-bindings))
1363 (define-key help-keys-map "c"
1364 '("Describe key briefly" . describe-key-briefly))
1365 (define-key help-keys-map "k"
1366 '("Describe key verbose" . describe-key))
1367 (define-key help-keys-map "f"
1368 '("Describe Lisp function" . describe-function))
1369 (define-key help-keys-map "w"
1370 '("Where is this command" . where-is))
1372 (define-key help-manual-map "i" '("Info system" . info))
1373 (define-key help-manual-map "t"
1374 '("Invoke Emacs tutorial" . help-with-tutorial))
1376 (define-key help-misc-map "l" '("Last 100 Keystrokes" . view-lossage))
1377 (define-key help-misc-map "s" '("Describe syntax table" . describe-syntax))
1379 (define-key help-modes-map "m"
1380 '("Describe current major mode" . describe-mode))
1381 (define-key help-modes-map "b"
1382 '("List all keystroke commands" . describe-bindings))
1384 (define-key help-admin-map "n"
1385 '("View Emacs news" . view-emacs-news))
1386 (define-key help-admin-map "l"
1387 '("View Emacs copying conditions" . describe-copying))
1388 (define-key help-admin-map "d"
1389 '("Describe distribution" . describe-distribution))
1390 (define-key help-admin-map "w"
1391 '("Describe (non)warranty" . describe-no-warranty))
1395 ;;; mouse.el ends here