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