(mail-strip-quoted-names): Catch errors from forward-sexp.
[bpt/emacs.git] / lisp / mouse.el
CommitLineData
6594deb0 1;;; mouse.el --- window system-independent mouse support.
84176303 2
9a408b1d 3;;; Copyright (C) 1993 Free Software Foundation, Inc.
eea8d4ef 4
84176303 5;; Maintainer: FSF
84176303
ER
6;; Keywords: hardware
7
cc0a8174 8;;; This file is part of GNU Emacs.
72ea54a4 9
cc0a8174
JB
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
87ef29fd 12;;; the Free Software Foundation; either version 2, or (at your option)
cc0a8174 13;;; any later version.
72ea54a4 14
cc0a8174
JB
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.
72ea54a4 19
cc0a8174
JB
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.
72ea54a4 23
edbd2f74
ER
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
aae56ea7
ER
32;;; Code:
33
cc0a8174 34;;; Utility functions.
72ea54a4 35
cc0a8174
JB
36;;; Indent track-mouse like progn.
37(put 'track-mouse 'lisp-indent-function 0)
72ea54a4 38
cc0a8174
JB
39\f
40(defun mouse-delete-window (click)
947da0c4 41 "Delete the window you click on.
cc0a8174 42This must be bound to a mouse click."
ec558adc 43 (interactive "e")
b5370f03 44 (delete-window (posn-window (event-start click))))
cc0a8174 45
b0f3a26b
JB
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
b5370f03 56(defun mouse-delete-other-windows ()
947da0c4 57 "Delete all window except the one you click on."
b5370f03 58 (interactive "@")
cc0a8174 59 (delete-other-windows))
72ea54a4 60
cc0a8174
JB
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."
947da0c4 65 (interactive "@e")
b5370f03
JB
66 (let ((start (event-start click)))
67 (select-window (posn-window start))
5ba2dc3f
JB
68 (let ((new-height (1+ (cdr (posn-col-row (event-end click)))))
69 (first-line window-min-height)
70 (last-line (- (window-height) window-min-height)))
71 (if (< last-line first-line)
72 (error "window too short to split")
73 (split-window-vertically
74 (min (max new-height first-line) last-line))))))
cc0a8174 75
947da0c4
RS
76(defun mouse-split-window-horizontally (click)
77 "Select Emacs window mouse is on, then split it horizontally in half.
78The window is split at the column clicked on.
79This command must be bound to a mouse click."
80 (interactive "@e")
5ba2dc3f
JB
81 (let ((start (event-start click)))
82 (select-window (posn-window start))
83 (let ((new-width (1+ (car (posn-col-row (event-end click)))))
84 (first-col window-min-width)
85 (last-col (- (window-width) window-min-width)))
86 (if (< last-col first-col)
87 (error "window too narrow to split")
88 (split-window-horizontally
89 (min (max new-width first-col) last-col))))))
947da0c4 90
cc0a8174
JB
91(defun mouse-set-point (click)
92 "Move point to the position clicked on with the mouse.
93This must be bound to a mouse click."
ec558adc 94 (interactive "e")
b5370f03
JB
95 (let ((posn (event-start click)))
96 (select-window (posn-window posn))
97 (if (numberp (posn-point posn))
98 (goto-char (posn-point posn)))))
cc0a8174 99
652ccd35
RS
100(defun mouse-set-region (click)
101 "Set the region to the text that the mouse is dragged over.
fcfc3c63 102This must be bound to a mouse drag event."
652ccd35
RS
103 (interactive "e")
104 (let ((posn (event-start click))
105 (end (event-end click)))
106 (select-window (posn-window posn))
107 (if (numberp (posn-point posn))
108 (goto-char (posn-point posn)))
fcfc3c63
RS
109 ;; If mark is highlighted, no need to bounce the cursor.
110 (or (and transient-mark-mode
111 (eq (framep (selected-frame)) 'x))
112 (sit-for 1))
652ccd35 113 (push-mark)
1cc8a3f4 114 (set-mark (point))
652ccd35
RS
115 (if (numberp (posn-point end))
116 (goto-char (posn-point end)))))
117
fcfc3c63
RS
118(defun mouse-drag-region (click)
119 "Set the region to the text that the mouse is dragged over.
120This must be bound to a button-down mouse event."
121 (interactive "e")
122 (let ((posn (event-start click))
123 done event (mark-active nil))
124 (select-window (posn-window posn))
125 ;; Set point temporarily, so user sees where it is.
126 (if (numberp (posn-point posn))
127 (goto-char (posn-point posn)))
128 ;; Turn off the old mark when we set up an empty region.
129 (setq deactivate-mark t)))
130
131;;;Nice hack, but too slow.
132;;;(defun mouse-drag-region-1 (click)
133;;; "Set the region to the text that the mouse is dragged over.
134;;;This must be bound to a button-down mouse event."
135;;; (interactive "e")
136;;; (let (newmark)
137;;; (let ((posn (event-start click))
138;;; done event omark (mark-active t))
139;;; (select-window (posn-window posn))
140;;; (setq omark (and mark-active (mark)))
141;;; (if (numberp (posn-point posn))
142;;; (goto-char (posn-point posn)))
143;;; ;; Set mark temporarily, so highlighting does what we want.
144;;; (set-marker (mark-marker) (point))
145;;; (track-mouse
146;;; (while (not done)
147;;; (setq event (read-event))
148;;; (if (eq (car-safe event) 'mouse-movement)
149;;; (goto-char (posn-point (event-start event)))
150;;; ;; Exit when we get the drag event; ignore that event.
151;;; (setq done t))))
152;;; (if (/= (mark) (point))
153;;; (setq newmark (mark)))
154;;; ;; Restore previous mark status.
155;;; (if omark (set-marker (mark-marker) omark)))
156;;; ;; Now, if we dragged, set the mark at the proper place.
157;;; (if newmark
158;;; (push-mark newmark t)
159;;; ;; Turn off the old mark when we set up an empty region.
160;;; (setq deactivate-mark t))))
161
cc0a8174
JB
162(defun mouse-set-mark (click)
163 "Set mark at the position clicked on with the mouse.
164Display cursor at that position for a second.
165This must be bound to a mouse click."
ec558adc 166 (interactive "e")
72ea54a4
RS
167 (let ((point-save (point)))
168 (unwind-protect
cc0a8174 169 (progn (mouse-set-point click)
72ea54a4 170 (push-mark nil t)
fe79ff61 171 (sit-for 1))
72ea54a4
RS
172 (goto-char point-save))))
173
cc0a8174
JB
174(defun mouse-kill (click)
175 "Kill the region between point and the mouse click.
176The text is saved in the kill ring, as with \\[kill-region]."
ec558adc 177 (interactive "e")
40a45a9f 178 (let ((click-posn (posn-point (event-start click))))
bd307392
JB
179 (if (numberp click-posn)
180 (kill-region (min (point) click-posn)
181 (max (point) click-posn)))))
72ea54a4 182
87ef29fd
JB
183(defun mouse-yank-at-click (click arg)
184 "Insert the last stretch of killed text at the position clicked on.
185Prefix arguments are interpreted as with \\[yank]."
ec558adc 186 (interactive "e\nP")
87ef29fd
JB
187 (mouse-set-point click)
188 (yank arg))
189
190(defun mouse-kill-ring-save (click)
cc0a8174
JB
191 "Copy the region between point and the mouse click in the kill ring.
192This does not delete the region; it acts like \\[kill-ring-save]."
ec558adc 193 (interactive "e")
cc0a8174 194 (mouse-set-mark click)
87ef29fd 195 (call-interactively 'kill-ring-save))
72ea54a4 196
dbc4e1c1
JB
197;;; This function used to delete the text between point and the mouse
198;;; whenever it was equal to the front of the kill ring, but some
199;;; people found that confusing.
200
201;;; A list (TEXT START END), describing the text and position of the last
202;;; invocation of mouse-save-then-kill.
203(defvar mouse-save-then-kill-posn nil)
204
947da0c4 205(defun mouse-save-then-kill (click)
40a45a9f
RS
206 "Save text to point in kill ring; the second time, kill the text.
207If the text between point and the mouse is the same as what's
208at the front of the kill ring, this deletes the text.
209Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
210which prepares for a second click to delete the text."
947da0c4 211 (interactive "e")
40a45a9f 212 (let ((click-posn (posn-point (event-start click))))
dbc4e1c1
JB
213 (if (and (eq last-command 'kill-region)
214 mouse-save-then-kill-posn
215 (eq (car mouse-save-then-kill-posn) (car kill-ring))
216 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
217 ;; If this is the second time we've called
218 ;; mouse-save-then-kill, delete the text from the buffer.
40a45a9f
RS
219 (progn
220 (let ((buffer-undo-list t))
221 (delete-region (point) (mark)))
222 ;; Make the undo list by hand so it is shared.
dbc4e1c1
JB
223 (if (not (eq buffer-undo-list t))
224 (setq buffer-undo-list
225 (cons (cons (car kill-ring) (point)) buffer-undo-list))))
40a45a9f
RS
226 ;; Otherwise, save this region.
227 (mouse-set-mark click)
dbc4e1c1
JB
228 (call-interactively 'kill-ring-save)
229 (setq mouse-save-then-kill-posn
230 (list (car kill-ring) (point) click-posn)))))
947da0c4 231
8b34e79d 232(defun mouse-buffer-menu (event)
2d82f7b9
RS
233 "Pop up a menu of buffers for selection with the mouse.
234This switches buffers in the window that you clicked on,
235and selects that window."
ec558adc 236 (interactive "e")
8b34e79d
RS
237 (let ((menu
238 (list "Buffer Menu"
239 (cons "Select Buffer"
240 (let ((tail (buffer-list))
241 head)
242 (while tail
243 (let ((elt (car tail)))
244 (if (not (string-match "^ "
245 (buffer-name elt)))
246 (setq head (cons
247 (cons
248 (format
1a786d29 249 "%-14s %s"
8b34e79d
RS
250 (buffer-name elt)
251 (or (buffer-file-name elt) ""))
252 elt)
253 head))))
254 (setq tail (cdr tail)))
255 (reverse head))))))
2d82f7b9
RS
256 (let ((buf (x-popup-menu event menu))
257 (window (posn-window (event-start event))))
258 (if buf
259 (progn
260 (select-window window)
261 (switch-to-buffer buf))))))
72ea54a4 262\f
5ba2dc3f 263;;; These need to be rewritten for the new scroll bar implementation.
dbc4e1c1
JB
264
265;;;!! ;; Commands for the scroll bar.
266;;;!!
267;;;!! (defun mouse-scroll-down (click)
268;;;!! (interactive "@e")
269;;;!! (scroll-down (1+ (cdr (mouse-coords click)))))
270;;;!!
271;;;!! (defun mouse-scroll-up (click)
272;;;!! (interactive "@e")
273;;;!! (scroll-up (1+ (cdr (mouse-coords click)))))
274;;;!!
275;;;!! (defun mouse-scroll-down-full ()
276;;;!! (interactive "@")
277;;;!! (scroll-down nil))
278;;;!!
279;;;!! (defun mouse-scroll-up-full ()
280;;;!! (interactive "@")
281;;;!! (scroll-up nil))
282;;;!!
283;;;!! (defun mouse-scroll-move-cursor (click)
284;;;!! (interactive "@e")
285;;;!! (move-to-window-line (1+ (cdr (mouse-coords click)))))
286;;;!!
287;;;!! (defun mouse-scroll-absolute (event)
288;;;!! (interactive "@e")
289;;;!! (let* ((pos (car event))
290;;;!! (position (car pos))
291;;;!! (length (car (cdr pos))))
292;;;!! (if (<= length 0) (setq length 1))
293;;;!! (let* ((scale-factor (max 1 (/ length (/ 8000000 (buffer-size)))))
294;;;!! (newpos (* (/ (* (/ (buffer-size) scale-factor)
295;;;!! position)
296;;;!! length)
297;;;!! scale-factor)))
298;;;!! (goto-char newpos)
299;;;!! (recenter '(4)))))
300;;;!!
301;;;!! (defun mouse-scroll-left (click)
302;;;!! (interactive "@e")
303;;;!! (scroll-left (1+ (car (mouse-coords click)))))
304;;;!!
305;;;!! (defun mouse-scroll-right (click)
306;;;!! (interactive "@e")
307;;;!! (scroll-right (1+ (car (mouse-coords click)))))
308;;;!!
309;;;!! (defun mouse-scroll-left-full ()
310;;;!! (interactive "@")
311;;;!! (scroll-left nil))
312;;;!!
313;;;!! (defun mouse-scroll-right-full ()
314;;;!! (interactive "@")
315;;;!! (scroll-right nil))
316;;;!!
317;;;!! (defun mouse-scroll-move-cursor-horizontally (click)
318;;;!! (interactive "@e")
319;;;!! (move-to-column (1+ (car (mouse-coords click)))))
320;;;!!
321;;;!! (defun mouse-scroll-absolute-horizontally (event)
322;;;!! (interactive "@e")
323;;;!! (let* ((pos (car event))
324;;;!! (position (car pos))
325;;;!! (length (car (cdr pos))))
326;;;!! (set-window-hscroll (selected-window) 33)))
327;;;!!
328;;;!! (global-set-key [scroll-bar mouse-1] 'mouse-scroll-up)
329;;;!! (global-set-key [scroll-bar mouse-2] 'mouse-scroll-absolute)
330;;;!! (global-set-key [scroll-bar mouse-3] 'mouse-scroll-down)
331;;;!!
332;;;!! (global-set-key [vertical-slider mouse-1] 'mouse-scroll-move-cursor)
333;;;!! (global-set-key [vertical-slider mouse-2] 'mouse-scroll-move-cursor)
334;;;!! (global-set-key [vertical-slider mouse-3] 'mouse-scroll-move-cursor)
335;;;!!
336;;;!! (global-set-key [thumbup mouse-1] 'mouse-scroll-up-full)
337;;;!! (global-set-key [thumbup mouse-2] 'mouse-scroll-up-full)
338;;;!! (global-set-key [thumbup mouse-3] 'mouse-scroll-up-full)
339;;;!!
340;;;!! (global-set-key [thumbdown mouse-1] 'mouse-scroll-down-full)
341;;;!! (global-set-key [thumbdown mouse-2] 'mouse-scroll-down-full)
342;;;!! (global-set-key [thumbdown mouse-3] 'mouse-scroll-down-full)
343;;;!!
344;;;!! (global-set-key [horizontal-scroll-bar mouse-1] 'mouse-scroll-left)
345;;;!! (global-set-key [horizontal-scroll-bar mouse-2]
346;;;!! 'mouse-scroll-absolute-horizontally)
347;;;!! (global-set-key [horizontal-scroll-bar mouse-3] 'mouse-scroll-right)
348;;;!!
349;;;!! (global-set-key [horizontal-slider mouse-1]
350;;;!! 'mouse-scroll-move-cursor-horizontally)
351;;;!! (global-set-key [horizontal-slider mouse-2]
352;;;!! 'mouse-scroll-move-cursor-horizontally)
353;;;!! (global-set-key [horizontal-slider mouse-3]
354;;;!! 'mouse-scroll-move-cursor-horizontally)
355;;;!!
356;;;!! (global-set-key [thumbleft mouse-1] 'mouse-scroll-left-full)
357;;;!! (global-set-key [thumbleft mouse-2] 'mouse-scroll-left-full)
358;;;!! (global-set-key [thumbleft mouse-3] 'mouse-scroll-left-full)
359;;;!!
360;;;!! (global-set-key [thumbright mouse-1] 'mouse-scroll-right-full)
361;;;!! (global-set-key [thumbright mouse-2] 'mouse-scroll-right-full)
362;;;!! (global-set-key [thumbright mouse-3] 'mouse-scroll-right-full)
363;;;!!
364;;;!! (global-set-key [horizontal-scroll-bar S-mouse-2]
365;;;!! 'mouse-split-window-horizontally)
366;;;!! (global-set-key [mode-line S-mouse-2]
367;;;!! 'mouse-split-window-horizontally)
368;;;!! (global-set-key [vertical-scroll-bar S-mouse-2]
369;;;!! 'mouse-split-window)
6b2154de 370\f
dbc4e1c1
JB
371;;;!! ;;;;
372;;;!! ;;;; Here are experimental things being tested. Mouse events
373;;;!! ;;;; are of the form:
374;;;!! ;;;; ((x y) window screen-part key-sequence timestamp)
375;;;!! ;;
376;;;!! ;;;;
377;;;!! ;;;; Dynamically track mouse coordinates
378;;;!! ;;;;
379;;;!! ;;
380;;;!! ;;(defun track-mouse (event)
381;;;!! ;; "Track the coordinates, absolute and relative, of the mouse."
382;;;!! ;; (interactive "@e")
383;;;!! ;; (while mouse-grabbed
384;;;!! ;; (let* ((pos (read-mouse-position (selected-screen)))
385;;;!! ;; (abs-x (car pos))
386;;;!! ;; (abs-y (cdr pos))
387;;;!! ;; (relative-coordinate (coordinates-in-window-p
388;;;!! ;; (list (car pos) (cdr pos))
389;;;!! ;; (selected-window))))
390;;;!! ;; (if (consp relative-coordinate)
391;;;!! ;; (message "mouse: [%d %d], (%d %d)" abs-x abs-y
392;;;!! ;; (car relative-coordinate)
393;;;!! ;; (car (cdr relative-coordinate)))
394;;;!! ;; (message "mouse: [%d %d]" abs-x abs-y)))))
395;;;!!
396;;;!! ;;
397;;;!! ;; Dynamically put a box around the line indicated by point
398;;;!! ;;
399;;;!! ;;
400;;;!! ;;(require 'backquote)
401;;;!! ;;
402;;;!! ;;(defun mouse-select-buffer-line (event)
403;;;!! ;; (interactive "@e")
404;;;!! ;; (let ((relative-coordinate
405;;;!! ;; (coordinates-in-window-p (car event) (selected-window)))
406;;;!! ;; (abs-y (car (cdr (car event)))))
407;;;!! ;; (if (consp relative-coordinate)
408;;;!! ;; (progn
409;;;!! ;; (save-excursion
410;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
411;;;!! ;; (x-draw-rectangle
412;;;!! ;; (selected-screen)
413;;;!! ;; abs-y 0
414;;;!! ;; (save-excursion
415;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
416;;;!! ;; (end-of-line)
417;;;!! ;; (push-mark nil t)
418;;;!! ;; (beginning-of-line)
419;;;!! ;; (- (region-end) (region-beginning))) 1))
420;;;!! ;; (sit-for 1)
421;;;!! ;; (x-erase-rectangle (selected-screen))))))
422;;;!! ;;
423;;;!! ;;(defvar last-line-drawn nil)
424;;;!! ;;(defvar begin-delim "[^ \t]")
425;;;!! ;;(defvar end-delim "[^ \t]")
426;;;!! ;;
427;;;!! ;;(defun mouse-boxing (event)
428;;;!! ;; (interactive "@e")
429;;;!! ;; (save-excursion
430;;;!! ;; (let ((screen (selected-screen)))
431;;;!! ;; (while (= (x-mouse-events) 0)
432;;;!! ;; (let* ((pos (read-mouse-position screen))
433;;;!! ;; (abs-x (car pos))
434;;;!! ;; (abs-y (cdr pos))
435;;;!! ;; (relative-coordinate
436;;;!! ;; (coordinates-in-window-p (` ((, abs-x) (, abs-y)))
437;;;!! ;; (selected-window)))
438;;;!! ;; (begin-reg nil)
439;;;!! ;; (end-reg nil)
440;;;!! ;; (end-column nil)
441;;;!! ;; (begin-column nil))
442;;;!! ;; (if (and (consp relative-coordinate)
443;;;!! ;; (or (not last-line-drawn)
444;;;!! ;; (not (= last-line-drawn abs-y))))
445;;;!! ;; (progn
446;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
447;;;!! ;; (if (= (following-char) 10)
448;;;!! ;; ()
449;;;!! ;; (progn
450;;;!! ;; (setq begin-reg (1- (re-search-forward end-delim)))
451;;;!! ;; (setq begin-column (1- (current-column)))
452;;;!! ;; (end-of-line)
453;;;!! ;; (setq end-reg (1+ (re-search-backward begin-delim)))
454;;;!! ;; (setq end-column (1+ (current-column)))
455;;;!! ;; (message "%s" (buffer-substring begin-reg end-reg))
456;;;!! ;; (x-draw-rectangle screen
457;;;!! ;; (setq last-line-drawn abs-y)
458;;;!! ;; begin-column
459;;;!! ;; (- end-column begin-column) 1))))))))))
460;;;!! ;;
461;;;!! ;;(defun mouse-erase-box ()
462;;;!! ;; (interactive)
463;;;!! ;; (if last-line-drawn
464;;;!! ;; (progn
465;;;!! ;; (x-erase-rectangle (selected-screen))
466;;;!! ;; (setq last-line-drawn nil))))
467;;;!!
468;;;!! ;;; (defun test-x-rectangle ()
469;;;!! ;;; (use-local-mouse-map (setq rectangle-test-map (make-sparse-keymap)))
470;;;!! ;;; (define-key rectangle-test-map mouse-motion-button-left 'mouse-boxing)
471;;;!! ;;; (define-key rectangle-test-map mouse-button-left-up 'mouse-erase-box))
472;;;!!
473;;;!! ;;
474;;;!! ;; Here is how to do double clicking in lisp. About to change.
475;;;!! ;;
476;;;!!
477;;;!! (defvar double-start nil)
478;;;!! (defconst double-click-interval 300
479;;;!! "Max ticks between clicks")
480;;;!!
481;;;!! (defun double-down (event)
482;;;!! (interactive "@e")
483;;;!! (if double-start
484;;;!! (let ((interval (- (nth 4 event) double-start)))
485;;;!! (if (< interval double-click-interval)
486;;;!! (progn
487;;;!! (backward-up-list 1)
488;;;!! ;; (message "Interval %d" interval)
489;;;!! (sleep-for 1)))
490;;;!! (setq double-start nil))
491;;;!! (setq double-start (nth 4 event))))
492;;;!!
493;;;!! (defun double-up (event)
494;;;!! (interactive "@e")
495;;;!! (and double-start
496;;;!! (> (- (nth 4 event ) double-start) double-click-interval)
497;;;!! (setq double-start nil)))
498;;;!!
499;;;!! ;;; (defun x-test-doubleclick ()
500;;;!! ;;; (use-local-mouse-map (setq doubleclick-test-map (make-sparse-keymap)))
501;;;!! ;;; (define-key doubleclick-test-map mouse-button-left 'double-down)
502;;;!! ;;; (define-key doubleclick-test-map mouse-button-left-up 'double-up))
503;;;!!
504;;;!! ;;
5ba2dc3f 505;;;!! ;; This scrolls while button is depressed. Use preferable in scroll bar.
dbc4e1c1
JB
506;;;!! ;;
507;;;!!
508;;;!! (defvar scrolled-lines 0)
509;;;!! (defconst scroll-speed 1)
510;;;!!
511;;;!! (defun incr-scroll-down (event)
512;;;!! (interactive "@e")
513;;;!! (setq scrolled-lines 0)
514;;;!! (incremental-scroll scroll-speed))
515;;;!!
516;;;!! (defun incr-scroll-up (event)
517;;;!! (interactive "@e")
518;;;!! (setq scrolled-lines 0)
519;;;!! (incremental-scroll (- scroll-speed)))
520;;;!!
521;;;!! (defun incremental-scroll (n)
522;;;!! (while (= (x-mouse-events) 0)
523;;;!! (setq scrolled-lines (1+ (* scroll-speed scrolled-lines)))
524;;;!! (scroll-down n)
525;;;!! (sit-for 300 t)))
526;;;!!
527;;;!! (defun incr-scroll-stop (event)
528;;;!! (interactive "@e")
529;;;!! (message "Scrolled %d lines" scrolled-lines)
530;;;!! (setq scrolled-lines 0)
531;;;!! (sleep-for 1))
532;;;!!
533;;;!! ;;; (defun x-testing-scroll ()
534;;;!! ;;; (let ((scrolling-map (function mouse-vertical-scroll-bar-prefix)))
535;;;!! ;;; (define-key scrolling-map mouse-button-left 'incr-scroll-down)
536;;;!! ;;; (define-key scrolling-map mouse-button-right 'incr-scroll-up)
537;;;!! ;;; (define-key scrolling-map mouse-button-left-up 'incr-scroll-stop)
538;;;!! ;;; (define-key scrolling-map mouse-button-right-up 'incr-scroll-stop)))
539;;;!!
540;;;!! ;;
541;;;!! ;; Some playthings suitable for picture mode? They need work.
542;;;!! ;;
543;;;!!
544;;;!! (defun mouse-kill-rectangle (event)
545;;;!! "Kill the rectangle between point and the mouse cursor."
546;;;!! (interactive "@e")
547;;;!! (let ((point-save (point)))
548;;;!! (save-excursion
549;;;!! (mouse-set-point event)
550;;;!! (push-mark nil t)
551;;;!! (if (> point-save (point))
552;;;!! (kill-rectangle (point) point-save)
553;;;!! (kill-rectangle point-save (point))))))
554;;;!!
555;;;!! (defun mouse-open-rectangle (event)
556;;;!! "Kill the rectangle between point and the mouse cursor."
557;;;!! (interactive "@e")
558;;;!! (let ((point-save (point)))
559;;;!! (save-excursion
560;;;!! (mouse-set-point event)
561;;;!! (push-mark nil t)
562;;;!! (if (> point-save (point))
563;;;!! (open-rectangle (point) point-save)
564;;;!! (open-rectangle point-save (point))))))
565;;;!!
566;;;!! ;; Must be a better way to do this.
567;;;!!
568;;;!! (defun mouse-multiple-insert (n char)
569;;;!! (while (> n 0)
570;;;!! (insert char)
571;;;!! (setq n (1- n))))
572;;;!!
573;;;!! ;; What this could do is not finalize until button was released.
574;;;!!
575;;;!! (defun mouse-move-text (event)
576;;;!! "Move text from point to cursor position, inserting spaces."
577;;;!! (interactive "@e")
578;;;!! (let* ((relative-coordinate
579;;;!! (coordinates-in-window-p (car event) (selected-window))))
580;;;!! (if (consp relative-coordinate)
581;;;!! (cond ((> (current-column) (car relative-coordinate))
582;;;!! (delete-char
583;;;!! (- (car relative-coordinate) (current-column))))
584;;;!! ((< (current-column) (car relative-coordinate))
585;;;!! (mouse-multiple-insert
586;;;!! (- (car relative-coordinate) (current-column)) " "))
587;;;!! ((= (current-column) (car relative-coordinate)) (ding))))))
07a78410
RS
588\f
589;; Font selection.
590
591(defvar x-fixed-font-alist
592 '("Font menu"
593 ("Misc"
594 ("fixed" "fixed")
595 ("6x10" "6x10")
596 ("6x12" "6x12")
597 ("6x13" "6x13")
598 ("7x13" "7x13")
599 ("7x14" "7x14")
600 ("8x13" "8x13")
601 ("8x13 bold" "8x13bold")
602 ("8x16" "8x16")
603 ("9x15" "9x15")
604 ("9x15 bold" "9x15bold")
605 ("10x20" "10x20")
606 ("11x18" "11x18")
607 ("12x24" "12x24"))
608;;; We don't seem to have these; who knows what they are.
609;;; ("fg-18" "fg-18")
610;;; ("fg-25" "fg-25")
611;;; ("lucidasanstypewriter-12" "lucidasanstypewriter-12")
612;;; ("lucidasanstypewriter-bold-14" "lucidasanstypewriter-bold-14")
613;;; ("lucidasanstypewriter-bold-24" "lucidasanstypewriter-bold-24")
614;;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
615;;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
616 ("Courier"
617 ("8" "-adobe-courier-medium-r-normal--8-*-*-*-m-*-iso8859-1")
618 ("10" "-adobe-courier-medium-r-normal--10-*-*-*-m-*-iso8859-1")
619 ("12" "-adobe-courier-medium-r-normal--12-*-*-*-m-*-iso8859-1")
620 ("14" "-adobe-courier-medium-r-normal--14-*-*-*-m-*-iso8859-1")
621 ("18" "-adobe-courier-medium-r-normal--18-*-*-*-m-*-iso8859-1")
622 ("24" "-adobe-courier-medium-r-normal--24-*-*-*-m-*-iso8859-1")
623 ("8 bold" "-adobe-courier-bold-r-normal--8-*-*-*-m-*-iso8859-1")
624 ("10 bold" "-adobe-courier-bold-r-normal--10-*-*-*-m-*-iso8859-1")
625 ("12 bold" "-adobe-courier-bold-r-normal--12-*-*-*-m-*-iso8859-1")
626 ("14 bold" "-adobe-courier-bold-r-normal--14-*-*-*-m-*-iso8859-1")
627 ("18 bold" "-adobe-courier-bold-r-normal--18-*-*-*-m-*-iso8859-1")
628 ("24 bold" "-adobe-courier-bold-r-normal--24-*-*-*-m-*-iso8859-1")
629 ("8 slant" "-adobe-courier-medium-o-normal--8-*-*-*-m-*-iso8859-1")
630 ("10 slant" "-adobe-courier-medium-o-normal--10-*-*-*-m-*-iso8859-1")
631 ("12 slant" "-adobe-courier-medium-o-normal--12-*-*-*-m-*-iso8859-1")
632 ("14 slant" "-adobe-courier-medium-o-normal--14-*-*-*-m-*-iso8859-1")
633 ("18 slant" "-adobe-courier-medium-o-normal--18-*-*-*-m-*-iso8859-1")
634 ("24 slant" "-adobe-courier-medium-o-normal--24-*-*-*-m-*-iso8859-1")
635 ("8 bold slant" "-adobe-courier-bold-o-normal--8-*-*-*-m-*-iso8859-1")
636 ("10 bold slant" "-adobe-courier-bold-o-normal--10-*-*-*-m-*-iso8859-1")
637 ("12 bold slant" "-adobe-courier-bold-o-normal--12-*-*-*-m-*-iso8859-1")
638 ("14 bold slant" "-adobe-courier-bold-o-normal--14-*-*-*-m-*-iso8859-1")
639 ("18 bold slant" "-adobe-courier-bold-o-normal--18-*-*-*-m-*-iso8859-1")
640 ("24 bold slant" "-adobe-courier-bold-o-normal--24-*-*-*-m-*-iso8859-1"))
641 )
642 "X fonts suitable for use in Emacs.")
643
dbc4e1c1 644(defun mouse-set-font (&optional font)
07a78410
RS
645 "Select an emacs font from a list of known good fonts"
646 (interactive
647 (x-popup-menu last-nonmenu-event x-fixed-font-alist))
dbc4e1c1
JB
648 (if font
649 (modify-frame-parameters (selected-frame)
650 (list (cons 'font font)))))
cc0a8174
JB
651\f
652;;; Bindings for mouse commands.
653
fcfc3c63 654(define-key global-map [down-mouse-1] 'mouse-drag-region)
dbc4e1c1 655(global-set-key [mouse-1] 'mouse-set-point)
dbc4e1c1 656(global-set-key [drag-mouse-1] 'mouse-set-region)
fcfc3c63 657
dbc4e1c1
JB
658(global-set-key [mouse-2] 'mouse-yank-at-click)
659(global-set-key [mouse-3] 'mouse-save-then-kill)
8b34e79d 660
dbc4e1c1
JB
661;; By binding these to down-going events, we let the user use the up-going
662;; event to make the selection, saving a click.
663(global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
664(global-set-key [C-down-mouse-3] 'mouse-set-font)
07a78410 665
8b34e79d
RS
666;; Replaced with dragging mouse-1
667;; (global-set-key [S-mouse-1] 'mouse-set-mark)
947da0c4 668
dbc4e1c1
JB
669(global-set-key [mode-line mouse-1] 'mouse-delete-other-windows)
670(global-set-key [mode-line mouse-3] 'mouse-delete-window)
671(global-set-key [mode-line S-mouse-2] 'mouse-split-window-horizontally)
8b34e79d 672\f
6b2154de
RS
673;; Define the mouse help menu tree.
674
8b34e79d 675(defvar help-menu-map '(keymap "Help"))
dbc4e1c1
JB
676(global-set-key [C-down-mouse-2] help-menu-map)
677
678(defvar help-apropos-map (make-sparse-keymap "Is there a command that..."))
679(defvar help-keys-map (make-sparse-keymap "Key Commands <==> Functions"))
680(defvar help-manual-map (make-sparse-keymap "Manual and tutorial"))
681(defvar help-misc-map (make-sparse-keymap "Odds and ends"))
682(defvar help-modes-map (make-sparse-keymap "Modes"))
683(defvar help-admin-map (make-sparse-keymap "Administrivia"))
8b34e79d 684
e7691e9c 685(define-key help-menu-map [apropos]
6ec3899e 686 (cons "@Is there a command that..." help-apropos-map))
e7691e9c 687(define-key help-menu-map [keys]
6ec3899e 688 (cons "@Key Commands <==> Functions" help-keys-map))
e7691e9c 689(define-key help-menu-map [manuals]
6ec3899e 690 (cons "@Manual and tutorial" help-manual-map))
e7691e9c 691(define-key help-menu-map [misc]
6ec3899e 692 (cons "@Odds and ends" help-misc-map))
e7691e9c 693(define-key help-menu-map [modes]
6ec3899e 694 (cons "@Modes" help-modes-map))
e7691e9c 695(define-key help-menu-map [admin]
6ec3899e 696 (cons "@Administrivia" help-admin-map))
8b34e79d
RS
697
698(define-key help-apropos-map "c" '("Command Apropos" . command-apropos))
699(define-key help-apropos-map "a" '("Apropos" . apropos))
700
701(define-key help-keys-map "b"
702 '("List all keystroke commands" . describe-bindings))
703(define-key help-keys-map "c"
704 '("Describe key briefly" . describe-key-briefly))
705(define-key help-keys-map "k"
706 '("Describe key verbose" . describe-key))
707(define-key help-keys-map "f"
708 '("Describe Lisp function" . describe-function))
709(define-key help-keys-map "w"
710 '("Where is this command" . where-is))
711
712(define-key help-manual-map "i" '("Info system" . info))
713(define-key help-manual-map "t"
714 '("Invoke Emacs tutorial" . help-with-tutorial))
715
716(define-key help-misc-map "l" '("Last 100 Keystrokes" . view-lossage))
717(define-key help-misc-map "s" '("Describe syntax table" . describe-syntax))
718
719(define-key help-modes-map "m"
720 '("Describe current major mode" . describe-mode))
721(define-key help-modes-map "b"
722 '("List all keystroke commands" . describe-bindings))
723
724(define-key help-admin-map "n"
725 '("view Emacs news" . view-emacs-news))
726(define-key help-admin-map "l"
727 '("View the GNU Emacs license" . describe-copying))
728(define-key help-admin-map "d"
729 '("Describe distribution" . describe-distribution))
730(define-key help-admin-map "w"
731 '("Describe (non)warranty" . describe-no-warranty))
49116ac0
JB
732
733(provide 'mouse)
734
6594deb0 735;;; mouse.el ends here