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