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