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