(mouse-menu-bar-buffers): Include % and * in each item.
[bpt/emacs.git] / lisp / mouse.el
... / ...
CommitLineData
1;;; mouse.el --- window system-independent mouse support.
2
3;;; Copyright (C) 1993 Free Software Foundation, Inc.
4
5;; Maintainer: FSF
6;; Keywords: hardware
7
8;;; This file is part of GNU Emacs.
9
10;;; GNU Emacs is free software; you can redistribute it and/or modify
11;;; it under the terms of the GNU General Public License as published by
12;;; the Free Software Foundation; either version 2, or (at your option)
13;;; any later version.
14
15;;; GNU Emacs is distributed in the hope that it will be useful,
16;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;;; GNU General Public License for more details.
19
20;;; You should have received a copy of the GNU General Public License
21;;; along with GNU Emacs; see the file COPYING. If not, write to
22;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
24;;; Commentary:
25
26;; This package provides various useful commands (including help
27;; system access) through the mouse. All this code assumes that mouse
28;; interpretation has been abstracted into Emacs input events.
29;;
30;; The code is rather X-dependent.
31
32;;; Code:
33
34;;; Utility functions.
35
36;;; Indent track-mouse like progn.
37(put 'track-mouse 'lisp-indent-function 0)
38
39\f
40(defun mouse-delete-window (click)
41 "Delete the window you click on.
42This must be bound to a mouse click."
43 (interactive "e")
44 (delete-window (posn-window (event-start click))))
45
46(defun mouse-tear-off-window (click)
47 "Delete the window clicked on, and create a new frame displaying its buffer."
48 (interactive "e")
49 (let* ((window (posn-window (event-start click)))
50 (buf (window-buffer window))
51 (frame (new-frame)))
52 (select-frame frame)
53 (switch-to-buffer buf)
54 (delete-window window)))
55
56(defun mouse-delete-other-windows ()
57 "Delete all window except the one you click on."
58 (interactive "@")
59 (delete-other-windows))
60
61(defun mouse-split-window-vertically (click)
62 "Select Emacs window mouse is on, then split it vertically in half.
63The window is split at the line clicked on.
64This command must be bound to a mouse click."
65 (interactive "@e")
66 (let ((start (event-start click)))
67 (select-window (posn-window start))
68 (let ((new-height (if (eq (posn-point start) 'vertical-scroll-bar)
69 (scroll-bar-scale (posn-col-row start)
70 (1- (window-height)))
71 (1+ (cdr (posn-col-row (event-end click))))))
72 (first-line window-min-height)
73 (last-line (- (window-height) window-min-height)))
74 (if (< last-line first-line)
75 (error "window too short to split")
76 (split-window-vertically
77 (min (max new-height first-line) last-line))))))
78
79(defun mouse-split-window-horizontally (click)
80 "Select Emacs window mouse is on, then split it horizontally in half.
81The window is split at the column clicked on.
82This command must be bound to a mouse click."
83 (interactive "@e")
84 (let ((start (event-start click)))
85 (select-window (posn-window start))
86 (let ((new-width (1+ (car (posn-col-row (event-end click)))))
87 (first-col window-min-width)
88 (last-col (- (window-width) window-min-width)))
89 (if (< last-col first-col)
90 (error "window too narrow to split")
91 (split-window-horizontally
92 (min (max new-width first-col) last-col))))))
93
94(defun mouse-set-point (click)
95 "Move point to the position clicked on with the mouse.
96This must be bound to a mouse click."
97 (interactive "e")
98 (let ((posn (event-start click)))
99 (select-window (posn-window posn))
100 (if (numberp (posn-point posn))
101 (goto-char (posn-point posn)))))
102
103(defun mouse-set-region (click)
104 "Set the region to the text that the mouse is dragged over.
105This must be bound to a mouse drag event."
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)))
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))
116 (push-mark)
117 (set-mark (point))
118 (if (numberp (posn-point end))
119 (goto-char (posn-point end)))))
120
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
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))))
164\f
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
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."
184 (interactive "e")
185 (let ((point-save (point)))
186 (unwind-protect
187 (progn (mouse-set-point click)
188 (push-mark nil t t)
189 (or transient-mark-mode
190 (sit-for 1)))
191 (goto-char point-save))))
192
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]."
196 (interactive "e")
197 (let ((click-posn (posn-point (event-start click))))
198 (if (numberp click-posn)
199 (kill-region (min (point) click-posn)
200 (max (point) click-posn)))))
201
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]."
205 (interactive "e\nP")
206 (mouse-set-point click)
207 (yank arg))
208
209(defun mouse-kill-ring-save (click)
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]."
212 (interactive "e")
213 (mouse-set-mark-fast click)
214 (kill-ring-save (point) (mark t))
215 (mouse-show-mark))
216
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
225(defun mouse-save-then-kill (click)
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."
231 (interactive "e")
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)
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.
242 (progn
243 (let ((buffer-undo-list t))
244 (delete-region (point) (mark)))
245 ;; Make the undo list by hand so it is shared.
246 (if (not (eq buffer-undo-list t))
247 (setq buffer-undo-list
248 (cons (cons (car kill-ring) (point)) buffer-undo-list))))
249 ;; Otherwise, save this region.
250 (mouse-set-mark-fast click)
251 (kill-ring-save (point) (mark t))
252 (mouse-show-mark)
253 (setq mouse-save-then-kill-posn
254 (list (car kill-ring) (point) click-posn)))))
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 (save-excursion
278 (set-buffer (window-buffer (posn-window posn)))
279 ;; Cancel any preexisting secondary selection.
280 (if mouse-secondary-overlay
281 (delete-overlay mouse-secondary-overlay))
282 (if (numberp (posn-point posn))
283 (progn
284 (or mouse-secondary-start
285 (setq mouse-secondary-start (make-marker)))
286 (move-marker mouse-secondary-start (posn-point posn)))))))
287
288(defun mouse-set-secondary (click)
289 "Set the secondary selection to the text that the mouse is dragged over.
290This must be bound to a mouse drag event."
291 (interactive "e")
292 (let ((posn (event-start click))
293 beg
294 (end (event-end click)))
295 (save-excursion
296 (set-buffer (window-buffer (posn-window posn)))
297 (if (numberp (posn-point posn))
298 (setq beg (posn-point posn)))
299 (if mouse-secondary-overlay
300 (move-overlay mouse-secondary-overlay beg (posn-point end))
301 (setq mouse-secondary-overlay (make-overlay beg (posn-point end))))
302 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))))
303
304(defun mouse-drag-secondary (click)
305 "Set the secondary selection to the text that the mouse is dragged over.
306This must be bound to a button-down mouse event."
307 (interactive "e")
308 (let ((posn (event-start click)))
309 (save-window-excursion
310 (select-window (posn-window posn))
311 ;; Set point temporarily, so user sees where it is.
312 (save-excursion
313 (if (numberp (posn-point posn))
314 (goto-char (posn-point posn)))
315 (setq unread-command-events
316 (cons (read-event) unread-command-events))))))
317
318(defun mouse-kill-secondary ()
319 "Kill the text in the secondary selection."
320 (interactive "*")
321 (kill-region (overlay-start mouse-secondary-overlay)
322 (overlay-end mouse-secondary-overlay))
323 (delete-overlay mouse-secondary-overlay)
324 (setq mouse-secondary-overlay nil))
325
326(defun mouse-secondary-save-then-kill (click)
327 "Save text to secondary start point in kill ring; if twice, kill it.
328If the text between secondary start point and the mouse is the same as what's
329at the front of the kill ring, this deletes the text.
330Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
331which prepares for a second click to delete the text."
332 (interactive "e")
333 (let ((click-posn (posn-point (event-start click)))
334 (start (+ 0 mouse-secondary-start))
335 ;; Don't let a subsequent kill command append to this one:
336 ;; prevent setting this-command to kill-region.
337 (this-command this-command))
338 (if (and (eq last-command 'mouse-secondary-save-then-kill)
339 mouse-save-then-kill-posn
340 (eq (car mouse-save-then-kill-posn) (car kill-ring))
341 (equal (cdr mouse-save-then-kill-posn)
342 (list start click-posn)))
343 ;; If this is the second time we've called
344 ;; mouse-save-then-kill, delete the text from the buffer.
345 (progn
346 (let ((buffer-undo-list t))
347 (delete-overlay mouse-secondary-overlay)
348 (delete-region start click-posn))
349 ;; Make the undo list by hand so it is shared.
350 (if (not (eq buffer-undo-list t))
351 (setq buffer-undo-list
352 (cons (cons (car kill-ring) start)
353 buffer-undo-list))))
354 ;; Otherwise, save this region.
355 (save-excursion
356 (set-buffer (window-buffer (posn-window (event-start click))))
357 (kill-ring-save start click-posn)
358 (if mouse-secondary-overlay
359 (move-overlay mouse-secondary-overlay start click-posn)
360 (setq mouse-secondary-overlay (make-overlay start click-posn)))
361 (overlay-put mouse-secondary-overlay 'face 'secondary-selection)
362 (setq mouse-save-then-kill-posn
363 (list (car kill-ring) start click-posn))))))
364\f
365(defun mouse-buffer-menu (event)
366 "Pop up a menu of buffers for selection with the mouse.
367This switches buffers in the window that you clicked on,
368and selects that window."
369 (interactive "e")
370 (let ((menu
371 (list "Buffer Menu"
372 (cons "Select Buffer"
373 (let ((tail (buffer-list))
374 head)
375 (while tail
376 (let ((elt (car tail)))
377 (if (not (string-match "^ "
378 (buffer-name elt)))
379 (setq head (cons
380 (cons
381 (format
382 "%-14s %s"
383 (buffer-name elt)
384 (or (buffer-file-name elt) ""))
385 elt)
386 head))))
387 (setq tail (cdr tail)))
388 (reverse head))))))
389 (let ((buf (x-popup-menu event menu))
390 (window (posn-window (event-start event))))
391 (if buf
392 (progn
393 (or (framep window) (select-window window))
394 (switch-to-buffer buf))))))
395\f
396;;; These need to be rewritten for the new scroll bar implementation.
397
398;;;!! ;; Commands for the scroll bar.
399;;;!!
400;;;!! (defun mouse-scroll-down (click)
401;;;!! (interactive "@e")
402;;;!! (scroll-down (1+ (cdr (mouse-coords click)))))
403;;;!!
404;;;!! (defun mouse-scroll-up (click)
405;;;!! (interactive "@e")
406;;;!! (scroll-up (1+ (cdr (mouse-coords click)))))
407;;;!!
408;;;!! (defun mouse-scroll-down-full ()
409;;;!! (interactive "@")
410;;;!! (scroll-down nil))
411;;;!!
412;;;!! (defun mouse-scroll-up-full ()
413;;;!! (interactive "@")
414;;;!! (scroll-up nil))
415;;;!!
416;;;!! (defun mouse-scroll-move-cursor (click)
417;;;!! (interactive "@e")
418;;;!! (move-to-window-line (1+ (cdr (mouse-coords click)))))
419;;;!!
420;;;!! (defun mouse-scroll-absolute (event)
421;;;!! (interactive "@e")
422;;;!! (let* ((pos (car event))
423;;;!! (position (car pos))
424;;;!! (length (car (cdr pos))))
425;;;!! (if (<= length 0) (setq length 1))
426;;;!! (let* ((scale-factor (max 1 (/ length (/ 8000000 (buffer-size)))))
427;;;!! (newpos (* (/ (* (/ (buffer-size) scale-factor)
428;;;!! position)
429;;;!! length)
430;;;!! scale-factor)))
431;;;!! (goto-char newpos)
432;;;!! (recenter '(4)))))
433;;;!!
434;;;!! (defun mouse-scroll-left (click)
435;;;!! (interactive "@e")
436;;;!! (scroll-left (1+ (car (mouse-coords click)))))
437;;;!!
438;;;!! (defun mouse-scroll-right (click)
439;;;!! (interactive "@e")
440;;;!! (scroll-right (1+ (car (mouse-coords click)))))
441;;;!!
442;;;!! (defun mouse-scroll-left-full ()
443;;;!! (interactive "@")
444;;;!! (scroll-left nil))
445;;;!!
446;;;!! (defun mouse-scroll-right-full ()
447;;;!! (interactive "@")
448;;;!! (scroll-right nil))
449;;;!!
450;;;!! (defun mouse-scroll-move-cursor-horizontally (click)
451;;;!! (interactive "@e")
452;;;!! (move-to-column (1+ (car (mouse-coords click)))))
453;;;!!
454;;;!! (defun mouse-scroll-absolute-horizontally (event)
455;;;!! (interactive "@e")
456;;;!! (let* ((pos (car event))
457;;;!! (position (car pos))
458;;;!! (length (car (cdr pos))))
459;;;!! (set-window-hscroll (selected-window) 33)))
460;;;!!
461;;;!! (global-set-key [scroll-bar mouse-1] 'mouse-scroll-up)
462;;;!! (global-set-key [scroll-bar mouse-2] 'mouse-scroll-absolute)
463;;;!! (global-set-key [scroll-bar mouse-3] 'mouse-scroll-down)
464;;;!!
465;;;!! (global-set-key [vertical-slider mouse-1] 'mouse-scroll-move-cursor)
466;;;!! (global-set-key [vertical-slider mouse-2] 'mouse-scroll-move-cursor)
467;;;!! (global-set-key [vertical-slider mouse-3] 'mouse-scroll-move-cursor)
468;;;!!
469;;;!! (global-set-key [thumbup mouse-1] 'mouse-scroll-up-full)
470;;;!! (global-set-key [thumbup mouse-2] 'mouse-scroll-up-full)
471;;;!! (global-set-key [thumbup mouse-3] 'mouse-scroll-up-full)
472;;;!!
473;;;!! (global-set-key [thumbdown mouse-1] 'mouse-scroll-down-full)
474;;;!! (global-set-key [thumbdown mouse-2] 'mouse-scroll-down-full)
475;;;!! (global-set-key [thumbdown mouse-3] 'mouse-scroll-down-full)
476;;;!!
477;;;!! (global-set-key [horizontal-scroll-bar mouse-1] 'mouse-scroll-left)
478;;;!! (global-set-key [horizontal-scroll-bar mouse-2]
479;;;!! 'mouse-scroll-absolute-horizontally)
480;;;!! (global-set-key [horizontal-scroll-bar mouse-3] 'mouse-scroll-right)
481;;;!!
482;;;!! (global-set-key [horizontal-slider mouse-1]
483;;;!! 'mouse-scroll-move-cursor-horizontally)
484;;;!! (global-set-key [horizontal-slider mouse-2]
485;;;!! 'mouse-scroll-move-cursor-horizontally)
486;;;!! (global-set-key [horizontal-slider mouse-3]
487;;;!! 'mouse-scroll-move-cursor-horizontally)
488;;;!!
489;;;!! (global-set-key [thumbleft mouse-1] 'mouse-scroll-left-full)
490;;;!! (global-set-key [thumbleft mouse-2] 'mouse-scroll-left-full)
491;;;!! (global-set-key [thumbleft mouse-3] 'mouse-scroll-left-full)
492;;;!!
493;;;!! (global-set-key [thumbright mouse-1] 'mouse-scroll-right-full)
494;;;!! (global-set-key [thumbright mouse-2] 'mouse-scroll-right-full)
495;;;!! (global-set-key [thumbright mouse-3] 'mouse-scroll-right-full)
496;;;!!
497;;;!! (global-set-key [horizontal-scroll-bar S-mouse-2]
498;;;!! 'mouse-split-window-horizontally)
499;;;!! (global-set-key [mode-line S-mouse-2]
500;;;!! 'mouse-split-window-horizontally)
501;;;!! (global-set-key [vertical-scroll-bar S-mouse-2]
502;;;!! 'mouse-split-window)
503\f
504;;;!! ;;;;
505;;;!! ;;;; Here are experimental things being tested. Mouse events
506;;;!! ;;;; are of the form:
507;;;!! ;;;; ((x y) window screen-part key-sequence timestamp)
508;;;!! ;;
509;;;!! ;;;;
510;;;!! ;;;; Dynamically track mouse coordinates
511;;;!! ;;;;
512;;;!! ;;
513;;;!! ;;(defun track-mouse (event)
514;;;!! ;; "Track the coordinates, absolute and relative, of the mouse."
515;;;!! ;; (interactive "@e")
516;;;!! ;; (while mouse-grabbed
517;;;!! ;; (let* ((pos (read-mouse-position (selected-screen)))
518;;;!! ;; (abs-x (car pos))
519;;;!! ;; (abs-y (cdr pos))
520;;;!! ;; (relative-coordinate (coordinates-in-window-p
521;;;!! ;; (list (car pos) (cdr pos))
522;;;!! ;; (selected-window))))
523;;;!! ;; (if (consp relative-coordinate)
524;;;!! ;; (message "mouse: [%d %d], (%d %d)" abs-x abs-y
525;;;!! ;; (car relative-coordinate)
526;;;!! ;; (car (cdr relative-coordinate)))
527;;;!! ;; (message "mouse: [%d %d]" abs-x abs-y)))))
528;;;!!
529;;;!! ;;
530;;;!! ;; Dynamically put a box around the line indicated by point
531;;;!! ;;
532;;;!! ;;
533;;;!! ;;(require 'backquote)
534;;;!! ;;
535;;;!! ;;(defun mouse-select-buffer-line (event)
536;;;!! ;; (interactive "@e")
537;;;!! ;; (let ((relative-coordinate
538;;;!! ;; (coordinates-in-window-p (car event) (selected-window)))
539;;;!! ;; (abs-y (car (cdr (car event)))))
540;;;!! ;; (if (consp relative-coordinate)
541;;;!! ;; (progn
542;;;!! ;; (save-excursion
543;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
544;;;!! ;; (x-draw-rectangle
545;;;!! ;; (selected-screen)
546;;;!! ;; abs-y 0
547;;;!! ;; (save-excursion
548;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
549;;;!! ;; (end-of-line)
550;;;!! ;; (push-mark nil t)
551;;;!! ;; (beginning-of-line)
552;;;!! ;; (- (region-end) (region-beginning))) 1))
553;;;!! ;; (sit-for 1)
554;;;!! ;; (x-erase-rectangle (selected-screen))))))
555;;;!! ;;
556;;;!! ;;(defvar last-line-drawn nil)
557;;;!! ;;(defvar begin-delim "[^ \t]")
558;;;!! ;;(defvar end-delim "[^ \t]")
559;;;!! ;;
560;;;!! ;;(defun mouse-boxing (event)
561;;;!! ;; (interactive "@e")
562;;;!! ;; (save-excursion
563;;;!! ;; (let ((screen (selected-screen)))
564;;;!! ;; (while (= (x-mouse-events) 0)
565;;;!! ;; (let* ((pos (read-mouse-position screen))
566;;;!! ;; (abs-x (car pos))
567;;;!! ;; (abs-y (cdr pos))
568;;;!! ;; (relative-coordinate
569;;;!! ;; (coordinates-in-window-p (` ((, abs-x) (, abs-y)))
570;;;!! ;; (selected-window)))
571;;;!! ;; (begin-reg nil)
572;;;!! ;; (end-reg nil)
573;;;!! ;; (end-column nil)
574;;;!! ;; (begin-column nil))
575;;;!! ;; (if (and (consp relative-coordinate)
576;;;!! ;; (or (not last-line-drawn)
577;;;!! ;; (not (= last-line-drawn abs-y))))
578;;;!! ;; (progn
579;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
580;;;!! ;; (if (= (following-char) 10)
581;;;!! ;; ()
582;;;!! ;; (progn
583;;;!! ;; (setq begin-reg (1- (re-search-forward end-delim)))
584;;;!! ;; (setq begin-column (1- (current-column)))
585;;;!! ;; (end-of-line)
586;;;!! ;; (setq end-reg (1+ (re-search-backward begin-delim)))
587;;;!! ;; (setq end-column (1+ (current-column)))
588;;;!! ;; (message "%s" (buffer-substring begin-reg end-reg))
589;;;!! ;; (x-draw-rectangle screen
590;;;!! ;; (setq last-line-drawn abs-y)
591;;;!! ;; begin-column
592;;;!! ;; (- end-column begin-column) 1))))))))))
593;;;!! ;;
594;;;!! ;;(defun mouse-erase-box ()
595;;;!! ;; (interactive)
596;;;!! ;; (if last-line-drawn
597;;;!! ;; (progn
598;;;!! ;; (x-erase-rectangle (selected-screen))
599;;;!! ;; (setq last-line-drawn nil))))
600;;;!!
601;;;!! ;;; (defun test-x-rectangle ()
602;;;!! ;;; (use-local-mouse-map (setq rectangle-test-map (make-sparse-keymap)))
603;;;!! ;;; (define-key rectangle-test-map mouse-motion-button-left 'mouse-boxing)
604;;;!! ;;; (define-key rectangle-test-map mouse-button-left-up 'mouse-erase-box))
605;;;!!
606;;;!! ;;
607;;;!! ;; Here is how to do double clicking in lisp. About to change.
608;;;!! ;;
609;;;!!
610;;;!! (defvar double-start nil)
611;;;!! (defconst double-click-interval 300
612;;;!! "Max ticks between clicks")
613;;;!!
614;;;!! (defun double-down (event)
615;;;!! (interactive "@e")
616;;;!! (if double-start
617;;;!! (let ((interval (- (nth 4 event) double-start)))
618;;;!! (if (< interval double-click-interval)
619;;;!! (progn
620;;;!! (backward-up-list 1)
621;;;!! ;; (message "Interval %d" interval)
622;;;!! (sleep-for 1)))
623;;;!! (setq double-start nil))
624;;;!! (setq double-start (nth 4 event))))
625;;;!!
626;;;!! (defun double-up (event)
627;;;!! (interactive "@e")
628;;;!! (and double-start
629;;;!! (> (- (nth 4 event ) double-start) double-click-interval)
630;;;!! (setq double-start nil)))
631;;;!!
632;;;!! ;;; (defun x-test-doubleclick ()
633;;;!! ;;; (use-local-mouse-map (setq doubleclick-test-map (make-sparse-keymap)))
634;;;!! ;;; (define-key doubleclick-test-map mouse-button-left 'double-down)
635;;;!! ;;; (define-key doubleclick-test-map mouse-button-left-up 'double-up))
636;;;!!
637;;;!! ;;
638;;;!! ;; This scrolls while button is depressed. Use preferable in scroll bar.
639;;;!! ;;
640;;;!!
641;;;!! (defvar scrolled-lines 0)
642;;;!! (defconst scroll-speed 1)
643;;;!!
644;;;!! (defun incr-scroll-down (event)
645;;;!! (interactive "@e")
646;;;!! (setq scrolled-lines 0)
647;;;!! (incremental-scroll scroll-speed))
648;;;!!
649;;;!! (defun incr-scroll-up (event)
650;;;!! (interactive "@e")
651;;;!! (setq scrolled-lines 0)
652;;;!! (incremental-scroll (- scroll-speed)))
653;;;!!
654;;;!! (defun incremental-scroll (n)
655;;;!! (while (= (x-mouse-events) 0)
656;;;!! (setq scrolled-lines (1+ (* scroll-speed scrolled-lines)))
657;;;!! (scroll-down n)
658;;;!! (sit-for 300 t)))
659;;;!!
660;;;!! (defun incr-scroll-stop (event)
661;;;!! (interactive "@e")
662;;;!! (message "Scrolled %d lines" scrolled-lines)
663;;;!! (setq scrolled-lines 0)
664;;;!! (sleep-for 1))
665;;;!!
666;;;!! ;;; (defun x-testing-scroll ()
667;;;!! ;;; (let ((scrolling-map (function mouse-vertical-scroll-bar-prefix)))
668;;;!! ;;; (define-key scrolling-map mouse-button-left 'incr-scroll-down)
669;;;!! ;;; (define-key scrolling-map mouse-button-right 'incr-scroll-up)
670;;;!! ;;; (define-key scrolling-map mouse-button-left-up 'incr-scroll-stop)
671;;;!! ;;; (define-key scrolling-map mouse-button-right-up 'incr-scroll-stop)))
672;;;!!
673;;;!! ;;
674;;;!! ;; Some playthings suitable for picture mode? They need work.
675;;;!! ;;
676;;;!!
677;;;!! (defun mouse-kill-rectangle (event)
678;;;!! "Kill the rectangle between point and the mouse cursor."
679;;;!! (interactive "@e")
680;;;!! (let ((point-save (point)))
681;;;!! (save-excursion
682;;;!! (mouse-set-point event)
683;;;!! (push-mark nil t)
684;;;!! (if (> point-save (point))
685;;;!! (kill-rectangle (point) point-save)
686;;;!! (kill-rectangle point-save (point))))))
687;;;!!
688;;;!! (defun mouse-open-rectangle (event)
689;;;!! "Kill the rectangle between point and the mouse cursor."
690;;;!! (interactive "@e")
691;;;!! (let ((point-save (point)))
692;;;!! (save-excursion
693;;;!! (mouse-set-point event)
694;;;!! (push-mark nil t)
695;;;!! (if (> point-save (point))
696;;;!! (open-rectangle (point) point-save)
697;;;!! (open-rectangle point-save (point))))))
698;;;!!
699;;;!! ;; Must be a better way to do this.
700;;;!!
701;;;!! (defun mouse-multiple-insert (n char)
702;;;!! (while (> n 0)
703;;;!! (insert char)
704;;;!! (setq n (1- n))))
705;;;!!
706;;;!! ;; What this could do is not finalize until button was released.
707;;;!!
708;;;!! (defun mouse-move-text (event)
709;;;!! "Move text from point to cursor position, inserting spaces."
710;;;!! (interactive "@e")
711;;;!! (let* ((relative-coordinate
712;;;!! (coordinates-in-window-p (car event) (selected-window))))
713;;;!! (if (consp relative-coordinate)
714;;;!! (cond ((> (current-column) (car relative-coordinate))
715;;;!! (delete-char
716;;;!! (- (car relative-coordinate) (current-column))))
717;;;!! ((< (current-column) (car relative-coordinate))
718;;;!! (mouse-multiple-insert
719;;;!! (- (car relative-coordinate) (current-column)) " "))
720;;;!! ((= (current-column) (car relative-coordinate)) (ding))))))
721\f
722;; Font selection.
723
724(defvar x-fixed-font-alist
725 '("Font menu"
726 ("Misc"
727 ("fixed" "fixed")
728 ("6x10" "6x10")
729 ("6x12" "6x12")
730 ("6x13" "6x13")
731 ("7x13" "7x13")
732 ("7x14" "7x14")
733 ("8x13" "8x13")
734 ("8x13 bold" "8x13bold")
735 ("8x16" "8x16")
736 ("9x15" "9x15")
737 ("9x15 bold" "9x15bold")
738 ("10x20" "10x20")
739 ("11x18" "11x18")
740 ("12x24" "12x24"))
741;;; We don't seem to have these; who knows what they are.
742;;; ("fg-18" "fg-18")
743;;; ("fg-25" "fg-25")
744;;; ("lucidasanstypewriter-12" "lucidasanstypewriter-12")
745;;; ("lucidasanstypewriter-bold-14" "lucidasanstypewriter-bold-14")
746;;; ("lucidasanstypewriter-bold-24" "lucidasanstypewriter-bold-24")
747;;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
748;;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
749 ("Courier"
750 ("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1")
751 ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1")
752 ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1")
753 ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1")
754 ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1")
755 ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1")
756 ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1")
757 ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1")
758 ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1")
759 ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1")
760 ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1")
761 ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1")
762 ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1")
763 ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1")
764 ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1")
765 ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1")
766 ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1")
767 ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1")
768 ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1")
769 ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1")
770 ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1")
771 ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1")
772 ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1")
773 ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1"))
774 )
775 "X fonts suitable for use in Emacs.")
776
777(defun mouse-set-font (&optional font)
778 "Select an emacs font from a list of known good fonts"
779 (interactive
780 (x-popup-menu last-nonmenu-event x-fixed-font-alist))
781 (if font
782 (modify-frame-parameters (selected-frame)
783 (list (cons 'font font)))))
784\f
785;;; Bindings for mouse commands.
786
787(define-key global-map [down-mouse-1] 'mouse-drag-region)
788(global-set-key [mouse-1] 'mouse-set-point)
789(global-set-key [drag-mouse-1] 'mouse-set-region)
790
791(global-set-key [mouse-2] 'mouse-yank-at-click)
792(global-set-key [mouse-3] 'mouse-save-then-kill)
793
794;; By binding these to down-going events, we let the user use the up-going
795;; event to make the selection, saving a click.
796(global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
797(global-set-key [C-down-mouse-3] 'mouse-set-font)
798
799;; Replaced with dragging mouse-1
800;; (global-set-key [S-mouse-1] 'mouse-set-mark)
801
802(global-set-key [mode-line mouse-1] 'mouse-delete-other-windows)
803(global-set-key [mode-line mouse-3] 'mouse-delete-window)
804(global-set-key [mode-line S-mouse-2] 'mouse-split-window-horizontally)
805\f
806;; Define the mouse help menu tree.
807
808(defvar help-menu-map '(keymap "Help"))
809(global-set-key [C-down-mouse-2] help-menu-map)
810
811(defvar help-apropos-map (make-sparse-keymap "Is there a command that..."))
812(defvar help-keys-map (make-sparse-keymap "Key Commands <==> Functions"))
813(defvar help-manual-map (make-sparse-keymap "Manual and tutorial"))
814(defvar help-misc-map (make-sparse-keymap "Odds and ends"))
815(defvar help-modes-map (make-sparse-keymap "Modes"))
816(defvar help-admin-map (make-sparse-keymap "Administrivia"))
817
818(define-key help-menu-map [apropos]
819 (cons "@Is there a command that..." help-apropos-map))
820(define-key help-menu-map [keys]
821 (cons "@Key Commands <==> Functions" help-keys-map))
822(define-key help-menu-map [manuals]
823 (cons "@Manual and tutorial" help-manual-map))
824(define-key help-menu-map [misc]
825 (cons "@Odds and ends" help-misc-map))
826(define-key help-menu-map [modes]
827 (cons "@Modes" help-modes-map))
828(define-key help-menu-map [admin]
829 (cons "@Administrivia" help-admin-map))
830
831(define-key help-apropos-map "c" '("Command Apropos" . command-apropos))
832(define-key help-apropos-map "a" '("Apropos" . apropos))
833
834(define-key help-keys-map "b"
835 '("List all keystroke commands" . describe-bindings))
836(define-key help-keys-map "c"
837 '("Describe key briefly" . describe-key-briefly))
838(define-key help-keys-map "k"
839 '("Describe key verbose" . describe-key))
840(define-key help-keys-map "f"
841 '("Describe Lisp function" . describe-function))
842(define-key help-keys-map "w"
843 '("Where is this command" . where-is))
844
845(define-key help-manual-map "i" '("Info system" . info))
846(define-key help-manual-map "t"
847 '("Invoke Emacs tutorial" . help-with-tutorial))
848
849(define-key help-misc-map "l" '("Last 100 Keystrokes" . view-lossage))
850(define-key help-misc-map "s" '("Describe syntax table" . describe-syntax))
851
852(define-key help-modes-map "m"
853 '("Describe current major mode" . describe-mode))
854(define-key help-modes-map "b"
855 '("List all keystroke commands" . describe-bindings))
856
857(define-key help-admin-map "n"
858 '("view Emacs news" . view-emacs-news))
859(define-key help-admin-map "l"
860 '("View the GNU Emacs license" . describe-copying))
861(define-key help-admin-map "d"
862 '("Describe distribution" . describe-distribution))
863(define-key help-admin-map "w"
864 '("Describe (non)warranty" . describe-no-warranty))
865
866(provide 'mouse)
867
868;;; mouse.el ends here