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