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