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