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