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