(rmail-summary-forward): Accept prefix arg
[bpt/emacs.git] / lisp / mouse.el
... / ...
CommitLineData
1;;; mouse.el --- window system-independent mouse support.
2
3;;; Copyright (C) 1993 Free Software Foundation, Inc.
4
5;; Maintainer: FSF
6;; Keywords: hardware
7
8;;; This file is part of GNU Emacs.
9
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.
14
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.
19
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.
23
24;;; Commentary:
25
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.
29;;
30;; The code is rather X-dependent.
31
32;;; Code:
33
34;;; Utility functions.
35
36;;; Indent track-mouse like progn.
37(put 'track-mouse 'lisp-indent-function 0)
38
39\f
40(defun mouse-delete-window (click)
41 "Delete the window you click on.
42This must be bound to a mouse click."
43 (interactive "e")
44 (delete-window (posn-window (event-start click))))
45
46(defun mouse-tear-off-window (click)
47 "Delete the window clicked on, and create a new frame displaying its buffer."
48 (interactive "e")
49 (let* ((window (posn-window (event-start click)))
50 (buf (window-buffer window))
51 (frame (new-frame)))
52 (select-frame frame)
53 (switch-to-buffer buf)
54 (delete-window window)))
55
56(defun mouse-delete-other-windows ()
57 "Delete all window except the one you click on."
58 (interactive "@")
59 (delete-other-windows))
60
61(defun mouse-split-window-vertically (click)
62 "Select Emacs window mouse is on, then split it vertically in half.
63The window is split at the line clicked on.
64This command must be bound to a mouse click."
65 (interactive "@e")
66 (let ((start (event-start click)))
67 (select-window (posn-window start))
68 (let ((new-height (if (eq (posn-point start) 'vertical-scroll-bar)
69 (scroll-bar-scale (posn-col-row start)
70 (1- (window-height)))
71 (1+ (cdr (posn-col-row (event-end click))))))
72 (first-line window-min-height)
73 (last-line (- (window-height) window-min-height)))
74 (if (< last-line first-line)
75 (error "window too short to split")
76 (split-window-vertically
77 (min (max new-height first-line) last-line))))))
78
79(defun mouse-split-window-horizontally (click)
80 "Select Emacs window mouse is on, then split it horizontally in half.
81The window is split at the column clicked on.
82This command must be bound to a mouse click."
83 (interactive "@e")
84 (let ((start (event-start click)))
85 (select-window (posn-window start))
86 (let ((new-width (1+ (car (posn-col-row (event-end click)))))
87 (first-col window-min-width)
88 (last-col (- (window-width) window-min-width)))
89 (if (< last-col first-col)
90 (error "window too narrow to split")
91 (split-window-horizontally
92 (min (max new-width first-col) last-col))))))
93
94(defun mouse-set-point (event)
95 "Move point to the position clicked on with the mouse.
96This should be bound to a mouse click event type."
97 (interactive "e")
98 ;; Use event-end in case called from mouse-drag-region.
99 ;; If EVENT is a click, event-end and event-start give same value.
100 (let ((posn (event-end event)))
101 (and (window-minibuffer-p (posn-window posn))
102 (not (minibuffer-window-active-p (posn-window posn)))
103 (error "Minibuffer window is not active"))
104 (select-window (posn-window posn))
105 (if (numberp (posn-point posn))
106 (goto-char (posn-point posn)))))
107
108(defun mouse-set-region (click)
109 "Set the region to the text dragged over, and copy to kill ring.
110This should be bound to a mouse drag event."
111 (interactive "e")
112 (let ((posn (event-start click))
113 (end (event-end click)))
114 (select-window (posn-window posn))
115 (if (numberp (posn-point posn))
116 (goto-char (posn-point posn)))
117 ;; If mark is highlighted, no need to bounce the cursor.
118 (or (and transient-mark-mode
119 (eq (framep (selected-frame)) 'x))
120 (sit-for 1))
121 (push-mark)
122 (set-mark (point))
123 (if (numberp (posn-point end))
124 (goto-char (posn-point end)))
125 ;; Don't set this-command to kill-region, so that a following
126 ;; C-w will not double the text in the kill ring.
127 (let (this-command)
128 (copy-region-as-kill (mark) (point)))))
129
130(defvar mouse-scroll-delay 0.25
131 "*The pause between scroll steps caused by mouse drags, in seconds.
132If you drag the mouse beyond the edge of a window, Emacs scrolls the
133window to bring the text beyond that edge into view, with a delay of
134this many seconds between scroll steps. Scrolling stops when you move
135the mouse back into the window, or release the button.
136This variable's value may be non-integral.
137Setting this to zero causes Emacs to scroll as fast as it can.")
138
139(defun mouse-scroll-subr (jump &optional overlay start)
140 "Scroll the selected window JUMP lines at a time, until new input arrives.
141If OVERLAY is an overlay, let it stretch from START to the far edge of
142the newly visible text.
143Upon exit, point is at the far edge of the newly visible text."
144 (while (progn
145 (goto-char (window-start))
146 (if (not (zerop (vertical-motion jump)))
147 (progn
148 (set-window-start (selected-window) (point))
149 (if (natnump jump)
150 (progn
151 (goto-char (window-end (selected-window)))
152 ;; window-end doesn't reflect the window's new
153 ;; start position until the next redisplay. Hurrah.
154 (vertical-motion (1- jump)))
155 (goto-char (window-start (selected-window))))
156 (if overlay
157 (move-overlay overlay start (point)))
158 (if (not (eobp))
159 (sit-for mouse-scroll-delay))))))
160 (point))
161
162(defvar mouse-drag-overlay (make-overlay 1 1))
163(overlay-put mouse-drag-overlay 'face 'region)
164
165(defvar mouse-selection-click-count nil)
166
167(defun mouse-drag-region (start-event)
168 "Set the region to the text that the mouse is dragged over.
169Highlight the drag area as you move the mouse.
170This must be bound to a button-down mouse event.
171In Transient Mark mode, the highlighting remains once you
172release the mouse button. Otherwise, it does not."
173 (interactive "e")
174 (let* ((start-posn (event-start start-event))
175 (start-point (posn-point start-posn))
176 (start-window (posn-window start-posn))
177 (start-frame (window-frame start-window))
178 (bounds (window-edges start-window))
179 (top (nth 1 bounds))
180 (bottom (if (window-minibuffer-p start-window)
181 (nth 3 bounds)
182 ;; Don't count the mode line.
183 (1- (nth 3 bounds))))
184 (click-count (1- (event-click-count start-event))))
185 (setq mouse-selection-click-count click-count)
186 (mouse-set-point start-event)
187 (let ((range (mouse-start-end start-point start-point click-count)))
188 (move-overlay mouse-drag-overlay (car range) (nth 1 range)
189 (window-buffer start-window)))
190 (deactivate-mark)
191 (let (event end end-point)
192 (track-mouse
193 (while (progn
194 (setq event (read-event))
195 (or (mouse-movement-p event)
196 (eq (car-safe event) 'switch-frame)))
197
198 (if (eq (car-safe event) 'switch-frame)
199 nil
200 (setq end (event-end event)
201 end-point (posn-point end))
202
203 (cond
204
205 ;; Ignore switch-frame events.
206 ((eq (car-safe event) 'switch-frame))
207
208 ;; Are we moving within the original window?
209 ((and (eq (posn-window end) start-window)
210 (integer-or-marker-p end-point))
211 (goto-char end-point)
212 (let ((range (mouse-start-end start-point (point) click-count)))
213 (move-overlay mouse-drag-overlay (car range) (nth 1 range))))
214
215 ;; Are we moving on a different window on the same frame?
216 ((and (windowp (posn-window end))
217 (eq (window-frame (posn-window end)) start-frame))
218 (let ((mouse-row
219 (+ (nth 1 (window-edges (posn-window end)))
220 (cdr (posn-col-row end)))))
221 (cond
222 ((< mouse-row top)
223 (mouse-scroll-subr
224 (- mouse-row top) mouse-drag-overlay start-point))
225 ((and (not (eobp))
226 (>= mouse-row bottom))
227 (mouse-scroll-subr (1+ (- mouse-row bottom))
228 mouse-drag-overlay start-point)))))
229
230 (t
231 (let ((mouse-y (cdr (cdr (mouse-position))))
232 (menu-bar-lines (or (cdr (assq 'menu-bar-lines
233 (frame-parameters)))
234 0)))
235
236 ;; Are we on the menu bar?
237 (and (integerp mouse-y) (< mouse-y menu-bar-lines)
238 (mouse-scroll-subr (- mouse-y menu-bar-lines)
239 mouse-drag-overlay start-point))))))))
240
241 (if (and (eq (get (event-basic-type event) 'event-kind) 'mouse-click)
242 (eq (posn-window (event-end event)) start-window)
243 (numberp (posn-point (event-end event))))
244 (let ((fun (key-binding (vector (car event)))))
245 (if (memq fun '(mouse-set-region mouse-set-point))
246 (if (not (= (overlay-start mouse-drag-overlay)
247 (overlay-end mouse-drag-overlay)))
248 (let (this-command)
249 (push-mark (overlay-start mouse-drag-overlay) t t)
250 (goto-char (overlay-end mouse-drag-overlay))
251 (copy-region-as-kill (point) (mark t)))
252 (goto-char (overlay-end mouse-drag-overlay))
253 (setq this-command 'mouse-set-point))
254 (if (fboundp fun)
255 (funcall fun event)))))
256 (delete-overlay mouse-drag-overlay))))
257\f
258;; Commands to handle xterm-style multiple clicks.
259
260(defun mouse-skip-word (dir)
261 "Skip over word, over whitespace, or over identical punctuation.
262If DIR is positive skip forward; if negative, skip backward."
263 (let* ((char (following-char))
264 (syntax (char-to-string (char-syntax char))))
265 (if (or (string= syntax "w") (string= syntax " "))
266 (if (< dir 0)
267 (skip-syntax-backward syntax)
268 (skip-syntax-forward syntax))
269 (if (< dir 0)
270 (while (and (not (bobp)) (= (preceding-char) char))
271 (forward-char -1))
272 (while (and (not (eobp)) (= (following-char) char))
273 (forward-char 1))))))
274
275;; Return a list of region bounds based on START and END according to MODE.
276;; If MODE is 0 then set point to (min START END), mark to (max START END).
277;; If MODE is 1 then set point to start of word at (min START END),
278;; mark to end of word at (max START END).
279;; If MODE is 2 then do the same for lines.
280(defun mouse-start-end (start end mode)
281 (if (> start end)
282 (let ((temp start))
283 (setq start end
284 end temp)))
285 (cond ((= mode 0)
286 (list start end))
287 ((and (= mode 1)
288 (= start end)
289 (not (eobp))
290 (= (char-syntax (char-after start)) ?\())
291 (list start (save-excursion (forward-sexp 1) (point))))
292 ((and (= mode 1)
293 (= start end)
294 (not (eobp))
295 (= (char-syntax (char-after start)) ?\)))
296 (list (save-excursion
297 (goto-char (1+ start))
298 (backward-sexp 1)
299 (point))
300 (1+ start)))
301 ((= mode 1)
302 (list (save-excursion
303 (goto-char start)
304 (mouse-skip-word -1)
305 (point))
306 (save-excursion
307 (goto-char end)
308 (mouse-skip-word 1)
309 (point))))
310 ((= mode 2)
311 (list (save-excursion
312 (goto-char start)
313 (beginning-of-line 1)
314 (point))
315 (save-excursion
316 (goto-char end)
317 (forward-line 1)
318 (point))))))
319\f
320;; Subroutine: set the mark where CLICK happened,
321;; but don't do anything else.
322(defun mouse-set-mark-fast (click)
323 (let ((posn (event-start click)))
324 (select-window (posn-window posn))
325 (if (numberp (posn-point posn))
326 (push-mark (posn-point posn) t t))))
327
328;; Momentarily show where the mark is, if highlighting doesn't show it.
329(defun mouse-show-mark ()
330 (or transient-mark-mode
331 (save-excursion
332 (goto-char (mark t))
333 (sit-for 1))))
334
335(defun mouse-set-mark (click)
336 "Set mark at the position clicked on with the mouse.
337Display cursor at that position for a second.
338This must be bound to a mouse click."
339 (interactive "e")
340 (let ((point-save (point)))
341 (unwind-protect
342 (progn (mouse-set-point click)
343 (push-mark nil t t)
344 (or transient-mark-mode
345 (sit-for 1)))
346 (goto-char point-save))))
347
348(defun mouse-kill (click)
349 "Kill the region between point and the mouse click.
350The text is saved in the kill ring, as with \\[kill-region]."
351 (interactive "e")
352 (let ((click-posn (posn-point (event-start click))))
353 (if (numberp click-posn)
354 (kill-region (min (point) click-posn)
355 (max (point) click-posn)))))
356
357(defun mouse-yank-at-click (click arg)
358 "Insert the last stretch of killed text at the position clicked on.
359Prefix arguments are interpreted as with \\[yank]."
360 (interactive "e\nP")
361 (mouse-set-point click)
362 (setq this-command 'yank)
363 (yank arg))
364
365(defun mouse-kill-ring-save (click)
366 "Copy the region between point and the mouse click in the kill ring.
367This does not delete the region; it acts like \\[kill-ring-save]."
368 (interactive "e")
369 (mouse-set-mark-fast click)
370 (kill-ring-save (point) (mark t))
371 (mouse-show-mark))
372
373;;; This function used to delete the text between point and the mouse
374;;; whenever it was equal to the front of the kill ring, but some
375;;; people found that confusing.
376
377;;; A list (TEXT START END), describing the text and position of the last
378;;; invocation of mouse-save-then-kill.
379(defvar mouse-save-then-kill-posn nil)
380
381(defun mouse-save-then-kill-delete-region ()
382 ;; Delete just one char, so in case buffer is being modified
383 ;; for the first time, the undo list records that fact.
384 (delete-region (point)
385 (+ (point) (if (> (mark) (point)) 1 -1)))
386 ;; Now delete the rest of the specified region,
387 ;; but don't record it.
388 (let ((buffer-undo-list t))
389 (delete-region (point) (mark)))
390 (if (not (eq buffer-undo-list t))
391 (let ((tail buffer-undo-list))
392 ;; Search back in buffer-undo-list for the string
393 ;; that came from the first delete-region.
394 (while (and tail (not (stringp (car (car tail)))))
395 (setq tail (cdr tail)))
396 ;; Replace it with an entry for the entire deleted text.
397 (and tail
398 (setcar tail (cons (car kill-ring) (point)))))))
399
400(defun mouse-save-then-kill (click)
401 "Save text to point in kill ring; the second time, kill the text.
402If the text between point and the mouse is the same as what's
403at the front of the kill ring, this deletes the text.
404Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
405which prepares for a second click to delete the text.
406
407If you have selected words or lines, this command extends the
408selection through the word or line clicked on. If you do this
409again in a different position, it extends the selection again.
410If you do this twice in the same position, the selection is killed."
411 (interactive "e")
412 (let ((click-posn (posn-point (event-start click)))
413 ;; Don't let a subsequent kill command append to this one:
414 ;; prevent setting this-command to kill-region.
415 (this-command this-command))
416 (if (> mouse-selection-click-count 0)
417 (if (not (and (eq last-command 'mouse-save-then-kill)
418 (equal click-posn
419 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
420 ;; Find both ends of the object selected by this click.
421 (let* ((range
422 (mouse-start-end click-posn click-posn
423 mouse-selection-click-count)))
424 ;; Move whichever end is closer to the click.
425 ;; That's what xterm does, and it seems reasonable.
426 (if (< (abs (- click-posn (mark t)))
427 (abs (- click-posn (point))))
428 (set-mark (car range))
429 (goto-char (nth 1 range)))
430 ;; We have already put the old region in the kill ring.
431 ;; Replace it with the extended region.
432 ;; (It would be annoying to make a separate entry.)
433 (setcar kill-ring (buffer-substring (point) (mark t)))
434 (if interprogram-cut-function
435 (funcall interprogram-cut-function (car kill-ring)))
436 ;; Arrange for a repeated mouse-3 to kill this region.
437 (setq mouse-save-then-kill-posn
438 (list (car kill-ring) (point) click-posn))
439 (mouse-show-mark))
440 ;; If we click this button again without moving it,
441 ;; that time kill.
442 (mouse-save-then-kill-delete-region))
443 (if (and (eq last-command 'mouse-save-then-kill)
444 mouse-save-then-kill-posn
445 (eq (car mouse-save-then-kill-posn) (car kill-ring))
446 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
447 ;; If this is the second time we've called
448 ;; mouse-save-then-kill, delete the text from the buffer.
449 (mouse-save-then-kill-delete-region)
450 (if (or (eq last-command 'mouse-save-then-kill)
451 (and mark-active transient-mark-mode)
452 (and (eq last-command 'mouse-drag-region)
453 (or mark-even-if-inactive
454 (not transient-mark-mode))))
455 ;; We have a selection or suitable region, so adjust it.
456 (let* ((posn (event-start click))
457 (new (posn-point posn)))
458 (select-window (posn-window posn))
459 (if (numberp new)
460 (progn
461 ;; Move whichever end of the region is closer to the click.
462 ;; That is what xterm does, and it seems reasonable.
463 (if (< (abs (- new (point))) (abs (- new (mark t))))
464 (goto-char new)
465 (set-mark new))
466 (setq deactivate-mark nil)))
467 (setcar kill-ring (buffer-substring (point) (mark t)))
468 (if interprogram-cut-function
469 (funcall interprogram-cut-function (car kill-ring))))
470 ;; We just have point, so set mark here.
471 (mouse-set-mark-fast click)
472 (kill-ring-save (point) (mark t))
473 (mouse-show-mark))
474 (setq mouse-save-then-kill-posn
475 (list (car kill-ring) (point) click-posn))))))
476\f
477(global-set-key [M-mouse-1] 'mouse-start-secondary)
478(global-set-key [M-drag-mouse-1] 'mouse-set-secondary)
479(global-set-key [M-down-mouse-1] 'mouse-drag-secondary)
480(global-set-key [M-mouse-3] 'mouse-secondary-save-then-kill)
481(global-set-key [M-mouse-2] 'mouse-kill-secondary)
482
483;; An overlay which records the current secondary selection
484;; or else is deleted when there is no secondary selection.
485;; May be nil.
486(defvar mouse-secondary-overlay nil)
487
488;; A marker which records the specified first end for a secondary selection.
489;; May be nil.
490(defvar mouse-secondary-start nil)
491
492(defun mouse-start-secondary (click)
493 "Set one end of the secondary selection to the position clicked on.
494Use \\[mouse-secondary-save-then-kill] to set the other end
495and complete the secondary selection."
496 (interactive "e")
497 (let ((posn (event-start click)))
498 (save-excursion
499 (set-buffer (window-buffer (posn-window posn)))
500 ;; Cancel any preexisting secondary selection.
501 (if mouse-secondary-overlay
502 (delete-overlay mouse-secondary-overlay))
503 (if (numberp (posn-point posn))
504 (progn
505 (or mouse-secondary-start
506 (setq mouse-secondary-start (make-marker)))
507 (move-marker mouse-secondary-start (posn-point posn)))))))
508
509(defun mouse-set-secondary (click)
510 "Set the secondary selection to the text that the mouse is dragged over.
511This must be bound to a mouse drag event."
512 (interactive "e")
513 (let ((posn (event-start click))
514 beg
515 (end (event-end click)))
516 (save-excursion
517 (set-buffer (window-buffer (posn-window posn)))
518 (if (numberp (posn-point posn))
519 (setq beg (posn-point posn)))
520 (if mouse-secondary-overlay
521 (move-overlay mouse-secondary-overlay beg (posn-point end))
522 (setq mouse-secondary-overlay (make-overlay beg (posn-point end))))
523 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))))
524
525(defun mouse-drag-secondary (start-event)
526 "Set the secondary selection to the text that the mouse is dragged over.
527Highlight the drag area as you move the mouse.
528This must be bound to a button-down mouse event."
529 (interactive "e")
530 (let* ((start-posn (event-start start-event))
531 (start-point (posn-point start-posn))
532 (start-window (posn-window start-posn))
533 (start-frame (window-frame start-window))
534 (bounds (window-edges start-window))
535 (top (nth 1 bounds))
536 (bottom (if (window-minibuffer-p start-window)
537 (nth 3 bounds)
538 ;; Don't count the mode line.
539 (1- (nth 3 bounds))))
540 (click-count (1- (event-click-count start-event))))
541 (save-excursion
542 (set-buffer (window-buffer start-window))
543 (setq mouse-selection-click-count click-count)
544 ;; Cancel any preexisting secondary selection.
545 (or mouse-secondary-overlay
546 (setq mouse-secondary-overlay
547 (make-overlay (point) (point))))
548 (if (> click-count 0)
549 (let ((range (mouse-start-end start-point start-point click-count)))
550 (set-marker mouse-secondary-start nil)
551 (move-overlay mouse-secondary-overlay 1 1
552 (window-buffer start-window))
553 (move-overlay mouse-secondary-overlay (car range) (nth 1 range)
554 (window-buffer start-window)))
555 (or mouse-secondary-start
556 (setq mouse-secondary-start (make-marker)))
557 (set-marker mouse-secondary-start start-point)
558 (delete-overlay mouse-secondary-overlay))
559 (let (event end end-point)
560 (track-mouse
561 (while (progn
562 (setq event (read-event))
563 (or (mouse-movement-p event)
564 (eq (car-safe event) 'switch-frame)))
565
566 (if (eq (car-safe event) 'switch-frame)
567 nil
568 (setq end (event-end event)
569 end-point (posn-point end))
570 (cond
571
572 ;; Ignore switch-frame events.
573 ((eq (car-safe event) 'switch-frame))
574
575 ;; Are we moving within the original window?
576 ((and (eq (posn-window end) start-window)
577 (integer-or-marker-p end-point))
578 (if (/= start-point end-point)
579 (set-marker mouse-secondary-start nil))
580 (let ((range (mouse-start-end start-point end-point
581 click-count)))
582 (move-overlay mouse-secondary-overlay
583 (car range) (nth 1 range))))
584
585 ;; Are we moving on a different window on the same frame?
586 ((and (windowp (posn-window end))
587 (eq (window-frame (posn-window end)) start-frame))
588 (let ((mouse-row
589 (+ (nth 1 (window-edges (posn-window end)))
590 (cdr (posn-col-row end)))))
591 (cond
592 ((< mouse-row top)
593 (mouse-scroll-subr
594 (- mouse-row top) mouse-secondary-overlay start-point))
595 ((and (not (eobp))
596 (>= mouse-row bottom))
597 (mouse-scroll-subr (1+ (- mouse-row bottom))
598 mouse-drag-overlay start-point)))))
599
600 (t
601 (let ((mouse-y (cdr (cdr (mouse-position))))
602 (menu-bar-lines (or (cdr (assq 'menu-bar-lines
603 (frame-parameters)))
604 0)))
605
606 ;; Are we on the menu bar?
607 (and (integerp mouse-y) (< mouse-y menu-bar-lines)
608 (mouse-scroll-subr (- mouse-y menu-bar-lines)
609 mouse-secondary-overlay start-point))))))))
610
611 (if (and (eq (get (event-basic-type event) 'event-kind) 'mouse-click)
612 (eq (posn-window (event-end event)) start-window)
613 (numberp (posn-point (event-end event))))
614 (if (marker-position mouse-secondary-start)
615 (save-window-excursion
616 (delete-overlay mouse-secondary-overlay)
617 (select-window start-window)
618 (save-excursion
619 (goto-char mouse-secondary-start)
620 (sit-for 1)))
621 (kill-ring-save (overlay-start mouse-secondary-overlay)
622 (overlay-end mouse-secondary-overlay))))))))
623
624(defun mouse-kill-secondary ()
625 "Kill the text in the secondary selection."
626 (interactive "*")
627 (kill-region (overlay-start mouse-secondary-overlay)
628 (overlay-end mouse-secondary-overlay))
629 (delete-overlay mouse-secondary-overlay)
630 (setq mouse-secondary-overlay nil))
631
632(defun mouse-secondary-save-then-kill (click)
633 "Save text to point in kill ring; the second time, kill the text.
634If the text between point and the mouse is the same as what's
635at the front of the kill ring, this deletes the text.
636Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
637which prepares for a second click to delete the text.
638
639If you have selected words or lines, this command extends the
640selection through the word or line clicked on. If you do this
641again in a different position, it extends the selection again.
642If you do this twice in the same position, the selection is killed."
643 (interactive "e")
644 (let ((posn (event-start click))
645 (click-posn (posn-point (event-start click)))
646 ;; Don't let a subsequent kill command append to this one:
647 ;; prevent setting this-command to kill-region.
648 (this-command this-command))
649 (if (> mouse-selection-click-count 0)
650 (if (not (and (eq last-command 'mouse-secondary-save-then-kill)
651 (equal click-posn
652 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
653 ;; Find both ends of the object selected by this click.
654 (let* ((range
655 (mouse-start-end click-posn click-posn
656 mouse-selection-click-count)))
657 ;; Move whichever end is closer to the click.
658 ;; That's what xterm does, and it seems reasonable.
659 (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay)))
660 (abs (- click-posn (overlay-end mouse-secondary-overlay))))
661 (move-overlay mouse-secondary-overlay (car range)
662 (overlay-end mouse-secondary-overlay))
663 (move-overlay mouse-secondary-overlay
664 (overlay-start mouse-secondary-overlay)
665 (nth 1 range)))
666 ;; We have already put the old region in the kill ring.
667 ;; Replace it with the extended region.
668 ;; (It would be annoying to make a separate entry.)
669 (setcar kill-ring (buffer-substring
670 (overlay-start mouse-secondary-overlay)
671 (overlay-end mouse-secondary-overlay)))
672 (if interprogram-cut-function
673 (funcall interprogram-cut-function (car kill-ring)))
674 ;; Arrange for a repeated mouse-3 to kill this region.
675 (setq mouse-save-then-kill-posn
676 (list (car kill-ring) (point) click-posn)))
677 ;; If we click this button again without moving it,
678 ;; that time kill.
679 (progn
680 (delete-overlay mouse-secondary-overlay)
681 (mouse-save-then-kill-delete-region)))
682 (if (and (eq last-command 'mouse-secondary-save-then-kill)
683 mouse-save-then-kill-posn
684 (eq (car mouse-save-then-kill-posn) (car kill-ring))
685 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
686 ;; If this is the second time we've called
687 ;; mouse-secondary-save-then-kill, delete the text from the buffer.
688 (progn
689 (delete-overlay mouse-secondary-overlay)
690 (mouse-save-then-kill-delete-region))
691 (if (overlay-start mouse-secondary-overlay)
692 ;; We have a selection, so adjust it.
693 (progn
694 (select-window (posn-window posn))
695 (if (numberp click-posn)
696 (progn
697 ;; Move whichever end of the region is closer to the click.
698 ;; That is what xterm does, and it seems reasonable.
699 (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay)))
700 (abs (- click-posn (overlay-end mouse-secondary-overlay))))
701 (move-overlay mouse-secondary-overlay click-posn
702 (overlay-end mouse-secondary-overlay))
703 (move-overlay mouse-secondary-overlay
704 (overlay-start mouse-secondary-overlay)
705 click-posn))
706 (setq deactivate-mark nil)))
707 (setcar kill-ring (buffer-substring
708 (overlay-start mouse-secondary-overlay)
709 (overlay-end mouse-secondary-overlay)))
710 (if interprogram-cut-function
711 (funcall interprogram-cut-function (car kill-ring))))
712 (if mouse-secondary-start
713 ;; All we have is one end of a selection,
714 ;; so put the other end here.
715 (let ((start (+ 0 mouse-secondary-start)))
716 (set-buffer (window-buffer (posn-window (event-start click))))
717 (kill-ring-save start click-posn)
718 (if mouse-secondary-overlay
719 (move-overlay mouse-secondary-overlay start click-posn)
720 (setq mouse-secondary-overlay (make-overlay start click-posn)))
721 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))))
722 (setq mouse-save-then-kill-posn
723 (list (car kill-ring) (point) click-posn))))))
724\f
725(defun mouse-buffer-menu (event)
726 "Pop up a menu of buffers for selection with the mouse.
727This switches buffers in the window that you clicked on,
728and selects that window."
729 (interactive "e")
730 (let ((menu
731 (list "Buffer Menu"
732 (cons "Select Buffer"
733 (let ((tail (buffer-list))
734 (maxbuf 0)
735 head)
736 (while tail
737 (or (eq ?\ (aref (buffer-name (car tail)) 0))
738 (setq maxbuf
739 (max maxbuf
740 (length (buffer-name (car tail))))))
741 (setq tail (cdr tail)))
742 (setq tail (buffer-list))
743 (while tail
744 (let ((elt (car tail)))
745 (if (not (string-match "^ "
746 (buffer-name elt)))
747 (setq head (cons
748 (cons
749 (format
750 (format "%%%ds %%s%%s %%s"
751 maxbuf)
752 (buffer-name elt)
753 (if (buffer-modified-p elt)
754 "*" " ")
755 (save-excursion
756 (set-buffer elt)
757 (if buffer-read-only "%" " "))
758 (or (buffer-file-name elt) ""))
759 elt)
760 head))))
761 (setq tail (cdr tail)))
762 (reverse head))))))
763 (let ((buf (x-popup-menu event menu))
764 (window (posn-window (event-start event))))
765 (if buf
766 (progn
767 (or (framep window) (select-window window))
768 (switch-to-buffer buf))))))
769\f
770;;; These need to be rewritten for the new scroll bar implementation.
771
772;;;!! ;; Commands for the scroll bar.
773;;;!!
774;;;!! (defun mouse-scroll-down (click)
775;;;!! (interactive "@e")
776;;;!! (scroll-down (1+ (cdr (mouse-coords click)))))
777;;;!!
778;;;!! (defun mouse-scroll-up (click)
779;;;!! (interactive "@e")
780;;;!! (scroll-up (1+ (cdr (mouse-coords click)))))
781;;;!!
782;;;!! (defun mouse-scroll-down-full ()
783;;;!! (interactive "@")
784;;;!! (scroll-down nil))
785;;;!!
786;;;!! (defun mouse-scroll-up-full ()
787;;;!! (interactive "@")
788;;;!! (scroll-up nil))
789;;;!!
790;;;!! (defun mouse-scroll-move-cursor (click)
791;;;!! (interactive "@e")
792;;;!! (move-to-window-line (1+ (cdr (mouse-coords click)))))
793;;;!!
794;;;!! (defun mouse-scroll-absolute (event)
795;;;!! (interactive "@e")
796;;;!! (let* ((pos (car event))
797;;;!! (position (car pos))
798;;;!! (length (car (cdr pos))))
799;;;!! (if (<= length 0) (setq length 1))
800;;;!! (let* ((scale-factor (max 1 (/ length (/ 8000000 (buffer-size)))))
801;;;!! (newpos (* (/ (* (/ (buffer-size) scale-factor)
802;;;!! position)
803;;;!! length)
804;;;!! scale-factor)))
805;;;!! (goto-char newpos)
806;;;!! (recenter '(4)))))
807;;;!!
808;;;!! (defun mouse-scroll-left (click)
809;;;!! (interactive "@e")
810;;;!! (scroll-left (1+ (car (mouse-coords click)))))
811;;;!!
812;;;!! (defun mouse-scroll-right (click)
813;;;!! (interactive "@e")
814;;;!! (scroll-right (1+ (car (mouse-coords click)))))
815;;;!!
816;;;!! (defun mouse-scroll-left-full ()
817;;;!! (interactive "@")
818;;;!! (scroll-left nil))
819;;;!!
820;;;!! (defun mouse-scroll-right-full ()
821;;;!! (interactive "@")
822;;;!! (scroll-right nil))
823;;;!!
824;;;!! (defun mouse-scroll-move-cursor-horizontally (click)
825;;;!! (interactive "@e")
826;;;!! (move-to-column (1+ (car (mouse-coords click)))))
827;;;!!
828;;;!! (defun mouse-scroll-absolute-horizontally (event)
829;;;!! (interactive "@e")
830;;;!! (let* ((pos (car event))
831;;;!! (position (car pos))
832;;;!! (length (car (cdr pos))))
833;;;!! (set-window-hscroll (selected-window) 33)))
834;;;!!
835;;;!! (global-set-key [scroll-bar mouse-1] 'mouse-scroll-up)
836;;;!! (global-set-key [scroll-bar mouse-2] 'mouse-scroll-absolute)
837;;;!! (global-set-key [scroll-bar mouse-3] 'mouse-scroll-down)
838;;;!!
839;;;!! (global-set-key [vertical-slider mouse-1] 'mouse-scroll-move-cursor)
840;;;!! (global-set-key [vertical-slider mouse-2] 'mouse-scroll-move-cursor)
841;;;!! (global-set-key [vertical-slider mouse-3] 'mouse-scroll-move-cursor)
842;;;!!
843;;;!! (global-set-key [thumbup mouse-1] 'mouse-scroll-up-full)
844;;;!! (global-set-key [thumbup mouse-2] 'mouse-scroll-up-full)
845;;;!! (global-set-key [thumbup mouse-3] 'mouse-scroll-up-full)
846;;;!!
847;;;!! (global-set-key [thumbdown mouse-1] 'mouse-scroll-down-full)
848;;;!! (global-set-key [thumbdown mouse-2] 'mouse-scroll-down-full)
849;;;!! (global-set-key [thumbdown mouse-3] 'mouse-scroll-down-full)
850;;;!!
851;;;!! (global-set-key [horizontal-scroll-bar mouse-1] 'mouse-scroll-left)
852;;;!! (global-set-key [horizontal-scroll-bar mouse-2]
853;;;!! 'mouse-scroll-absolute-horizontally)
854;;;!! (global-set-key [horizontal-scroll-bar mouse-3] 'mouse-scroll-right)
855;;;!!
856;;;!! (global-set-key [horizontal-slider mouse-1]
857;;;!! 'mouse-scroll-move-cursor-horizontally)
858;;;!! (global-set-key [horizontal-slider mouse-2]
859;;;!! 'mouse-scroll-move-cursor-horizontally)
860;;;!! (global-set-key [horizontal-slider mouse-3]
861;;;!! 'mouse-scroll-move-cursor-horizontally)
862;;;!!
863;;;!! (global-set-key [thumbleft mouse-1] 'mouse-scroll-left-full)
864;;;!! (global-set-key [thumbleft mouse-2] 'mouse-scroll-left-full)
865;;;!! (global-set-key [thumbleft mouse-3] 'mouse-scroll-left-full)
866;;;!!
867;;;!! (global-set-key [thumbright mouse-1] 'mouse-scroll-right-full)
868;;;!! (global-set-key [thumbright mouse-2] 'mouse-scroll-right-full)
869;;;!! (global-set-key [thumbright mouse-3] 'mouse-scroll-right-full)
870;;;!!
871;;;!! (global-set-key [horizontal-scroll-bar S-mouse-2]
872;;;!! 'mouse-split-window-horizontally)
873;;;!! (global-set-key [mode-line S-mouse-2]
874;;;!! 'mouse-split-window-horizontally)
875;;;!! (global-set-key [vertical-scroll-bar S-mouse-2]
876;;;!! 'mouse-split-window)
877\f
878;;;!! ;;;;
879;;;!! ;;;; Here are experimental things being tested. Mouse events
880;;;!! ;;;; are of the form:
881;;;!! ;;;; ((x y) window screen-part key-sequence timestamp)
882;;;!! ;;
883;;;!! ;;;;
884;;;!! ;;;; Dynamically track mouse coordinates
885;;;!! ;;;;
886;;;!! ;;
887;;;!! ;;(defun track-mouse (event)
888;;;!! ;; "Track the coordinates, absolute and relative, of the mouse."
889;;;!! ;; (interactive "@e")
890;;;!! ;; (while mouse-grabbed
891;;;!! ;; (let* ((pos (read-mouse-position (selected-screen)))
892;;;!! ;; (abs-x (car pos))
893;;;!! ;; (abs-y (cdr pos))
894;;;!! ;; (relative-coordinate (coordinates-in-window-p
895;;;!! ;; (list (car pos) (cdr pos))
896;;;!! ;; (selected-window))))
897;;;!! ;; (if (consp relative-coordinate)
898;;;!! ;; (message "mouse: [%d %d], (%d %d)" abs-x abs-y
899;;;!! ;; (car relative-coordinate)
900;;;!! ;; (car (cdr relative-coordinate)))
901;;;!! ;; (message "mouse: [%d %d]" abs-x abs-y)))))
902;;;!!
903;;;!! ;;
904;;;!! ;; Dynamically put a box around the line indicated by point
905;;;!! ;;
906;;;!! ;;
907;;;!! ;;(require 'backquote)
908;;;!! ;;
909;;;!! ;;(defun mouse-select-buffer-line (event)
910;;;!! ;; (interactive "@e")
911;;;!! ;; (let ((relative-coordinate
912;;;!! ;; (coordinates-in-window-p (car event) (selected-window)))
913;;;!! ;; (abs-y (car (cdr (car event)))))
914;;;!! ;; (if (consp relative-coordinate)
915;;;!! ;; (progn
916;;;!! ;; (save-excursion
917;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
918;;;!! ;; (x-draw-rectangle
919;;;!! ;; (selected-screen)
920;;;!! ;; abs-y 0
921;;;!! ;; (save-excursion
922;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
923;;;!! ;; (end-of-line)
924;;;!! ;; (push-mark nil t)
925;;;!! ;; (beginning-of-line)
926;;;!! ;; (- (region-end) (region-beginning))) 1))
927;;;!! ;; (sit-for 1)
928;;;!! ;; (x-erase-rectangle (selected-screen))))))
929;;;!! ;;
930;;;!! ;;(defvar last-line-drawn nil)
931;;;!! ;;(defvar begin-delim "[^ \t]")
932;;;!! ;;(defvar end-delim "[^ \t]")
933;;;!! ;;
934;;;!! ;;(defun mouse-boxing (event)
935;;;!! ;; (interactive "@e")
936;;;!! ;; (save-excursion
937;;;!! ;; (let ((screen (selected-screen)))
938;;;!! ;; (while (= (x-mouse-events) 0)
939;;;!! ;; (let* ((pos (read-mouse-position screen))
940;;;!! ;; (abs-x (car pos))
941;;;!! ;; (abs-y (cdr pos))
942;;;!! ;; (relative-coordinate
943;;;!! ;; (coordinates-in-window-p (` ((, abs-x) (, abs-y)))
944;;;!! ;; (selected-window)))
945;;;!! ;; (begin-reg nil)
946;;;!! ;; (end-reg nil)
947;;;!! ;; (end-column nil)
948;;;!! ;; (begin-column nil))
949;;;!! ;; (if (and (consp relative-coordinate)
950;;;!! ;; (or (not last-line-drawn)
951;;;!! ;; (not (= last-line-drawn abs-y))))
952;;;!! ;; (progn
953;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
954;;;!! ;; (if (= (following-char) 10)
955;;;!! ;; ()
956;;;!! ;; (progn
957;;;!! ;; (setq begin-reg (1- (re-search-forward end-delim)))
958;;;!! ;; (setq begin-column (1- (current-column)))
959;;;!! ;; (end-of-line)
960;;;!! ;; (setq end-reg (1+ (re-search-backward begin-delim)))
961;;;!! ;; (setq end-column (1+ (current-column)))
962;;;!! ;; (message "%s" (buffer-substring begin-reg end-reg))
963;;;!! ;; (x-draw-rectangle screen
964;;;!! ;; (setq last-line-drawn abs-y)
965;;;!! ;; begin-column
966;;;!! ;; (- end-column begin-column) 1))))))))))
967;;;!! ;;
968;;;!! ;;(defun mouse-erase-box ()
969;;;!! ;; (interactive)
970;;;!! ;; (if last-line-drawn
971;;;!! ;; (progn
972;;;!! ;; (x-erase-rectangle (selected-screen))
973;;;!! ;; (setq last-line-drawn nil))))
974;;;!!
975;;;!! ;;; (defun test-x-rectangle ()
976;;;!! ;;; (use-local-mouse-map (setq rectangle-test-map (make-sparse-keymap)))
977;;;!! ;;; (define-key rectangle-test-map mouse-motion-button-left 'mouse-boxing)
978;;;!! ;;; (define-key rectangle-test-map mouse-button-left-up 'mouse-erase-box))
979;;;!!
980;;;!! ;;
981;;;!! ;; Here is how to do double clicking in lisp. About to change.
982;;;!! ;;
983;;;!!
984;;;!! (defvar double-start nil)
985;;;!! (defconst double-click-interval 300
986;;;!! "Max ticks between clicks")
987;;;!!
988;;;!! (defun double-down (event)
989;;;!! (interactive "@e")
990;;;!! (if double-start
991;;;!! (let ((interval (- (nth 4 event) double-start)))
992;;;!! (if (< interval double-click-interval)
993;;;!! (progn
994;;;!! (backward-up-list 1)
995;;;!! ;; (message "Interval %d" interval)
996;;;!! (sleep-for 1)))
997;;;!! (setq double-start nil))
998;;;!! (setq double-start (nth 4 event))))
999;;;!!
1000;;;!! (defun double-up (event)
1001;;;!! (interactive "@e")
1002;;;!! (and double-start
1003;;;!! (> (- (nth 4 event ) double-start) double-click-interval)
1004;;;!! (setq double-start nil)))
1005;;;!!
1006;;;!! ;;; (defun x-test-doubleclick ()
1007;;;!! ;;; (use-local-mouse-map (setq doubleclick-test-map (make-sparse-keymap)))
1008;;;!! ;;; (define-key doubleclick-test-map mouse-button-left 'double-down)
1009;;;!! ;;; (define-key doubleclick-test-map mouse-button-left-up 'double-up))
1010;;;!!
1011;;;!! ;;
1012;;;!! ;; This scrolls while button is depressed. Use preferable in scroll bar.
1013;;;!! ;;
1014;;;!!
1015;;;!! (defvar scrolled-lines 0)
1016;;;!! (defconst scroll-speed 1)
1017;;;!!
1018;;;!! (defun incr-scroll-down (event)
1019;;;!! (interactive "@e")
1020;;;!! (setq scrolled-lines 0)
1021;;;!! (incremental-scroll scroll-speed))
1022;;;!!
1023;;;!! (defun incr-scroll-up (event)
1024;;;!! (interactive "@e")
1025;;;!! (setq scrolled-lines 0)
1026;;;!! (incremental-scroll (- scroll-speed)))
1027;;;!!
1028;;;!! (defun incremental-scroll (n)
1029;;;!! (while (= (x-mouse-events) 0)
1030;;;!! (setq scrolled-lines (1+ (* scroll-speed scrolled-lines)))
1031;;;!! (scroll-down n)
1032;;;!! (sit-for 300 t)))
1033;;;!!
1034;;;!! (defun incr-scroll-stop (event)
1035;;;!! (interactive "@e")
1036;;;!! (message "Scrolled %d lines" scrolled-lines)
1037;;;!! (setq scrolled-lines 0)
1038;;;!! (sleep-for 1))
1039;;;!!
1040;;;!! ;;; (defun x-testing-scroll ()
1041;;;!! ;;; (let ((scrolling-map (function mouse-vertical-scroll-bar-prefix)))
1042;;;!! ;;; (define-key scrolling-map mouse-button-left 'incr-scroll-down)
1043;;;!! ;;; (define-key scrolling-map mouse-button-right 'incr-scroll-up)
1044;;;!! ;;; (define-key scrolling-map mouse-button-left-up 'incr-scroll-stop)
1045;;;!! ;;; (define-key scrolling-map mouse-button-right-up 'incr-scroll-stop)))
1046;;;!!
1047;;;!! ;;
1048;;;!! ;; Some playthings suitable for picture mode? They need work.
1049;;;!! ;;
1050;;;!!
1051;;;!! (defun mouse-kill-rectangle (event)
1052;;;!! "Kill the rectangle between point and the mouse cursor."
1053;;;!! (interactive "@e")
1054;;;!! (let ((point-save (point)))
1055;;;!! (save-excursion
1056;;;!! (mouse-set-point event)
1057;;;!! (push-mark nil t)
1058;;;!! (if (> point-save (point))
1059;;;!! (kill-rectangle (point) point-save)
1060;;;!! (kill-rectangle point-save (point))))))
1061;;;!!
1062;;;!! (defun mouse-open-rectangle (event)
1063;;;!! "Kill the rectangle between point and the mouse cursor."
1064;;;!! (interactive "@e")
1065;;;!! (let ((point-save (point)))
1066;;;!! (save-excursion
1067;;;!! (mouse-set-point event)
1068;;;!! (push-mark nil t)
1069;;;!! (if (> point-save (point))
1070;;;!! (open-rectangle (point) point-save)
1071;;;!! (open-rectangle point-save (point))))))
1072;;;!!
1073;;;!! ;; Must be a better way to do this.
1074;;;!!
1075;;;!! (defun mouse-multiple-insert (n char)
1076;;;!! (while (> n 0)
1077;;;!! (insert char)
1078;;;!! (setq n (1- n))))
1079;;;!!
1080;;;!! ;; What this could do is not finalize until button was released.
1081;;;!!
1082;;;!! (defun mouse-move-text (event)
1083;;;!! "Move text from point to cursor position, inserting spaces."
1084;;;!! (interactive "@e")
1085;;;!! (let* ((relative-coordinate
1086;;;!! (coordinates-in-window-p (car event) (selected-window))))
1087;;;!! (if (consp relative-coordinate)
1088;;;!! (cond ((> (current-column) (car relative-coordinate))
1089;;;!! (delete-char
1090;;;!! (- (car relative-coordinate) (current-column))))
1091;;;!! ((< (current-column) (car relative-coordinate))
1092;;;!! (mouse-multiple-insert
1093;;;!! (- (car relative-coordinate) (current-column)) " "))
1094;;;!! ((= (current-column) (car relative-coordinate)) (ding))))))
1095\f
1096;; Choose a completion with the mouse.
1097
1098;; Delete the longest partial match for STRING
1099;; that can be found before POINT.
1100(defun mouse-delete-max-match (string)
1101 (let ((len (min (length string)
1102 (- (point-max) (point-min)))))
1103 (goto-char (max (point-min) (- (point) (length string))))
1104 (while (and (> len 0)
1105 (let ((tail (buffer-substring (point)
1106 (+ (point) len))))
1107 (not (string= tail (substring string 0 len)))))
1108 (setq len (1- len))
1109 (forward-char 1))
1110 (delete-char len)))
1111
1112(defun mouse-choose-completion (event)
1113 "Click on an alternative in the `*Completions*' buffer to choose it."
1114 (interactive "e")
1115 (let ((buffer (window-buffer))
1116 choice)
1117 (save-excursion
1118 (set-buffer (window-buffer (posn-window (event-start event))))
1119 (save-excursion
1120 (goto-char (posn-point (event-start event)))
1121 (skip-chars-backward "^ \t\n")
1122 (let ((beg (point)))
1123 (skip-chars-forward "^ \t\n")
1124 (setq choice (buffer-substring beg (point))))))
1125 (set-buffer buffer)
1126 (mouse-delete-max-match choice)
1127 (insert choice)
1128 (and (equal buffer (window-buffer (minibuffer-window)))
1129 (minibuffer-complete-and-exit))))
1130\f
1131;; Font selection.
1132
1133(defun font-menu-add-default ()
1134 (let* ((default (cdr (assq 'font (frame-parameters (selected-frame)))))
1135 (font-alist x-fixed-font-alist)
1136 (elt (or (assoc "Misc" font-alist) (nth 1 font-alist))))
1137 (if (assoc "Default" elt)
1138 (delete (assoc "Default" elt) elt))
1139 (setcdr elt
1140 (cons (list "Default"
1141 (cdr (assq 'font (frame-parameters (selected-frame)))))
1142 (cdr elt)))))
1143
1144(defvar x-fixed-font-alist
1145 '("Font menu"
1146 ("Misc"
1147 ("6x10" "-misc-fixed-medium-r-semicondensed--10-110-75-75-c-60-*-1")
1148 ("6x12" "-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-*-1")
1149 ("6x13" "-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-*-1")
1150 ("lucida 13"
1151 "-b&h-lucidatypewriter-medium-r-normal-sans-0-0-0-0-m-0-*-1")
1152 ("7x13" "-misc-fixed-medium-r-normal--13-120-75-75-c-70-*-1")
1153 ("7x14" "-misc-fixed-medium-r-normal--14-130-75-75-c-70-*-1")
1154 ("9x15" "-misc-fixed-medium-r-normal--15-140-*-*-c-*-*-1")
1155 ("")
1156 ("clean 8x8" "-schumacher-clean-medium-r-normal--*-80-*-*-c-*-*-1")
1157 ("clean 8x14" "-schumacher-clean-medium-r-normal--*-140-*-*-c-*-*-1")
1158 ("clean 8x10" "-schumacher-clean-medium-r-normal--*-100-*-*-c-*-*-1")
1159 ("clean 8x16" "-schumacher-clean-medium-r-normal--*-160-*-*-c-*-*-1")
1160 ("")
1161 ("sony 8x16" "-sony-fixed-medium-r-normal--16-120-100-100-c-80-*-1")
1162 ("")
1163 ("fixed" "fixed")
1164 ("10x20" "10x20")
1165 ("11x18" "11x18")
1166 ("12x24" "12x24"))
1167;;; We don't seem to have these; who knows what they are.
1168;;; ("fg-18" "fg-18")
1169;;; ("fg-25" "fg-25")
1170;;; ("lucidasanstypewriter-12" "lucidasanstypewriter-12")
1171;;; ("lucidasanstypewriter-bold-14" "lucidasanstypewriter-bold-14")
1172;;; ("lucidasanstypewriter-bold-24" "lucidasanstypewriter-bold-24")
1173;;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
1174;;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
1175 ("Courier"
1176 ("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1")
1177 ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1")
1178 ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1")
1179 ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1")
1180 ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1")
1181 ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1")
1182 ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1")
1183 ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1")
1184 ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1")
1185 ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1")
1186 ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1")
1187 ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1")
1188 ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1")
1189 ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1")
1190 ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1")
1191 ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1")
1192 ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1")
1193 ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1")
1194 ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1")
1195 ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1")
1196 ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1")
1197 ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1")
1198 ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1")
1199 ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1"))
1200 )
1201 "X fonts suitable for use in Emacs.")
1202
1203(defun mouse-set-font (&optional font)
1204 "Select an emacs font from a list of known good fonts"
1205 (interactive
1206 (x-popup-menu last-nonmenu-event x-fixed-font-alist))
1207 (if font
1208 (progn (modify-frame-parameters (selected-frame)
1209 (list (cons 'font font)))
1210 ;; Update some standard faces too.
1211 (set-face-font 'bold nil (selected-frame))
1212 (make-face-bold 'bold (selected-frame) t)
1213 (set-face-font 'italic nil (selected-frame))
1214 (make-face-italic 'italic (selected-frame) t)
1215 (set-face-font 'bold-italic nil (selected-frame))
1216 (make-face-bold-italic 'bold-italic (selected-frame) t))))
1217\f
1218;;; Bindings for mouse commands.
1219
1220(define-key global-map [down-mouse-1] 'mouse-drag-region)
1221(global-set-key [mouse-1] 'mouse-set-point)
1222(global-set-key [drag-mouse-1] 'mouse-set-region)
1223
1224;; These are tested for in mouse-drag-region.
1225(global-set-key [double-mouse-1] 'mouse-set-point)
1226(global-set-key [triple-mouse-1] 'mouse-set-point)
1227
1228(global-set-key [mouse-2] 'mouse-yank-at-click)
1229(global-set-key [mouse-3] 'mouse-save-then-kill)
1230
1231;; By binding these to down-going events, we let the user use the up-going
1232;; event to make the selection, saving a click.
1233(global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
1234(global-set-key [C-down-mouse-3] 'mouse-set-font)
1235
1236;; Replaced with dragging mouse-1
1237;; (global-set-key [S-mouse-1] 'mouse-set-mark)
1238
1239(global-set-key [mode-line mouse-1] 'mouse-delete-other-windows)
1240(global-set-key [mode-line mouse-3] 'mouse-delete-window)
1241(global-set-key [mode-line S-mouse-2] 'mouse-split-window-horizontally)
1242\f
1243;; Define the mouse help menu tree.
1244
1245(defvar help-menu-map '(keymap "Help"))
1246(global-set-key [C-down-mouse-2] help-menu-map)
1247
1248(defvar help-apropos-map (make-sparse-keymap "Is there a command that..."))
1249(defvar help-keys-map (make-sparse-keymap "Key Commands <==> Functions"))
1250(defvar help-manual-map (make-sparse-keymap "Manual and tutorial"))
1251(defvar help-misc-map (make-sparse-keymap "Odds and ends"))
1252(defvar help-modes-map (make-sparse-keymap "Modes"))
1253(defvar help-admin-map (make-sparse-keymap "Administrivia"))
1254
1255(define-key help-menu-map [apropos]
1256 (cons "@Is there a command that..." help-apropos-map))
1257(define-key help-menu-map [keys]
1258 (cons "@Key Commands <==> Functions" help-keys-map))
1259(define-key help-menu-map [manuals]
1260 (cons "@Manual and tutorial" help-manual-map))
1261(define-key help-menu-map [misc]
1262 (cons "@Odds and ends" help-misc-map))
1263(define-key help-menu-map [modes]
1264 (cons "@Modes" help-modes-map))
1265(define-key help-menu-map [admin]
1266 (cons "@Administrivia" help-admin-map))
1267
1268(define-key help-apropos-map "c" '("Command Apropos" . command-apropos))
1269(define-key help-apropos-map "a" '("Apropos" . apropos))
1270
1271(define-key help-keys-map "b"
1272 '("List all keystroke commands" . describe-bindings))
1273(define-key help-keys-map "c"
1274 '("Describe key briefly" . describe-key-briefly))
1275(define-key help-keys-map "k"
1276 '("Describe key verbose" . describe-key))
1277(define-key help-keys-map "f"
1278 '("Describe Lisp function" . describe-function))
1279(define-key help-keys-map "w"
1280 '("Where is this command" . where-is))
1281
1282(define-key help-manual-map "i" '("Info system" . info))
1283(define-key help-manual-map "t"
1284 '("Invoke Emacs tutorial" . help-with-tutorial))
1285
1286(define-key help-misc-map "l" '("Last 100 Keystrokes" . view-lossage))
1287(define-key help-misc-map "s" '("Describe syntax table" . describe-syntax))
1288
1289(define-key help-modes-map "m"
1290 '("Describe current major mode" . describe-mode))
1291(define-key help-modes-map "b"
1292 '("List all keystroke commands" . describe-bindings))
1293
1294(define-key help-admin-map "n"
1295 '("View Emacs news" . view-emacs-news))
1296(define-key help-admin-map "l"
1297 '("View Emacs copying conditions" . describe-copying))
1298(define-key help-admin-map "d"
1299 '("Describe distribution" . describe-distribution))
1300(define-key help-admin-map "w"
1301 '("Describe (non)warranty" . describe-no-warranty))
1302
1303(provide 'mouse)
1304
1305;;; mouse.el ends here