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