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-select-window (click)
49 "Select the window clicked on; don't move point."
51 (let ((oframe (selected-frame))
52 (frame (window-frame (posn-window (event-start click
)))))
53 (select-window (posn-window (event-start click
)))
57 (set-mouse-position (selected-frame) (1- (frame-width)) 0))
60 (defun mouse-tear-off-window (click)
61 "Delete the window clicked on, and create a new frame displaying its buffer."
63 (let* ((window (posn-window (event-start click
)))
64 (buf (window-buffer window
))
67 (switch-to-buffer buf
)
68 (delete-window window
)))
70 (defun mouse-delete-other-windows ()
71 "Delete all window except the one you click on."
73 (delete-other-windows))
75 (defun mouse-split-window-vertically (click)
76 "Select Emacs window mouse is on, then split it vertically in half.
77 The window is split at the line clicked on.
78 This command must be bound to a mouse click."
80 (let ((start (event-start click
)))
81 (select-window (posn-window start
))
82 (let ((new-height (if (eq (posn-point start
) 'vertical-scroll-bar
)
83 (scroll-bar-scale (posn-col-row start
)
85 (1+ (cdr (posn-col-row (event-end click
))))))
86 (first-line window-min-height
)
87 (last-line (- (window-height) window-min-height
)))
88 (if (< last-line first-line
)
89 (error "window too short to split")
90 (split-window-vertically
91 (min (max new-height first-line
) last-line
))))))
93 (defun mouse-split-window-horizontally (click)
94 "Select Emacs window mouse is on, then split it horizontally in half.
95 The window is split at the column clicked on.
96 This command must be bound to a mouse click."
98 (let ((start (event-start click
)))
99 (select-window (posn-window start
))
100 (let ((new-width (1+ (car (posn-col-row (event-end click
)))))
101 (first-col window-min-width
)
102 (last-col (- (window-width) window-min-width
)))
103 (if (< last-col first-col
)
104 (error "window too narrow to split")
105 (split-window-horizontally
106 (min (max new-width first-col
) last-col
))))))
108 (defun mouse-set-point (event)
109 "Move point to the position clicked on with the mouse.
110 This should be bound to a mouse click event type."
112 ;; Use event-end in case called from mouse-drag-region.
113 ;; If EVENT is a click, event-end and event-start give same value.
114 (let ((posn (event-end event
)))
115 (and (window-minibuffer-p (posn-window posn
))
116 (not (minibuffer-window-active-p (posn-window posn
)))
117 (error "Minibuffer window is not active"))
118 (select-window (posn-window posn
))
119 (if (numberp (posn-point posn
))
120 (goto-char (posn-point posn
)))))
122 (defun mouse-set-region (click)
123 "Set the region to the text dragged over, and copy to kill ring.
124 This should be bound to a mouse drag event."
126 (let ((posn (event-start click
))
127 (end (event-end click
)))
128 (select-window (posn-window posn
))
129 (if (numberp (posn-point posn
))
130 (goto-char (posn-point posn
)))
131 ;; If mark is highlighted, no need to bounce the cursor.
132 (or (and transient-mark-mode
133 (eq (framep (selected-frame)) 'x
))
137 (if (numberp (posn-point end
))
138 (goto-char (posn-point end
)))
139 ;; Don't set this-command to kill-region, so that a following
140 ;; C-w will not double the text in the kill ring.
142 (copy-region-as-kill (mark) (point)))))
144 (defvar mouse-scroll-delay
0.25
145 "*The pause between scroll steps caused by mouse drags, in seconds.
146 If you drag the mouse beyond the edge of a window, Emacs scrolls the
147 window to bring the text beyond that edge into view, with a delay of
148 this many seconds between scroll steps. Scrolling stops when you move
149 the mouse back into the window, or release the button.
150 This variable's value may be non-integral.
151 Setting this to zero causes Emacs to scroll as fast as it can.")
153 (defun mouse-scroll-subr (jump &optional overlay start
)
154 "Scroll the selected window JUMP lines at a time, until new input arrives.
155 If OVERLAY is an overlay, let it stretch from START to the far edge of
156 the newly visible text.
157 Upon exit, point is at the far edge of the newly visible text."
159 (goto-char (window-start))
160 (if (not (zerop (vertical-motion jump
)))
162 (set-window-start (selected-window) (point))
165 (goto-char (window-end (selected-window)))
166 ;; window-end doesn't reflect the window's new
167 ;; start position until the next redisplay. Hurrah.
168 (vertical-motion (1- jump
)))
169 (goto-char (window-start (selected-window))))
171 (move-overlay overlay start
(point)))
173 (sit-for mouse-scroll-delay
))))))
176 (defvar mouse-drag-overlay
(make-overlay 1 1))
177 (overlay-put mouse-drag-overlay
'face
'region
)
179 (defvar mouse-selection-click-count
0)
181 (defun mouse-drag-region (start-event)
182 "Set the region to the text that the mouse is dragged over.
183 Highlight the drag area as you move the mouse.
184 This must be bound to a button-down mouse event.
185 In Transient Mark mode, the highlighting remains once you
186 release the mouse button. Otherwise, it does not."
188 (let* ((start-posn (event-start start-event
))
189 (start-point (posn-point start-posn
))
190 (start-window (posn-window start-posn
))
191 (start-frame (window-frame start-window
))
192 (bounds (window-edges start-window
))
194 (bottom (if (window-minibuffer-p start-window
)
196 ;; Don't count the mode line.
197 (1- (nth 3 bounds
))))
198 (click-count (1- (event-click-count start-event
))))
199 (setq mouse-selection-click-count click-count
)
200 (mouse-set-point start-event
)
201 (let ((range (mouse-start-end start-point start-point click-count
)))
202 (move-overlay mouse-drag-overlay
(car range
) (nth 1 range
)
203 (window-buffer start-window
)))
205 (let (event end end-point
)
208 (setq event
(read-event))
209 (or (mouse-movement-p event
)
210 (eq (car-safe event
) 'switch-frame
)))
211 (if (eq (car-safe event
) 'switch-frame
)
213 (setq end
(event-end event
)
214 end-point
(posn-point end
))
218 ;; Ignore switch-frame events.
219 ((eq (car-safe event
) 'switch-frame
))
221 ;; Are we moving within the original window?
222 ((and (eq (posn-window end
) start-window
)
223 (integer-or-marker-p end-point
))
224 (goto-char end-point
)
225 (let ((range (mouse-start-end start-point
(point) click-count
)))
226 (move-overlay mouse-drag-overlay
(car range
) (nth 1 range
))))
228 ;; Are we moving on a different window on the same frame?
229 ((and (windowp (posn-window end
))
230 (eq (window-frame (posn-window end
)) start-frame
))
232 (+ (nth 1 (window-edges (posn-window end
)))
233 (cdr (posn-col-row end
)))))
237 (- mouse-row top
) mouse-drag-overlay start-point
))
239 (>= mouse-row bottom
))
240 (mouse-scroll-subr (1+ (- mouse-row bottom
))
241 mouse-drag-overlay start-point
)))))
244 (let ((mouse-y (cdr (cdr (mouse-position))))
245 (menu-bar-lines (or (cdr (assq 'menu-bar-lines
249 ;; Are we on the menu bar?
250 (and (integerp mouse-y
) (< mouse-y menu-bar-lines
)
251 (mouse-scroll-subr (- mouse-y menu-bar-lines
)
252 mouse-drag-overlay start-point
))))))))
254 (if (and (eq (get (event-basic-type event
) 'event-kind
) 'mouse-click
)
255 (eq (posn-window (event-end event
)) start-window
)
256 (numberp (posn-point (event-end event
))))
257 (let ((fun (key-binding (vector (car event
)))))
258 (if (memq fun
'(mouse-set-region mouse-set-point
))
259 (if (not (= (overlay-start mouse-drag-overlay
)
260 (overlay-end mouse-drag-overlay
)))
262 (push-mark (overlay-start mouse-drag-overlay
) t t
)
263 (goto-char (overlay-end mouse-drag-overlay
))
264 (copy-region-as-kill (point) (mark t
)))
265 (goto-char (overlay-end mouse-drag-overlay
))
266 (setq this-command
'mouse-set-point
))
268 (funcall fun event
)))))
269 (delete-overlay mouse-drag-overlay
))))
271 ;; Commands to handle xterm-style multiple clicks.
273 (defun mouse-skip-word (dir)
274 "Skip over word, over whitespace, or over identical punctuation.
275 If DIR is positive skip forward; if negative, skip backward."
276 (let* ((char (following-char))
277 (syntax (char-to-string (char-syntax char
))))
278 (if (or (string= syntax
"w") (string= syntax
" "))
280 (skip-syntax-backward syntax
)
281 (skip-syntax-forward syntax
))
283 (while (and (not (bobp)) (= (preceding-char) char
))
285 (while (and (not (eobp)) (= (following-char) char
))
286 (forward-char 1))))))
288 ;; Return a list of region bounds based on START and END according to MODE.
289 ;; If MODE is 0 then set point to (min START END), mark to (max START END).
290 ;; If MODE is 1 then set point to start of word at (min START END),
291 ;; mark to end of word at (max START END).
292 ;; If MODE is 2 then do the same for lines.
293 (defun mouse-start-end (start end mode
)
298 (setq mode
(mod mode
3))
304 (= (char-syntax (char-after start
)) ?\
())
313 (= (char-syntax (char-after start
)) ?\
)))
314 (list (save-excursion
315 (goto-char (1+ start
))
320 (list (save-excursion
329 (list (save-excursion
331 (beginning-of-line 1)
338 ;; Subroutine: set the mark where CLICK happened,
339 ;; but don't do anything else.
340 (defun mouse-set-mark-fast (click)
341 (let ((posn (event-start click
)))
342 (select-window (posn-window posn
))
343 (if (numberp (posn-point posn
))
344 (push-mark (posn-point posn
) t t
))))
346 ;; Momentarily show where the mark is, if highlighting doesn't show it.
347 (defun mouse-show-mark ()
348 (or transient-mark-mode
353 (defun mouse-set-mark (click)
354 "Set mark at the position clicked on with the mouse.
355 Display cursor at that position for a second.
356 This must be bound to a mouse click."
358 (let ((point-save (point)))
360 (progn (mouse-set-point click
)
362 (or transient-mark-mode
364 (goto-char point-save
))))
366 (defun mouse-kill (click)
367 "Kill the region between point and the mouse click.
368 The text is saved in the kill ring, as with \\[kill-region]."
370 (let ((click-posn (posn-point (event-start click
))))
371 (if (numberp click-posn
)
372 (kill-region (min (point) click-posn
)
373 (max (point) click-posn
)))))
375 (defun mouse-yank-at-click (click arg
)
376 "Insert the last stretch of killed text at the position clicked on.
377 Also move point to one end of the text thus inserted (normally the end).
378 Prefix arguments are interpreted as with \\[yank].
379 If `mouse-yank-at-point' is non-nil, insert at point
380 regardless of where you click."
382 (or mouse-yank-at-point
(mouse-set-point click
))
383 (setq this-command
'yank
)
386 (defun mouse-kill-ring-save (click)
387 "Copy the region between point and the mouse click in the kill ring.
388 This does not delete the region; it acts like \\[kill-ring-save]."
390 (mouse-set-mark-fast click
)
391 (kill-ring-save (point) (mark t
))
394 ;;; This function used to delete the text between point and the mouse
395 ;;; whenever it was equal to the front of the kill ring, but some
396 ;;; people found that confusing.
398 ;;; A list (TEXT START END), describing the text and position of the last
399 ;;; invocation of mouse-save-then-kill.
400 (defvar mouse-save-then-kill-posn nil
)
402 (defun mouse-save-then-kill-delete-region (beg end
)
403 ;; We must make our own undo boundaries
404 ;; because they happen automatically only for the current buffer.
406 (if (or (= beg end
) (eq buffer-undo-list t
))
407 ;; If we have no undo list in this buffer,
409 (delete-region beg end
)
410 ;; Delete, but make the undo-list entry share with the kill ring.
411 ;; First, delete just one char, so in case buffer is being modified
412 ;; for the first time, the undo list records that fact.
414 (+ beg
(if (> end beg
) 1 -
1)))
415 (let ((buffer-undo-list buffer-undo-list
))
416 ;; Undo that deletion--but don't change the undo list!
417 (primitive-undo 1 buffer-undo-list
)
418 ;; Now delete the rest of the specified region,
419 ;; but don't record it.
420 (setq buffer-undo-list t
)
421 (if (/= (length (car kill-ring
)) (- (max end beg
) (min end beg
)))
422 (error "Lossage in mouse-save-then-kill-delete-region"))
423 (delete-region beg end
))
424 (let ((tail buffer-undo-list
))
425 ;; Search back in buffer-undo-list for the string
426 ;; that came from deleting one character.
427 (while (and tail
(not (stringp (car (car tail
)))))
428 (setq tail
(cdr tail
)))
429 ;; Replace it with an entry for the entire deleted text.
431 (setcar tail
(cons (car kill-ring
) (min beg end
))))))
434 (defun mouse-save-then-kill (click)
435 "Save text to point in kill ring; the second time, kill the text.
436 If the text between point and the mouse is the same as what's
437 at the front of the kill ring, this deletes the text.
438 Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
439 which prepares for a second click to delete the text.
441 If you have selected words or lines, this command extends the
442 selection through the word or line clicked on. If you do this
443 again in a different position, it extends the selection again.
444 If you do this twice in the same position, the selection is killed."
446 (let ((click-posn (posn-point (event-start click
)))
447 ;; Don't let a subsequent kill command append to this one:
448 ;; prevent setting this-command to kill-region.
449 (this-command this-command
))
450 (if (> (mod mouse-selection-click-count
3) 0)
451 (if (not (and (eq last-command
'mouse-save-then-kill
)
453 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn
))))))
454 ;; Find both ends of the object selected by this click.
456 (mouse-start-end click-posn click-posn
457 mouse-selection-click-count
)))
458 ;; Move whichever end is closer to the click.
459 ;; That's what xterm does, and it seems reasonable.
460 (if (< (abs (- click-posn
(mark t
)))
461 (abs (- click-posn
(point))))
462 (set-mark (car range
))
463 (goto-char (nth 1 range
)))
464 ;; We have already put the old region in the kill ring.
465 ;; Replace it with the extended region.
466 ;; (It would be annoying to make a separate entry.)
467 (setcar kill-ring
(buffer-substring (point) (mark t
)))
468 (if interprogram-cut-function
469 (funcall interprogram-cut-function
(car kill-ring
)))
470 ;; Arrange for a repeated mouse-3 to kill this region.
471 (setq mouse-save-then-kill-posn
472 (list (car kill-ring
) (point) click-posn
))
474 ;; If we click this button again without moving it,
476 (mouse-save-then-kill-delete-region (point) (mark))
477 (setq mouse-selection-click-count
0)
478 (setq mouse-save-then-kill-posn nil
))
479 (if (and (eq last-command
'mouse-save-then-kill
)
480 mouse-save-then-kill-posn
481 (eq (car mouse-save-then-kill-posn
) (car kill-ring
))
482 (equal (cdr mouse-save-then-kill-posn
) (list (point) click-posn
)))
483 ;; If this is the second time we've called
484 ;; mouse-save-then-kill, delete the text from the buffer.
486 (mouse-save-then-kill-delete-region (point) (mark))
487 ;; After we kill, another click counts as "the first time".
488 (setq mouse-save-then-kill-posn nil
))
489 (if (or (and (eq last-command
'mouse-save-then-kill
)
490 mouse-save-then-kill-posn
)
491 (and mark-active transient-mark-mode
)
492 (and (eq last-command
'mouse-drag-region
)
493 (or mark-even-if-inactive
494 (not transient-mark-mode
))))
495 ;; We have a selection or suitable region, so adjust it.
496 (let* ((posn (event-start click
))
497 (new (posn-point posn
)))
498 (select-window (posn-window posn
))
501 ;; Move whichever end of the region is closer to the click.
502 ;; That is what xterm does, and it seems reasonable.
503 (if (< (abs (- new
(point))) (abs (- new
(mark t
))))
506 (setq deactivate-mark nil
)))
507 (setcar kill-ring
(buffer-substring (point) (mark t
)))
508 (if interprogram-cut-function
509 (funcall interprogram-cut-function
(car kill-ring
))))
510 ;; We just have point, so set mark here.
511 (mouse-set-mark-fast click
)
512 (kill-ring-save (point) (mark t
))
514 (setq mouse-save-then-kill-posn
515 (list (car kill-ring
) (point) click-posn
))))))
517 (global-set-key [M-mouse-1
] 'mouse-start-secondary
)
518 (global-set-key [M-drag-mouse-1
] 'mouse-set-secondary
)
519 (global-set-key [M-down-mouse-1
] 'mouse-drag-secondary
)
520 (global-set-key [M-mouse-3
] 'mouse-secondary-save-then-kill
)
521 (global-set-key [M-mouse-2
] 'mouse-yank-secondary
)
523 ;; An overlay which records the current secondary selection
524 ;; or else is deleted when there is no secondary selection.
526 (defvar mouse-secondary-overlay nil
)
528 ;; A marker which records the specified first end for a secondary selection.
530 (defvar mouse-secondary-start nil
)
532 (defun mouse-start-secondary (click)
533 "Set one end of the secondary selection to the position clicked on.
534 Use \\[mouse-secondary-save-then-kill] to set the other end
535 and complete the secondary selection."
537 (let ((posn (event-start click
)))
539 (set-buffer (window-buffer (posn-window posn
)))
540 ;; Cancel any preexisting secondary selection.
541 (if mouse-secondary-overlay
542 (delete-overlay mouse-secondary-overlay
))
543 (if (numberp (posn-point posn
))
545 (or mouse-secondary-start
546 (setq mouse-secondary-start
(make-marker)))
547 (move-marker mouse-secondary-start
(posn-point posn
)))))))
549 (defun mouse-set-secondary (click)
550 "Set the secondary selection to the text that the mouse is dragged over.
551 This must be bound to a mouse drag event."
553 (let ((posn (event-start click
))
555 (end (event-end click
)))
557 (set-buffer (window-buffer (posn-window posn
)))
558 (if (numberp (posn-point posn
))
559 (setq beg
(posn-point posn
)))
560 (if mouse-secondary-overlay
561 (move-overlay mouse-secondary-overlay beg
(posn-point end
))
562 (setq mouse-secondary-overlay
(make-overlay beg
(posn-point end
))))
563 (overlay-put mouse-secondary-overlay
'face
'secondary-selection
))))
565 (defun mouse-drag-secondary (start-event)
566 "Set the secondary selection to the text that the mouse is dragged over.
567 Highlight the drag area as you move the mouse.
568 This must be bound to a button-down mouse event."
570 (let* ((start-posn (event-start start-event
))
571 (start-point (posn-point start-posn
))
572 (start-window (posn-window start-posn
))
573 (start-frame (window-frame start-window
))
574 (bounds (window-edges start-window
))
576 (bottom (if (window-minibuffer-p start-window
)
578 ;; Don't count the mode line.
579 (1- (nth 3 bounds
))))
580 (click-count (1- (event-click-count start-event
))))
582 (set-buffer (window-buffer start-window
))
583 (setq mouse-selection-click-count click-count
)
584 (or mouse-secondary-overlay
585 (setq mouse-secondary-overlay
586 (make-overlay (point) (point))))
587 (overlay-put mouse-secondary-overlay
'face
'secondary-selection
)
588 (if (> (mod click-count
3) 0)
589 ;; Double or triple press: make an initial selection
590 ;; of one word or line.
591 (let ((range (mouse-start-end start-point start-point click-count
)))
592 (set-marker mouse-secondary-start nil
)
593 (move-overlay mouse-secondary-overlay
1 1
594 (window-buffer start-window
))
595 (move-overlay mouse-secondary-overlay
(car range
) (nth 1 range
)
596 (window-buffer start-window
)))
597 ;; Single-press: cancel any preexisting secondary selection.
598 (or mouse-secondary-start
599 (setq mouse-secondary-start
(make-marker)))
600 (set-marker mouse-secondary-start start-point
)
601 (delete-overlay mouse-secondary-overlay
))
602 (let (event end end-point
)
605 (setq event
(read-event))
606 (or (mouse-movement-p event
)
607 (eq (car-safe event
) 'switch-frame
)))
609 (if (eq (car-safe event
) 'switch-frame
)
611 (setq end
(event-end event
)
612 end-point
(posn-point end
))
615 ;; Ignore switch-frame events.
616 ((eq (car-safe event
) 'switch-frame
))
618 ;; Are we moving within the original window?
619 ((and (eq (posn-window end
) start-window
)
620 (integer-or-marker-p end-point
))
621 (if (/= start-point end-point
)
622 (set-marker mouse-secondary-start nil
))
623 (let ((range (mouse-start-end start-point end-point
625 (move-overlay mouse-secondary-overlay
626 (car range
) (nth 1 range
))))
628 ;; Are we moving on a different window on the same frame?
629 ((and (windowp (posn-window end
))
630 (eq (window-frame (posn-window end
)) start-frame
))
632 (+ (nth 1 (window-edges (posn-window end
)))
633 (cdr (posn-col-row end
)))))
637 (- mouse-row top
) mouse-secondary-overlay start-point
))
639 (>= mouse-row bottom
))
640 (mouse-scroll-subr (1+ (- mouse-row bottom
))
641 mouse-drag-overlay start-point
)))))
644 (let ((mouse-y (cdr (cdr (mouse-position))))
645 (menu-bar-lines (or (cdr (assq 'menu-bar-lines
649 ;; Are we on the menu bar?
650 (and (integerp mouse-y
) (< mouse-y menu-bar-lines
)
651 (mouse-scroll-subr (- mouse-y menu-bar-lines
)
652 mouse-secondary-overlay start-point
))))))))
654 (if (and (eq (get (event-basic-type event
) 'event-kind
) 'mouse-click
)
655 (eq (posn-window (event-end event
)) start-window
)
656 (numberp (posn-point (event-end event
))))
657 (if (marker-position mouse-secondary-start
)
658 (save-window-excursion
659 (delete-overlay mouse-secondary-overlay
)
660 (x-set-selection 'SECONDARY nil
)
661 (select-window start-window
)
663 (goto-char mouse-secondary-start
)
667 (buffer-substring (overlay-start mouse-secondary-overlay
)
668 (overlay-end mouse-secondary-overlay
)))))))))
670 (defun mouse-yank-secondary (click)
671 "Insert the secondary selection at the position clicked on.
672 Move point to the end of the inserted text.
673 If `mouse-yank-at-point' is non-nil, insert at point
674 regardless of where you click."
676 (or mouse-yank-at-point
(mouse-set-point click
))
677 (insert (x-get-selection 'SECONDARY
)))
679 (defun mouse-kill-secondary ()
680 "Kill the text in the secondary selection.
681 This is intended more as a keyboard command than as a mouse command
682 but it can work as either one.
684 The current buffer (in case of keyboard use), or the buffer clicked on,
685 must be the one that the secondary selection is in. This requirement
686 is to prevent accidents."
688 (let* ((keys (this-command-keys))
689 (click (elt keys
(1- (length keys
)))))
690 (or (eq (overlay-buffer mouse-secondary-overlay
)
692 (window-buffer (posn-window (event-start click
)))
694 (error "Select or click on the buffer where the secondary selection is")))
696 (set-buffer (overlay-buffer mouse-secondary-overlay
))
697 (kill-region (overlay-start mouse-secondary-overlay
)
698 (overlay-end mouse-secondary-overlay
)))
699 (delete-overlay mouse-secondary-overlay
)
700 (x-set-selection 'SECONDARY nil
)
701 (setq mouse-secondary-overlay nil
))
703 (defun mouse-secondary-save-then-kill (click)
704 "Save text to point in kill ring; the second time, kill the text.
705 If the text between point and the mouse is the same as what's
706 at the front of the kill ring, this deletes the text.
707 Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
708 which prepares for a second click to delete the text.
710 If you have selected words or lines, this command extends the
711 selection through the word or line clicked on. If you do this
712 again in a different position, it extends the selection again.
713 If you do this twice in the same position, the selection is killed."
715 (let ((posn (event-start click
))
716 (click-posn (posn-point (event-start click
)))
717 ;; Don't let a subsequent kill command append to this one:
718 ;; prevent setting this-command to kill-region.
719 (this-command this-command
))
720 (or (eq (window-buffer (posn-window posn
))
721 (or (and mouse-secondary-overlay
722 (overlay-buffer mouse-secondary-overlay
))
723 (if mouse-secondary-start
724 (marker-buffer mouse-secondary-start
))))
725 (error "Wrong buffer"))
727 (set-buffer (window-buffer (posn-window posn
)))
728 (if (> (mod mouse-selection-click-count
3) 0)
729 (if (not (and (eq last-command
'mouse-secondary-save-then-kill
)
731 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn
))))))
732 ;; Find both ends of the object selected by this click.
734 (mouse-start-end click-posn click-posn
735 mouse-selection-click-count
)))
736 ;; Move whichever end is closer to the click.
737 ;; That's what xterm does, and it seems reasonable.
738 (if (< (abs (- click-posn
(overlay-start mouse-secondary-overlay
)))
739 (abs (- click-posn
(overlay-end mouse-secondary-overlay
))))
740 (move-overlay mouse-secondary-overlay
(car range
)
741 (overlay-end mouse-secondary-overlay
))
742 (move-overlay mouse-secondary-overlay
743 (overlay-start mouse-secondary-overlay
)
745 ;; We have already put the old region in the kill ring.
746 ;; Replace it with the extended region.
747 ;; (It would be annoying to make a separate entry.)
748 (setcar kill-ring
(buffer-substring
749 (overlay-start mouse-secondary-overlay
)
750 (overlay-end mouse-secondary-overlay
)))
751 (if interprogram-cut-function
752 (funcall interprogram-cut-function
(car kill-ring
)))
753 ;; Arrange for a repeated mouse-3 to kill this region.
754 (setq mouse-save-then-kill-posn
755 (list (car kill-ring
) (point) click-posn
)))
756 ;; If we click this button again without moving it,
759 (mouse-save-then-kill-delete-region
760 (overlay-start mouse-secondary-overlay
)
761 (overlay-end mouse-secondary-overlay
))
762 (setq mouse-save-then-kill-posn nil
)
763 (setq mouse-selection-click-count
0)
764 (delete-overlay mouse-secondary-overlay
)))
765 (if (and (eq last-command
'mouse-secondary-save-then-kill
)
766 mouse-save-then-kill-posn
767 (eq (car mouse-save-then-kill-posn
) (car kill-ring
))
768 (equal (cdr mouse-save-then-kill-posn
) (list (point) click-posn
)))
769 ;; If this is the second time we've called
770 ;; mouse-secondary-save-then-kill, delete the text from the buffer.
772 (mouse-save-then-kill-delete-region
773 (overlay-start mouse-secondary-overlay
)
774 (overlay-end mouse-secondary-overlay
))
775 (setq mouse-save-then-kill-posn nil
)
776 (delete-overlay mouse-secondary-overlay
))
777 (if (overlay-start mouse-secondary-overlay
)
778 ;; We have a selection, so adjust it.
780 (if (numberp click-posn
)
782 ;; Move whichever end of the region is closer to the click.
783 ;; That is what xterm does, and it seems reasonable.
784 (if (< (abs (- click-posn
(overlay-start mouse-secondary-overlay
)))
785 (abs (- click-posn
(overlay-end mouse-secondary-overlay
))))
786 (move-overlay mouse-secondary-overlay click-posn
787 (overlay-end mouse-secondary-overlay
))
788 (move-overlay mouse-secondary-overlay
789 (overlay-start mouse-secondary-overlay
)
791 (setq deactivate-mark nil
)))
792 (setcar kill-ring
(buffer-substring
793 (overlay-start mouse-secondary-overlay
)
794 (overlay-end mouse-secondary-overlay
)))
795 (if interprogram-cut-function
796 (funcall interprogram-cut-function
(car kill-ring
))))
797 (if mouse-secondary-start
798 ;; All we have is one end of a selection,
799 ;; so put the other end here.
800 (let ((start (+ 0 mouse-secondary-start
)))
801 (kill-ring-save start click-posn
)
802 (if mouse-secondary-overlay
803 (move-overlay mouse-secondary-overlay start click-posn
)
804 (setq mouse-secondary-overlay
(make-overlay start click-posn
)))
805 (overlay-put mouse-secondary-overlay
'face
'secondary-selection
))))
806 (setq mouse-save-then-kill-posn
807 (list (car kill-ring
) (point) click-posn
))))
808 (x-set-selection 'SECONDARY
809 (if (overlay-buffer mouse-secondary-overlay
)
811 (overlay-start mouse-secondary-overlay
)
812 (overlay-end mouse-secondary-overlay
)))))))
814 (defun mouse-buffer-menu (event)
815 "Pop up a menu of buffers for selection with the mouse.
816 This switches buffers in the window that you clicked on,
817 and selects that window."
821 (cons "Select Buffer"
822 (let ((tail (buffer-list))
826 (or (eq ?\
(aref (buffer-name (car tail
)) 0))
829 (length (buffer-name (car tail
))))))
830 (setq tail
(cdr tail
)))
831 (setq tail
(buffer-list))
833 (let ((elt (car tail
)))
834 (if (not (string-match "^ "
839 (format "%%%ds %%s%%s %%s"
842 (if (buffer-modified-p elt
)
846 (if buffer-read-only
"%" " "))
847 (or (buffer-file-name elt
) ""))
850 (setq tail
(cdr tail
)))
852 (let ((buf (x-popup-menu event menu
))
853 (window (posn-window (event-start event
))))
856 (or (framep window
) (select-window window
))
857 (switch-to-buffer buf
))))))
859 ;;; These need to be rewritten for the new scroll bar implementation.
861 ;;;!! ;; Commands for the scroll bar.
863 ;;;!! (defun mouse-scroll-down (click)
864 ;;;!! (interactive "@e")
865 ;;;!! (scroll-down (1+ (cdr (mouse-coords click)))))
867 ;;;!! (defun mouse-scroll-up (click)
868 ;;;!! (interactive "@e")
869 ;;;!! (scroll-up (1+ (cdr (mouse-coords click)))))
871 ;;;!! (defun mouse-scroll-down-full ()
872 ;;;!! (interactive "@")
873 ;;;!! (scroll-down nil))
875 ;;;!! (defun mouse-scroll-up-full ()
876 ;;;!! (interactive "@")
877 ;;;!! (scroll-up nil))
879 ;;;!! (defun mouse-scroll-move-cursor (click)
880 ;;;!! (interactive "@e")
881 ;;;!! (move-to-window-line (1+ (cdr (mouse-coords click)))))
883 ;;;!! (defun mouse-scroll-absolute (event)
884 ;;;!! (interactive "@e")
885 ;;;!! (let* ((pos (car event))
886 ;;;!! (position (car pos))
887 ;;;!! (length (car (cdr pos))))
888 ;;;!! (if (<= length 0) (setq length 1))
889 ;;;!! (let* ((scale-factor (max 1 (/ length (/ 8000000 (buffer-size)))))
890 ;;;!! (newpos (* (/ (* (/ (buffer-size) scale-factor)
893 ;;;!! scale-factor)))
894 ;;;!! (goto-char newpos)
895 ;;;!! (recenter '(4)))))
897 ;;;!! (defun mouse-scroll-left (click)
898 ;;;!! (interactive "@e")
899 ;;;!! (scroll-left (1+ (car (mouse-coords click)))))
901 ;;;!! (defun mouse-scroll-right (click)
902 ;;;!! (interactive "@e")
903 ;;;!! (scroll-right (1+ (car (mouse-coords click)))))
905 ;;;!! (defun mouse-scroll-left-full ()
906 ;;;!! (interactive "@")
907 ;;;!! (scroll-left nil))
909 ;;;!! (defun mouse-scroll-right-full ()
910 ;;;!! (interactive "@")
911 ;;;!! (scroll-right nil))
913 ;;;!! (defun mouse-scroll-move-cursor-horizontally (click)
914 ;;;!! (interactive "@e")
915 ;;;!! (move-to-column (1+ (car (mouse-coords click)))))
917 ;;;!! (defun mouse-scroll-absolute-horizontally (event)
918 ;;;!! (interactive "@e")
919 ;;;!! (let* ((pos (car event))
920 ;;;!! (position (car pos))
921 ;;;!! (length (car (cdr pos))))
922 ;;;!! (set-window-hscroll (selected-window) 33)))
924 ;;;!! (global-set-key [scroll-bar mouse-1] 'mouse-scroll-up)
925 ;;;!! (global-set-key [scroll-bar mouse-2] 'mouse-scroll-absolute)
926 ;;;!! (global-set-key [scroll-bar mouse-3] 'mouse-scroll-down)
928 ;;;!! (global-set-key [vertical-slider mouse-1] 'mouse-scroll-move-cursor)
929 ;;;!! (global-set-key [vertical-slider mouse-2] 'mouse-scroll-move-cursor)
930 ;;;!! (global-set-key [vertical-slider mouse-3] 'mouse-scroll-move-cursor)
932 ;;;!! (global-set-key [thumbup mouse-1] 'mouse-scroll-up-full)
933 ;;;!! (global-set-key [thumbup mouse-2] 'mouse-scroll-up-full)
934 ;;;!! (global-set-key [thumbup mouse-3] 'mouse-scroll-up-full)
936 ;;;!! (global-set-key [thumbdown mouse-1] 'mouse-scroll-down-full)
937 ;;;!! (global-set-key [thumbdown mouse-2] 'mouse-scroll-down-full)
938 ;;;!! (global-set-key [thumbdown mouse-3] 'mouse-scroll-down-full)
940 ;;;!! (global-set-key [horizontal-scroll-bar mouse-1] 'mouse-scroll-left)
941 ;;;!! (global-set-key [horizontal-scroll-bar mouse-2]
942 ;;;!! 'mouse-scroll-absolute-horizontally)
943 ;;;!! (global-set-key [horizontal-scroll-bar mouse-3] 'mouse-scroll-right)
945 ;;;!! (global-set-key [horizontal-slider mouse-1]
946 ;;;!! 'mouse-scroll-move-cursor-horizontally)
947 ;;;!! (global-set-key [horizontal-slider mouse-2]
948 ;;;!! 'mouse-scroll-move-cursor-horizontally)
949 ;;;!! (global-set-key [horizontal-slider mouse-3]
950 ;;;!! 'mouse-scroll-move-cursor-horizontally)
952 ;;;!! (global-set-key [thumbleft mouse-1] 'mouse-scroll-left-full)
953 ;;;!! (global-set-key [thumbleft mouse-2] 'mouse-scroll-left-full)
954 ;;;!! (global-set-key [thumbleft mouse-3] 'mouse-scroll-left-full)
956 ;;;!! (global-set-key [thumbright mouse-1] 'mouse-scroll-right-full)
957 ;;;!! (global-set-key [thumbright mouse-2] 'mouse-scroll-right-full)
958 ;;;!! (global-set-key [thumbright mouse-3] 'mouse-scroll-right-full)
960 ;;;!! (global-set-key [horizontal-scroll-bar S-mouse-2]
961 ;;;!! 'mouse-split-window-horizontally)
962 ;;;!! (global-set-key [mode-line S-mouse-2]
963 ;;;!! 'mouse-split-window-horizontally)
964 ;;;!! (global-set-key [vertical-scroll-bar S-mouse-2]
965 ;;;!! 'mouse-split-window)
968 ;;;!! ;;;; Here are experimental things being tested. Mouse events
969 ;;;!! ;;;; are of the form:
970 ;;;!! ;;;; ((x y) window screen-part key-sequence timestamp)
973 ;;;!! ;;;; Dynamically track mouse coordinates
976 ;;;!! ;;(defun track-mouse (event)
977 ;;;!! ;; "Track the coordinates, absolute and relative, of the mouse."
978 ;;;!! ;; (interactive "@e")
979 ;;;!! ;; (while mouse-grabbed
980 ;;;!! ;; (let* ((pos (read-mouse-position (selected-screen)))
981 ;;;!! ;; (abs-x (car pos))
982 ;;;!! ;; (abs-y (cdr pos))
983 ;;;!! ;; (relative-coordinate (coordinates-in-window-p
984 ;;;!! ;; (list (car pos) (cdr pos))
985 ;;;!! ;; (selected-window))))
986 ;;;!! ;; (if (consp relative-coordinate)
987 ;;;!! ;; (message "mouse: [%d %d], (%d %d)" abs-x abs-y
988 ;;;!! ;; (car relative-coordinate)
989 ;;;!! ;; (car (cdr relative-coordinate)))
990 ;;;!! ;; (message "mouse: [%d %d]" abs-x abs-y)))))
993 ;;;!! ;; Dynamically put a box around the line indicated by point
996 ;;;!! ;;(require 'backquote)
998 ;;;!! ;;(defun mouse-select-buffer-line (event)
999 ;;;!! ;; (interactive "@e")
1000 ;;;!! ;; (let ((relative-coordinate
1001 ;;;!! ;; (coordinates-in-window-p (car event) (selected-window)))
1002 ;;;!! ;; (abs-y (car (cdr (car event)))))
1003 ;;;!! ;; (if (consp relative-coordinate)
1005 ;;;!! ;; (save-excursion
1006 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1007 ;;;!! ;; (x-draw-rectangle
1008 ;;;!! ;; (selected-screen)
1010 ;;;!! ;; (save-excursion
1011 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1012 ;;;!! ;; (end-of-line)
1013 ;;;!! ;; (push-mark nil t)
1014 ;;;!! ;; (beginning-of-line)
1015 ;;;!! ;; (- (region-end) (region-beginning))) 1))
1016 ;;;!! ;; (sit-for 1)
1017 ;;;!! ;; (x-erase-rectangle (selected-screen))))))
1019 ;;;!! ;;(defvar last-line-drawn nil)
1020 ;;;!! ;;(defvar begin-delim "[^ \t]")
1021 ;;;!! ;;(defvar end-delim "[^ \t]")
1023 ;;;!! ;;(defun mouse-boxing (event)
1024 ;;;!! ;; (interactive "@e")
1025 ;;;!! ;; (save-excursion
1026 ;;;!! ;; (let ((screen (selected-screen)))
1027 ;;;!! ;; (while (= (x-mouse-events) 0)
1028 ;;;!! ;; (let* ((pos (read-mouse-position screen))
1029 ;;;!! ;; (abs-x (car pos))
1030 ;;;!! ;; (abs-y (cdr pos))
1031 ;;;!! ;; (relative-coordinate
1032 ;;;!! ;; (coordinates-in-window-p (` ((, abs-x) (, abs-y)))
1033 ;;;!! ;; (selected-window)))
1034 ;;;!! ;; (begin-reg nil)
1035 ;;;!! ;; (end-reg nil)
1036 ;;;!! ;; (end-column nil)
1037 ;;;!! ;; (begin-column nil))
1038 ;;;!! ;; (if (and (consp relative-coordinate)
1039 ;;;!! ;; (or (not last-line-drawn)
1040 ;;;!! ;; (not (= last-line-drawn abs-y))))
1042 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1043 ;;;!! ;; (if (= (following-char) 10)
1046 ;;;!! ;; (setq begin-reg (1- (re-search-forward end-delim)))
1047 ;;;!! ;; (setq begin-column (1- (current-column)))
1048 ;;;!! ;; (end-of-line)
1049 ;;;!! ;; (setq end-reg (1+ (re-search-backward begin-delim)))
1050 ;;;!! ;; (setq end-column (1+ (current-column)))
1051 ;;;!! ;; (message "%s" (buffer-substring begin-reg end-reg))
1052 ;;;!! ;; (x-draw-rectangle screen
1053 ;;;!! ;; (setq last-line-drawn abs-y)
1054 ;;;!! ;; begin-column
1055 ;;;!! ;; (- end-column begin-column) 1))))))))))
1057 ;;;!! ;;(defun mouse-erase-box ()
1058 ;;;!! ;; (interactive)
1059 ;;;!! ;; (if last-line-drawn
1061 ;;;!! ;; (x-erase-rectangle (selected-screen))
1062 ;;;!! ;; (setq last-line-drawn nil))))
1064 ;;;!! ;;; (defun test-x-rectangle ()
1065 ;;;!! ;;; (use-local-mouse-map (setq rectangle-test-map (make-sparse-keymap)))
1066 ;;;!! ;;; (define-key rectangle-test-map mouse-motion-button-left 'mouse-boxing)
1067 ;;;!! ;;; (define-key rectangle-test-map mouse-button-left-up 'mouse-erase-box))
1070 ;;;!! ;; Here is how to do double clicking in lisp. About to change.
1073 ;;;!! (defvar double-start nil)
1074 ;;;!! (defconst double-click-interval 300
1075 ;;;!! "Max ticks between clicks")
1077 ;;;!! (defun double-down (event)
1078 ;;;!! (interactive "@e")
1079 ;;;!! (if double-start
1080 ;;;!! (let ((interval (- (nth 4 event) double-start)))
1081 ;;;!! (if (< interval double-click-interval)
1083 ;;;!! (backward-up-list 1)
1084 ;;;!! ;; (message "Interval %d" interval)
1085 ;;;!! (sleep-for 1)))
1086 ;;;!! (setq double-start nil))
1087 ;;;!! (setq double-start (nth 4 event))))
1089 ;;;!! (defun double-up (event)
1090 ;;;!! (interactive "@e")
1091 ;;;!! (and double-start
1092 ;;;!! (> (- (nth 4 event ) double-start) double-click-interval)
1093 ;;;!! (setq double-start nil)))
1095 ;;;!! ;;; (defun x-test-doubleclick ()
1096 ;;;!! ;;; (use-local-mouse-map (setq doubleclick-test-map (make-sparse-keymap)))
1097 ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left 'double-down)
1098 ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left-up 'double-up))
1101 ;;;!! ;; This scrolls while button is depressed. Use preferable in scroll bar.
1104 ;;;!! (defvar scrolled-lines 0)
1105 ;;;!! (defconst scroll-speed 1)
1107 ;;;!! (defun incr-scroll-down (event)
1108 ;;;!! (interactive "@e")
1109 ;;;!! (setq scrolled-lines 0)
1110 ;;;!! (incremental-scroll scroll-speed))
1112 ;;;!! (defun incr-scroll-up (event)
1113 ;;;!! (interactive "@e")
1114 ;;;!! (setq scrolled-lines 0)
1115 ;;;!! (incremental-scroll (- scroll-speed)))
1117 ;;;!! (defun incremental-scroll (n)
1118 ;;;!! (while (= (x-mouse-events) 0)
1119 ;;;!! (setq scrolled-lines (1+ (* scroll-speed scrolled-lines)))
1120 ;;;!! (scroll-down n)
1121 ;;;!! (sit-for 300 t)))
1123 ;;;!! (defun incr-scroll-stop (event)
1124 ;;;!! (interactive "@e")
1125 ;;;!! (message "Scrolled %d lines" scrolled-lines)
1126 ;;;!! (setq scrolled-lines 0)
1127 ;;;!! (sleep-for 1))
1129 ;;;!! ;;; (defun x-testing-scroll ()
1130 ;;;!! ;;; (let ((scrolling-map (function mouse-vertical-scroll-bar-prefix)))
1131 ;;;!! ;;; (define-key scrolling-map mouse-button-left 'incr-scroll-down)
1132 ;;;!! ;;; (define-key scrolling-map mouse-button-right 'incr-scroll-up)
1133 ;;;!! ;;; (define-key scrolling-map mouse-button-left-up 'incr-scroll-stop)
1134 ;;;!! ;;; (define-key scrolling-map mouse-button-right-up 'incr-scroll-stop)))
1137 ;;;!! ;; Some playthings suitable for picture mode? They need work.
1140 ;;;!! (defun mouse-kill-rectangle (event)
1141 ;;;!! "Kill the rectangle between point and the mouse cursor."
1142 ;;;!! (interactive "@e")
1143 ;;;!! (let ((point-save (point)))
1144 ;;;!! (save-excursion
1145 ;;;!! (mouse-set-point event)
1146 ;;;!! (push-mark nil t)
1147 ;;;!! (if (> point-save (point))
1148 ;;;!! (kill-rectangle (point) point-save)
1149 ;;;!! (kill-rectangle point-save (point))))))
1151 ;;;!! (defun mouse-open-rectangle (event)
1152 ;;;!! "Kill the rectangle between point and the mouse cursor."
1153 ;;;!! (interactive "@e")
1154 ;;;!! (let ((point-save (point)))
1155 ;;;!! (save-excursion
1156 ;;;!! (mouse-set-point event)
1157 ;;;!! (push-mark nil t)
1158 ;;;!! (if (> point-save (point))
1159 ;;;!! (open-rectangle (point) point-save)
1160 ;;;!! (open-rectangle point-save (point))))))
1162 ;;;!! ;; Must be a better way to do this.
1164 ;;;!! (defun mouse-multiple-insert (n char)
1165 ;;;!! (while (> n 0)
1167 ;;;!! (setq n (1- n))))
1169 ;;;!! ;; What this could do is not finalize until button was released.
1171 ;;;!! (defun mouse-move-text (event)
1172 ;;;!! "Move text from point to cursor position, inserting spaces."
1173 ;;;!! (interactive "@e")
1174 ;;;!! (let* ((relative-coordinate
1175 ;;;!! (coordinates-in-window-p (car event) (selected-window))))
1176 ;;;!! (if (consp relative-coordinate)
1177 ;;;!! (cond ((> (current-column) (car relative-coordinate))
1179 ;;;!! (- (car relative-coordinate) (current-column))))
1180 ;;;!! ((< (current-column) (car relative-coordinate))
1181 ;;;!! (mouse-multiple-insert
1182 ;;;!! (- (car relative-coordinate) (current-column)) " "))
1183 ;;;!! ((= (current-column) (car relative-coordinate)) (ding))))))
1185 ;; Choose a completion with the mouse.
1187 ;; Delete the longest partial match for STRING
1188 ;; that can be found before POINT.
1189 (defun mouse-delete-max-match (string)
1190 (let ((opoint (point))
1191 (len (min (length string
)
1192 (- (point) (point-min)))))
1193 (goto-char (- (point) (length string
)))
1194 (while (and (> len
0)
1195 (let ((tail (buffer-substring (point)
1197 (not (string= tail
(substring string
0 len
)))))
1202 (defun mouse-choose-completion (event)
1203 "Click on an alternative in the `*Completions*' buffer to choose it."
1205 (let ((buffer (window-buffer))
1208 (set-buffer (window-buffer (posn-window (event-start event
))))
1209 (if completion-reference-buffer
1210 (setq buffer completion-reference-buffer
))
1212 (goto-char (posn-point (event-start event
)))
1213 (skip-chars-backward "^ \t\n")
1214 (let ((beg (point)))
1215 (skip-chars-forward "^ \t\n")
1216 (setq choice
(buffer-substring beg
(point))))))
1217 (let ((owindow (selected-window)))
1218 (select-window (posn-window (event-start event
)))
1220 (select-window owindow
))
1222 (mouse-delete-max-match choice
)
1224 ;; Update point in the window that BUFFER is showing in.
1225 (let ((window (get-buffer-window buffer t
)))
1226 (set-window-point window
(point)))
1227 (and (equal buffer
(window-buffer (minibuffer-window)))
1228 (minibuffer-complete-and-exit))))
1232 (defun font-menu-add-default ()
1233 (let* ((default (cdr (assq 'font
(frame-parameters (selected-frame)))))
1234 (font-alist x-fixed-font-alist
)
1235 (elt (or (assoc "Misc" font-alist
) (nth 1 font-alist
))))
1236 (if (assoc "Default" elt
)
1237 (delete (assoc "Default" elt
) elt
))
1239 (cons (list "Default"
1240 (cdr (assq 'font
(frame-parameters (selected-frame)))))
1243 (defvar x-fixed-font-alist
1246 ("6x10" "-misc-fixed-medium-r-normal--10-100-75-75-c-60-*-1")
1247 ("6x12" "-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-*-1")
1248 ("6x13" "-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-*-1")
1250 "-b&h-lucidatypewriter-medium-r-normal-sans-0-0-0-0-m-0-*-1")
1251 ("7x13" "-misc-fixed-medium-r-normal--13-120-75-75-c-70-*-1")
1252 ("7x14" "-misc-fixed-medium-r-normal--14-130-75-75-c-70-*-1")
1253 ("9x15" "-misc-fixed-medium-r-normal--15-140-*-*-c-*-*-1")
1255 ("clean 8x8" "-schumacher-clean-medium-r-normal--*-80-*-*-c-*-*-1")
1256 ("clean 8x14" "-schumacher-clean-medium-r-normal--*-140-*-*-c-*-*-1")
1257 ("clean 8x10" "-schumacher-clean-medium-r-normal--*-100-*-*-c-*-*-1")
1258 ("clean 8x16" "-schumacher-clean-medium-r-normal--*-160-*-*-c-*-*-1")
1260 ("sony 8x16" "-sony-fixed-medium-r-normal--16-120-100-100-c-80-*-1")
1266 ;;; We don't seem to have these; who knows what they are.
1267 ;;; ("fg-18" "fg-18")
1268 ;;; ("fg-25" "fg-25")
1269 ;;; ("lucidasanstypewriter-12" "lucidasanstypewriter-12")
1270 ;;; ("lucidasanstypewriter-bold-14" "lucidasanstypewriter-bold-14")
1271 ;;; ("lucidasanstypewriter-bold-24" "lucidasanstypewriter-bold-24")
1272 ;;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
1273 ;;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
1275 ("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1")
1276 ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1")
1277 ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1")
1278 ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1")
1279 ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1")
1280 ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1")
1281 ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1")
1282 ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1")
1283 ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1")
1284 ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1")
1285 ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1")
1286 ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1")
1287 ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1")
1288 ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1")
1289 ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1")
1290 ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1")
1291 ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1")
1292 ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1")
1293 ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1")
1294 ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1")
1295 ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1")
1296 ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1")
1297 ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1")
1298 ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1"))
1300 "X fonts suitable for use in Emacs.")
1302 (defun mouse-set-font (&optional font
)
1303 "Select an emacs font from a list of known good fonts"
1305 (x-popup-menu last-nonmenu-event x-fixed-font-alist
))
1307 (progn (modify-frame-parameters (selected-frame)
1308 (list (cons 'font font
)))
1309 ;; Update some standard faces too.
1310 (set-face-font 'bold nil
(selected-frame))
1311 (make-face-bold 'bold
(selected-frame) t
)
1312 (set-face-font 'italic nil
(selected-frame))
1313 (make-face-italic 'italic
(selected-frame) t
)
1314 (set-face-font 'bold-italic nil
(selected-frame))
1315 (make-face-bold-italic 'bold-italic
(selected-frame) t
)
1316 ;; Update any nonstandard faces whose definition is
1317 ;; "a bold/italic/bold&italic version of the frame's font".
1318 (let ((rest global-face-data
))
1321 (if (listp (face-font (cdr (car rest
))))
1322 (let ((bold (memq 'bold
(face-font (cdr (car rest
)))))
1323 (italic (memq 'italic
(face-font (cdr (car rest
))))))
1324 (if (and bold italic
)
1325 (make-face-bold-italic (car (car rest
)) (selected-frame))
1327 (make-face-bold (car (car rest
)) (selected-frame))
1329 (make-face-italic (car (car rest
)) (selected-frame)))))))
1331 (setq rest
(cdr rest
))))
1334 ;;; Bindings for mouse commands.
1336 (define-key global-map
[down-mouse-1
] 'mouse-drag-region
)
1337 (global-set-key [mouse-1
] 'mouse-set-point
)
1338 (global-set-key [drag-mouse-1
] 'mouse-set-region
)
1340 ;; These are tested for in mouse-drag-region.
1341 (global-set-key [double-mouse-1
] 'mouse-set-point
)
1342 (global-set-key [triple-mouse-1
] 'mouse-set-point
)
1344 (global-set-key [mouse-2
] 'mouse-yank-at-click
)
1345 (global-set-key [mouse-3
] 'mouse-save-then-kill
)
1347 ;; By binding these to down-going events, we let the user use the up-going
1348 ;; event to make the selection, saving a click.
1349 (global-set-key [C-down-mouse-1
] 'mouse-buffer-menu
)
1350 (global-set-key [C-down-mouse-3
] 'mouse-set-font
)
1352 ;; Replaced with dragging mouse-1
1353 ;; (global-set-key [S-mouse-1] 'mouse-set-mark)
1355 (global-set-key [mode-line mouse-1
] 'mouse-select-window
)
1356 (global-set-key [mode-line mouse-2
] 'mouse-delete-other-windows
)
1357 (global-set-key [mode-line mouse-3
] 'mouse-delete-window
)
1358 (global-set-key [mode-line C-mouse-2
] 'mouse-split-window-horizontally
)
1362 ;;; mouse.el ends here