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