Fix bug in determination of output string.
[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
600c6e3a 383(defun mouse-drag-region (start-event)
bcd5aef1 384 "Set the region to the text that the mouse is dragged over.
78210c95
RS
385Highlight the drag area as you move the mouse.
386This must be bound to a button-down mouse event.
387In Transient Mark mode, the highlighting remains once you
388release the mouse button. Otherwise, it does not."
bcd5aef1 389 (interactive "e")
d65147f6 390 (mouse-minibuffer-check start-event)
600c6e3a
JB
391 (let* ((start-posn (event-start start-event))
392 (start-point (posn-point start-posn))
393 (start-window (posn-window start-posn))
b846d039 394 (start-frame (window-frame start-window))
600c6e3a
JB
395 (bounds (window-edges start-window))
396 (top (nth 1 bounds))
397 (bottom (if (window-minibuffer-p start-window)
398 (nth 3 bounds)
399 ;; Don't count the mode line.
e37de120
RS
400 (1- (nth 3 bounds))))
401 (click-count (1- (event-click-count start-event))))
eb6ff46f 402 (setq mouse-selection-click-count click-count)
b80f1928 403 (mouse-set-point start-event)
e37de120
RS
404 (let ((range (mouse-start-end start-point start-point click-count)))
405 (move-overlay mouse-drag-overlay (car range) (nth 1 range)
406 (window-buffer start-window)))
f767385c 407 (deactivate-mark)
600c6e3a 408 (let (event end end-point)
bcd5aef1 409 (track-mouse
600c6e3a 410 (while (progn
b846d039
JB
411 (setq event (read-event))
412 (or (mouse-movement-p event)
413 (eq (car-safe event) 'switch-frame)))
b846d039
JB
414 (if (eq (car-safe event) 'switch-frame)
415 nil
416 (setq end (event-end event)
417 end-point (posn-point end))
418
419 (cond
b846d039
JB
420 ;; Are we moving within the original window?
421 ((and (eq (posn-window end) start-window)
422 (integer-or-marker-p end-point))
423 (goto-char end-point)
e37de120
RS
424 (let ((range (mouse-start-end start-point (point) click-count)))
425 (move-overlay mouse-drag-overlay (car range) (nth 1 range))))
b846d039 426
50e527bc
KH
427 (t
428 (let ((mouse-row (cdr (cdr (mouse-position)))))
b846d039 429 (cond
50e527bc 430 ((null mouse-row))
b846d039 431 ((< mouse-row top)
e919a622
RS
432 (mouse-scroll-subr start-window (- mouse-row top)
433 mouse-drag-overlay start-point))
d2287ded 434 ((>= mouse-row bottom)
e919a622 435 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
50e527bc 436 mouse-drag-overlay start-point)))))))))
4e399a53 437 (if (consp event)
e37de120 438 (let ((fun (key-binding (vector (car event)))))
bfbcf12e
RS
439 ;; Run the binding of the terminating up-event, if possible.
440 ;; In the case of a multiple click, it gives the wrong results,
441 ;; because it would fail to set up a region.
442 (if (and (= (mod mouse-selection-click-count 3) 0) (fboundp fun))
b64548c7
RS
443 (progn
444 (setq this-command fun)
e6c2f5d4
RS
445 ;; Delete the overlay before calling the function,
446 ;; because delete-overlay increases buffer-modified-tick.
447 (delete-overlay mouse-drag-overlay)
b64548c7 448 (funcall fun event))
44dc5252
RS
449 (if (not (= (overlay-start mouse-drag-overlay)
450 (overlay-end mouse-drag-overlay)))
451 (let (last-command this-command)
452 (push-mark (overlay-start mouse-drag-overlay) t t)
453 (goto-char (overlay-end mouse-drag-overlay))
e6c2f5d4
RS
454 (delete-overlay mouse-drag-overlay)
455 (copy-region-as-kill (point) (mark t))
456 (mouse-set-region-1))
44dc5252 457 (goto-char (overlay-end mouse-drag-overlay))
e6c2f5d4
RS
458 (setq this-command 'mouse-set-point)
459 (delete-overlay mouse-drag-overlay))))
460 (delete-overlay mouse-drag-overlay)))))
e37de120
RS
461\f
462;; Commands to handle xterm-style multiple clicks.
600c6e3a 463
e37de120
RS
464(defun mouse-skip-word (dir)
465 "Skip over word, over whitespace, or over identical punctuation.
466If DIR is positive skip forward; if negative, skip backward."
467 (let* ((char (following-char))
468 (syntax (char-to-string (char-syntax char))))
469 (if (or (string= syntax "w") (string= syntax " "))
470 (if (< dir 0)
471 (skip-syntax-backward syntax)
472 (skip-syntax-forward syntax))
473 (if (< dir 0)
d89a4a47 474 (while (and (not (bobp)) (= (preceding-char) char))
e37de120 475 (forward-char -1))
d89a4a47 476 (while (and (not (eobp)) (= (following-char) char))
e37de120
RS
477 (forward-char 1))))))
478
479;; Return a list of region bounds based on START and END according to MODE.
480;; If MODE is 0 then set point to (min START END), mark to (max START END).
481;; If MODE is 1 then set point to start of word at (min START END),
482;; mark to end of word at (max START END).
483;; If MODE is 2 then do the same for lines.
eb6ff46f 484(defun mouse-start-end (start end mode)
e37de120
RS
485 (if (> start end)
486 (let ((temp start))
487 (setq start end
488 end temp)))
9a974c88 489 (setq mode (mod mode 3))
e37de120
RS
490 (cond ((= mode 0)
491 (list start end))
492 ((and (= mode 1)
493 (= start end)
1ec71583 494 (char-after start)
e37de120 495 (= (char-syntax (char-after start)) ?\())
6f482eec
RS
496 (list start
497 (save-excursion
498 (goto-char start)
499 (forward-sexp 1)
500 (point))))
e37de120
RS
501 ((and (= mode 1)
502 (= start end)
1ec71583 503 (char-after start)
e37de120
RS
504 (= (char-syntax (char-after start)) ?\)))
505 (list (save-excursion
506 (goto-char (1+ start))
d89a4a47
RS
507 (backward-sexp 1)
508 (point))
e37de120
RS
509 (1+ start)))
510 ((= mode 1)
511 (list (save-excursion
512 (goto-char start)
513 (mouse-skip-word -1)
514 (point))
515 (save-excursion
516 (goto-char end)
517 (mouse-skip-word 1)
518 (point))))
519 ((= mode 2)
520 (list (save-excursion
521 (goto-char start)
522 (beginning-of-line 1)
523 (point))
524 (save-excursion
525 (goto-char end)
526 (forward-line 1)
527 (point))))))
e66feb07 528\f
3f26b32a
RS
529;; Subroutine: set the mark where CLICK happened,
530;; but don't do anything else.
531(defun mouse-set-mark-fast (click)
d65147f6 532 (mouse-minibuffer-check click)
3f26b32a
RS
533 (let ((posn (event-start click)))
534 (select-window (posn-window posn))
535 (if (numberp (posn-point posn))
536 (push-mark (posn-point posn) t t))))
537
538;; Momentarily show where the mark is, if highlighting doesn't show it.
539(defun mouse-show-mark ()
540 (or transient-mark-mode
541 (save-excursion
542 (goto-char (mark t))
543 (sit-for 1))))
544
cc0a8174
JB
545(defun mouse-set-mark (click)
546 "Set mark at the position clicked on with the mouse.
547Display cursor at that position for a second.
548This must be bound to a mouse click."
ec558adc 549 (interactive "e")
f598fb03
RS
550 (mouse-minibuffer-check click)
551 (select-window (posn-window (event-start click)))
552 ;; We don't use save-excursion because that preserves the mark too.
72ea54a4
RS
553 (let ((point-save (point)))
554 (unwind-protect
cc0a8174 555 (progn (mouse-set-point click)
897897e3
RS
556 (push-mark nil t t)
557 (or transient-mark-mode
558 (sit-for 1)))
72ea54a4
RS
559 (goto-char point-save))))
560
cc0a8174
JB
561(defun mouse-kill (click)
562 "Kill the region between point and the mouse click.
563The text is saved in the kill ring, as with \\[kill-region]."
ec558adc 564 (interactive "e")
d65147f6 565 (mouse-minibuffer-check click)
142c7672
KH
566 (let* ((posn (event-start click))
567 (click-posn (posn-point posn)))
568 (select-window (posn-window posn))
bd307392
JB
569 (if (numberp click-posn)
570 (kill-region (min (point) click-posn)
571 (max (point) click-posn)))))
72ea54a4 572
87ef29fd
JB
573(defun mouse-yank-at-click (click arg)
574 "Insert the last stretch of killed text at the position clicked on.
50f58001
RS
575Also move point to one end of the text thus inserted (normally the end).
576Prefix arguments are interpreted as with \\[yank].
577If `mouse-yank-at-point' is non-nil, insert at point
578regardless of where you click."
ec558adc 579 (interactive "e\nP")
33c448cd
RS
580 ;; Give temporary modes such as isearch a chance to turn off.
581 (run-hooks 'mouse-leave-buffer-hook)
50f58001 582 (or mouse-yank-at-point (mouse-set-point click))
d89a4a47 583 (setq this-command 'yank)
87ef29fd
JB
584 (yank arg))
585
586(defun mouse-kill-ring-save (click)
cc0a8174
JB
587 "Copy the region between point and the mouse click in the kill ring.
588This does not delete the region; it acts like \\[kill-ring-save]."
ec558adc 589 (interactive "e")
3f26b32a 590 (mouse-set-mark-fast click)
6452d8a6
RS
591 (let (this-command last-command)
592 (kill-ring-save (point) (mark t)))
3f26b32a 593 (mouse-show-mark))
72ea54a4 594
dbc4e1c1
JB
595;;; This function used to delete the text between point and the mouse
596;;; whenever it was equal to the front of the kill ring, but some
597;;; people found that confusing.
598
599;;; A list (TEXT START END), describing the text and position of the last
600;;; invocation of mouse-save-then-kill.
601(defvar mouse-save-then-kill-posn nil)
602
26d280b9 603(defun mouse-save-then-kill-delete-region (beg end)
9a974c88
RS
604 ;; We must make our own undo boundaries
605 ;; because they happen automatically only for the current buffer.
606 (undo-boundary)
dd524dbd
RS
607 (if (or (= beg end) (eq buffer-undo-list t))
608 ;; If we have no undo list in this buffer,
609 ;; just delete.
610 (delete-region beg end)
611 ;; Delete, but make the undo-list entry share with the kill ring.
612 ;; First, delete just one char, so in case buffer is being modified
613 ;; for the first time, the undo list records that fact.
2f4b15ef
RS
614 (let (before-change-function after-change-function
615 before-change-functions after-change-functions)
616 (delete-region beg
617 (+ beg (if (> end beg) 1 -1))))
dd524dbd
RS
618 (let ((buffer-undo-list buffer-undo-list))
619 ;; Undo that deletion--but don't change the undo list!
2f4b15ef
RS
620 (let (before-change-function after-change-function
621 before-change-functions after-change-functions)
622 (primitive-undo 1 buffer-undo-list))
dd524dbd
RS
623 ;; Now delete the rest of the specified region,
624 ;; but don't record it.
625 (setq buffer-undo-list t)
9a974c88
RS
626 (if (/= (length (car kill-ring)) (- (max end beg) (min end beg)))
627 (error "Lossage in mouse-save-then-kill-delete-region"))
dd524dbd
RS
628 (delete-region beg end))
629 (let ((tail buffer-undo-list))
630 ;; Search back in buffer-undo-list for the string
631 ;; that came from deleting one character.
632 (while (and tail (not (stringp (car (car tail)))))
633 (setq tail (cdr tail)))
634 ;; Replace it with an entry for the entire deleted text.
635 (and tail
9a974c88
RS
636 (setcar tail (cons (car kill-ring) (min beg end))))))
637 (undo-boundary))
eb6ff46f 638
947da0c4 639(defun mouse-save-then-kill (click)
40a45a9f
RS
640 "Save text to point in kill ring; the second time, kill the text.
641If the text between point and the mouse is the same as what's
642at the front of the kill ring, this deletes the text.
643Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
eb6ff46f
RS
644which prepares for a second click to delete the text.
645
646If you have selected words or lines, this command extends the
647selection through the word or line clicked on. If you do this
648again in a different position, it extends the selection again.
649If you do this twice in the same position, the selection is killed."
947da0c4 650 (interactive "e")
b64548c7
RS
651 (let ((before-scroll point-before-scroll))
652 (mouse-minibuffer-check click)
653 (let ((click-posn (posn-point (event-start click)))
654 ;; Don't let a subsequent kill command append to this one:
655 ;; prevent setting this-command to kill-region.
656 (this-command this-command))
657 (if (and (mark t) (> (mod mouse-selection-click-count 3) 0))
658 (if (not (and (eq last-command 'mouse-save-then-kill)
659 (equal click-posn
660 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
661 ;; Find both ends of the object selected by this click.
662 (let* ((range
663 (mouse-start-end click-posn click-posn
664 mouse-selection-click-count)))
665 ;; Move whichever end is closer to the click.
666 ;; That's what xterm does, and it seems reasonable.
667 (if (< (abs (- click-posn (mark t)))
668 (abs (- click-posn (point))))
669 (set-mark (car range))
670 (goto-char (nth 1 range)))
671 ;; We have already put the old region in the kill ring.
672 ;; Replace it with the extended region.
673 ;; (It would be annoying to make a separate entry.)
674 (kill-new (buffer-substring (point) (mark t)) t)
e6c2f5d4 675 (mouse-set-region-1)
b64548c7
RS
676 ;; Arrange for a repeated mouse-3 to kill this region.
677 (setq mouse-save-then-kill-posn
678 (list (car kill-ring) (point) click-posn))
679 (mouse-show-mark))
680 ;; If we click this button again without moving it,
681 ;; that time kill.
bcde3748 682 (mouse-save-then-kill-delete-region (mark) (point))
b64548c7 683 (setq mouse-selection-click-count 0)
dd524dbd 684 (setq mouse-save-then-kill-posn nil))
b64548c7
RS
685 (if (and (eq last-command 'mouse-save-then-kill)
686 mouse-save-then-kill-posn
687 (eq (car mouse-save-then-kill-posn) (car kill-ring))
688 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
689 ;; If this is the second time we've called
690 ;; mouse-save-then-kill, delete the text from the buffer.
691 (progn
692 (mouse-save-then-kill-delete-region (point) (mark))
693 ;; After we kill, another click counts as "the first time".
694 (setq mouse-save-then-kill-posn nil))
695 (if (or (and (eq last-command 'mouse-save-then-kill)
696 mouse-save-then-kill-posn)
697 (and mark-active transient-mark-mode)
698 (and (memq last-command
699 '(mouse-drag-region mouse-set-region))
700 (or mark-even-if-inactive
701 (not transient-mark-mode))))
702 ;; We have a selection or suitable region, so adjust it.
703 (let* ((posn (event-start click))
704 (new (posn-point posn)))
705 (select-window (posn-window posn))
706 (if (numberp new)
707 (progn
708 ;; Move whichever end of the region is closer to the click.
709 ;; That is what xterm does, and it seems reasonable.
710 (if (< (abs (- new (point))) (abs (- new (mark t))))
711 (goto-char new)
712 (set-mark new))
713 (setq deactivate-mark nil)))
bcde3748
RS
714 (kill-new (buffer-substring (point) (mark t)) t)
715 (mouse-show-mark))
b64548c7
RS
716 ;; Set the mark where point is, then move where clicked.
717 (mouse-set-mark-fast click)
718 (if before-scroll
719 (goto-char before-scroll))
720 (exchange-point-and-mark)
eb9780b0 721 (kill-new (buffer-substring (point) (mark t))))
e6c2f5d4 722 (mouse-set-region-1)
b64548c7
RS
723 (setq mouse-save-then-kill-posn
724 (list (car kill-ring) (point) click-posn)))))))
e66feb07
RS
725\f
726(global-set-key [M-mouse-1] 'mouse-start-secondary)
727(global-set-key [M-drag-mouse-1] 'mouse-set-secondary)
728(global-set-key [M-down-mouse-1] 'mouse-drag-secondary)
729(global-set-key [M-mouse-3] 'mouse-secondary-save-then-kill)
9a974c88 730(global-set-key [M-mouse-2] 'mouse-yank-secondary)
e66feb07
RS
731
732;; An overlay which records the current secondary selection
733;; or else is deleted when there is no secondary selection.
734;; May be nil.
735(defvar mouse-secondary-overlay nil)
736
a94c7fcc
RS
737(defvar mouse-secondary-click-count 0)
738
e66feb07
RS
739;; A marker which records the specified first end for a secondary selection.
740;; May be nil.
741(defvar mouse-secondary-start nil)
742
743(defun mouse-start-secondary (click)
744 "Set one end of the secondary selection to the position clicked on.
745Use \\[mouse-secondary-save-then-kill] to set the other end
746and complete the secondary selection."
747 (interactive "e")
d65147f6 748 (mouse-minibuffer-check click)
e66feb07 749 (let ((posn (event-start click)))
230aaa73
RS
750 (save-excursion
751 (set-buffer (window-buffer (posn-window posn)))
752 ;; Cancel any preexisting secondary selection.
753 (if mouse-secondary-overlay
754 (delete-overlay mouse-secondary-overlay))
755 (if (numberp (posn-point posn))
756 (progn
757 (or mouse-secondary-start
758 (setq mouse-secondary-start (make-marker)))
759 (move-marker mouse-secondary-start (posn-point posn)))))))
e66feb07
RS
760
761(defun mouse-set-secondary (click)
762 "Set the secondary selection to the text that the mouse is dragged over.
763This must be bound to a mouse drag event."
764 (interactive "e")
d65147f6 765 (mouse-minibuffer-check click)
e66feb07
RS
766 (let ((posn (event-start click))
767 beg
768 (end (event-end click)))
230aaa73
RS
769 (save-excursion
770 (set-buffer (window-buffer (posn-window posn)))
771 (if (numberp (posn-point posn))
772 (setq beg (posn-point posn)))
773 (if mouse-secondary-overlay
774 (move-overlay mouse-secondary-overlay beg (posn-point end))
775 (setq mouse-secondary-overlay (make-overlay beg (posn-point end))))
776 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))))
947da0c4 777
d89a4a47 778(defun mouse-drag-secondary (start-event)
e66feb07 779 "Set the secondary selection to the text that the mouse is dragged over.
d89a4a47 780Highlight the drag area as you move the mouse.
e66feb07
RS
781This must be bound to a button-down mouse event."
782 (interactive "e")
d65147f6 783 (mouse-minibuffer-check start-event)
d89a4a47
RS
784 (let* ((start-posn (event-start start-event))
785 (start-point (posn-point start-posn))
786 (start-window (posn-window start-posn))
787 (start-frame (window-frame start-window))
788 (bounds (window-edges start-window))
789 (top (nth 1 bounds))
790 (bottom (if (window-minibuffer-p start-window)
791 (nth 3 bounds)
792 ;; Don't count the mode line.
793 (1- (nth 3 bounds))))
794 (click-count (1- (event-click-count start-event))))
795 (save-excursion
796 (set-buffer (window-buffer start-window))
a94c7fcc 797 (setq mouse-secondary-click-count click-count)
d89a4a47
RS
798 (or mouse-secondary-overlay
799 (setq mouse-secondary-overlay
800 (make-overlay (point) (point))))
26d280b9 801 (overlay-put mouse-secondary-overlay 'face 'secondary-selection)
9a974c88 802 (if (> (mod click-count 3) 0)
26d280b9
RS
803 ;; Double or triple press: make an initial selection
804 ;; of one word or line.
d89a4a47
RS
805 (let ((range (mouse-start-end start-point start-point click-count)))
806 (set-marker mouse-secondary-start nil)
807 (move-overlay mouse-secondary-overlay 1 1
808 (window-buffer start-window))
809 (move-overlay mouse-secondary-overlay (car range) (nth 1 range)
810 (window-buffer start-window)))
26d280b9 811 ;; Single-press: cancel any preexisting secondary selection.
d89a4a47
RS
812 (or mouse-secondary-start
813 (setq mouse-secondary-start (make-marker)))
814 (set-marker mouse-secondary-start start-point)
815 (delete-overlay mouse-secondary-overlay))
816 (let (event end end-point)
817 (track-mouse
818 (while (progn
819 (setq event (read-event))
820 (or (mouse-movement-p event)
821 (eq (car-safe event) 'switch-frame)))
822
823 (if (eq (car-safe event) 'switch-frame)
824 nil
825 (setq end (event-end event)
826 end-point (posn-point end))
827 (cond
d89a4a47
RS
828 ;; Are we moving within the original window?
829 ((and (eq (posn-window end) start-window)
830 (integer-or-marker-p end-point))
d89a4a47
RS
831 (let ((range (mouse-start-end start-point end-point
832 click-count)))
0136e1e3
RS
833 (if (or (/= start-point end-point)
834 (null (marker-position mouse-secondary-start)))
835 (progn
836 (set-marker mouse-secondary-start nil)
837 (move-overlay mouse-secondary-overlay
838 (car range) (nth 1 range))))))
3b0aebe9
RS
839 (t
840 (let ((mouse-row (cdr (cdr (mouse-position)))))
841 (cond
842 ((null mouse-row))
843 ((< mouse-row top)
e919a622
RS
844 (mouse-scroll-subr start-window (- mouse-row top)
845 mouse-secondary-overlay start-point))
d2287ded 846 ((>= mouse-row bottom)
e919a622 847 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
3b0aebe9 848 mouse-secondary-overlay start-point)))))))))
d89a4a47 849
4e399a53
RS
850 (if (consp event)
851;;; (eq (get (event-basic-type event) 'event-kind) 'mouse-click)
852;;; (eq (posn-window (event-end event)) start-window)
853;;; (numberp (posn-point (event-end event)))
d89a4a47
RS
854 (if (marker-position mouse-secondary-start)
855 (save-window-excursion
856 (delete-overlay mouse-secondary-overlay)
9a974c88 857 (x-set-selection 'SECONDARY nil)
d89a4a47
RS
858 (select-window start-window)
859 (save-excursion
860 (goto-char mouse-secondary-start)
861 (sit-for 1)))
9a974c88
RS
862 (x-set-selection
863 'SECONDARY
864 (buffer-substring (overlay-start mouse-secondary-overlay)
865 (overlay-end mouse-secondary-overlay)))))))))
e66feb07 866
9a974c88 867(defun mouse-yank-secondary (click)
50f58001
RS
868 "Insert the secondary selection at the position clicked on.
869Move point to the end of the inserted text.
870If `mouse-yank-at-point' is non-nil, insert at point
871regardless of where you click."
9a974c88 872 (interactive "e")
33c448cd
RS
873 ;; Give temporary modes such as isearch a chance to turn off.
874 (run-hooks 'mouse-leave-buffer-hook)
50f58001
RS
875 (or mouse-yank-at-point (mouse-set-point click))
876 (insert (x-get-selection 'SECONDARY)))
9a974c88 877
7e6404f6 878(defun mouse-kill-secondary ()
9a974c88
RS
879 "Kill the text in the secondary selection.
880This is intended more as a keyboard command than as a mouse command
881but it can work as either one.
882
883The current buffer (in case of keyboard use), or the buffer clicked on,
884must be the one that the secondary selection is in. This requirement
885is to prevent accidents."
7e6404f6
RS
886 (interactive)
887 (let* ((keys (this-command-keys))
888 (click (elt keys (1- (length keys)))))
889 (or (eq (overlay-buffer mouse-secondary-overlay)
890 (if (listp click)
891 (window-buffer (posn-window (event-start click)))
892 (current-buffer)))
893 (error "Select or click on the buffer where the secondary selection is")))
9dfab550
RS
894 (let (this-command)
895 (save-excursion
896 (set-buffer (overlay-buffer mouse-secondary-overlay))
897 (kill-region (overlay-start mouse-secondary-overlay)
898 (overlay-end mouse-secondary-overlay))))
e66feb07 899 (delete-overlay mouse-secondary-overlay)
9dfab550 900;;; (x-set-selection 'SECONDARY nil)
e66feb07
RS
901 (setq mouse-secondary-overlay nil))
902
903(defun mouse-secondary-save-then-kill (click)
d89a4a47 904 "Save text to point in kill ring; the second time, kill the text.
7bbe2cc7
RS
905You must use this in a buffer where you have recently done \\[mouse-start-secondary].
906If the text between where you did \\[mouse-start-secondary] and where
907you use this command matches the text at the front of the kill ring,
908this command deletes the text.
e66feb07 909Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
7bbe2cc7 910which prepares for a second click with this command to delete the text.
d89a4a47 911
7bbe2cc7
RS
912If you have already made a secondary selection in that buffer,
913this command extends or retracts the selection to where you click.
914If you do this again in a different position, it extends or retracts
915again. If you do this twice in the same position, it kills the selection."
e66feb07 916 (interactive "e")
d65147f6 917 (mouse-minibuffer-check click)
d89a4a47
RS
918 (let ((posn (event-start click))
919 (click-posn (posn-point (event-start click)))
e66feb07
RS
920 ;; Don't let a subsequent kill command append to this one:
921 ;; prevent setting this-command to kill-region.
922 (this-command this-command))
9a974c88
RS
923 (or (eq (window-buffer (posn-window posn))
924 (or (and mouse-secondary-overlay
925 (overlay-buffer mouse-secondary-overlay))
926 (if mouse-secondary-start
927 (marker-buffer mouse-secondary-start))))
928 (error "Wrong buffer"))
929 (save-excursion
930 (set-buffer (window-buffer (posn-window posn)))
a94c7fcc 931 (if (> (mod mouse-secondary-click-count 3) 0)
9a974c88
RS
932 (if (not (and (eq last-command 'mouse-secondary-save-then-kill)
933 (equal click-posn
934 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
935 ;; Find both ends of the object selected by this click.
936 (let* ((range
937 (mouse-start-end click-posn click-posn
a94c7fcc 938 mouse-secondary-click-count)))
9a974c88
RS
939 ;; Move whichever end is closer to the click.
940 ;; That's what xterm does, and it seems reasonable.
941 (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay)))
942 (abs (- click-posn (overlay-end mouse-secondary-overlay))))
943 (move-overlay mouse-secondary-overlay (car range)
944 (overlay-end mouse-secondary-overlay))
d89a4a47
RS
945 (move-overlay mouse-secondary-overlay
946 (overlay-start mouse-secondary-overlay)
947 (nth 1 range)))
9a974c88
RS
948 ;; We have already put the old region in the kill ring.
949 ;; Replace it with the extended region.
950 ;; (It would be annoying to make a separate entry.)
f69140fd
KH
951 (kill-new (buffer-substring
952 (overlay-start mouse-secondary-overlay)
953 (overlay-end mouse-secondary-overlay)) t)
9a974c88
RS
954 ;; Arrange for a repeated mouse-3 to kill this region.
955 (setq mouse-save-then-kill-posn
956 (list (car kill-ring) (point) click-posn)))
957 ;; If we click this button again without moving it,
958 ;; that time kill.
d89a4a47 959 (progn
9a974c88
RS
960 (mouse-save-then-kill-delete-region
961 (overlay-start mouse-secondary-overlay)
962 (overlay-end mouse-secondary-overlay))
963 (setq mouse-save-then-kill-posn nil)
a94c7fcc 964 (setq mouse-secondary-click-count 0)
9a974c88
RS
965 (delete-overlay mouse-secondary-overlay)))
966 (if (and (eq last-command 'mouse-secondary-save-then-kill)
967 mouse-save-then-kill-posn
968 (eq (car mouse-save-then-kill-posn) (car kill-ring))
969 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
970 ;; If this is the second time we've called
971 ;; mouse-secondary-save-then-kill, delete the text from the buffer.
972 (progn
973 (mouse-save-then-kill-delete-region
974 (overlay-start mouse-secondary-overlay)
975 (overlay-end mouse-secondary-overlay))
976 (setq mouse-save-then-kill-posn nil)
977 (delete-overlay mouse-secondary-overlay))
978 (if (overlay-start mouse-secondary-overlay)
979 ;; We have a selection, so adjust it.
980 (progn
981 (if (numberp click-posn)
982 (progn
983 ;; Move whichever end of the region is closer to the click.
984 ;; That is what xterm does, and it seems reasonable.
985 (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay)))
986 (abs (- click-posn (overlay-end mouse-secondary-overlay))))
987 (move-overlay mouse-secondary-overlay click-posn
988 (overlay-end mouse-secondary-overlay))
d89a4a47
RS
989 (move-overlay mouse-secondary-overlay
990 (overlay-start mouse-secondary-overlay)
991 click-posn))
9a974c88 992 (setq deactivate-mark nil)))
0136e1e3 993 (if (eq last-command 'mouse-secondary-save-then-kill)
f69140fd
KH
994 ;; If the front of the kill ring comes from
995 ;; an immediately previous use of this command,
996 ;; replace it with the extended region.
997 ;; (It would be annoying to make a separate entry.)
998 (kill-new (buffer-substring
0136e1e3 999 (overlay-start mouse-secondary-overlay)
f69140fd 1000 (overlay-end mouse-secondary-overlay)) t)
0136e1e3
RS
1001 (copy-region-as-kill (overlay-start mouse-secondary-overlay)
1002 (overlay-end mouse-secondary-overlay))))
9a974c88
RS
1003 (if mouse-secondary-start
1004 ;; All we have is one end of a selection,
1005 ;; so put the other end here.
1006 (let ((start (+ 0 mouse-secondary-start)))
1007 (kill-ring-save start click-posn)
1008 (if mouse-secondary-overlay
1009 (move-overlay mouse-secondary-overlay start click-posn)
1010 (setq mouse-secondary-overlay (make-overlay start click-posn)))
1011 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))))
1012 (setq mouse-save-then-kill-posn
1013 (list (car kill-ring) (point) click-posn))))
fb28fd5b
RS
1014 (if (overlay-buffer mouse-secondary-overlay)
1015 (x-set-selection 'SECONDARY
9a974c88
RS
1016 (buffer-substring
1017 (overlay-start mouse-secondary-overlay)
1018 (overlay-end mouse-secondary-overlay)))))))
e66feb07 1019\f
8b34e79d 1020(defun mouse-buffer-menu (event)
2d82f7b9
RS
1021 "Pop up a menu of buffers for selection with the mouse.
1022This switches buffers in the window that you clicked on,
1023and selects that window."
ec558adc 1024 (interactive "e")
d65147f6 1025 (mouse-minibuffer-check event)
8b34e79d
RS
1026 (let ((menu
1027 (list "Buffer Menu"
1028 (cons "Select Buffer"
1029 (let ((tail (buffer-list))
af2a85fe 1030 (maxbuf 0)
8b34e79d 1031 head)
af2a85fe
RS
1032 (while tail
1033 (or (eq ?\ (aref (buffer-name (car tail)) 0))
1034 (setq maxbuf
1035 (max maxbuf
1036 (length (buffer-name (car tail))))))
1037 (setq tail (cdr tail)))
1038 (setq tail (buffer-list))
8b34e79d
RS
1039 (while tail
1040 (let ((elt (car tail)))
1041 (if (not (string-match "^ "
1042 (buffer-name elt)))
95e5bde9
SM
1043 (setq head
1044 (cons
1045 (cons
1046 (format
1047 (format "%%%ds %%s%%s %%s" maxbuf)
1048 (buffer-name elt)
1049 (if (buffer-modified-p elt) "*" " ")
1050 (save-excursion
1051 (set-buffer elt)
1052 (if buffer-read-only "%" " "))
1053 (or (buffer-file-name elt)
1054 (save-excursion
1055 (set-buffer elt)
1056 (if list-buffers-directory
1057 (expand-file-name
1058 list-buffers-directory)))
1059 ""))
1060 elt)
1061 head))))
8b34e79d
RS
1062 (setq tail (cdr tail)))
1063 (reverse head))))))
2d82f7b9
RS
1064 (let ((buf (x-popup-menu event menu))
1065 (window (posn-window (event-start event))))
1066 (if buf
1067 (progn
c0bb9f3b 1068 (or (framep window) (select-window window))
2d82f7b9 1069 (switch-to-buffer buf))))))
72ea54a4 1070\f
5ba2dc3f 1071;;; These need to be rewritten for the new scroll bar implementation.
dbc4e1c1
JB
1072
1073;;;!! ;; Commands for the scroll bar.
1074;;;!!
1075;;;!! (defun mouse-scroll-down (click)
1076;;;!! (interactive "@e")
1077;;;!! (scroll-down (1+ (cdr (mouse-coords click)))))
1078;;;!!
1079;;;!! (defun mouse-scroll-up (click)
1080;;;!! (interactive "@e")
1081;;;!! (scroll-up (1+ (cdr (mouse-coords click)))))
1082;;;!!
1083;;;!! (defun mouse-scroll-down-full ()
1084;;;!! (interactive "@")
1085;;;!! (scroll-down nil))
1086;;;!!
1087;;;!! (defun mouse-scroll-up-full ()
1088;;;!! (interactive "@")
1089;;;!! (scroll-up nil))
1090;;;!!
1091;;;!! (defun mouse-scroll-move-cursor (click)
1092;;;!! (interactive "@e")
1093;;;!! (move-to-window-line (1+ (cdr (mouse-coords click)))))
1094;;;!!
1095;;;!! (defun mouse-scroll-absolute (event)
1096;;;!! (interactive "@e")
1097;;;!! (let* ((pos (car event))
1098;;;!! (position (car pos))
1099;;;!! (length (car (cdr pos))))
1100;;;!! (if (<= length 0) (setq length 1))
1101;;;!! (let* ((scale-factor (max 1 (/ length (/ 8000000 (buffer-size)))))
1102;;;!! (newpos (* (/ (* (/ (buffer-size) scale-factor)
1103;;;!! position)
1104;;;!! length)
1105;;;!! scale-factor)))
1106;;;!! (goto-char newpos)
1107;;;!! (recenter '(4)))))
1108;;;!!
1109;;;!! (defun mouse-scroll-left (click)
1110;;;!! (interactive "@e")
1111;;;!! (scroll-left (1+ (car (mouse-coords click)))))
1112;;;!!
1113;;;!! (defun mouse-scroll-right (click)
1114;;;!! (interactive "@e")
1115;;;!! (scroll-right (1+ (car (mouse-coords click)))))
1116;;;!!
1117;;;!! (defun mouse-scroll-left-full ()
1118;;;!! (interactive "@")
1119;;;!! (scroll-left nil))
1120;;;!!
1121;;;!! (defun mouse-scroll-right-full ()
1122;;;!! (interactive "@")
1123;;;!! (scroll-right nil))
1124;;;!!
1125;;;!! (defun mouse-scroll-move-cursor-horizontally (click)
1126;;;!! (interactive "@e")
1127;;;!! (move-to-column (1+ (car (mouse-coords click)))))
1128;;;!!
1129;;;!! (defun mouse-scroll-absolute-horizontally (event)
1130;;;!! (interactive "@e")
1131;;;!! (let* ((pos (car event))
1132;;;!! (position (car pos))
1133;;;!! (length (car (cdr pos))))
1134;;;!! (set-window-hscroll (selected-window) 33)))
1135;;;!!
1136;;;!! (global-set-key [scroll-bar mouse-1] 'mouse-scroll-up)
1137;;;!! (global-set-key [scroll-bar mouse-2] 'mouse-scroll-absolute)
1138;;;!! (global-set-key [scroll-bar mouse-3] 'mouse-scroll-down)
1139;;;!!
1140;;;!! (global-set-key [vertical-slider mouse-1] 'mouse-scroll-move-cursor)
1141;;;!! (global-set-key [vertical-slider mouse-2] 'mouse-scroll-move-cursor)
1142;;;!! (global-set-key [vertical-slider mouse-3] 'mouse-scroll-move-cursor)
1143;;;!!
1144;;;!! (global-set-key [thumbup mouse-1] 'mouse-scroll-up-full)
1145;;;!! (global-set-key [thumbup mouse-2] 'mouse-scroll-up-full)
1146;;;!! (global-set-key [thumbup mouse-3] 'mouse-scroll-up-full)
1147;;;!!
1148;;;!! (global-set-key [thumbdown mouse-1] 'mouse-scroll-down-full)
1149;;;!! (global-set-key [thumbdown mouse-2] 'mouse-scroll-down-full)
1150;;;!! (global-set-key [thumbdown mouse-3] 'mouse-scroll-down-full)
1151;;;!!
1152;;;!! (global-set-key [horizontal-scroll-bar mouse-1] 'mouse-scroll-left)
1153;;;!! (global-set-key [horizontal-scroll-bar mouse-2]
1154;;;!! 'mouse-scroll-absolute-horizontally)
1155;;;!! (global-set-key [horizontal-scroll-bar mouse-3] 'mouse-scroll-right)
1156;;;!!
1157;;;!! (global-set-key [horizontal-slider mouse-1]
1158;;;!! 'mouse-scroll-move-cursor-horizontally)
1159;;;!! (global-set-key [horizontal-slider mouse-2]
1160;;;!! 'mouse-scroll-move-cursor-horizontally)
1161;;;!! (global-set-key [horizontal-slider mouse-3]
1162;;;!! 'mouse-scroll-move-cursor-horizontally)
1163;;;!!
1164;;;!! (global-set-key [thumbleft mouse-1] 'mouse-scroll-left-full)
1165;;;!! (global-set-key [thumbleft mouse-2] 'mouse-scroll-left-full)
1166;;;!! (global-set-key [thumbleft mouse-3] 'mouse-scroll-left-full)
1167;;;!!
1168;;;!! (global-set-key [thumbright mouse-1] 'mouse-scroll-right-full)
1169;;;!! (global-set-key [thumbright mouse-2] 'mouse-scroll-right-full)
1170;;;!! (global-set-key [thumbright mouse-3] 'mouse-scroll-right-full)
1171;;;!!
1172;;;!! (global-set-key [horizontal-scroll-bar S-mouse-2]
1173;;;!! 'mouse-split-window-horizontally)
1174;;;!! (global-set-key [mode-line S-mouse-2]
1175;;;!! 'mouse-split-window-horizontally)
1176;;;!! (global-set-key [vertical-scroll-bar S-mouse-2]
1177;;;!! 'mouse-split-window)
6b2154de 1178\f
dbc4e1c1
JB
1179;;;!! ;;;;
1180;;;!! ;;;; Here are experimental things being tested. Mouse events
1181;;;!! ;;;; are of the form:
1182;;;!! ;;;; ((x y) window screen-part key-sequence timestamp)
1183;;;!! ;;
1184;;;!! ;;;;
1185;;;!! ;;;; Dynamically track mouse coordinates
1186;;;!! ;;;;
1187;;;!! ;;
1188;;;!! ;;(defun track-mouse (event)
1189;;;!! ;; "Track the coordinates, absolute and relative, of the mouse."
1190;;;!! ;; (interactive "@e")
1191;;;!! ;; (while mouse-grabbed
1192;;;!! ;; (let* ((pos (read-mouse-position (selected-screen)))
1193;;;!! ;; (abs-x (car pos))
1194;;;!! ;; (abs-y (cdr pos))
1195;;;!! ;; (relative-coordinate (coordinates-in-window-p
1196;;;!! ;; (list (car pos) (cdr pos))
1197;;;!! ;; (selected-window))))
1198;;;!! ;; (if (consp relative-coordinate)
1199;;;!! ;; (message "mouse: [%d %d], (%d %d)" abs-x abs-y
1200;;;!! ;; (car relative-coordinate)
1201;;;!! ;; (car (cdr relative-coordinate)))
1202;;;!! ;; (message "mouse: [%d %d]" abs-x abs-y)))))
1203;;;!!
1204;;;!! ;;
1205;;;!! ;; Dynamically put a box around the line indicated by point
1206;;;!! ;;
1207;;;!! ;;
1208;;;!! ;;(require 'backquote)
1209;;;!! ;;
1210;;;!! ;;(defun mouse-select-buffer-line (event)
1211;;;!! ;; (interactive "@e")
1212;;;!! ;; (let ((relative-coordinate
1213;;;!! ;; (coordinates-in-window-p (car event) (selected-window)))
1214;;;!! ;; (abs-y (car (cdr (car event)))))
1215;;;!! ;; (if (consp relative-coordinate)
1216;;;!! ;; (progn
1217;;;!! ;; (save-excursion
1218;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1219;;;!! ;; (x-draw-rectangle
1220;;;!! ;; (selected-screen)
1221;;;!! ;; abs-y 0
1222;;;!! ;; (save-excursion
1223;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1224;;;!! ;; (end-of-line)
1225;;;!! ;; (push-mark nil t)
1226;;;!! ;; (beginning-of-line)
1227;;;!! ;; (- (region-end) (region-beginning))) 1))
1228;;;!! ;; (sit-for 1)
1229;;;!! ;; (x-erase-rectangle (selected-screen))))))
1230;;;!! ;;
1231;;;!! ;;(defvar last-line-drawn nil)
1232;;;!! ;;(defvar begin-delim "[^ \t]")
1233;;;!! ;;(defvar end-delim "[^ \t]")
1234;;;!! ;;
1235;;;!! ;;(defun mouse-boxing (event)
1236;;;!! ;; (interactive "@e")
1237;;;!! ;; (save-excursion
1238;;;!! ;; (let ((screen (selected-screen)))
1239;;;!! ;; (while (= (x-mouse-events) 0)
1240;;;!! ;; (let* ((pos (read-mouse-position screen))
1241;;;!! ;; (abs-x (car pos))
1242;;;!! ;; (abs-y (cdr pos))
1243;;;!! ;; (relative-coordinate
1244;;;!! ;; (coordinates-in-window-p (` ((, abs-x) (, abs-y)))
1245;;;!! ;; (selected-window)))
1246;;;!! ;; (begin-reg nil)
1247;;;!! ;; (end-reg nil)
1248;;;!! ;; (end-column nil)
1249;;;!! ;; (begin-column nil))
1250;;;!! ;; (if (and (consp relative-coordinate)
1251;;;!! ;; (or (not last-line-drawn)
1252;;;!! ;; (not (= last-line-drawn abs-y))))
1253;;;!! ;; (progn
1254;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1255;;;!! ;; (if (= (following-char) 10)
1256;;;!! ;; ()
1257;;;!! ;; (progn
1258;;;!! ;; (setq begin-reg (1- (re-search-forward end-delim)))
1259;;;!! ;; (setq begin-column (1- (current-column)))
1260;;;!! ;; (end-of-line)
1261;;;!! ;; (setq end-reg (1+ (re-search-backward begin-delim)))
1262;;;!! ;; (setq end-column (1+ (current-column)))
1263;;;!! ;; (message "%s" (buffer-substring begin-reg end-reg))
1264;;;!! ;; (x-draw-rectangle screen
1265;;;!! ;; (setq last-line-drawn abs-y)
1266;;;!! ;; begin-column
1267;;;!! ;; (- end-column begin-column) 1))))))))))
1268;;;!! ;;
1269;;;!! ;;(defun mouse-erase-box ()
1270;;;!! ;; (interactive)
1271;;;!! ;; (if last-line-drawn
1272;;;!! ;; (progn
1273;;;!! ;; (x-erase-rectangle (selected-screen))
1274;;;!! ;; (setq last-line-drawn nil))))
1275;;;!!
1276;;;!! ;;; (defun test-x-rectangle ()
1277;;;!! ;;; (use-local-mouse-map (setq rectangle-test-map (make-sparse-keymap)))
1278;;;!! ;;; (define-key rectangle-test-map mouse-motion-button-left 'mouse-boxing)
1279;;;!! ;;; (define-key rectangle-test-map mouse-button-left-up 'mouse-erase-box))
1280;;;!!
1281;;;!! ;;
1282;;;!! ;; Here is how to do double clicking in lisp. About to change.
1283;;;!! ;;
1284;;;!!
1285;;;!! (defvar double-start nil)
1286;;;!! (defconst double-click-interval 300
1287;;;!! "Max ticks between clicks")
1288;;;!!
1289;;;!! (defun double-down (event)
1290;;;!! (interactive "@e")
1291;;;!! (if double-start
1292;;;!! (let ((interval (- (nth 4 event) double-start)))
1293;;;!! (if (< interval double-click-interval)
1294;;;!! (progn
1295;;;!! (backward-up-list 1)
1296;;;!! ;; (message "Interval %d" interval)
1297;;;!! (sleep-for 1)))
1298;;;!! (setq double-start nil))
1299;;;!! (setq double-start (nth 4 event))))
1300;;;!!
1301;;;!! (defun double-up (event)
1302;;;!! (interactive "@e")
1303;;;!! (and double-start
1304;;;!! (> (- (nth 4 event ) double-start) double-click-interval)
1305;;;!! (setq double-start nil)))
1306;;;!!
1307;;;!! ;;; (defun x-test-doubleclick ()
1308;;;!! ;;; (use-local-mouse-map (setq doubleclick-test-map (make-sparse-keymap)))
1309;;;!! ;;; (define-key doubleclick-test-map mouse-button-left 'double-down)
1310;;;!! ;;; (define-key doubleclick-test-map mouse-button-left-up 'double-up))
1311;;;!!
1312;;;!! ;;
5ba2dc3f 1313;;;!! ;; This scrolls while button is depressed. Use preferable in scroll bar.
dbc4e1c1
JB
1314;;;!! ;;
1315;;;!!
1316;;;!! (defvar scrolled-lines 0)
1317;;;!! (defconst scroll-speed 1)
1318;;;!!
1319;;;!! (defun incr-scroll-down (event)
1320;;;!! (interactive "@e")
1321;;;!! (setq scrolled-lines 0)
1322;;;!! (incremental-scroll scroll-speed))
1323;;;!!
1324;;;!! (defun incr-scroll-up (event)
1325;;;!! (interactive "@e")
1326;;;!! (setq scrolled-lines 0)
1327;;;!! (incremental-scroll (- scroll-speed)))
1328;;;!!
1329;;;!! (defun incremental-scroll (n)
1330;;;!! (while (= (x-mouse-events) 0)
1331;;;!! (setq scrolled-lines (1+ (* scroll-speed scrolled-lines)))
1332;;;!! (scroll-down n)
1333;;;!! (sit-for 300 t)))
1334;;;!!
1335;;;!! (defun incr-scroll-stop (event)
1336;;;!! (interactive "@e")
1337;;;!! (message "Scrolled %d lines" scrolled-lines)
1338;;;!! (setq scrolled-lines 0)
1339;;;!! (sleep-for 1))
1340;;;!!
1341;;;!! ;;; (defun x-testing-scroll ()
1342;;;!! ;;; (let ((scrolling-map (function mouse-vertical-scroll-bar-prefix)))
1343;;;!! ;;; (define-key scrolling-map mouse-button-left 'incr-scroll-down)
1344;;;!! ;;; (define-key scrolling-map mouse-button-right 'incr-scroll-up)
1345;;;!! ;;; (define-key scrolling-map mouse-button-left-up 'incr-scroll-stop)
1346;;;!! ;;; (define-key scrolling-map mouse-button-right-up 'incr-scroll-stop)))
1347;;;!!
1348;;;!! ;;
1349;;;!! ;; Some playthings suitable for picture mode? They need work.
1350;;;!! ;;
1351;;;!!
1352;;;!! (defun mouse-kill-rectangle (event)
1353;;;!! "Kill the rectangle between point and the mouse cursor."
1354;;;!! (interactive "@e")
1355;;;!! (let ((point-save (point)))
1356;;;!! (save-excursion
1357;;;!! (mouse-set-point event)
1358;;;!! (push-mark nil t)
1359;;;!! (if (> point-save (point))
1360;;;!! (kill-rectangle (point) point-save)
1361;;;!! (kill-rectangle point-save (point))))))
1362;;;!!
1363;;;!! (defun mouse-open-rectangle (event)
1364;;;!! "Kill the rectangle between point and the mouse cursor."
1365;;;!! (interactive "@e")
1366;;;!! (let ((point-save (point)))
1367;;;!! (save-excursion
1368;;;!! (mouse-set-point event)
1369;;;!! (push-mark nil t)
1370;;;!! (if (> point-save (point))
1371;;;!! (open-rectangle (point) point-save)
1372;;;!! (open-rectangle point-save (point))))))
1373;;;!!
1374;;;!! ;; Must be a better way to do this.
1375;;;!!
1376;;;!! (defun mouse-multiple-insert (n char)
1377;;;!! (while (> n 0)
1378;;;!! (insert char)
1379;;;!! (setq n (1- n))))
1380;;;!!
1381;;;!! ;; What this could do is not finalize until button was released.
1382;;;!!
1383;;;!! (defun mouse-move-text (event)
1384;;;!! "Move text from point to cursor position, inserting spaces."
1385;;;!! (interactive "@e")
1386;;;!! (let* ((relative-coordinate
1387;;;!! (coordinates-in-window-p (car event) (selected-window))))
1388;;;!! (if (consp relative-coordinate)
1389;;;!! (cond ((> (current-column) (car relative-coordinate))
1390;;;!! (delete-char
1391;;;!! (- (car relative-coordinate) (current-column))))
1392;;;!! ((< (current-column) (car relative-coordinate))
1393;;;!! (mouse-multiple-insert
1394;;;!! (- (car relative-coordinate) (current-column)) " "))
1395;;;!! ((= (current-column) (car relative-coordinate)) (ding))))))
07a78410 1396\f
f936ae06
RS
1397;; Choose a completion with the mouse.
1398
1399(defun mouse-choose-completion (event)
49e61c42 1400 "Click on an alternative in the `*Completions*' buffer to choose it."
f936ae06 1401 (interactive "e")
33c448cd
RS
1402 ;; Give temporary modes such as isearch a chance to turn off.
1403 (run-hooks 'mouse-leave-buffer-hook)
d89a4a47 1404 (let ((buffer (window-buffer))
02680e9b
RS
1405 choice
1406 base-size)
f936ae06
RS
1407 (save-excursion
1408 (set-buffer (window-buffer (posn-window (event-start event))))
f36f4e9e
RS
1409 (if completion-reference-buffer
1410 (setq buffer completion-reference-buffer))
02680e9b 1411 (setq base-size completion-base-size)
f936ae06
RS
1412 (save-excursion
1413 (goto-char (posn-point (event-start event)))
b6be5d95 1414 (let (beg end)
9a43a594
RS
1415 (if (and (not (eobp)) (get-text-property (point) 'mouse-face))
1416 (setq end (point) beg (1+ (point))))
1417 (if (null beg)
1418 (error "No completion here"))
1419 (setq beg (previous-single-property-change beg 'mouse-face))
2f5ed2e8
RS
1420 (setq end (or (next-single-property-change end 'mouse-face)
1421 (point-max)))
b6be5d95 1422 (setq choice (buffer-substring beg end)))))
73e2025f
RS
1423 (let ((owindow (selected-window)))
1424 (select-window (posn-window (event-start event)))
874a2cbd
RS
1425 (if (and (one-window-p t 'selected-frame)
1426 (window-dedicated-p (selected-window)))
1427 ;; This is a special buffer's frame
1428 (iconify-frame (selected-frame))
1429 (or (window-dedicated-p (selected-window))
1430 (bury-buffer)))
73e2025f 1431 (select-window owindow))
02680e9b 1432 (choose-completion-string choice buffer base-size)))
f936ae06 1433\f
07a78410
RS
1434;; Font selection.
1435
0eb9fef3
RS
1436(defun font-menu-add-default ()
1437 (let* ((default (cdr (assq 'font (frame-parameters (selected-frame)))))
1438 (font-alist x-fixed-font-alist)
0d94f5ca 1439 (elt (or (assoc "Misc" font-alist) (nth 1 font-alist))))
0eb9fef3
RS
1440 (if (assoc "Default" elt)
1441 (delete (assoc "Default" elt) elt))
1442 (setcdr elt
3d64d15b 1443 (cons (list "Default"
0eb9fef3
RS
1444 (cdr (assq 'font (frame-parameters (selected-frame)))))
1445 (cdr elt)))))
1446
07a78410
RS
1447(defvar x-fixed-font-alist
1448 '("Font menu"
1449 ("Misc"
19d973e8
RS
1450 ;; For these, we specify the pixel height and width.
1451 ("fixed" "fixed")
1452 ("6x10" "-misc-fixed-medium-r-normal--10-*-*-*-c-60-iso8859-1" "6x10")
1453 ("6x12"
1454 "-misc-fixed-medium-r-semicondensed--12-*-*-*-c-60-iso8859-1" "6x12")
1455 ("6x13"
1456 "-misc-fixed-medium-r-semicondensed--13-*-*-*-c-60-iso8859-1" "6x13")
1457 ("7x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-70-iso8859-1" "7x13")
1458 ("7x14" "-misc-fixed-medium-r-normal--14-*-*-*-c-70-iso8859-1" "7x14")
1459 ("8x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-80-iso8859-1" "8x13")
1460 ("9x15" "-misc-fixed-medium-r-normal--15-*-*-*-c-90-iso8859-1" "9x15")
1461 ("10x20" "-misc-fixed-medium-r-normal--20-*-*-*-c-100-iso8859-1" "10x20")
1462 ("11x18" "-misc-fixed-medium-r-normal--18-*-*-*-c-110-iso8859-1" "11x18")
1463 ("12x24" "-misc-fixed-medium-r-normal--24-*-*-*-c-120-iso8859-1" "12x24")
fa21fdec 1464 ("")
f29c3695
RS
1465 ("clean 5x8"
1466 "-schumacher-clean-medium-r-normal--8-*-*-*-c-50-iso8859-1")
1467 ("clean 6x8"
1468 "-schumacher-clean-medium-r-normal--8-*-*-*-c-60-iso8859-1")
19d973e8
RS
1469 ("clean 8x8"
1470 "-schumacher-clean-medium-r-normal--8-*-*-*-c-80-iso8859-1")
1471 ("clean 8x10"
1472 "-schumacher-clean-medium-r-normal--10-*-*-*-c-80-iso8859-1")
1473 ("clean 8x14"
1474 "-schumacher-clean-medium-r-normal--14-*-*-*-c-80-iso8859-1")
1475 ("clean 8x16"
1476 "-schumacher-clean-medium-r-normal--16-*-*-*-c-80-iso8859-1")
fa21fdec 1477 ("")
19d973e8 1478 ("sony 8x16" "-sony-fixed-medium-r-normal--16-*-*-*-c-80-iso8859-1"))
07a78410
RS
1479;;; We don't seem to have these; who knows what they are.
1480;;; ("fg-18" "fg-18")
1481;;; ("fg-25" "fg-25")
1482;;; ("lucidasanstypewriter-12" "lucidasanstypewriter-12")
1483;;; ("lucidasanstypewriter-bold-14" "lucidasanstypewriter-bold-14")
1484;;; ("lucidasanstypewriter-bold-24" "lucidasanstypewriter-bold-24")
1485;;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
1486;;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
1487 ("Courier"
19d973e8 1488 ;; For these, we specify the point height.
82c048a9
RS
1489 ("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1")
1490 ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1")
1491 ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1")
1492 ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1")
1493 ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1")
1494 ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1")
1495 ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1")
1496 ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1")
1497 ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1")
1498 ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1")
1499 ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1")
1500 ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1")
1501 ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1")
1502 ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1")
1503 ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1")
1504 ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1")
1505 ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1")
1506 ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1")
1507 ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1")
1508 ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1")
1509 ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1")
1510 ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1")
1511 ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1")
1512 ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1"))
07a78410
RS
1513 )
1514 "X fonts suitable for use in Emacs.")
1515
1900a92b 1516(defun mouse-set-font (&rest fonts)
07a78410
RS
1517 "Select an emacs font from a list of known good fonts"
1518 (interactive
1519 (x-popup-menu last-nonmenu-event x-fixed-font-alist))
df4de8c6
KH
1520 (if fonts
1521 (let (font)
1522 (while fonts
1523 (condition-case nil
1524 (progn
3fadec1a 1525 (set-default-font (car fonts))
df4de8c6
KH
1526 (setq font (car fonts))
1527 (setq fonts nil))
3fadec1a
RS
1528 (error
1529 (setq fonts (cdr fonts)))))
df4de8c6 1530 (if (null font)
3fadec1a 1531 (error "Font not found")))))
cc0a8174
JB
1532\f
1533;;; Bindings for mouse commands.
1534
fcfc3c63 1535(define-key global-map [down-mouse-1] 'mouse-drag-region)
dbc4e1c1 1536(global-set-key [mouse-1] 'mouse-set-point)
dbc4e1c1 1537(global-set-key [drag-mouse-1] 'mouse-set-region)
fcfc3c63 1538
e37de120
RS
1539;; These are tested for in mouse-drag-region.
1540(global-set-key [double-mouse-1] 'mouse-set-point)
1541(global-set-key [triple-mouse-1] 'mouse-set-point)
1542
dbc4e1c1
JB
1543(global-set-key [mouse-2] 'mouse-yank-at-click)
1544(global-set-key [mouse-3] 'mouse-save-then-kill)
8b34e79d 1545
dbc4e1c1
JB
1546;; By binding these to down-going events, we let the user use the up-going
1547;; event to make the selection, saving a click.
eef805d7
RS
1548(global-set-key [C-down-mouse-1] 'mouse-set-font)
1549;; C-down-mouse-2 is bound in facemenu.el.
95132d1c
RS
1550(global-set-key [C-down-mouse-3] 'mouse-major-mode-menu)
1551
07a78410 1552
8b34e79d
RS
1553;; Replaced with dragging mouse-1
1554;; (global-set-key [S-mouse-1] 'mouse-set-mark)
947da0c4 1555
3c2dd2c0 1556(global-set-key [mode-line mouse-1] 'mouse-select-window)
544e7e73
RS
1557(global-set-key [mode-line drag-mouse-1] 'mouse-select-window)
1558(global-set-key [mode-line down-mouse-1] 'mouse-drag-mode-line)
3c2dd2c0 1559(global-set-key [mode-line mouse-2] 'mouse-delete-other-windows)
dbc4e1c1 1560(global-set-key [mode-line mouse-3] 'mouse-delete-window)
3c2dd2c0 1561(global-set-key [mode-line C-mouse-2] 'mouse-split-window-horizontally)
9926ab64 1562(global-set-key [vertical-scroll-bar C-mouse-2] 'mouse-split-window-vertically)
b6522df6 1563(global-set-key [vertical-line C-mouse-2] 'mouse-split-window-vertically)
49116ac0
JB
1564
1565(provide 'mouse)
1566
6594deb0 1567;;; mouse.el ends here