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