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