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)) | |
3f26b32a RS |
68 | (let ((new-height (if (eq (posn-point start) 'vertical-scroll-bar) |
69 | (scroll-bar-scale (posn-col-row start) | |
70 | (1- (window-height))) | |
71 | (1+ (cdr (posn-col-row (event-end click)))))) | |
5ba2dc3f JB |
72 | (first-line window-min-height) |
73 | (last-line (- (window-height) window-min-height))) | |
74 | (if (< last-line first-line) | |
75 | (error "window too short to split") | |
76 | (split-window-vertically | |
77 | (min (max new-height first-line) last-line)))))) | |
cc0a8174 | 78 | |
947da0c4 RS |
79 | (defun mouse-split-window-horizontally (click) |
80 | "Select Emacs window mouse is on, then split it horizontally in half. | |
81 | The window is split at the column clicked on. | |
82 | This command must be bound to a mouse click." | |
83 | (interactive "@e") | |
5ba2dc3f JB |
84 | (let ((start (event-start click))) |
85 | (select-window (posn-window start)) | |
86 | (let ((new-width (1+ (car (posn-col-row (event-end click))))) | |
87 | (first-col window-min-width) | |
88 | (last-col (- (window-width) window-min-width))) | |
89 | (if (< last-col first-col) | |
90 | (error "window too narrow to split") | |
91 | (split-window-horizontally | |
92 | (min (max new-width first-col) last-col)))))) | |
947da0c4 | 93 | |
2a5fa27b | 94 | (defun mouse-set-point (event) |
cc0a8174 | 95 | "Move point to the position clicked on with the mouse. |
2a5fa27b | 96 | This should be bound to a mouse click event type." |
ec558adc | 97 | (interactive "e") |
2a5fa27b RS |
98 | ;; Use event-end in case called from mouse-drag-region. |
99 | ;; If EVENT is a click, event-end and event-start give same value. | |
100 | (let ((posn (event-end event))) | |
b80f1928 RS |
101 | (and (window-minibuffer-p (posn-window posn)) |
102 | (not (minibuffer-window-active-p (posn-window posn))) | |
103 | (error "Minibuffer window is not active")) | |
b5370f03 JB |
104 | (select-window (posn-window posn)) |
105 | (if (numberp (posn-point posn)) | |
106 | (goto-char (posn-point posn))))) | |
cc0a8174 | 107 | |
652ccd35 RS |
108 | (defun mouse-set-region (click) |
109 | "Set the region to the text that the mouse is dragged over. | |
2a5fa27b | 110 | This should be bound to a mouse drag event." |
652ccd35 RS |
111 | (interactive "e") |
112 | (let ((posn (event-start click)) | |
113 | (end (event-end click))) | |
114 | (select-window (posn-window posn)) | |
115 | (if (numberp (posn-point posn)) | |
116 | (goto-char (posn-point posn))) | |
fcfc3c63 RS |
117 | ;; If mark is highlighted, no need to bounce the cursor. |
118 | (or (and transient-mark-mode | |
119 | (eq (framep (selected-frame)) 'x)) | |
120 | (sit-for 1)) | |
652ccd35 | 121 | (push-mark) |
1cc8a3f4 | 122 | (set-mark (point)) |
652ccd35 RS |
123 | (if (numberp (posn-point end)) |
124 | (goto-char (posn-point end))))) | |
125 | ||
600c6e3a JB |
126 | (defvar mouse-scroll-delay 0.25 |
127 | "*The pause between scroll steps caused by mouse drags, in seconds. | |
128 | If you drag the mouse beyond the edge of a window, Emacs scrolls the | |
129 | window to bring the text beyond that edge into view, with a delay of | |
130 | this many seconds between scroll steps. Scrolling stops when you move | |
131 | the mouse back into the window, or release the button. | |
132 | This variable's value may be non-integral. | |
133 | Setting this to zero causes Emacs to scroll as fast as it can.") | |
134 | ||
135 | (defun mouse-scroll-subr (jump &optional overlay start) | |
136 | "Scroll the selected window JUMP lines at a time, until new input arrives. | |
137 | If OVERLAY is an overlay, let it stretch from START to the far edge of | |
138 | the newly visible text. | |
139 | Upon exit, point is at the far edge of the newly visible text." | |
140 | (while (progn | |
141 | (goto-char (window-start)) | |
142 | (if (not (zerop (vertical-motion jump))) | |
143 | (progn | |
144 | (set-window-start (selected-window) (point)) | |
145 | (if (natnump jump) | |
146 | (progn | |
147 | (goto-char (window-end (selected-window))) | |
148 | ;; window-end doesn't reflect the window's new | |
149 | ;; start position until the next redisplay. Hurrah. | |
150 | (vertical-motion (1- jump))) | |
151 | (goto-char (window-start (selected-window)))) | |
152 | (if overlay | |
153 | (move-overlay overlay start (point))) | |
154 | (if (not (eobp)) | |
155 | (sit-for mouse-scroll-delay)))))) | |
156 | (point)) | |
fcfc3c63 | 157 | |
600c6e3a JB |
158 | (defvar mouse-drag-overlay (make-overlay 1 1)) |
159 | (overlay-put mouse-drag-overlay 'face 'region) | |
160 | ||
161 | (defun mouse-drag-region (start-event) | |
bcd5aef1 | 162 | "Set the region to the text that the mouse is dragged over. |
78210c95 RS |
163 | Highlight the drag area as you move the mouse. |
164 | This must be bound to a button-down mouse event. | |
165 | In Transient Mark mode, the highlighting remains once you | |
166 | release the mouse button. Otherwise, it does not." | |
bcd5aef1 | 167 | (interactive "e") |
600c6e3a JB |
168 | (let* ((start-posn (event-start start-event)) |
169 | (start-point (posn-point start-posn)) | |
170 | (start-window (posn-window start-posn)) | |
b846d039 | 171 | (start-frame (window-frame start-window)) |
600c6e3a JB |
172 | (bounds (window-edges start-window)) |
173 | (top (nth 1 bounds)) | |
174 | (bottom (if (window-minibuffer-p start-window) | |
175 | (nth 3 bounds) | |
176 | ;; Don't count the mode line. | |
177 | (1- (nth 3 bounds))))) | |
b80f1928 | 178 | (mouse-set-point start-event) |
600c6e3a JB |
179 | (move-overlay mouse-drag-overlay |
180 | start-point start-point | |
181 | (window-buffer start-window)) | |
f767385c | 182 | (deactivate-mark) |
600c6e3a | 183 | (let (event end end-point) |
bcd5aef1 | 184 | (track-mouse |
600c6e3a | 185 | (while (progn |
b846d039 JB |
186 | (setq event (read-event)) |
187 | (or (mouse-movement-p event) | |
188 | (eq (car-safe event) 'switch-frame))) | |
189 | ||
190 | (if (eq (car-safe event) 'switch-frame) | |
191 | nil | |
192 | (setq end (event-end event) | |
193 | end-point (posn-point end)) | |
194 | ||
195 | (cond | |
196 | ||
197 | ;; Ignore switch-frame events. | |
198 | ((eq (car-safe event) 'switch-frame)) | |
199 | ||
200 | ;; Are we moving within the original window? | |
201 | ((and (eq (posn-window end) start-window) | |
202 | (integer-or-marker-p end-point)) | |
203 | (goto-char end-point) | |
204 | (move-overlay mouse-drag-overlay | |
205 | start-point (point))) | |
206 | ||
207 | ;; Are we moving on a different window on the same frame? | |
208 | ((and (windowp (posn-window end)) | |
209 | (eq (window-frame (posn-window end)) start-frame)) | |
210 | (let ((mouse-row | |
211 | (+ (nth 1 (window-edges (posn-window end))) | |
212 | (cdr (posn-col-row end))))) | |
213 | (cond | |
214 | ((< mouse-row top) | |
215 | (mouse-scroll-subr | |
216 | (- mouse-row top) mouse-drag-overlay start-point)) | |
217 | ((and (not (eobp)) | |
218 | (>= mouse-row bottom)) | |
219 | (mouse-scroll-subr (1+ (- mouse-row bottom)) | |
220 | mouse-drag-overlay start-point))))) | |
221 | ||
1e49aa29 RS |
222 | (t |
223 | (let ((mouse-y (cdr (cdr (mouse-position)))) | |
224 | (menu-bar-lines (or (cdr (assq 'menu-bar-lines | |
225 | (frame-parameters))) | |
226 | 0))) | |
227 | ||
228 | ;; Are we on the menu bar? | |
229 | (and (integerp mouse-y) (< mouse-y menu-bar-lines) | |
230 | (mouse-scroll-subr (- mouse-y menu-bar-lines) | |
231 | mouse-drag-overlay start-point)))))))) | |
b846d039 | 232 | |
600c6e3a JB |
233 | (if (and (eq (get (event-basic-type event) 'event-kind) 'mouse-click) |
234 | (eq (posn-window (event-end event)) start-window) | |
235 | (numberp (posn-point (event-end event)))) | |
b80f1928 RS |
236 | (progn |
237 | (mouse-set-point event) | |
238 | (if (= (point) start-point) | |
239 | (deactivate-mark) | |
240 | (set-mark start-point)))) | |
600c6e3a JB |
241 | (delete-overlay mouse-drag-overlay)))) |
242 | ||
243 | ;;;! (defun mouse-drag-region (click) | |
244 | ;;;! "Set the region to the text that the mouse is dragged over. | |
245 | ;;;! This must be bound to a button-down mouse event." | |
246 | ;;;! (interactive "e") | |
247 | ;;;! (let ((posn (event-start click)) | |
248 | ;;;! done event (mark-active nil)) | |
249 | ;;;! (select-window (posn-window posn)) | |
250 | ;;;! ;; Set point temporarily, so user sees where it is. | |
251 | ;;;! (if (numberp (posn-point posn)) | |
252 | ;;;! (goto-char (posn-point posn))) | |
253 | ;;;! ;; Turn off the old mark when we set up an empty region. | |
254 | ;;;! (setq deactivate-mark t))) | |
255 | ;;;! | |
256 | ;;;! ;;;Nice hack, but too slow, so not normally in use. | |
257 | ;;;! (defun mouse-drag-region-1 (click) | |
258 | ;;;! "Set the region to the text that the mouse is dragged over. | |
259 | ;;;! This must be bound to a button-down mouse event." | |
260 | ;;;! (interactive "e") | |
261 | ;;;! (let (newmark) | |
262 | ;;;! (let ((posn (event-start click)) | |
263 | ;;;! done event omark (mark-active t)) | |
264 | ;;;! (select-window (posn-window posn)) | |
265 | ;;;! (setq omark (and mark-active (mark))) | |
266 | ;;;! (if (numberp (posn-point posn)) | |
267 | ;;;! (goto-char (posn-point posn))) | |
268 | ;;;! ;; Set mark temporarily, so highlighting does what we want. | |
269 | ;;;! (set-marker (mark-marker) (point)) | |
270 | ;;;! (track-mouse | |
271 | ;;;! (while (not done) | |
272 | ;;;! (setq event (read-event)) | |
273 | ;;;! (if (eq (car-safe event) 'mouse-movement) | |
274 | ;;;! (goto-char (posn-point (event-start event))) | |
275 | ;;;! ;; Exit when we get the drag event; ignore that event. | |
276 | ;;;! (setq done t)))) | |
277 | ;;;! (if (/= (mark) (point)) | |
278 | ;;;! (setq newmark (mark))) | |
279 | ;;;! ;; Restore previous mark status. | |
280 | ;;;! (if omark (set-marker (mark-marker) omark))) | |
281 | ;;;! ;; Now, if we dragged, set the mark at the proper place. | |
282 | ;;;! (if newmark | |
283 | ;;;! (push-mark newmark t t) | |
284 | ;;;! ;; Turn off the old mark when we set up an empty region. | |
285 | ;;;! (setq deactivate-mark t)))) | |
e66feb07 | 286 | \f |
3f26b32a RS |
287 | ;; Subroutine: set the mark where CLICK happened, |
288 | ;; but don't do anything else. | |
289 | (defun mouse-set-mark-fast (click) | |
290 | (let ((posn (event-start click))) | |
291 | (select-window (posn-window posn)) | |
292 | (if (numberp (posn-point posn)) | |
293 | (push-mark (posn-point posn) t t)))) | |
294 | ||
295 | ;; Momentarily show where the mark is, if highlighting doesn't show it. | |
296 | (defun mouse-show-mark () | |
297 | (or transient-mark-mode | |
298 | (save-excursion | |
299 | (goto-char (mark t)) | |
300 | (sit-for 1)))) | |
301 | ||
cc0a8174 JB |
302 | (defun mouse-set-mark (click) |
303 | "Set mark at the position clicked on with the mouse. | |
304 | Display cursor at that position for a second. | |
305 | This must be bound to a mouse click." | |
ec558adc | 306 | (interactive "e") |
72ea54a4 RS |
307 | (let ((point-save (point))) |
308 | (unwind-protect | |
cc0a8174 | 309 | (progn (mouse-set-point click) |
897897e3 RS |
310 | (push-mark nil t t) |
311 | (or transient-mark-mode | |
312 | (sit-for 1))) | |
72ea54a4 RS |
313 | (goto-char point-save)))) |
314 | ||
cc0a8174 JB |
315 | (defun mouse-kill (click) |
316 | "Kill the region between point and the mouse click. | |
317 | The text is saved in the kill ring, as with \\[kill-region]." | |
ec558adc | 318 | (interactive "e") |
40a45a9f | 319 | (let ((click-posn (posn-point (event-start click)))) |
bd307392 JB |
320 | (if (numberp click-posn) |
321 | (kill-region (min (point) click-posn) | |
322 | (max (point) click-posn))))) | |
72ea54a4 | 323 | |
87ef29fd JB |
324 | (defun mouse-yank-at-click (click arg) |
325 | "Insert the last stretch of killed text at the position clicked on. | |
326 | Prefix arguments are interpreted as with \\[yank]." | |
ec558adc | 327 | (interactive "e\nP") |
87ef29fd JB |
328 | (mouse-set-point click) |
329 | (yank arg)) | |
330 | ||
331 | (defun mouse-kill-ring-save (click) | |
cc0a8174 JB |
332 | "Copy the region between point and the mouse click in the kill ring. |
333 | This does not delete the region; it acts like \\[kill-ring-save]." | |
ec558adc | 334 | (interactive "e") |
3f26b32a RS |
335 | (mouse-set-mark-fast click) |
336 | (kill-ring-save (point) (mark t)) | |
337 | (mouse-show-mark)) | |
72ea54a4 | 338 | |
dbc4e1c1 JB |
339 | ;;; This function used to delete the text between point and the mouse |
340 | ;;; whenever it was equal to the front of the kill ring, but some | |
341 | ;;; people found that confusing. | |
342 | ||
343 | ;;; A list (TEXT START END), describing the text and position of the last | |
344 | ;;; invocation of mouse-save-then-kill. | |
345 | (defvar mouse-save-then-kill-posn nil) | |
346 | ||
947da0c4 | 347 | (defun mouse-save-then-kill (click) |
40a45a9f RS |
348 | "Save text to point in kill ring; the second time, kill the text. |
349 | If the text between point and the mouse is the same as what's | |
350 | at the front of the kill ring, this deletes the text. | |
351 | Otherwise, it adds the text to the kill ring, like \\[kill-ring-save], | |
352 | which prepares for a second click to delete the text." | |
947da0c4 | 353 | (interactive "e") |
3f26b32a RS |
354 | (let ((click-posn (posn-point (event-start click))) |
355 | ;; Don't let a subsequent kill command append to this one: | |
356 | ;; prevent setting this-command to kill-region. | |
357 | (this-command this-command)) | |
358 | (if (and (eq last-command 'mouse-save-then-kill) | |
dbc4e1c1 JB |
359 | mouse-save-then-kill-posn |
360 | (eq (car mouse-save-then-kill-posn) (car kill-ring)) | |
361 | (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn))) | |
362 | ;; If this is the second time we've called | |
363 | ;; mouse-save-then-kill, delete the text from the buffer. | |
40a45a9f | 364 | (progn |
a2d24e95 RS |
365 | ;; Delete just one char, so in case buffer is being modified |
366 | ;; for the first time, the undo list records that fact. | |
367 | (delete-region (point) | |
368 | (+ (point) (if (> (mark) (point)) 1 -1))) | |
369 | ;; Now delete the rest of the specified region, | |
370 | ;; but don't record it. | |
40a45a9f RS |
371 | (let ((buffer-undo-list t)) |
372 | (delete-region (point) (mark))) | |
dbc4e1c1 | 373 | (if (not (eq buffer-undo-list t)) |
a2d24e95 RS |
374 | (let ((tail buffer-undo-list)) |
375 | ;; Search back in buffer-undo-list for the string | |
376 | ;; that came from the first delete-region. | |
377 | (while (and tail (not (stringp (car (car tail))))) | |
378 | (setq tail (cdr tail))) | |
379 | ;; Replace it with an entry for the entire deleted text. | |
380 | (and tail | |
c4fc9e31 | 381 | (setcar tail (cons (car kill-ring) (point))))))) |
40a45a9f | 382 | ;; Otherwise, save this region. |
3f26b32a | 383 | (mouse-set-mark-fast click) |
897897e3 | 384 | (kill-ring-save (point) (mark t)) |
3f26b32a | 385 | (mouse-show-mark) |
dbc4e1c1 JB |
386 | (setq mouse-save-then-kill-posn |
387 | (list (car kill-ring) (point) click-posn))))) | |
e66feb07 RS |
388 | \f |
389 | (global-set-key [M-mouse-1] 'mouse-start-secondary) | |
390 | (global-set-key [M-drag-mouse-1] 'mouse-set-secondary) | |
391 | (global-set-key [M-down-mouse-1] 'mouse-drag-secondary) | |
392 | (global-set-key [M-mouse-3] 'mouse-secondary-save-then-kill) | |
393 | (global-set-key [M-mouse-2] 'mouse-kill-secondary) | |
394 | ||
395 | ;; An overlay which records the current secondary selection | |
396 | ;; or else is deleted when there is no secondary selection. | |
397 | ;; May be nil. | |
398 | (defvar mouse-secondary-overlay nil) | |
399 | ||
400 | ;; A marker which records the specified first end for a secondary selection. | |
401 | ;; May be nil. | |
402 | (defvar mouse-secondary-start nil) | |
403 | ||
404 | (defun mouse-start-secondary (click) | |
405 | "Set one end of the secondary selection to the position clicked on. | |
406 | Use \\[mouse-secondary-save-then-kill] to set the other end | |
407 | and complete the secondary selection." | |
408 | (interactive "e") | |
409 | (let ((posn (event-start click))) | |
230aaa73 RS |
410 | (save-excursion |
411 | (set-buffer (window-buffer (posn-window posn))) | |
412 | ;; Cancel any preexisting secondary selection. | |
413 | (if mouse-secondary-overlay | |
414 | (delete-overlay mouse-secondary-overlay)) | |
415 | (if (numberp (posn-point posn)) | |
416 | (progn | |
417 | (or mouse-secondary-start | |
418 | (setq mouse-secondary-start (make-marker))) | |
419 | (move-marker mouse-secondary-start (posn-point posn))))))) | |
e66feb07 RS |
420 | |
421 | (defun mouse-set-secondary (click) | |
422 | "Set the secondary selection to the text that the mouse is dragged over. | |
423 | This must be bound to a mouse drag event." | |
424 | (interactive "e") | |
425 | (let ((posn (event-start click)) | |
426 | beg | |
427 | (end (event-end click))) | |
230aaa73 RS |
428 | (save-excursion |
429 | (set-buffer (window-buffer (posn-window posn))) | |
430 | (if (numberp (posn-point posn)) | |
431 | (setq beg (posn-point posn))) | |
432 | (if mouse-secondary-overlay | |
433 | (move-overlay mouse-secondary-overlay beg (posn-point end)) | |
434 | (setq mouse-secondary-overlay (make-overlay beg (posn-point end)))) | |
435 | (overlay-put mouse-secondary-overlay 'face 'secondary-selection)))) | |
947da0c4 | 436 | |
e66feb07 RS |
437 | (defun mouse-drag-secondary (click) |
438 | "Set the secondary selection to the text that the mouse is dragged over. | |
439 | This must be bound to a button-down mouse event." | |
440 | (interactive "e") | |
441 | (let ((posn (event-start click))) | |
230aaa73 RS |
442 | (save-window-excursion |
443 | (select-window (posn-window posn)) | |
444 | ;; Set point temporarily, so user sees where it is. | |
445 | (save-excursion | |
446 | (if (numberp (posn-point posn)) | |
447 | (goto-char (posn-point posn))) | |
448 | (setq unread-command-events | |
449 | (cons (read-event) unread-command-events)))))) | |
e66feb07 RS |
450 | |
451 | (defun mouse-kill-secondary () | |
452 | "Kill the text in the secondary selection." | |
453 | (interactive "*") | |
454 | (kill-region (overlay-start mouse-secondary-overlay) | |
455 | (overlay-end mouse-secondary-overlay)) | |
456 | (delete-overlay mouse-secondary-overlay) | |
457 | (setq mouse-secondary-overlay nil)) | |
458 | ||
459 | (defun mouse-secondary-save-then-kill (click) | |
460 | "Save text to secondary start point in kill ring; if twice, kill it. | |
461 | If the text between secondary start point and the mouse is the same as what's | |
462 | at the front of the kill ring, this deletes the text. | |
463 | Otherwise, it adds the text to the kill ring, like \\[kill-ring-save], | |
464 | which prepares for a second click to delete the text." | |
465 | (interactive "e") | |
466 | (let ((click-posn (posn-point (event-start click))) | |
467 | (start (+ 0 mouse-secondary-start)) | |
468 | ;; Don't let a subsequent kill command append to this one: | |
469 | ;; prevent setting this-command to kill-region. | |
470 | (this-command this-command)) | |
471 | (if (and (eq last-command 'mouse-secondary-save-then-kill) | |
472 | mouse-save-then-kill-posn | |
473 | (eq (car mouse-save-then-kill-posn) (car kill-ring)) | |
474 | (equal (cdr mouse-save-then-kill-posn) | |
475 | (list start click-posn))) | |
476 | ;; If this is the second time we've called | |
477 | ;; mouse-save-then-kill, delete the text from the buffer. | |
478 | (progn | |
479 | (let ((buffer-undo-list t)) | |
480 | (delete-overlay mouse-secondary-overlay) | |
481 | (delete-region start click-posn)) | |
482 | ;; Make the undo list by hand so it is shared. | |
483 | (if (not (eq buffer-undo-list t)) | |
484 | (setq buffer-undo-list | |
367ee8f4 | 485 | (cons (cons (car kill-ring) (marker-position start)) |
e66feb07 RS |
486 | buffer-undo-list)))) |
487 | ;; Otherwise, save this region. | |
230aaa73 RS |
488 | (save-excursion |
489 | (set-buffer (window-buffer (posn-window (event-start click)))) | |
490 | (kill-ring-save start click-posn) | |
491 | (if mouse-secondary-overlay | |
492 | (move-overlay mouse-secondary-overlay start click-posn) | |
493 | (setq mouse-secondary-overlay (make-overlay start click-posn))) | |
494 | (overlay-put mouse-secondary-overlay 'face 'secondary-selection) | |
495 | (setq mouse-save-then-kill-posn | |
496 | (list (car kill-ring) start click-posn)))))) | |
e66feb07 | 497 | \f |
8b34e79d | 498 | (defun mouse-buffer-menu (event) |
2d82f7b9 RS |
499 | "Pop up a menu of buffers for selection with the mouse. |
500 | This switches buffers in the window that you clicked on, | |
501 | and selects that window." | |
ec558adc | 502 | (interactive "e") |
8b34e79d RS |
503 | (let ((menu |
504 | (list "Buffer Menu" | |
505 | (cons "Select Buffer" | |
506 | (let ((tail (buffer-list)) | |
af2a85fe | 507 | (maxbuf 0) |
8b34e79d | 508 | head) |
af2a85fe RS |
509 | (while tail |
510 | (or (eq ?\ (aref (buffer-name (car tail)) 0)) | |
511 | (setq maxbuf | |
512 | (max maxbuf | |
513 | (length (buffer-name (car tail)))))) | |
514 | (setq tail (cdr tail))) | |
515 | (setq tail (buffer-list)) | |
8b34e79d RS |
516 | (while tail |
517 | (let ((elt (car tail))) | |
518 | (if (not (string-match "^ " | |
519 | (buffer-name elt))) | |
520 | (setq head (cons | |
521 | (cons | |
522 | (format | |
af2a85fe RS |
523 | (format "%%%ds %%s%%s %%s" |
524 | maxbuf) | |
8b34e79d | 525 | (buffer-name elt) |
af2a85fe RS |
526 | (if (buffer-modified-p elt) |
527 | "*" " ") | |
528 | (save-excursion | |
529 | (set-buffer elt) | |
530 | (if buffer-read-only "%" " ")) | |
8b34e79d RS |
531 | (or (buffer-file-name elt) "")) |
532 | elt) | |
533 | head)))) | |
534 | (setq tail (cdr tail))) | |
535 | (reverse head)))))) | |
2d82f7b9 RS |
536 | (let ((buf (x-popup-menu event menu)) |
537 | (window (posn-window (event-start event)))) | |
538 | (if buf | |
539 | (progn | |
c0bb9f3b | 540 | (or (framep window) (select-window window)) |
2d82f7b9 | 541 | (switch-to-buffer buf)))))) |
72ea54a4 | 542 | \f |
5ba2dc3f | 543 | ;;; These need to be rewritten for the new scroll bar implementation. |
dbc4e1c1 JB |
544 | |
545 | ;;;!! ;; Commands for the scroll bar. | |
546 | ;;;!! | |
547 | ;;;!! (defun mouse-scroll-down (click) | |
548 | ;;;!! (interactive "@e") | |
549 | ;;;!! (scroll-down (1+ (cdr (mouse-coords click))))) | |
550 | ;;;!! | |
551 | ;;;!! (defun mouse-scroll-up (click) | |
552 | ;;;!! (interactive "@e") | |
553 | ;;;!! (scroll-up (1+ (cdr (mouse-coords click))))) | |
554 | ;;;!! | |
555 | ;;;!! (defun mouse-scroll-down-full () | |
556 | ;;;!! (interactive "@") | |
557 | ;;;!! (scroll-down nil)) | |
558 | ;;;!! | |
559 | ;;;!! (defun mouse-scroll-up-full () | |
560 | ;;;!! (interactive "@") | |
561 | ;;;!! (scroll-up nil)) | |
562 | ;;;!! | |
563 | ;;;!! (defun mouse-scroll-move-cursor (click) | |
564 | ;;;!! (interactive "@e") | |
565 | ;;;!! (move-to-window-line (1+ (cdr (mouse-coords click))))) | |
566 | ;;;!! | |
567 | ;;;!! (defun mouse-scroll-absolute (event) | |
568 | ;;;!! (interactive "@e") | |
569 | ;;;!! (let* ((pos (car event)) | |
570 | ;;;!! (position (car pos)) | |
571 | ;;;!! (length (car (cdr pos)))) | |
572 | ;;;!! (if (<= length 0) (setq length 1)) | |
573 | ;;;!! (let* ((scale-factor (max 1 (/ length (/ 8000000 (buffer-size))))) | |
574 | ;;;!! (newpos (* (/ (* (/ (buffer-size) scale-factor) | |
575 | ;;;!! position) | |
576 | ;;;!! length) | |
577 | ;;;!! scale-factor))) | |
578 | ;;;!! (goto-char newpos) | |
579 | ;;;!! (recenter '(4))))) | |
580 | ;;;!! | |
581 | ;;;!! (defun mouse-scroll-left (click) | |
582 | ;;;!! (interactive "@e") | |
583 | ;;;!! (scroll-left (1+ (car (mouse-coords click))))) | |
584 | ;;;!! | |
585 | ;;;!! (defun mouse-scroll-right (click) | |
586 | ;;;!! (interactive "@e") | |
587 | ;;;!! (scroll-right (1+ (car (mouse-coords click))))) | |
588 | ;;;!! | |
589 | ;;;!! (defun mouse-scroll-left-full () | |
590 | ;;;!! (interactive "@") | |
591 | ;;;!! (scroll-left nil)) | |
592 | ;;;!! | |
593 | ;;;!! (defun mouse-scroll-right-full () | |
594 | ;;;!! (interactive "@") | |
595 | ;;;!! (scroll-right nil)) | |
596 | ;;;!! | |
597 | ;;;!! (defun mouse-scroll-move-cursor-horizontally (click) | |
598 | ;;;!! (interactive "@e") | |
599 | ;;;!! (move-to-column (1+ (car (mouse-coords click))))) | |
600 | ;;;!! | |
601 | ;;;!! (defun mouse-scroll-absolute-horizontally (event) | |
602 | ;;;!! (interactive "@e") | |
603 | ;;;!! (let* ((pos (car event)) | |
604 | ;;;!! (position (car pos)) | |
605 | ;;;!! (length (car (cdr pos)))) | |
606 | ;;;!! (set-window-hscroll (selected-window) 33))) | |
607 | ;;;!! | |
608 | ;;;!! (global-set-key [scroll-bar mouse-1] 'mouse-scroll-up) | |
609 | ;;;!! (global-set-key [scroll-bar mouse-2] 'mouse-scroll-absolute) | |
610 | ;;;!! (global-set-key [scroll-bar mouse-3] 'mouse-scroll-down) | |
611 | ;;;!! | |
612 | ;;;!! (global-set-key [vertical-slider mouse-1] 'mouse-scroll-move-cursor) | |
613 | ;;;!! (global-set-key [vertical-slider mouse-2] 'mouse-scroll-move-cursor) | |
614 | ;;;!! (global-set-key [vertical-slider mouse-3] 'mouse-scroll-move-cursor) | |
615 | ;;;!! | |
616 | ;;;!! (global-set-key [thumbup mouse-1] 'mouse-scroll-up-full) | |
617 | ;;;!! (global-set-key [thumbup mouse-2] 'mouse-scroll-up-full) | |
618 | ;;;!! (global-set-key [thumbup mouse-3] 'mouse-scroll-up-full) | |
619 | ;;;!! | |
620 | ;;;!! (global-set-key [thumbdown mouse-1] 'mouse-scroll-down-full) | |
621 | ;;;!! (global-set-key [thumbdown mouse-2] 'mouse-scroll-down-full) | |
622 | ;;;!! (global-set-key [thumbdown mouse-3] 'mouse-scroll-down-full) | |
623 | ;;;!! | |
624 | ;;;!! (global-set-key [horizontal-scroll-bar mouse-1] 'mouse-scroll-left) | |
625 | ;;;!! (global-set-key [horizontal-scroll-bar mouse-2] | |
626 | ;;;!! 'mouse-scroll-absolute-horizontally) | |
627 | ;;;!! (global-set-key [horizontal-scroll-bar mouse-3] 'mouse-scroll-right) | |
628 | ;;;!! | |
629 | ;;;!! (global-set-key [horizontal-slider mouse-1] | |
630 | ;;;!! 'mouse-scroll-move-cursor-horizontally) | |
631 | ;;;!! (global-set-key [horizontal-slider mouse-2] | |
632 | ;;;!! 'mouse-scroll-move-cursor-horizontally) | |
633 | ;;;!! (global-set-key [horizontal-slider mouse-3] | |
634 | ;;;!! 'mouse-scroll-move-cursor-horizontally) | |
635 | ;;;!! | |
636 | ;;;!! (global-set-key [thumbleft mouse-1] 'mouse-scroll-left-full) | |
637 | ;;;!! (global-set-key [thumbleft mouse-2] 'mouse-scroll-left-full) | |
638 | ;;;!! (global-set-key [thumbleft mouse-3] 'mouse-scroll-left-full) | |
639 | ;;;!! | |
640 | ;;;!! (global-set-key [thumbright mouse-1] 'mouse-scroll-right-full) | |
641 | ;;;!! (global-set-key [thumbright mouse-2] 'mouse-scroll-right-full) | |
642 | ;;;!! (global-set-key [thumbright mouse-3] 'mouse-scroll-right-full) | |
643 | ;;;!! | |
644 | ;;;!! (global-set-key [horizontal-scroll-bar S-mouse-2] | |
645 | ;;;!! 'mouse-split-window-horizontally) | |
646 | ;;;!! (global-set-key [mode-line S-mouse-2] | |
647 | ;;;!! 'mouse-split-window-horizontally) | |
648 | ;;;!! (global-set-key [vertical-scroll-bar S-mouse-2] | |
649 | ;;;!! 'mouse-split-window) | |
6b2154de | 650 | \f |
dbc4e1c1 JB |
651 | ;;;!! ;;;; |
652 | ;;;!! ;;;; Here are experimental things being tested. Mouse events | |
653 | ;;;!! ;;;; are of the form: | |
654 | ;;;!! ;;;; ((x y) window screen-part key-sequence timestamp) | |
655 | ;;;!! ;; | |
656 | ;;;!! ;;;; | |
657 | ;;;!! ;;;; Dynamically track mouse coordinates | |
658 | ;;;!! ;;;; | |
659 | ;;;!! ;; | |
660 | ;;;!! ;;(defun track-mouse (event) | |
661 | ;;;!! ;; "Track the coordinates, absolute and relative, of the mouse." | |
662 | ;;;!! ;; (interactive "@e") | |
663 | ;;;!! ;; (while mouse-grabbed | |
664 | ;;;!! ;; (let* ((pos (read-mouse-position (selected-screen))) | |
665 | ;;;!! ;; (abs-x (car pos)) | |
666 | ;;;!! ;; (abs-y (cdr pos)) | |
667 | ;;;!! ;; (relative-coordinate (coordinates-in-window-p | |
668 | ;;;!! ;; (list (car pos) (cdr pos)) | |
669 | ;;;!! ;; (selected-window)))) | |
670 | ;;;!! ;; (if (consp relative-coordinate) | |
671 | ;;;!! ;; (message "mouse: [%d %d], (%d %d)" abs-x abs-y | |
672 | ;;;!! ;; (car relative-coordinate) | |
673 | ;;;!! ;; (car (cdr relative-coordinate))) | |
674 | ;;;!! ;; (message "mouse: [%d %d]" abs-x abs-y))))) | |
675 | ;;;!! | |
676 | ;;;!! ;; | |
677 | ;;;!! ;; Dynamically put a box around the line indicated by point | |
678 | ;;;!! ;; | |
679 | ;;;!! ;; | |
680 | ;;;!! ;;(require 'backquote) | |
681 | ;;;!! ;; | |
682 | ;;;!! ;;(defun mouse-select-buffer-line (event) | |
683 | ;;;!! ;; (interactive "@e") | |
684 | ;;;!! ;; (let ((relative-coordinate | |
685 | ;;;!! ;; (coordinates-in-window-p (car event) (selected-window))) | |
686 | ;;;!! ;; (abs-y (car (cdr (car event))))) | |
687 | ;;;!! ;; (if (consp relative-coordinate) | |
688 | ;;;!! ;; (progn | |
689 | ;;;!! ;; (save-excursion | |
690 | ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate))) | |
691 | ;;;!! ;; (x-draw-rectangle | |
692 | ;;;!! ;; (selected-screen) | |
693 | ;;;!! ;; abs-y 0 | |
694 | ;;;!! ;; (save-excursion | |
695 | ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate))) | |
696 | ;;;!! ;; (end-of-line) | |
697 | ;;;!! ;; (push-mark nil t) | |
698 | ;;;!! ;; (beginning-of-line) | |
699 | ;;;!! ;; (- (region-end) (region-beginning))) 1)) | |
700 | ;;;!! ;; (sit-for 1) | |
701 | ;;;!! ;; (x-erase-rectangle (selected-screen)))))) | |
702 | ;;;!! ;; | |
703 | ;;;!! ;;(defvar last-line-drawn nil) | |
704 | ;;;!! ;;(defvar begin-delim "[^ \t]") | |
705 | ;;;!! ;;(defvar end-delim "[^ \t]") | |
706 | ;;;!! ;; | |
707 | ;;;!! ;;(defun mouse-boxing (event) | |
708 | ;;;!! ;; (interactive "@e") | |
709 | ;;;!! ;; (save-excursion | |
710 | ;;;!! ;; (let ((screen (selected-screen))) | |
711 | ;;;!! ;; (while (= (x-mouse-events) 0) | |
712 | ;;;!! ;; (let* ((pos (read-mouse-position screen)) | |
713 | ;;;!! ;; (abs-x (car pos)) | |
714 | ;;;!! ;; (abs-y (cdr pos)) | |
715 | ;;;!! ;; (relative-coordinate | |
716 | ;;;!! ;; (coordinates-in-window-p (` ((, abs-x) (, abs-y))) | |
717 | ;;;!! ;; (selected-window))) | |
718 | ;;;!! ;; (begin-reg nil) | |
719 | ;;;!! ;; (end-reg nil) | |
720 | ;;;!! ;; (end-column nil) | |
721 | ;;;!! ;; (begin-column nil)) | |
722 | ;;;!! ;; (if (and (consp relative-coordinate) | |
723 | ;;;!! ;; (or (not last-line-drawn) | |
724 | ;;;!! ;; (not (= last-line-drawn abs-y)))) | |
725 | ;;;!! ;; (progn | |
726 | ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate))) | |
727 | ;;;!! ;; (if (= (following-char) 10) | |
728 | ;;;!! ;; () | |
729 | ;;;!! ;; (progn | |
730 | ;;;!! ;; (setq begin-reg (1- (re-search-forward end-delim))) | |
731 | ;;;!! ;; (setq begin-column (1- (current-column))) | |
732 | ;;;!! ;; (end-of-line) | |
733 | ;;;!! ;; (setq end-reg (1+ (re-search-backward begin-delim))) | |
734 | ;;;!! ;; (setq end-column (1+ (current-column))) | |
735 | ;;;!! ;; (message "%s" (buffer-substring begin-reg end-reg)) | |
736 | ;;;!! ;; (x-draw-rectangle screen | |
737 | ;;;!! ;; (setq last-line-drawn abs-y) | |
738 | ;;;!! ;; begin-column | |
739 | ;;;!! ;; (- end-column begin-column) 1)))))))))) | |
740 | ;;;!! ;; | |
741 | ;;;!! ;;(defun mouse-erase-box () | |
742 | ;;;!! ;; (interactive) | |
743 | ;;;!! ;; (if last-line-drawn | |
744 | ;;;!! ;; (progn | |
745 | ;;;!! ;; (x-erase-rectangle (selected-screen)) | |
746 | ;;;!! ;; (setq last-line-drawn nil)))) | |
747 | ;;;!! | |
748 | ;;;!! ;;; (defun test-x-rectangle () | |
749 | ;;;!! ;;; (use-local-mouse-map (setq rectangle-test-map (make-sparse-keymap))) | |
750 | ;;;!! ;;; (define-key rectangle-test-map mouse-motion-button-left 'mouse-boxing) | |
751 | ;;;!! ;;; (define-key rectangle-test-map mouse-button-left-up 'mouse-erase-box)) | |
752 | ;;;!! | |
753 | ;;;!! ;; | |
754 | ;;;!! ;; Here is how to do double clicking in lisp. About to change. | |
755 | ;;;!! ;; | |
756 | ;;;!! | |
757 | ;;;!! (defvar double-start nil) | |
758 | ;;;!! (defconst double-click-interval 300 | |
759 | ;;;!! "Max ticks between clicks") | |
760 | ;;;!! | |
761 | ;;;!! (defun double-down (event) | |
762 | ;;;!! (interactive "@e") | |
763 | ;;;!! (if double-start | |
764 | ;;;!! (let ((interval (- (nth 4 event) double-start))) | |
765 | ;;;!! (if (< interval double-click-interval) | |
766 | ;;;!! (progn | |
767 | ;;;!! (backward-up-list 1) | |
768 | ;;;!! ;; (message "Interval %d" interval) | |
769 | ;;;!! (sleep-for 1))) | |
770 | ;;;!! (setq double-start nil)) | |
771 | ;;;!! (setq double-start (nth 4 event)))) | |
772 | ;;;!! | |
773 | ;;;!! (defun double-up (event) | |
774 | ;;;!! (interactive "@e") | |
775 | ;;;!! (and double-start | |
776 | ;;;!! (> (- (nth 4 event ) double-start) double-click-interval) | |
777 | ;;;!! (setq double-start nil))) | |
778 | ;;;!! | |
779 | ;;;!! ;;; (defun x-test-doubleclick () | |
780 | ;;;!! ;;; (use-local-mouse-map (setq doubleclick-test-map (make-sparse-keymap))) | |
781 | ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left 'double-down) | |
782 | ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left-up 'double-up)) | |
783 | ;;;!! | |
784 | ;;;!! ;; | |
5ba2dc3f | 785 | ;;;!! ;; This scrolls while button is depressed. Use preferable in scroll bar. |
dbc4e1c1 JB |
786 | ;;;!! ;; |
787 | ;;;!! | |
788 | ;;;!! (defvar scrolled-lines 0) | |
789 | ;;;!! (defconst scroll-speed 1) | |
790 | ;;;!! | |
791 | ;;;!! (defun incr-scroll-down (event) | |
792 | ;;;!! (interactive "@e") | |
793 | ;;;!! (setq scrolled-lines 0) | |
794 | ;;;!! (incremental-scroll scroll-speed)) | |
795 | ;;;!! | |
796 | ;;;!! (defun incr-scroll-up (event) | |
797 | ;;;!! (interactive "@e") | |
798 | ;;;!! (setq scrolled-lines 0) | |
799 | ;;;!! (incremental-scroll (- scroll-speed))) | |
800 | ;;;!! | |
801 | ;;;!! (defun incremental-scroll (n) | |
802 | ;;;!! (while (= (x-mouse-events) 0) | |
803 | ;;;!! (setq scrolled-lines (1+ (* scroll-speed scrolled-lines))) | |
804 | ;;;!! (scroll-down n) | |
805 | ;;;!! (sit-for 300 t))) | |
806 | ;;;!! | |
807 | ;;;!! (defun incr-scroll-stop (event) | |
808 | ;;;!! (interactive "@e") | |
809 | ;;;!! (message "Scrolled %d lines" scrolled-lines) | |
810 | ;;;!! (setq scrolled-lines 0) | |
811 | ;;;!! (sleep-for 1)) | |
812 | ;;;!! | |
813 | ;;;!! ;;; (defun x-testing-scroll () | |
814 | ;;;!! ;;; (let ((scrolling-map (function mouse-vertical-scroll-bar-prefix))) | |
815 | ;;;!! ;;; (define-key scrolling-map mouse-button-left 'incr-scroll-down) | |
816 | ;;;!! ;;; (define-key scrolling-map mouse-button-right 'incr-scroll-up) | |
817 | ;;;!! ;;; (define-key scrolling-map mouse-button-left-up 'incr-scroll-stop) | |
818 | ;;;!! ;;; (define-key scrolling-map mouse-button-right-up 'incr-scroll-stop))) | |
819 | ;;;!! | |
820 | ;;;!! ;; | |
821 | ;;;!! ;; Some playthings suitable for picture mode? They need work. | |
822 | ;;;!! ;; | |
823 | ;;;!! | |
824 | ;;;!! (defun mouse-kill-rectangle (event) | |
825 | ;;;!! "Kill the rectangle between point and the mouse cursor." | |
826 | ;;;!! (interactive "@e") | |
827 | ;;;!! (let ((point-save (point))) | |
828 | ;;;!! (save-excursion | |
829 | ;;;!! (mouse-set-point event) | |
830 | ;;;!! (push-mark nil t) | |
831 | ;;;!! (if (> point-save (point)) | |
832 | ;;;!! (kill-rectangle (point) point-save) | |
833 | ;;;!! (kill-rectangle point-save (point)))))) | |
834 | ;;;!! | |
835 | ;;;!! (defun mouse-open-rectangle (event) | |
836 | ;;;!! "Kill the rectangle between point and the mouse cursor." | |
837 | ;;;!! (interactive "@e") | |
838 | ;;;!! (let ((point-save (point))) | |
839 | ;;;!! (save-excursion | |
840 | ;;;!! (mouse-set-point event) | |
841 | ;;;!! (push-mark nil t) | |
842 | ;;;!! (if (> point-save (point)) | |
843 | ;;;!! (open-rectangle (point) point-save) | |
844 | ;;;!! (open-rectangle point-save (point)))))) | |
845 | ;;;!! | |
846 | ;;;!! ;; Must be a better way to do this. | |
847 | ;;;!! | |
848 | ;;;!! (defun mouse-multiple-insert (n char) | |
849 | ;;;!! (while (> n 0) | |
850 | ;;;!! (insert char) | |
851 | ;;;!! (setq n (1- n)))) | |
852 | ;;;!! | |
853 | ;;;!! ;; What this could do is not finalize until button was released. | |
854 | ;;;!! | |
855 | ;;;!! (defun mouse-move-text (event) | |
856 | ;;;!! "Move text from point to cursor position, inserting spaces." | |
857 | ;;;!! (interactive "@e") | |
858 | ;;;!! (let* ((relative-coordinate | |
859 | ;;;!! (coordinates-in-window-p (car event) (selected-window)))) | |
860 | ;;;!! (if (consp relative-coordinate) | |
861 | ;;;!! (cond ((> (current-column) (car relative-coordinate)) | |
862 | ;;;!! (delete-char | |
863 | ;;;!! (- (car relative-coordinate) (current-column)))) | |
864 | ;;;!! ((< (current-column) (car relative-coordinate)) | |
865 | ;;;!! (mouse-multiple-insert | |
866 | ;;;!! (- (car relative-coordinate) (current-column)) " ")) | |
867 | ;;;!! ((= (current-column) (car relative-coordinate)) (ding)))))) | |
07a78410 | 868 | \f |
f936ae06 RS |
869 | ;; Choose a completion with the mouse. |
870 | ||
871 | (defun mouse-choose-completion (event) | |
49e61c42 | 872 | "Click on an alternative in the `*Completions*' buffer to choose it." |
f936ae06 RS |
873 | (interactive "e") |
874 | (let (choice) | |
875 | (save-excursion | |
876 | (set-buffer (window-buffer (posn-window (event-start event)))) | |
877 | (save-excursion | |
878 | (goto-char (posn-point (event-start event))) | |
879 | (skip-chars-backward "^ \t\n") | |
880 | (let ((beg (point))) | |
881 | (skip-chars-forward "^ \t\n") | |
882 | (setq choice (buffer-substring beg (point)))))) | |
324710ca RS |
883 | (set-buffer (window-buffer (minibuffer-window))) |
884 | (goto-char (max (point-min) (- (point-max) (length choice)))) | |
885 | (while (and (not (eobp)) | |
886 | (let ((tail (buffer-substring (point) (point-max)))) | |
887 | (not (string= tail (substring choice 0 (length tail)))))) | |
888 | (forward-char 1)) | |
889 | (insert choice) | |
890 | (delete-region (point) (point-max)) | |
891 | (minibuffer-complete-and-exit))) | |
f936ae06 | 892 | \f |
07a78410 RS |
893 | ;; Font selection. |
894 | ||
0eb9fef3 RS |
895 | (defun font-menu-add-default () |
896 | (let* ((default (cdr (assq 'font (frame-parameters (selected-frame))))) | |
897 | (font-alist x-fixed-font-alist) | |
0d94f5ca | 898 | (elt (or (assoc "Misc" font-alist) (nth 1 font-alist)))) |
0eb9fef3 RS |
899 | (if (assoc "Default" elt) |
900 | (delete (assoc "Default" elt) elt)) | |
901 | (setcdr elt | |
3d64d15b | 902 | (cons (list "Default" |
0eb9fef3 RS |
903 | (cdr (assq 'font (frame-parameters (selected-frame))))) |
904 | (cdr elt))))) | |
905 | ||
07a78410 RS |
906 | (defvar x-fixed-font-alist |
907 | '("Font menu" | |
908 | ("Misc" | |
fa21fdec RS |
909 | ("6x10" "-misc-fixed-medium-r-semicondensed--10-110-75-75-c-60-*-1") |
910 | ("6x12" "-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-*-1") | |
911 | ("6x13" "-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-*-1") | |
912 | ("lucida 13" | |
913 | "-b&h-lucidatypewriter-medium-r-normal-sans-0-0-0-0-m-0-*-1") | |
914 | ("7x13" "-misc-fixed-medium-r-normal--13-120-75-75-c-70-*-1") | |
915 | ("7x14" "-misc-fixed-medium-r-normal--14-130-75-75-c-70-*-1") | |
916 | ("9x15" "-misc-fixed-medium-r-normal--15-140-*-*-c-*-*-1") | |
917 | ("") | |
918 | ("clean 8x8" "-schumacher-clean-medium-r-normal--*-80-*-*-c-*-*-1") | |
919 | ("clean 8x14" "-schumacher-clean-medium-r-normal--*-140-*-*-c-*-*-1") | |
920 | ("clean 8x10" "-schumacher-clean-medium-r-normal--*-100-*-*-c-*-*-1") | |
921 | ("clean 8x16" "-schumacher-clean-medium-r-normal--*-160-*-*-c-*-*-1") | |
922 | ("") | |
923 | ("sony 8x16" "-sony-fixed-medium-r-normal--16-120-100-100-c-80-*-1") | |
924 | ("") | |
07a78410 | 925 | ("fixed" "fixed") |
07a78410 RS |
926 | ("10x20" "10x20") |
927 | ("11x18" "11x18") | |
928 | ("12x24" "12x24")) | |
929 | ;;; We don't seem to have these; who knows what they are. | |
930 | ;;; ("fg-18" "fg-18") | |
931 | ;;; ("fg-25" "fg-25") | |
932 | ;;; ("lucidasanstypewriter-12" "lucidasanstypewriter-12") | |
933 | ;;; ("lucidasanstypewriter-bold-14" "lucidasanstypewriter-bold-14") | |
934 | ;;; ("lucidasanstypewriter-bold-24" "lucidasanstypewriter-bold-24") | |
935 | ;;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1") | |
936 | ;;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*") | |
937 | ("Courier" | |
82c048a9 RS |
938 | ("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1") |
939 | ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1") | |
940 | ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1") | |
941 | ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1") | |
942 | ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1") | |
943 | ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1") | |
944 | ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1") | |
945 | ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1") | |
946 | ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1") | |
947 | ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1") | |
948 | ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1") | |
949 | ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1") | |
950 | ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1") | |
951 | ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1") | |
952 | ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1") | |
953 | ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1") | |
954 | ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1") | |
955 | ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1") | |
956 | ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1") | |
957 | ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1") | |
958 | ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1") | |
959 | ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1") | |
960 | ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1") | |
961 | ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1")) | |
07a78410 RS |
962 | ) |
963 | "X fonts suitable for use in Emacs.") | |
964 | ||
dbc4e1c1 | 965 | (defun mouse-set-font (&optional font) |
07a78410 RS |
966 | "Select an emacs font from a list of known good fonts" |
967 | (interactive | |
968 | (x-popup-menu last-nonmenu-event x-fixed-font-alist)) | |
dbc4e1c1 | 969 | (if font |
26d86f19 RS |
970 | (progn (modify-frame-parameters (selected-frame) |
971 | (list (cons 'font font))) | |
972 | ;; Update some standard faces too. | |
973 | (set-face-font 'bold nil (selected-frame)) | |
974 | (make-face-bold 'bold (selected-frame) t) | |
975 | (set-face-font 'italic nil (selected-frame)) | |
976 | (make-face-italic 'italic (selected-frame) t) | |
977 | (set-face-font 'bold-italic nil (selected-frame)) | |
978 | (make-face-bold-italic 'bold-italic (selected-frame) t)))) | |
cc0a8174 JB |
979 | \f |
980 | ;;; Bindings for mouse commands. | |
981 | ||
fcfc3c63 | 982 | (define-key global-map [down-mouse-1] 'mouse-drag-region) |
dbc4e1c1 | 983 | (global-set-key [mouse-1] 'mouse-set-point) |
dbc4e1c1 | 984 | (global-set-key [drag-mouse-1] 'mouse-set-region) |
fcfc3c63 | 985 | |
dbc4e1c1 JB |
986 | (global-set-key [mouse-2] 'mouse-yank-at-click) |
987 | (global-set-key [mouse-3] 'mouse-save-then-kill) | |
8b34e79d | 988 | |
dbc4e1c1 JB |
989 | ;; By binding these to down-going events, we let the user use the up-going |
990 | ;; event to make the selection, saving a click. | |
991 | (global-set-key [C-down-mouse-1] 'mouse-buffer-menu) | |
992 | (global-set-key [C-down-mouse-3] 'mouse-set-font) | |
07a78410 | 993 | |
8b34e79d RS |
994 | ;; Replaced with dragging mouse-1 |
995 | ;; (global-set-key [S-mouse-1] 'mouse-set-mark) | |
947da0c4 | 996 | |
dbc4e1c1 JB |
997 | (global-set-key [mode-line mouse-1] 'mouse-delete-other-windows) |
998 | (global-set-key [mode-line mouse-3] 'mouse-delete-window) | |
999 | (global-set-key [mode-line S-mouse-2] 'mouse-split-window-horizontally) | |
8b34e79d | 1000 | \f |
6b2154de RS |
1001 | ;; Define the mouse help menu tree. |
1002 | ||
8b34e79d | 1003 | (defvar help-menu-map '(keymap "Help")) |
dbc4e1c1 JB |
1004 | (global-set-key [C-down-mouse-2] help-menu-map) |
1005 | ||
1006 | (defvar help-apropos-map (make-sparse-keymap "Is there a command that...")) | |
1007 | (defvar help-keys-map (make-sparse-keymap "Key Commands <==> Functions")) | |
1008 | (defvar help-manual-map (make-sparse-keymap "Manual and tutorial")) | |
1009 | (defvar help-misc-map (make-sparse-keymap "Odds and ends")) | |
1010 | (defvar help-modes-map (make-sparse-keymap "Modes")) | |
1011 | (defvar help-admin-map (make-sparse-keymap "Administrivia")) | |
8b34e79d | 1012 | |
e7691e9c | 1013 | (define-key help-menu-map [apropos] |
6ec3899e | 1014 | (cons "@Is there a command that..." help-apropos-map)) |
e7691e9c | 1015 | (define-key help-menu-map [keys] |
6ec3899e | 1016 | (cons "@Key Commands <==> Functions" help-keys-map)) |
e7691e9c | 1017 | (define-key help-menu-map [manuals] |
6ec3899e | 1018 | (cons "@Manual and tutorial" help-manual-map)) |
e7691e9c | 1019 | (define-key help-menu-map [misc] |
6ec3899e | 1020 | (cons "@Odds and ends" help-misc-map)) |
e7691e9c | 1021 | (define-key help-menu-map [modes] |
6ec3899e | 1022 | (cons "@Modes" help-modes-map)) |
e7691e9c | 1023 | (define-key help-menu-map [admin] |
6ec3899e | 1024 | (cons "@Administrivia" help-admin-map)) |
8b34e79d RS |
1025 | |
1026 | (define-key help-apropos-map "c" '("Command Apropos" . command-apropos)) | |
1027 | (define-key help-apropos-map "a" '("Apropos" . apropos)) | |
1028 | ||
1029 | (define-key help-keys-map "b" | |
1030 | '("List all keystroke commands" . describe-bindings)) | |
1031 | (define-key help-keys-map "c" | |
1032 | '("Describe key briefly" . describe-key-briefly)) | |
1033 | (define-key help-keys-map "k" | |
1034 | '("Describe key verbose" . describe-key)) | |
1035 | (define-key help-keys-map "f" | |
1036 | '("Describe Lisp function" . describe-function)) | |
1037 | (define-key help-keys-map "w" | |
1038 | '("Where is this command" . where-is)) | |
1039 | ||
1040 | (define-key help-manual-map "i" '("Info system" . info)) | |
1041 | (define-key help-manual-map "t" | |
1042 | '("Invoke Emacs tutorial" . help-with-tutorial)) | |
1043 | ||
1044 | (define-key help-misc-map "l" '("Last 100 Keystrokes" . view-lossage)) | |
1045 | (define-key help-misc-map "s" '("Describe syntax table" . describe-syntax)) | |
1046 | ||
1047 | (define-key help-modes-map "m" | |
1048 | '("Describe current major mode" . describe-mode)) | |
1049 | (define-key help-modes-map "b" | |
1050 | '("List all keystroke commands" . describe-bindings)) | |
1051 | ||
1052 | (define-key help-admin-map "n" | |
8b213da7 | 1053 | '("View Emacs news" . view-emacs-news)) |
8b34e79d | 1054 | (define-key help-admin-map "l" |
8b213da7 | 1055 | '("View Emacs copying conditions" . describe-copying)) |
8b34e79d RS |
1056 | (define-key help-admin-map "d" |
1057 | '("Describe distribution" . describe-distribution)) | |
1058 | (define-key help-admin-map "w" | |
1059 | '("Describe (non)warranty" . describe-no-warranty)) | |
49116ac0 JB |
1060 | |
1061 | (provide 'mouse) | |
1062 | ||
6594deb0 | 1063 | ;;; mouse.el ends here |