Commit | Line | Data |
---|---|---|
6594deb0 | 1 | ;;; mouse.el --- window system-independent mouse support. |
84176303 | 2 | |
d733c5ec | 3 | ;;; Copyright (C) 1993, 1994 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 | |
50f58001 RS |
39 | (defvar mouse-yank-at-point nil |
40 | "*If non-nil, mouse yank commands yank at point instead of at click.") | |
cc0a8174 | 41 | \f |
d65147f6 KH |
42 | (defun mouse-minibuffer-check (event) |
43 | (let ((w (posn-window (event-start event)))) | |
44 | (and (window-minibuffer-p w) | |
45 | (not (minibuffer-window-active-p w)) | |
46 | (error "Minibuffer window is not active")))) | |
47 | ||
cc0a8174 | 48 | (defun mouse-delete-window (click) |
947da0c4 | 49 | "Delete the window you click on. |
cc0a8174 | 50 | This must be bound to a mouse click." |
ec558adc | 51 | (interactive "e") |
d65147f6 | 52 | (mouse-minibuffer-check click) |
b5370f03 | 53 | (delete-window (posn-window (event-start click)))) |
cc0a8174 | 54 | |
3c2dd2c0 RS |
55 | (defun mouse-select-window (click) |
56 | "Select the window clicked on; don't move point." | |
57 | (interactive "e") | |
d65147f6 | 58 | (mouse-minibuffer-check click) |
3c2dd2c0 RS |
59 | (let ((oframe (selected-frame)) |
60 | (frame (window-frame (posn-window (event-start click))))) | |
61 | (select-window (posn-window (event-start click))) | |
62 | (raise-frame frame) | |
63 | (select-frame frame) | |
64 | (or (eq frame oframe) | |
65 | (set-mouse-position (selected-frame) (1- (frame-width)) 0)) | |
66 | (unfocus-frame))) | |
67 | ||
b0f3a26b JB |
68 | (defun mouse-tear-off-window (click) |
69 | "Delete the window clicked on, and create a new frame displaying its buffer." | |
70 | (interactive "e") | |
d65147f6 | 71 | (mouse-minibuffer-check click) |
b0f3a26b JB |
72 | (let* ((window (posn-window (event-start click))) |
73 | (buf (window-buffer window)) | |
01a911e3 | 74 | (frame (make-frame))) |
b0f3a26b JB |
75 | (select-frame frame) |
76 | (switch-to-buffer buf) | |
77 | (delete-window window))) | |
78 | ||
b5370f03 | 79 | (defun mouse-delete-other-windows () |
947da0c4 | 80 | "Delete all window except the one you click on." |
b5370f03 | 81 | (interactive "@") |
cc0a8174 | 82 | (delete-other-windows)) |
72ea54a4 | 83 | |
cc0a8174 JB |
84 | (defun mouse-split-window-vertically (click) |
85 | "Select Emacs window mouse is on, then split it vertically in half. | |
86 | The window is split at the line clicked on. | |
87 | This command must be bound to a mouse click." | |
947da0c4 | 88 | (interactive "@e") |
d65147f6 | 89 | (mouse-minibuffer-check click) |
b5370f03 JB |
90 | (let ((start (event-start click))) |
91 | (select-window (posn-window start)) | |
3f26b32a RS |
92 | (let ((new-height (if (eq (posn-point start) 'vertical-scroll-bar) |
93 | (scroll-bar-scale (posn-col-row start) | |
94 | (1- (window-height))) | |
95 | (1+ (cdr (posn-col-row (event-end click)))))) | |
5ba2dc3f JB |
96 | (first-line window-min-height) |
97 | (last-line (- (window-height) window-min-height))) | |
98 | (if (< last-line first-line) | |
99 | (error "window too short to split") | |
100 | (split-window-vertically | |
101 | (min (max new-height first-line) last-line)))))) | |
cc0a8174 | 102 | |
947da0c4 RS |
103 | (defun mouse-split-window-horizontally (click) |
104 | "Select Emacs window mouse is on, then split it horizontally in half. | |
105 | The window is split at the column clicked on. | |
106 | This command must be bound to a mouse click." | |
107 | (interactive "@e") | |
d65147f6 | 108 | (mouse-minibuffer-check click) |
5ba2dc3f JB |
109 | (let ((start (event-start click))) |
110 | (select-window (posn-window start)) | |
111 | (let ((new-width (1+ (car (posn-col-row (event-end click))))) | |
112 | (first-col window-min-width) | |
113 | (last-col (- (window-width) window-min-width))) | |
114 | (if (< last-col first-col) | |
115 | (error "window too narrow to split") | |
116 | (split-window-horizontally | |
117 | (min (max new-width first-col) last-col)))))) | |
947da0c4 | 118 | |
2a5fa27b | 119 | (defun mouse-set-point (event) |
cc0a8174 | 120 | "Move point to the position clicked on with the mouse. |
2a5fa27b | 121 | This should be bound to a mouse click event type." |
ec558adc | 122 | (interactive "e") |
d65147f6 | 123 | (mouse-minibuffer-check event) |
2a5fa27b RS |
124 | ;; Use event-end in case called from mouse-drag-region. |
125 | ;; If EVENT is a click, event-end and event-start give same value. | |
126 | (let ((posn (event-end event))) | |
b5370f03 JB |
127 | (select-window (posn-window posn)) |
128 | (if (numberp (posn-point posn)) | |
129 | (goto-char (posn-point posn))))) | |
cc0a8174 | 130 | |
652ccd35 | 131 | (defun mouse-set-region (click) |
e37de120 | 132 | "Set the region to the text dragged over, and copy to kill ring. |
2a5fa27b | 133 | This should be bound to a mouse drag event." |
652ccd35 | 134 | (interactive "e") |
d65147f6 | 135 | (mouse-minibuffer-check click) |
652ccd35 RS |
136 | (let ((posn (event-start click)) |
137 | (end (event-end click))) | |
138 | (select-window (posn-window posn)) | |
139 | (if (numberp (posn-point posn)) | |
140 | (goto-char (posn-point posn))) | |
fcfc3c63 RS |
141 | ;; If mark is highlighted, no need to bounce the cursor. |
142 | (or (and transient-mark-mode | |
143 | (eq (framep (selected-frame)) 'x)) | |
144 | (sit-for 1)) | |
652ccd35 | 145 | (push-mark) |
1cc8a3f4 | 146 | (set-mark (point)) |
652ccd35 | 147 | (if (numberp (posn-point end)) |
e37de120 RS |
148 | (goto-char (posn-point end))) |
149 | ;; Don't set this-command to kill-region, so that a following | |
150 | ;; C-w will not double the text in the kill ring. | |
151 | (let (this-command) | |
152 | (copy-region-as-kill (mark) (point))))) | |
652ccd35 | 153 | |
600c6e3a JB |
154 | (defvar mouse-scroll-delay 0.25 |
155 | "*The pause between scroll steps caused by mouse drags, in seconds. | |
156 | If you drag the mouse beyond the edge of a window, Emacs scrolls the | |
157 | window to bring the text beyond that edge into view, with a delay of | |
158 | this many seconds between scroll steps. Scrolling stops when you move | |
159 | the mouse back into the window, or release the button. | |
160 | This variable's value may be non-integral. | |
161 | Setting this to zero causes Emacs to scroll as fast as it can.") | |
162 | ||
163 | (defun mouse-scroll-subr (jump &optional overlay start) | |
164 | "Scroll the selected window JUMP lines at a time, until new input arrives. | |
165 | If OVERLAY is an overlay, let it stretch from START to the far edge of | |
166 | the newly visible text. | |
167 | Upon exit, point is at the far edge of the newly visible text." | |
168 | (while (progn | |
169 | (goto-char (window-start)) | |
170 | (if (not (zerop (vertical-motion jump))) | |
171 | (progn | |
172 | (set-window-start (selected-window) (point)) | |
173 | (if (natnump jump) | |
174 | (progn | |
175 | (goto-char (window-end (selected-window))) | |
176 | ;; window-end doesn't reflect the window's new | |
177 | ;; start position until the next redisplay. Hurrah. | |
178 | (vertical-motion (1- jump))) | |
179 | (goto-char (window-start (selected-window)))) | |
180 | (if overlay | |
181 | (move-overlay overlay start (point))) | |
182 | (if (not (eobp)) | |
183 | (sit-for mouse-scroll-delay)))))) | |
184 | (point)) | |
fcfc3c63 | 185 | |
600c6e3a JB |
186 | (defvar mouse-drag-overlay (make-overlay 1 1)) |
187 | (overlay-put mouse-drag-overlay 'face 'region) | |
188 | ||
dd524dbd | 189 | (defvar mouse-selection-click-count 0) |
eb6ff46f | 190 | |
600c6e3a | 191 | (defun mouse-drag-region (start-event) |
bcd5aef1 | 192 | "Set the region to the text that the mouse is dragged over. |
78210c95 RS |
193 | Highlight the drag area as you move the mouse. |
194 | This must be bound to a button-down mouse event. | |
195 | In Transient Mark mode, the highlighting remains once you | |
196 | release the mouse button. Otherwise, it does not." | |
bcd5aef1 | 197 | (interactive "e") |
d65147f6 | 198 | (mouse-minibuffer-check start-event) |
600c6e3a JB |
199 | (let* ((start-posn (event-start start-event)) |
200 | (start-point (posn-point start-posn)) | |
201 | (start-window (posn-window start-posn)) | |
b846d039 | 202 | (start-frame (window-frame start-window)) |
600c6e3a JB |
203 | (bounds (window-edges start-window)) |
204 | (top (nth 1 bounds)) | |
205 | (bottom (if (window-minibuffer-p start-window) | |
206 | (nth 3 bounds) | |
207 | ;; Don't count the mode line. | |
e37de120 RS |
208 | (1- (nth 3 bounds)))) |
209 | (click-count (1- (event-click-count start-event)))) | |
eb6ff46f | 210 | (setq mouse-selection-click-count click-count) |
b80f1928 | 211 | (mouse-set-point start-event) |
e37de120 RS |
212 | (let ((range (mouse-start-end start-point start-point click-count))) |
213 | (move-overlay mouse-drag-overlay (car range) (nth 1 range) | |
214 | (window-buffer start-window))) | |
f767385c | 215 | (deactivate-mark) |
600c6e3a | 216 | (let (event end end-point) |
bcd5aef1 | 217 | (track-mouse |
600c6e3a | 218 | (while (progn |
b846d039 JB |
219 | (setq event (read-event)) |
220 | (or (mouse-movement-p event) | |
221 | (eq (car-safe event) 'switch-frame))) | |
b846d039 JB |
222 | (if (eq (car-safe event) 'switch-frame) |
223 | nil | |
224 | (setq end (event-end event) | |
225 | end-point (posn-point end)) | |
226 | ||
227 | (cond | |
228 | ||
229 | ;; Ignore switch-frame events. | |
230 | ((eq (car-safe event) 'switch-frame)) | |
231 | ||
232 | ;; Are we moving within the original window? | |
233 | ((and (eq (posn-window end) start-window) | |
234 | (integer-or-marker-p end-point)) | |
235 | (goto-char end-point) | |
e37de120 RS |
236 | (let ((range (mouse-start-end start-point (point) click-count))) |
237 | (move-overlay mouse-drag-overlay (car range) (nth 1 range)))) | |
b846d039 | 238 | |
50e527bc KH |
239 | (t |
240 | (let ((mouse-row (cdr (cdr (mouse-position))))) | |
b846d039 | 241 | (cond |
50e527bc | 242 | ((null mouse-row)) |
b846d039 JB |
243 | ((< mouse-row top) |
244 | (mouse-scroll-subr | |
245 | (- mouse-row top) mouse-drag-overlay start-point)) | |
246 | ((and (not (eobp)) | |
247 | (>= mouse-row bottom)) | |
248 | (mouse-scroll-subr (1+ (- mouse-row bottom)) | |
50e527bc | 249 | mouse-drag-overlay start-point))))))))) |
b846d039 | 250 | |
600c6e3a JB |
251 | (if (and (eq (get (event-basic-type event) 'event-kind) 'mouse-click) |
252 | (eq (posn-window (event-end event)) start-window) | |
253 | (numberp (posn-point (event-end event)))) | |
e37de120 RS |
254 | (let ((fun (key-binding (vector (car event))))) |
255 | (if (memq fun '(mouse-set-region mouse-set-point)) | |
d89a4a47 RS |
256 | (if (not (= (overlay-start mouse-drag-overlay) |
257 | (overlay-end mouse-drag-overlay))) | |
258 | (let (this-command) | |
259 | (push-mark (overlay-start mouse-drag-overlay) t t) | |
260 | (goto-char (overlay-end mouse-drag-overlay)) | |
261 | (copy-region-as-kill (point) (mark t))) | |
3544cfc9 RS |
262 | (goto-char (overlay-end mouse-drag-overlay)) |
263 | (setq this-command 'mouse-set-point)) | |
e37de120 RS |
264 | (if (fboundp fun) |
265 | (funcall fun event))))) | |
600c6e3a | 266 | (delete-overlay mouse-drag-overlay)))) |
e37de120 RS |
267 | \f |
268 | ;; Commands to handle xterm-style multiple clicks. | |
600c6e3a | 269 | |
e37de120 RS |
270 | (defun mouse-skip-word (dir) |
271 | "Skip over word, over whitespace, or over identical punctuation. | |
272 | If DIR is positive skip forward; if negative, skip backward." | |
273 | (let* ((char (following-char)) | |
274 | (syntax (char-to-string (char-syntax char)))) | |
275 | (if (or (string= syntax "w") (string= syntax " ")) | |
276 | (if (< dir 0) | |
277 | (skip-syntax-backward syntax) | |
278 | (skip-syntax-forward syntax)) | |
279 | (if (< dir 0) | |
d89a4a47 | 280 | (while (and (not (bobp)) (= (preceding-char) char)) |
e37de120 | 281 | (forward-char -1)) |
d89a4a47 | 282 | (while (and (not (eobp)) (= (following-char) char)) |
e37de120 RS |
283 | (forward-char 1)))))) |
284 | ||
285 | ;; Return a list of region bounds based on START and END according to MODE. | |
286 | ;; If MODE is 0 then set point to (min START END), mark to (max START END). | |
287 | ;; If MODE is 1 then set point to start of word at (min START END), | |
288 | ;; mark to end of word at (max START END). | |
289 | ;; If MODE is 2 then do the same for lines. | |
eb6ff46f | 290 | (defun mouse-start-end (start end mode) |
e37de120 RS |
291 | (if (> start end) |
292 | (let ((temp start)) | |
293 | (setq start end | |
294 | end temp))) | |
9a974c88 | 295 | (setq mode (mod mode 3)) |
e37de120 RS |
296 | (cond ((= mode 0) |
297 | (list start end)) | |
298 | ((and (= mode 1) | |
299 | (= start end) | |
1ec71583 | 300 | (char-after start) |
e37de120 | 301 | (= (char-syntax (char-after start)) ?\()) |
6f482eec RS |
302 | (list start |
303 | (save-excursion | |
304 | (goto-char start) | |
305 | (forward-sexp 1) | |
306 | (point)))) | |
e37de120 RS |
307 | ((and (= mode 1) |
308 | (= start end) | |
1ec71583 | 309 | (char-after start) |
e37de120 RS |
310 | (= (char-syntax (char-after start)) ?\))) |
311 | (list (save-excursion | |
312 | (goto-char (1+ start)) | |
d89a4a47 RS |
313 | (backward-sexp 1) |
314 | (point)) | |
e37de120 RS |
315 | (1+ start))) |
316 | ((= mode 1) | |
317 | (list (save-excursion | |
318 | (goto-char start) | |
319 | (mouse-skip-word -1) | |
320 | (point)) | |
321 | (save-excursion | |
322 | (goto-char end) | |
323 | (mouse-skip-word 1) | |
324 | (point)))) | |
325 | ((= mode 2) | |
326 | (list (save-excursion | |
327 | (goto-char start) | |
328 | (beginning-of-line 1) | |
329 | (point)) | |
330 | (save-excursion | |
331 | (goto-char end) | |
332 | (forward-line 1) | |
333 | (point)))))) | |
e66feb07 | 334 | \f |
3f26b32a RS |
335 | ;; Subroutine: set the mark where CLICK happened, |
336 | ;; but don't do anything else. | |
337 | (defun mouse-set-mark-fast (click) | |
d65147f6 | 338 | (mouse-minibuffer-check click) |
3f26b32a RS |
339 | (let ((posn (event-start click))) |
340 | (select-window (posn-window posn)) | |
341 | (if (numberp (posn-point posn)) | |
342 | (push-mark (posn-point posn) t t)))) | |
343 | ||
344 | ;; Momentarily show where the mark is, if highlighting doesn't show it. | |
345 | (defun mouse-show-mark () | |
346 | (or transient-mark-mode | |
347 | (save-excursion | |
348 | (goto-char (mark t)) | |
349 | (sit-for 1)))) | |
350 | ||
cc0a8174 JB |
351 | (defun mouse-set-mark (click) |
352 | "Set mark at the position clicked on with the mouse. | |
353 | Display cursor at that position for a second. | |
354 | This must be bound to a mouse click." | |
ec558adc | 355 | (interactive "e") |
72ea54a4 RS |
356 | (let ((point-save (point))) |
357 | (unwind-protect | |
cc0a8174 | 358 | (progn (mouse-set-point click) |
897897e3 RS |
359 | (push-mark nil t t) |
360 | (or transient-mark-mode | |
361 | (sit-for 1))) | |
72ea54a4 RS |
362 | (goto-char point-save)))) |
363 | ||
cc0a8174 JB |
364 | (defun mouse-kill (click) |
365 | "Kill the region between point and the mouse click. | |
366 | The text is saved in the kill ring, as with \\[kill-region]." | |
ec558adc | 367 | (interactive "e") |
d65147f6 | 368 | (mouse-minibuffer-check click) |
142c7672 KH |
369 | (let* ((posn (event-start click)) |
370 | (click-posn (posn-point posn))) | |
371 | (select-window (posn-window posn)) | |
bd307392 JB |
372 | (if (numberp click-posn) |
373 | (kill-region (min (point) click-posn) | |
374 | (max (point) click-posn))))) | |
72ea54a4 | 375 | |
87ef29fd JB |
376 | (defun mouse-yank-at-click (click arg) |
377 | "Insert the last stretch of killed text at the position clicked on. | |
50f58001 RS |
378 | Also move point to one end of the text thus inserted (normally the end). |
379 | Prefix arguments are interpreted as with \\[yank]. | |
380 | If `mouse-yank-at-point' is non-nil, insert at point | |
381 | regardless of where you click." | |
ec558adc | 382 | (interactive "e\nP") |
50f58001 | 383 | (or mouse-yank-at-point (mouse-set-point click)) |
d89a4a47 | 384 | (setq this-command 'yank) |
87ef29fd JB |
385 | (yank arg)) |
386 | ||
387 | (defun mouse-kill-ring-save (click) | |
cc0a8174 JB |
388 | "Copy the region between point and the mouse click in the kill ring. |
389 | This does not delete the region; it acts like \\[kill-ring-save]." | |
ec558adc | 390 | (interactive "e") |
3f26b32a RS |
391 | (mouse-set-mark-fast click) |
392 | (kill-ring-save (point) (mark t)) | |
393 | (mouse-show-mark)) | |
72ea54a4 | 394 | |
dbc4e1c1 JB |
395 | ;;; This function used to delete the text between point and the mouse |
396 | ;;; whenever it was equal to the front of the kill ring, but some | |
397 | ;;; people found that confusing. | |
398 | ||
399 | ;;; A list (TEXT START END), describing the text and position of the last | |
400 | ;;; invocation of mouse-save-then-kill. | |
401 | (defvar mouse-save-then-kill-posn nil) | |
402 | ||
26d280b9 | 403 | (defun mouse-save-then-kill-delete-region (beg end) |
9a974c88 RS |
404 | ;; We must make our own undo boundaries |
405 | ;; because they happen automatically only for the current buffer. | |
406 | (undo-boundary) | |
dd524dbd RS |
407 | (if (or (= beg end) (eq buffer-undo-list t)) |
408 | ;; If we have no undo list in this buffer, | |
409 | ;; just delete. | |
410 | (delete-region beg end) | |
411 | ;; Delete, but make the undo-list entry share with the kill ring. | |
412 | ;; First, delete just one char, so in case buffer is being modified | |
413 | ;; for the first time, the undo list records that fact. | |
414 | (delete-region beg | |
415 | (+ beg (if (> end beg) 1 -1))) | |
416 | (let ((buffer-undo-list buffer-undo-list)) | |
417 | ;; Undo that deletion--but don't change the undo list! | |
418 | (primitive-undo 1 buffer-undo-list) | |
419 | ;; Now delete the rest of the specified region, | |
420 | ;; but don't record it. | |
421 | (setq buffer-undo-list t) | |
9a974c88 RS |
422 | (if (/= (length (car kill-ring)) (- (max end beg) (min end beg))) |
423 | (error "Lossage in mouse-save-then-kill-delete-region")) | |
dd524dbd RS |
424 | (delete-region beg end)) |
425 | (let ((tail buffer-undo-list)) | |
426 | ;; Search back in buffer-undo-list for the string | |
427 | ;; that came from deleting one character. | |
428 | (while (and tail (not (stringp (car (car tail))))) | |
429 | (setq tail (cdr tail))) | |
430 | ;; Replace it with an entry for the entire deleted text. | |
431 | (and tail | |
9a974c88 RS |
432 | (setcar tail (cons (car kill-ring) (min beg end)))))) |
433 | (undo-boundary)) | |
eb6ff46f | 434 | |
947da0c4 | 435 | (defun mouse-save-then-kill (click) |
40a45a9f RS |
436 | "Save text to point in kill ring; the second time, kill the text. |
437 | If the text between point and the mouse is the same as what's | |
438 | at the front of the kill ring, this deletes the text. | |
439 | Otherwise, it adds the text to the kill ring, like \\[kill-ring-save], | |
eb6ff46f RS |
440 | which prepares for a second click to delete the text. |
441 | ||
442 | If you have selected words or lines, this command extends the | |
443 | selection through the word or line clicked on. If you do this | |
444 | again in a different position, it extends the selection again. | |
445 | If you do this twice in the same position, the selection is killed." | |
947da0c4 | 446 | (interactive "e") |
d65147f6 | 447 | (mouse-minibuffer-check click) |
3f26b32a RS |
448 | (let ((click-posn (posn-point (event-start click))) |
449 | ;; Don't let a subsequent kill command append to this one: | |
450 | ;; prevent setting this-command to kill-region. | |
451 | (this-command this-command)) | |
9a974c88 | 452 | (if (> (mod mouse-selection-click-count 3) 0) |
eb6ff46f RS |
453 | (if (not (and (eq last-command 'mouse-save-then-kill) |
454 | (equal click-posn | |
455 | (car (cdr-safe (cdr-safe mouse-save-then-kill-posn)))))) | |
d89a4a47 RS |
456 | ;; Find both ends of the object selected by this click. |
457 | (let* ((range | |
458 | (mouse-start-end click-posn click-posn | |
459 | mouse-selection-click-count))) | |
460 | ;; Move whichever end is closer to the click. | |
461 | ;; That's what xterm does, and it seems reasonable. | |
462 | (if (< (abs (- click-posn (mark t))) | |
463 | (abs (- click-posn (point)))) | |
464 | (set-mark (car range)) | |
465 | (goto-char (nth 1 range))) | |
eb6ff46f RS |
466 | ;; We have already put the old region in the kill ring. |
467 | ;; Replace it with the extended region. | |
468 | ;; (It would be annoying to make a separate entry.) | |
469 | (setcar kill-ring (buffer-substring (point) (mark t))) | |
d89a4a47 RS |
470 | (if interprogram-cut-function |
471 | (funcall interprogram-cut-function (car kill-ring))) | |
472 | ;; Arrange for a repeated mouse-3 to kill this region. | |
473 | (setq mouse-save-then-kill-posn | |
474 | (list (car kill-ring) (point) click-posn)) | |
eb6ff46f RS |
475 | (mouse-show-mark)) |
476 | ;; If we click this button again without moving it, | |
477 | ;; that time kill. | |
dd524dbd RS |
478 | (mouse-save-then-kill-delete-region (point) (mark)) |
479 | (setq mouse-selection-click-count 0) | |
480 | (setq mouse-save-then-kill-posn nil)) | |
eb6ff46f RS |
481 | (if (and (eq last-command 'mouse-save-then-kill) |
482 | mouse-save-then-kill-posn | |
483 | (eq (car mouse-save-then-kill-posn) (car kill-ring)) | |
484 | (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn))) | |
485 | ;; If this is the second time we've called | |
486 | ;; mouse-save-then-kill, delete the text from the buffer. | |
dd524dbd RS |
487 | (progn |
488 | (mouse-save-then-kill-delete-region (point) (mark)) | |
489 | ;; After we kill, another click counts as "the first time". | |
490 | (setq mouse-save-then-kill-posn nil)) | |
491 | (if (or (and (eq last-command 'mouse-save-then-kill) | |
492 | mouse-save-then-kill-posn) | |
3544cfc9 | 493 | (and mark-active transient-mark-mode) |
d89a4a47 | 494 | (and (eq last-command 'mouse-drag-region) |
d89a4a47 RS |
495 | (or mark-even-if-inactive |
496 | (not transient-mark-mode)))) | |
497 | ;; We have a selection or suitable region, so adjust it. | |
498 | (let* ((posn (event-start click)) | |
499 | (new (posn-point posn))) | |
500 | (select-window (posn-window posn)) | |
501 | (if (numberp new) | |
502 | (progn | |
503 | ;; Move whichever end of the region is closer to the click. | |
504 | ;; That is what xterm does, and it seems reasonable. | |
505 | (if (< (abs (- new (point))) (abs (- new (mark t)))) | |
506 | (goto-char new) | |
507 | (set-mark new)) | |
508 | (setq deactivate-mark nil))) | |
509 | (setcar kill-ring (buffer-substring (point) (mark t))) | |
510 | (if interprogram-cut-function | |
511 | (funcall interprogram-cut-function (car kill-ring)))) | |
512 | ;; We just have point, so set mark here. | |
513 | (mouse-set-mark-fast click) | |
514 | (kill-ring-save (point) (mark t)) | |
515 | (mouse-show-mark)) | |
eb6ff46f RS |
516 | (setq mouse-save-then-kill-posn |
517 | (list (car kill-ring) (point) click-posn)))))) | |
e66feb07 RS |
518 | \f |
519 | (global-set-key [M-mouse-1] 'mouse-start-secondary) | |
520 | (global-set-key [M-drag-mouse-1] 'mouse-set-secondary) | |
521 | (global-set-key [M-down-mouse-1] 'mouse-drag-secondary) | |
522 | (global-set-key [M-mouse-3] 'mouse-secondary-save-then-kill) | |
9a974c88 | 523 | (global-set-key [M-mouse-2] 'mouse-yank-secondary) |
e66feb07 RS |
524 | |
525 | ;; An overlay which records the current secondary selection | |
526 | ;; or else is deleted when there is no secondary selection. | |
527 | ;; May be nil. | |
528 | (defvar mouse-secondary-overlay nil) | |
529 | ||
530 | ;; A marker which records the specified first end for a secondary selection. | |
531 | ;; May be nil. | |
532 | (defvar mouse-secondary-start nil) | |
533 | ||
534 | (defun mouse-start-secondary (click) | |
535 | "Set one end of the secondary selection to the position clicked on. | |
536 | Use \\[mouse-secondary-save-then-kill] to set the other end | |
537 | and complete the secondary selection." | |
538 | (interactive "e") | |
d65147f6 | 539 | (mouse-minibuffer-check click) |
e66feb07 | 540 | (let ((posn (event-start click))) |
230aaa73 RS |
541 | (save-excursion |
542 | (set-buffer (window-buffer (posn-window posn))) | |
543 | ;; Cancel any preexisting secondary selection. | |
544 | (if mouse-secondary-overlay | |
545 | (delete-overlay mouse-secondary-overlay)) | |
546 | (if (numberp (posn-point posn)) | |
547 | (progn | |
548 | (or mouse-secondary-start | |
549 | (setq mouse-secondary-start (make-marker))) | |
550 | (move-marker mouse-secondary-start (posn-point posn))))))) | |
e66feb07 RS |
551 | |
552 | (defun mouse-set-secondary (click) | |
553 | "Set the secondary selection to the text that the mouse is dragged over. | |
554 | This must be bound to a mouse drag event." | |
555 | (interactive "e") | |
d65147f6 | 556 | (mouse-minibuffer-check click) |
e66feb07 RS |
557 | (let ((posn (event-start click)) |
558 | beg | |
559 | (end (event-end click))) | |
230aaa73 RS |
560 | (save-excursion |
561 | (set-buffer (window-buffer (posn-window posn))) | |
562 | (if (numberp (posn-point posn)) | |
563 | (setq beg (posn-point posn))) | |
564 | (if mouse-secondary-overlay | |
565 | (move-overlay mouse-secondary-overlay beg (posn-point end)) | |
566 | (setq mouse-secondary-overlay (make-overlay beg (posn-point end)))) | |
567 | (overlay-put mouse-secondary-overlay 'face 'secondary-selection)))) | |
947da0c4 | 568 | |
d89a4a47 | 569 | (defun mouse-drag-secondary (start-event) |
e66feb07 | 570 | "Set the secondary selection to the text that the mouse is dragged over. |
d89a4a47 | 571 | Highlight the drag area as you move the mouse. |
e66feb07 RS |
572 | This must be bound to a button-down mouse event." |
573 | (interactive "e") | |
d65147f6 | 574 | (mouse-minibuffer-check start-event) |
d89a4a47 RS |
575 | (let* ((start-posn (event-start start-event)) |
576 | (start-point (posn-point start-posn)) | |
577 | (start-window (posn-window start-posn)) | |
578 | (start-frame (window-frame start-window)) | |
579 | (bounds (window-edges start-window)) | |
580 | (top (nth 1 bounds)) | |
581 | (bottom (if (window-minibuffer-p start-window) | |
582 | (nth 3 bounds) | |
583 | ;; Don't count the mode line. | |
584 | (1- (nth 3 bounds)))) | |
585 | (click-count (1- (event-click-count start-event)))) | |
586 | (save-excursion | |
587 | (set-buffer (window-buffer start-window)) | |
588 | (setq mouse-selection-click-count click-count) | |
d89a4a47 RS |
589 | (or mouse-secondary-overlay |
590 | (setq mouse-secondary-overlay | |
591 | (make-overlay (point) (point)))) | |
26d280b9 | 592 | (overlay-put mouse-secondary-overlay 'face 'secondary-selection) |
9a974c88 | 593 | (if (> (mod click-count 3) 0) |
26d280b9 RS |
594 | ;; Double or triple press: make an initial selection |
595 | ;; of one word or line. | |
d89a4a47 RS |
596 | (let ((range (mouse-start-end start-point start-point click-count))) |
597 | (set-marker mouse-secondary-start nil) | |
598 | (move-overlay mouse-secondary-overlay 1 1 | |
599 | (window-buffer start-window)) | |
600 | (move-overlay mouse-secondary-overlay (car range) (nth 1 range) | |
601 | (window-buffer start-window))) | |
26d280b9 | 602 | ;; Single-press: cancel any preexisting secondary selection. |
d89a4a47 RS |
603 | (or mouse-secondary-start |
604 | (setq mouse-secondary-start (make-marker))) | |
605 | (set-marker mouse-secondary-start start-point) | |
606 | (delete-overlay mouse-secondary-overlay)) | |
607 | (let (event end end-point) | |
608 | (track-mouse | |
609 | (while (progn | |
610 | (setq event (read-event)) | |
611 | (or (mouse-movement-p event) | |
612 | (eq (car-safe event) 'switch-frame))) | |
613 | ||
614 | (if (eq (car-safe event) 'switch-frame) | |
615 | nil | |
616 | (setq end (event-end event) | |
617 | end-point (posn-point end)) | |
618 | (cond | |
619 | ||
620 | ;; Ignore switch-frame events. | |
621 | ((eq (car-safe event) 'switch-frame)) | |
622 | ||
623 | ;; Are we moving within the original window? | |
624 | ((and (eq (posn-window end) start-window) | |
625 | (integer-or-marker-p end-point)) | |
626 | (if (/= start-point end-point) | |
627 | (set-marker mouse-secondary-start nil)) | |
628 | (let ((range (mouse-start-end start-point end-point | |
629 | click-count))) | |
630 | (move-overlay mouse-secondary-overlay | |
631 | (car range) (nth 1 range)))) | |
632 | ||
633 | ;; Are we moving on a different window on the same frame? | |
634 | ((and (windowp (posn-window end)) | |
635 | (eq (window-frame (posn-window end)) start-frame)) | |
636 | (let ((mouse-row | |
637 | (+ (nth 1 (window-edges (posn-window end))) | |
638 | (cdr (posn-col-row end))))) | |
639 | (cond | |
640 | ((< mouse-row top) | |
641 | (mouse-scroll-subr | |
642 | (- mouse-row top) mouse-secondary-overlay start-point)) | |
643 | ((and (not (eobp)) | |
644 | (>= mouse-row bottom)) | |
645 | (mouse-scroll-subr (1+ (- mouse-row bottom)) | |
646 | mouse-drag-overlay start-point))))) | |
647 | ||
648 | (t | |
649 | (let ((mouse-y (cdr (cdr (mouse-position)))) | |
650 | (menu-bar-lines (or (cdr (assq 'menu-bar-lines | |
651 | (frame-parameters))) | |
652 | 0))) | |
653 | ||
654 | ;; Are we on the menu bar? | |
655 | (and (integerp mouse-y) (< mouse-y menu-bar-lines) | |
656 | (mouse-scroll-subr (- mouse-y menu-bar-lines) | |
657 | mouse-secondary-overlay start-point)))))))) | |
658 | ||
659 | (if (and (eq (get (event-basic-type event) 'event-kind) 'mouse-click) | |
660 | (eq (posn-window (event-end event)) start-window) | |
661 | (numberp (posn-point (event-end event)))) | |
662 | (if (marker-position mouse-secondary-start) | |
663 | (save-window-excursion | |
664 | (delete-overlay mouse-secondary-overlay) | |
9a974c88 | 665 | (x-set-selection 'SECONDARY nil) |
d89a4a47 RS |
666 | (select-window start-window) |
667 | (save-excursion | |
668 | (goto-char mouse-secondary-start) | |
669 | (sit-for 1))) | |
9a974c88 RS |
670 | (x-set-selection |
671 | 'SECONDARY | |
672 | (buffer-substring (overlay-start mouse-secondary-overlay) | |
673 | (overlay-end mouse-secondary-overlay))))))))) | |
e66feb07 | 674 | |
9a974c88 | 675 | (defun mouse-yank-secondary (click) |
50f58001 RS |
676 | "Insert the secondary selection at the position clicked on. |
677 | Move point to the end of the inserted text. | |
678 | If `mouse-yank-at-point' is non-nil, insert at point | |
679 | regardless of where you click." | |
9a974c88 | 680 | (interactive "e") |
50f58001 RS |
681 | (or mouse-yank-at-point (mouse-set-point click)) |
682 | (insert (x-get-selection 'SECONDARY))) | |
9a974c88 | 683 | |
7e6404f6 | 684 | (defun mouse-kill-secondary () |
9a974c88 RS |
685 | "Kill the text in the secondary selection. |
686 | This is intended more as a keyboard command than as a mouse command | |
687 | but it can work as either one. | |
688 | ||
689 | The current buffer (in case of keyboard use), or the buffer clicked on, | |
690 | must be the one that the secondary selection is in. This requirement | |
691 | is to prevent accidents." | |
7e6404f6 RS |
692 | (interactive) |
693 | (let* ((keys (this-command-keys)) | |
694 | (click (elt keys (1- (length keys))))) | |
695 | (or (eq (overlay-buffer mouse-secondary-overlay) | |
696 | (if (listp click) | |
697 | (window-buffer (posn-window (event-start click))) | |
698 | (current-buffer))) | |
699 | (error "Select or click on the buffer where the secondary selection is"))) | |
9a974c88 RS |
700 | (save-excursion |
701 | (set-buffer (overlay-buffer mouse-secondary-overlay)) | |
702 | (kill-region (overlay-start mouse-secondary-overlay) | |
703 | (overlay-end mouse-secondary-overlay))) | |
e66feb07 | 704 | (delete-overlay mouse-secondary-overlay) |
9a974c88 | 705 | (x-set-selection 'SECONDARY nil) |
e66feb07 RS |
706 | (setq mouse-secondary-overlay nil)) |
707 | ||
708 | (defun mouse-secondary-save-then-kill (click) | |
d89a4a47 | 709 | "Save text to point in kill ring; the second time, kill the text. |
7bbe2cc7 RS |
710 | You must use this in a buffer where you have recently done \\[mouse-start-secondary]. |
711 | If the text between where you did \\[mouse-start-secondary] and where | |
712 | you use this command matches the text at the front of the kill ring, | |
713 | this command deletes the text. | |
e66feb07 | 714 | Otherwise, it adds the text to the kill ring, like \\[kill-ring-save], |
7bbe2cc7 | 715 | which prepares for a second click with this command to delete the text. |
d89a4a47 | 716 | |
7bbe2cc7 RS |
717 | If you have already made a secondary selection in that buffer, |
718 | this command extends or retracts the selection to where you click. | |
719 | If you do this again in a different position, it extends or retracts | |
720 | again. If you do this twice in the same position, it kills the selection." | |
e66feb07 | 721 | (interactive "e") |
d65147f6 | 722 | (mouse-minibuffer-check click) |
d89a4a47 RS |
723 | (let ((posn (event-start click)) |
724 | (click-posn (posn-point (event-start click))) | |
e66feb07 RS |
725 | ;; Don't let a subsequent kill command append to this one: |
726 | ;; prevent setting this-command to kill-region. | |
727 | (this-command this-command)) | |
9a974c88 RS |
728 | (or (eq (window-buffer (posn-window posn)) |
729 | (or (and mouse-secondary-overlay | |
730 | (overlay-buffer mouse-secondary-overlay)) | |
731 | (if mouse-secondary-start | |
732 | (marker-buffer mouse-secondary-start)))) | |
733 | (error "Wrong buffer")) | |
734 | (save-excursion | |
735 | (set-buffer (window-buffer (posn-window posn))) | |
736 | (if (> (mod mouse-selection-click-count 3) 0) | |
737 | (if (not (and (eq last-command 'mouse-secondary-save-then-kill) | |
738 | (equal click-posn | |
739 | (car (cdr-safe (cdr-safe mouse-save-then-kill-posn)))))) | |
740 | ;; Find both ends of the object selected by this click. | |
741 | (let* ((range | |
742 | (mouse-start-end click-posn click-posn | |
743 | mouse-selection-click-count))) | |
744 | ;; Move whichever end is closer to the click. | |
745 | ;; That's what xterm does, and it seems reasonable. | |
746 | (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay))) | |
747 | (abs (- click-posn (overlay-end mouse-secondary-overlay)))) | |
748 | (move-overlay mouse-secondary-overlay (car range) | |
749 | (overlay-end mouse-secondary-overlay)) | |
d89a4a47 RS |
750 | (move-overlay mouse-secondary-overlay |
751 | (overlay-start mouse-secondary-overlay) | |
752 | (nth 1 range))) | |
9a974c88 RS |
753 | ;; We have already put the old region in the kill ring. |
754 | ;; Replace it with the extended region. | |
755 | ;; (It would be annoying to make a separate entry.) | |
756 | (setcar kill-ring (buffer-substring | |
757 | (overlay-start mouse-secondary-overlay) | |
758 | (overlay-end mouse-secondary-overlay))) | |
759 | (if interprogram-cut-function | |
760 | (funcall interprogram-cut-function (car kill-ring))) | |
761 | ;; Arrange for a repeated mouse-3 to kill this region. | |
762 | (setq mouse-save-then-kill-posn | |
763 | (list (car kill-ring) (point) click-posn))) | |
764 | ;; If we click this button again without moving it, | |
765 | ;; that time kill. | |
d89a4a47 | 766 | (progn |
9a974c88 RS |
767 | (mouse-save-then-kill-delete-region |
768 | (overlay-start mouse-secondary-overlay) | |
769 | (overlay-end mouse-secondary-overlay)) | |
770 | (setq mouse-save-then-kill-posn nil) | |
771 | (setq mouse-selection-click-count 0) | |
772 | (delete-overlay mouse-secondary-overlay))) | |
773 | (if (and (eq last-command 'mouse-secondary-save-then-kill) | |
774 | mouse-save-then-kill-posn | |
775 | (eq (car mouse-save-then-kill-posn) (car kill-ring)) | |
776 | (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn))) | |
777 | ;; If this is the second time we've called | |
778 | ;; mouse-secondary-save-then-kill, delete the text from the buffer. | |
779 | (progn | |
780 | (mouse-save-then-kill-delete-region | |
781 | (overlay-start mouse-secondary-overlay) | |
782 | (overlay-end mouse-secondary-overlay)) | |
783 | (setq mouse-save-then-kill-posn nil) | |
784 | (delete-overlay mouse-secondary-overlay)) | |
785 | (if (overlay-start mouse-secondary-overlay) | |
786 | ;; We have a selection, so adjust it. | |
787 | (progn | |
788 | (if (numberp click-posn) | |
789 | (progn | |
790 | ;; Move whichever end of the region is closer to the click. | |
791 | ;; That is what xterm does, and it seems reasonable. | |
792 | (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay))) | |
793 | (abs (- click-posn (overlay-end mouse-secondary-overlay)))) | |
794 | (move-overlay mouse-secondary-overlay click-posn | |
795 | (overlay-end mouse-secondary-overlay)) | |
d89a4a47 RS |
796 | (move-overlay mouse-secondary-overlay |
797 | (overlay-start mouse-secondary-overlay) | |
798 | click-posn)) | |
9a974c88 RS |
799 | (setq deactivate-mark nil))) |
800 | (setcar kill-ring (buffer-substring | |
801 | (overlay-start mouse-secondary-overlay) | |
802 | (overlay-end mouse-secondary-overlay))) | |
803 | (if interprogram-cut-function | |
804 | (funcall interprogram-cut-function (car kill-ring)))) | |
805 | (if mouse-secondary-start | |
806 | ;; All we have is one end of a selection, | |
807 | ;; so put the other end here. | |
808 | (let ((start (+ 0 mouse-secondary-start))) | |
809 | (kill-ring-save start click-posn) | |
810 | (if mouse-secondary-overlay | |
811 | (move-overlay mouse-secondary-overlay start click-posn) | |
812 | (setq mouse-secondary-overlay (make-overlay start click-posn))) | |
813 | (overlay-put mouse-secondary-overlay 'face 'secondary-selection)))) | |
814 | (setq mouse-save-then-kill-posn | |
815 | (list (car kill-ring) (point) click-posn)))) | |
816 | (x-set-selection 'SECONDARY | |
817 | (if (overlay-buffer mouse-secondary-overlay) | |
818 | (buffer-substring | |
819 | (overlay-start mouse-secondary-overlay) | |
820 | (overlay-end mouse-secondary-overlay))))))) | |
e66feb07 | 821 | \f |
8b34e79d | 822 | (defun mouse-buffer-menu (event) |
2d82f7b9 RS |
823 | "Pop up a menu of buffers for selection with the mouse. |
824 | This switches buffers in the window that you clicked on, | |
825 | and selects that window." | |
ec558adc | 826 | (interactive "e") |
d65147f6 | 827 | (mouse-minibuffer-check event) |
8b34e79d RS |
828 | (let ((menu |
829 | (list "Buffer Menu" | |
830 | (cons "Select Buffer" | |
831 | (let ((tail (buffer-list)) | |
af2a85fe | 832 | (maxbuf 0) |
8b34e79d | 833 | head) |
af2a85fe RS |
834 | (while tail |
835 | (or (eq ?\ (aref (buffer-name (car tail)) 0)) | |
836 | (setq maxbuf | |
837 | (max maxbuf | |
838 | (length (buffer-name (car tail)))))) | |
839 | (setq tail (cdr tail))) | |
840 | (setq tail (buffer-list)) | |
8b34e79d RS |
841 | (while tail |
842 | (let ((elt (car tail))) | |
843 | (if (not (string-match "^ " | |
844 | (buffer-name elt))) | |
845 | (setq head (cons | |
846 | (cons | |
847 | (format | |
af2a85fe RS |
848 | (format "%%%ds %%s%%s %%s" |
849 | maxbuf) | |
8b34e79d | 850 | (buffer-name elt) |
af2a85fe RS |
851 | (if (buffer-modified-p elt) |
852 | "*" " ") | |
853 | (save-excursion | |
854 | (set-buffer elt) | |
855 | (if buffer-read-only "%" " ")) | |
8b34e79d RS |
856 | (or (buffer-file-name elt) "")) |
857 | elt) | |
858 | head)))) | |
859 | (setq tail (cdr tail))) | |
860 | (reverse head)))))) | |
2d82f7b9 RS |
861 | (let ((buf (x-popup-menu event menu)) |
862 | (window (posn-window (event-start event)))) | |
863 | (if buf | |
864 | (progn | |
c0bb9f3b | 865 | (or (framep window) (select-window window)) |
2d82f7b9 | 866 | (switch-to-buffer buf)))))) |
72ea54a4 | 867 | \f |
5ba2dc3f | 868 | ;;; These need to be rewritten for the new scroll bar implementation. |
dbc4e1c1 JB |
869 | |
870 | ;;;!! ;; Commands for the scroll bar. | |
871 | ;;;!! | |
872 | ;;;!! (defun mouse-scroll-down (click) | |
873 | ;;;!! (interactive "@e") | |
874 | ;;;!! (scroll-down (1+ (cdr (mouse-coords click))))) | |
875 | ;;;!! | |
876 | ;;;!! (defun mouse-scroll-up (click) | |
877 | ;;;!! (interactive "@e") | |
878 | ;;;!! (scroll-up (1+ (cdr (mouse-coords click))))) | |
879 | ;;;!! | |
880 | ;;;!! (defun mouse-scroll-down-full () | |
881 | ;;;!! (interactive "@") | |
882 | ;;;!! (scroll-down nil)) | |
883 | ;;;!! | |
884 | ;;;!! (defun mouse-scroll-up-full () | |
885 | ;;;!! (interactive "@") | |
886 | ;;;!! (scroll-up nil)) | |
887 | ;;;!! | |
888 | ;;;!! (defun mouse-scroll-move-cursor (click) | |
889 | ;;;!! (interactive "@e") | |
890 | ;;;!! (move-to-window-line (1+ (cdr (mouse-coords click))))) | |
891 | ;;;!! | |
892 | ;;;!! (defun mouse-scroll-absolute (event) | |
893 | ;;;!! (interactive "@e") | |
894 | ;;;!! (let* ((pos (car event)) | |
895 | ;;;!! (position (car pos)) | |
896 | ;;;!! (length (car (cdr pos)))) | |
897 | ;;;!! (if (<= length 0) (setq length 1)) | |
898 | ;;;!! (let* ((scale-factor (max 1 (/ length (/ 8000000 (buffer-size))))) | |
899 | ;;;!! (newpos (* (/ (* (/ (buffer-size) scale-factor) | |
900 | ;;;!! position) | |
901 | ;;;!! length) | |
902 | ;;;!! scale-factor))) | |
903 | ;;;!! (goto-char newpos) | |
904 | ;;;!! (recenter '(4))))) | |
905 | ;;;!! | |
906 | ;;;!! (defun mouse-scroll-left (click) | |
907 | ;;;!! (interactive "@e") | |
908 | ;;;!! (scroll-left (1+ (car (mouse-coords click))))) | |
909 | ;;;!! | |
910 | ;;;!! (defun mouse-scroll-right (click) | |
911 | ;;;!! (interactive "@e") | |
912 | ;;;!! (scroll-right (1+ (car (mouse-coords click))))) | |
913 | ;;;!! | |
914 | ;;;!! (defun mouse-scroll-left-full () | |
915 | ;;;!! (interactive "@") | |
916 | ;;;!! (scroll-left nil)) | |
917 | ;;;!! | |
918 | ;;;!! (defun mouse-scroll-right-full () | |
919 | ;;;!! (interactive "@") | |
920 | ;;;!! (scroll-right nil)) | |
921 | ;;;!! | |
922 | ;;;!! (defun mouse-scroll-move-cursor-horizontally (click) | |
923 | ;;;!! (interactive "@e") | |
924 | ;;;!! (move-to-column (1+ (car (mouse-coords click))))) | |
925 | ;;;!! | |
926 | ;;;!! (defun mouse-scroll-absolute-horizontally (event) | |
927 | ;;;!! (interactive "@e") | |
928 | ;;;!! (let* ((pos (car event)) | |
929 | ;;;!! (position (car pos)) | |
930 | ;;;!! (length (car (cdr pos)))) | |
931 | ;;;!! (set-window-hscroll (selected-window) 33))) | |
932 | ;;;!! | |
933 | ;;;!! (global-set-key [scroll-bar mouse-1] 'mouse-scroll-up) | |
934 | ;;;!! (global-set-key [scroll-bar mouse-2] 'mouse-scroll-absolute) | |
935 | ;;;!! (global-set-key [scroll-bar mouse-3] 'mouse-scroll-down) | |
936 | ;;;!! | |
937 | ;;;!! (global-set-key [vertical-slider mouse-1] 'mouse-scroll-move-cursor) | |
938 | ;;;!! (global-set-key [vertical-slider mouse-2] 'mouse-scroll-move-cursor) | |
939 | ;;;!! (global-set-key [vertical-slider mouse-3] 'mouse-scroll-move-cursor) | |
940 | ;;;!! | |
941 | ;;;!! (global-set-key [thumbup mouse-1] 'mouse-scroll-up-full) | |
942 | ;;;!! (global-set-key [thumbup mouse-2] 'mouse-scroll-up-full) | |
943 | ;;;!! (global-set-key [thumbup mouse-3] 'mouse-scroll-up-full) | |
944 | ;;;!! | |
945 | ;;;!! (global-set-key [thumbdown mouse-1] 'mouse-scroll-down-full) | |
946 | ;;;!! (global-set-key [thumbdown mouse-2] 'mouse-scroll-down-full) | |
947 | ;;;!! (global-set-key [thumbdown mouse-3] 'mouse-scroll-down-full) | |
948 | ;;;!! | |
949 | ;;;!! (global-set-key [horizontal-scroll-bar mouse-1] 'mouse-scroll-left) | |
950 | ;;;!! (global-set-key [horizontal-scroll-bar mouse-2] | |
951 | ;;;!! 'mouse-scroll-absolute-horizontally) | |
952 | ;;;!! (global-set-key [horizontal-scroll-bar mouse-3] 'mouse-scroll-right) | |
953 | ;;;!! | |
954 | ;;;!! (global-set-key [horizontal-slider mouse-1] | |
955 | ;;;!! 'mouse-scroll-move-cursor-horizontally) | |
956 | ;;;!! (global-set-key [horizontal-slider mouse-2] | |
957 | ;;;!! 'mouse-scroll-move-cursor-horizontally) | |
958 | ;;;!! (global-set-key [horizontal-slider mouse-3] | |
959 | ;;;!! 'mouse-scroll-move-cursor-horizontally) | |
960 | ;;;!! | |
961 | ;;;!! (global-set-key [thumbleft mouse-1] 'mouse-scroll-left-full) | |
962 | ;;;!! (global-set-key [thumbleft mouse-2] 'mouse-scroll-left-full) | |
963 | ;;;!! (global-set-key [thumbleft mouse-3] 'mouse-scroll-left-full) | |
964 | ;;;!! | |
965 | ;;;!! (global-set-key [thumbright mouse-1] 'mouse-scroll-right-full) | |
966 | ;;;!! (global-set-key [thumbright mouse-2] 'mouse-scroll-right-full) | |
967 | ;;;!! (global-set-key [thumbright mouse-3] 'mouse-scroll-right-full) | |
968 | ;;;!! | |
969 | ;;;!! (global-set-key [horizontal-scroll-bar S-mouse-2] | |
970 | ;;;!! 'mouse-split-window-horizontally) | |
971 | ;;;!! (global-set-key [mode-line S-mouse-2] | |
972 | ;;;!! 'mouse-split-window-horizontally) | |
973 | ;;;!! (global-set-key [vertical-scroll-bar S-mouse-2] | |
974 | ;;;!! 'mouse-split-window) | |
6b2154de | 975 | \f |
dbc4e1c1 JB |
976 | ;;;!! ;;;; |
977 | ;;;!! ;;;; Here are experimental things being tested. Mouse events | |
978 | ;;;!! ;;;; are of the form: | |
979 | ;;;!! ;;;; ((x y) window screen-part key-sequence timestamp) | |
980 | ;;;!! ;; | |
981 | ;;;!! ;;;; | |
982 | ;;;!! ;;;; Dynamically track mouse coordinates | |
983 | ;;;!! ;;;; | |
984 | ;;;!! ;; | |
985 | ;;;!! ;;(defun track-mouse (event) | |
986 | ;;;!! ;; "Track the coordinates, absolute and relative, of the mouse." | |
987 | ;;;!! ;; (interactive "@e") | |
988 | ;;;!! ;; (while mouse-grabbed | |
989 | ;;;!! ;; (let* ((pos (read-mouse-position (selected-screen))) | |
990 | ;;;!! ;; (abs-x (car pos)) | |
991 | ;;;!! ;; (abs-y (cdr pos)) | |
992 | ;;;!! ;; (relative-coordinate (coordinates-in-window-p | |
993 | ;;;!! ;; (list (car pos) (cdr pos)) | |
994 | ;;;!! ;; (selected-window)))) | |
995 | ;;;!! ;; (if (consp relative-coordinate) | |
996 | ;;;!! ;; (message "mouse: [%d %d], (%d %d)" abs-x abs-y | |
997 | ;;;!! ;; (car relative-coordinate) | |
998 | ;;;!! ;; (car (cdr relative-coordinate))) | |
999 | ;;;!! ;; (message "mouse: [%d %d]" abs-x abs-y))))) | |
1000 | ;;;!! | |
1001 | ;;;!! ;; | |
1002 | ;;;!! ;; Dynamically put a box around the line indicated by point | |
1003 | ;;;!! ;; | |
1004 | ;;;!! ;; | |
1005 | ;;;!! ;;(require 'backquote) | |
1006 | ;;;!! ;; | |
1007 | ;;;!! ;;(defun mouse-select-buffer-line (event) | |
1008 | ;;;!! ;; (interactive "@e") | |
1009 | ;;;!! ;; (let ((relative-coordinate | |
1010 | ;;;!! ;; (coordinates-in-window-p (car event) (selected-window))) | |
1011 | ;;;!! ;; (abs-y (car (cdr (car event))))) | |
1012 | ;;;!! ;; (if (consp relative-coordinate) | |
1013 | ;;;!! ;; (progn | |
1014 | ;;;!! ;; (save-excursion | |
1015 | ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate))) | |
1016 | ;;;!! ;; (x-draw-rectangle | |
1017 | ;;;!! ;; (selected-screen) | |
1018 | ;;;!! ;; abs-y 0 | |
1019 | ;;;!! ;; (save-excursion | |
1020 | ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate))) | |
1021 | ;;;!! ;; (end-of-line) | |
1022 | ;;;!! ;; (push-mark nil t) | |
1023 | ;;;!! ;; (beginning-of-line) | |
1024 | ;;;!! ;; (- (region-end) (region-beginning))) 1)) | |
1025 | ;;;!! ;; (sit-for 1) | |
1026 | ;;;!! ;; (x-erase-rectangle (selected-screen)))))) | |
1027 | ;;;!! ;; | |
1028 | ;;;!! ;;(defvar last-line-drawn nil) | |
1029 | ;;;!! ;;(defvar begin-delim "[^ \t]") | |
1030 | ;;;!! ;;(defvar end-delim "[^ \t]") | |
1031 | ;;;!! ;; | |
1032 | ;;;!! ;;(defun mouse-boxing (event) | |
1033 | ;;;!! ;; (interactive "@e") | |
1034 | ;;;!! ;; (save-excursion | |
1035 | ;;;!! ;; (let ((screen (selected-screen))) | |
1036 | ;;;!! ;; (while (= (x-mouse-events) 0) | |
1037 | ;;;!! ;; (let* ((pos (read-mouse-position screen)) | |
1038 | ;;;!! ;; (abs-x (car pos)) | |
1039 | ;;;!! ;; (abs-y (cdr pos)) | |
1040 | ;;;!! ;; (relative-coordinate | |
1041 | ;;;!! ;; (coordinates-in-window-p (` ((, abs-x) (, abs-y))) | |
1042 | ;;;!! ;; (selected-window))) | |
1043 | ;;;!! ;; (begin-reg nil) | |
1044 | ;;;!! ;; (end-reg nil) | |
1045 | ;;;!! ;; (end-column nil) | |
1046 | ;;;!! ;; (begin-column nil)) | |
1047 | ;;;!! ;; (if (and (consp relative-coordinate) | |
1048 | ;;;!! ;; (or (not last-line-drawn) | |
1049 | ;;;!! ;; (not (= last-line-drawn abs-y)))) | |
1050 | ;;;!! ;; (progn | |
1051 | ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate))) | |
1052 | ;;;!! ;; (if (= (following-char) 10) | |
1053 | ;;;!! ;; () | |
1054 | ;;;!! ;; (progn | |
1055 | ;;;!! ;; (setq begin-reg (1- (re-search-forward end-delim))) | |
1056 | ;;;!! ;; (setq begin-column (1- (current-column))) | |
1057 | ;;;!! ;; (end-of-line) | |
1058 | ;;;!! ;; (setq end-reg (1+ (re-search-backward begin-delim))) | |
1059 | ;;;!! ;; (setq end-column (1+ (current-column))) | |
1060 | ;;;!! ;; (message "%s" (buffer-substring begin-reg end-reg)) | |
1061 | ;;;!! ;; (x-draw-rectangle screen | |
1062 | ;;;!! ;; (setq last-line-drawn abs-y) | |
1063 | ;;;!! ;; begin-column | |
1064 | ;;;!! ;; (- end-column begin-column) 1)))))))))) | |
1065 | ;;;!! ;; | |
1066 | ;;;!! ;;(defun mouse-erase-box () | |
1067 | ;;;!! ;; (interactive) | |
1068 | ;;;!! ;; (if last-line-drawn | |
1069 | ;;;!! ;; (progn | |
1070 | ;;;!! ;; (x-erase-rectangle (selected-screen)) | |
1071 | ;;;!! ;; (setq last-line-drawn nil)))) | |
1072 | ;;;!! | |
1073 | ;;;!! ;;; (defun test-x-rectangle () | |
1074 | ;;;!! ;;; (use-local-mouse-map (setq rectangle-test-map (make-sparse-keymap))) | |
1075 | ;;;!! ;;; (define-key rectangle-test-map mouse-motion-button-left 'mouse-boxing) | |
1076 | ;;;!! ;;; (define-key rectangle-test-map mouse-button-left-up 'mouse-erase-box)) | |
1077 | ;;;!! | |
1078 | ;;;!! ;; | |
1079 | ;;;!! ;; Here is how to do double clicking in lisp. About to change. | |
1080 | ;;;!! ;; | |
1081 | ;;;!! | |
1082 | ;;;!! (defvar double-start nil) | |
1083 | ;;;!! (defconst double-click-interval 300 | |
1084 | ;;;!! "Max ticks between clicks") | |
1085 | ;;;!! | |
1086 | ;;;!! (defun double-down (event) | |
1087 | ;;;!! (interactive "@e") | |
1088 | ;;;!! (if double-start | |
1089 | ;;;!! (let ((interval (- (nth 4 event) double-start))) | |
1090 | ;;;!! (if (< interval double-click-interval) | |
1091 | ;;;!! (progn | |
1092 | ;;;!! (backward-up-list 1) | |
1093 | ;;;!! ;; (message "Interval %d" interval) | |
1094 | ;;;!! (sleep-for 1))) | |
1095 | ;;;!! (setq double-start nil)) | |
1096 | ;;;!! (setq double-start (nth 4 event)))) | |
1097 | ;;;!! | |
1098 | ;;;!! (defun double-up (event) | |
1099 | ;;;!! (interactive "@e") | |
1100 | ;;;!! (and double-start | |
1101 | ;;;!! (> (- (nth 4 event ) double-start) double-click-interval) | |
1102 | ;;;!! (setq double-start nil))) | |
1103 | ;;;!! | |
1104 | ;;;!! ;;; (defun x-test-doubleclick () | |
1105 | ;;;!! ;;; (use-local-mouse-map (setq doubleclick-test-map (make-sparse-keymap))) | |
1106 | ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left 'double-down) | |
1107 | ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left-up 'double-up)) | |
1108 | ;;;!! | |
1109 | ;;;!! ;; | |
5ba2dc3f | 1110 | ;;;!! ;; This scrolls while button is depressed. Use preferable in scroll bar. |
dbc4e1c1 JB |
1111 | ;;;!! ;; |
1112 | ;;;!! | |
1113 | ;;;!! (defvar scrolled-lines 0) | |
1114 | ;;;!! (defconst scroll-speed 1) | |
1115 | ;;;!! | |
1116 | ;;;!! (defun incr-scroll-down (event) | |
1117 | ;;;!! (interactive "@e") | |
1118 | ;;;!! (setq scrolled-lines 0) | |
1119 | ;;;!! (incremental-scroll scroll-speed)) | |
1120 | ;;;!! | |
1121 | ;;;!! (defun incr-scroll-up (event) | |
1122 | ;;;!! (interactive "@e") | |
1123 | ;;;!! (setq scrolled-lines 0) | |
1124 | ;;;!! (incremental-scroll (- scroll-speed))) | |
1125 | ;;;!! | |
1126 | ;;;!! (defun incremental-scroll (n) | |
1127 | ;;;!! (while (= (x-mouse-events) 0) | |
1128 | ;;;!! (setq scrolled-lines (1+ (* scroll-speed scrolled-lines))) | |
1129 | ;;;!! (scroll-down n) | |
1130 | ;;;!! (sit-for 300 t))) | |
1131 | ;;;!! | |
1132 | ;;;!! (defun incr-scroll-stop (event) | |
1133 | ;;;!! (interactive "@e") | |
1134 | ;;;!! (message "Scrolled %d lines" scrolled-lines) | |
1135 | ;;;!! (setq scrolled-lines 0) | |
1136 | ;;;!! (sleep-for 1)) | |
1137 | ;;;!! | |
1138 | ;;;!! ;;; (defun x-testing-scroll () | |
1139 | ;;;!! ;;; (let ((scrolling-map (function mouse-vertical-scroll-bar-prefix))) | |
1140 | ;;;!! ;;; (define-key scrolling-map mouse-button-left 'incr-scroll-down) | |
1141 | ;;;!! ;;; (define-key scrolling-map mouse-button-right 'incr-scroll-up) | |
1142 | ;;;!! ;;; (define-key scrolling-map mouse-button-left-up 'incr-scroll-stop) | |
1143 | ;;;!! ;;; (define-key scrolling-map mouse-button-right-up 'incr-scroll-stop))) | |
1144 | ;;;!! | |
1145 | ;;;!! ;; | |
1146 | ;;;!! ;; Some playthings suitable for picture mode? They need work. | |
1147 | ;;;!! ;; | |
1148 | ;;;!! | |
1149 | ;;;!! (defun mouse-kill-rectangle (event) | |
1150 | ;;;!! "Kill the rectangle between point and the mouse cursor." | |
1151 | ;;;!! (interactive "@e") | |
1152 | ;;;!! (let ((point-save (point))) | |
1153 | ;;;!! (save-excursion | |
1154 | ;;;!! (mouse-set-point event) | |
1155 | ;;;!! (push-mark nil t) | |
1156 | ;;;!! (if (> point-save (point)) | |
1157 | ;;;!! (kill-rectangle (point) point-save) | |
1158 | ;;;!! (kill-rectangle point-save (point)))))) | |
1159 | ;;;!! | |
1160 | ;;;!! (defun mouse-open-rectangle (event) | |
1161 | ;;;!! "Kill the rectangle between point and the mouse cursor." | |
1162 | ;;;!! (interactive "@e") | |
1163 | ;;;!! (let ((point-save (point))) | |
1164 | ;;;!! (save-excursion | |
1165 | ;;;!! (mouse-set-point event) | |
1166 | ;;;!! (push-mark nil t) | |
1167 | ;;;!! (if (> point-save (point)) | |
1168 | ;;;!! (open-rectangle (point) point-save) | |
1169 | ;;;!! (open-rectangle point-save (point)))))) | |
1170 | ;;;!! | |
1171 | ;;;!! ;; Must be a better way to do this. | |
1172 | ;;;!! | |
1173 | ;;;!! (defun mouse-multiple-insert (n char) | |
1174 | ;;;!! (while (> n 0) | |
1175 | ;;;!! (insert char) | |
1176 | ;;;!! (setq n (1- n)))) | |
1177 | ;;;!! | |
1178 | ;;;!! ;; What this could do is not finalize until button was released. | |
1179 | ;;;!! | |
1180 | ;;;!! (defun mouse-move-text (event) | |
1181 | ;;;!! "Move text from point to cursor position, inserting spaces." | |
1182 | ;;;!! (interactive "@e") | |
1183 | ;;;!! (let* ((relative-coordinate | |
1184 | ;;;!! (coordinates-in-window-p (car event) (selected-window)))) | |
1185 | ;;;!! (if (consp relative-coordinate) | |
1186 | ;;;!! (cond ((> (current-column) (car relative-coordinate)) | |
1187 | ;;;!! (delete-char | |
1188 | ;;;!! (- (car relative-coordinate) (current-column)))) | |
1189 | ;;;!! ((< (current-column) (car relative-coordinate)) | |
1190 | ;;;!! (mouse-multiple-insert | |
1191 | ;;;!! (- (car relative-coordinate) (current-column)) " ")) | |
1192 | ;;;!! ((= (current-column) (car relative-coordinate)) (ding)))))) | |
07a78410 | 1193 | \f |
f936ae06 RS |
1194 | ;; Choose a completion with the mouse. |
1195 | ||
1196 | (defun mouse-choose-completion (event) | |
49e61c42 | 1197 | "Click on an alternative in the `*Completions*' buffer to choose it." |
f936ae06 | 1198 | (interactive "e") |
d89a4a47 RS |
1199 | (let ((buffer (window-buffer)) |
1200 | choice) | |
f936ae06 RS |
1201 | (save-excursion |
1202 | (set-buffer (window-buffer (posn-window (event-start event)))) | |
f36f4e9e RS |
1203 | (if completion-reference-buffer |
1204 | (setq buffer completion-reference-buffer)) | |
f936ae06 RS |
1205 | (save-excursion |
1206 | (goto-char (posn-point (event-start event))) | |
1207 | (skip-chars-backward "^ \t\n") | |
1208 | (let ((beg (point))) | |
1209 | (skip-chars-forward "^ \t\n") | |
1210 | (setq choice (buffer-substring beg (point)))))) | |
73e2025f RS |
1211 | (let ((owindow (selected-window))) |
1212 | (select-window (posn-window (event-start event))) | |
1213 | (bury-buffer) | |
1214 | (select-window owindow)) | |
40fc4836 | 1215 | (choose-completion-string choice buffer))) |
f936ae06 | 1216 | \f |
07a78410 RS |
1217 | ;; Font selection. |
1218 | ||
0eb9fef3 RS |
1219 | (defun font-menu-add-default () |
1220 | (let* ((default (cdr (assq 'font (frame-parameters (selected-frame))))) | |
1221 | (font-alist x-fixed-font-alist) | |
0d94f5ca | 1222 | (elt (or (assoc "Misc" font-alist) (nth 1 font-alist)))) |
0eb9fef3 RS |
1223 | (if (assoc "Default" elt) |
1224 | (delete (assoc "Default" elt) elt)) | |
1225 | (setcdr elt | |
3d64d15b | 1226 | (cons (list "Default" |
0eb9fef3 RS |
1227 | (cdr (assq 'font (frame-parameters (selected-frame))))) |
1228 | (cdr elt))))) | |
1229 | ||
07a78410 RS |
1230 | (defvar x-fixed-font-alist |
1231 | '("Font menu" | |
1232 | ("Misc" | |
1900a92b RS |
1233 | ("6x10" "-misc-fixed-medium-r-normal--10-100-75-75-c-60-*-1" "6x10") |
1234 | ("6x12" "-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-*-1" "6x12") | |
1235 | ("6x13" "-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-*-1" "6x13") | |
fa21fdec RS |
1236 | ("lucida 13" |
1237 | "-b&h-lucidatypewriter-medium-r-normal-sans-0-0-0-0-m-0-*-1") | |
1900a92b RS |
1238 | ("7x13" "-misc-fixed-medium-r-normal--13-120-75-75-c-70-*-1" "7x13") |
1239 | ("7x14" "-misc-fixed-medium-r-normal--14-130-75-75-c-70-*-1" "7x14") | |
1240 | ("9x15" "-misc-fixed-medium-r-normal--15-140-*-*-c-*-*-1" "9x15") | |
fa21fdec RS |
1241 | ("") |
1242 | ("clean 8x8" "-schumacher-clean-medium-r-normal--*-80-*-*-c-*-*-1") | |
1243 | ("clean 8x14" "-schumacher-clean-medium-r-normal--*-140-*-*-c-*-*-1") | |
1244 | ("clean 8x10" "-schumacher-clean-medium-r-normal--*-100-*-*-c-*-*-1") | |
1245 | ("clean 8x16" "-schumacher-clean-medium-r-normal--*-160-*-*-c-*-*-1") | |
1246 | ("") | |
1247 | ("sony 8x16" "-sony-fixed-medium-r-normal--16-120-100-100-c-80-*-1") | |
1248 | ("") | |
07a78410 | 1249 | ("fixed" "fixed") |
07a78410 RS |
1250 | ("10x20" "10x20") |
1251 | ("11x18" "11x18") | |
1252 | ("12x24" "12x24")) | |
1253 | ;;; We don't seem to have these; who knows what they are. | |
1254 | ;;; ("fg-18" "fg-18") | |
1255 | ;;; ("fg-25" "fg-25") | |
1256 | ;;; ("lucidasanstypewriter-12" "lucidasanstypewriter-12") | |
1257 | ;;; ("lucidasanstypewriter-bold-14" "lucidasanstypewriter-bold-14") | |
1258 | ;;; ("lucidasanstypewriter-bold-24" "lucidasanstypewriter-bold-24") | |
1259 | ;;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1") | |
1260 | ;;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*") | |
1261 | ("Courier" | |
82c048a9 RS |
1262 | ("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1") |
1263 | ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1") | |
1264 | ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1") | |
1265 | ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1") | |
1266 | ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1") | |
1267 | ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1") | |
1268 | ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1") | |
1269 | ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1") | |
1270 | ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1") | |
1271 | ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1") | |
1272 | ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1") | |
1273 | ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1") | |
1274 | ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1") | |
1275 | ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1") | |
1276 | ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1") | |
1277 | ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1") | |
1278 | ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1") | |
1279 | ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1") | |
1280 | ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1") | |
1281 | ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1") | |
1282 | ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1") | |
1283 | ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1") | |
1284 | ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1") | |
1285 | ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1")) | |
07a78410 RS |
1286 | ) |
1287 | "X fonts suitable for use in Emacs.") | |
1288 | ||
1900a92b | 1289 | (defun mouse-set-font (&rest fonts) |
07a78410 RS |
1290 | "Select an emacs font from a list of known good fonts" |
1291 | (interactive | |
1292 | (x-popup-menu last-nonmenu-event x-fixed-font-alist)) | |
df4de8c6 KH |
1293 | (if fonts |
1294 | (let (font) | |
1295 | (while fonts | |
1296 | (condition-case nil | |
1297 | (progn | |
3fadec1a | 1298 | (set-default-font (car fonts)) |
df4de8c6 KH |
1299 | (setq font (car fonts)) |
1300 | (setq fonts nil)) | |
3fadec1a RS |
1301 | (error |
1302 | (setq fonts (cdr fonts))))) | |
df4de8c6 | 1303 | (if (null font) |
3fadec1a | 1304 | (error "Font not found"))))) |
cc0a8174 JB |
1305 | \f |
1306 | ;;; Bindings for mouse commands. | |
1307 | ||
fcfc3c63 | 1308 | (define-key global-map [down-mouse-1] 'mouse-drag-region) |
dbc4e1c1 | 1309 | (global-set-key [mouse-1] 'mouse-set-point) |
dbc4e1c1 | 1310 | (global-set-key [drag-mouse-1] 'mouse-set-region) |
fcfc3c63 | 1311 | |
e37de120 RS |
1312 | ;; These are tested for in mouse-drag-region. |
1313 | (global-set-key [double-mouse-1] 'mouse-set-point) | |
1314 | (global-set-key [triple-mouse-1] 'mouse-set-point) | |
1315 | ||
dbc4e1c1 JB |
1316 | (global-set-key [mouse-2] 'mouse-yank-at-click) |
1317 | (global-set-key [mouse-3] 'mouse-save-then-kill) | |
8b34e79d | 1318 | |
dbc4e1c1 JB |
1319 | ;; By binding these to down-going events, we let the user use the up-going |
1320 | ;; event to make the selection, saving a click. | |
1321 | (global-set-key [C-down-mouse-1] 'mouse-buffer-menu) | |
1322 | (global-set-key [C-down-mouse-3] 'mouse-set-font) | |
07a78410 | 1323 | |
8b34e79d RS |
1324 | ;; Replaced with dragging mouse-1 |
1325 | ;; (global-set-key [S-mouse-1] 'mouse-set-mark) | |
947da0c4 | 1326 | |
3c2dd2c0 RS |
1327 | (global-set-key [mode-line mouse-1] 'mouse-select-window) |
1328 | (global-set-key [mode-line mouse-2] 'mouse-delete-other-windows) | |
dbc4e1c1 | 1329 | (global-set-key [mode-line mouse-3] 'mouse-delete-window) |
3c2dd2c0 | 1330 | (global-set-key [mode-line C-mouse-2] 'mouse-split-window-horizontally) |
49116ac0 JB |
1331 | |
1332 | (provide 'mouse) | |
1333 | ||
6594deb0 | 1334 | ;;; mouse.el ends here |