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