(keymap_panes): Pass the keymap's prompt as the pane
[bpt/emacs.git] / lisp / mouse.el
CommitLineData
be010748 1;;; mouse.el --- window system-independent mouse support
84176303 2
de420e82 3;; Copyright (C) 1993, 1994, 1995, 1999, 2000 Free Software Foundation, Inc.
eea8d4ef 4
84176303 5;; Maintainer: FSF
de420e82 6;; Keywords: hardware, mouse
84176303 7
be010748 8;; This file is part of GNU Emacs.
72ea54a4 9
be010748
RS
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
12;; the Free Software Foundation; either version 2, or (at your option)
13;; any later version.
72ea54a4 14
be010748
RS
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
be010748 20;; You should have received a copy of the GNU General Public License
4c9afcbe
RS
21;; along with GNU Emacs; see the file COPYING. If not, write to the
22;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23;; Boston, MA 02111-1307, USA.
72ea54a4 24
edbd2f74
ER
25;;; Commentary:
26
27;; This package provides various useful commands (including help
28;; system access) through the mouse. All this code assumes that mouse
29;; interpretation has been abstracted into Emacs input events.
30;;
31;; The code is rather X-dependent.
32
aae56ea7
ER
33;;; Code:
34
cc0a8174 35;;; Utility functions.
72ea54a4 36
cc0a8174
JB
37;;; Indent track-mouse like progn.
38(put 'track-mouse 'lisp-indent-function 0)
72ea54a4 39
3b558d41
RS
40(defcustom mouse-yank-at-point nil
41 "*If non-nil, mouse yank commands yank at point instead of at click."
42 :type 'boolean
43 :group 'mouse)
cc0a8174 44\f
95132d1c
RS
45;; Provide a mode-specific menu on a mouse button.
46
21ad0f7b
SM
47(defun popup-menu (menu &optional position prefix)
48 "Popup the given menu and call the selected option.
de420e82
DL
49MENU can be a keymap, an easymenu-style menu or a list of keymaps as for
50`x-popup-menu'.
21ad0f7b
SM
51POSITION can be a click event or ((XOFFSET YOFFSET) WINDOW) and defaults to
52 the current mouse position.
53PREFIX is the prefix argument (if any) to pass to the command."
de420e82
DL
54 (let* ((map (cond
55 ((keymapp menu) menu)
56 ((and (listp menu) (keymapp (car menu))) menu)
57 (t (let* ((map (easy-menu-create-menu (car menu) (cdr menu)))
21ad0f7b
SM
58 (filter (when (symbolp map)
59 (plist-get (get map 'menu-pro) :filter))))
de420e82 60 (if filter (funcall filter (symbol-function map)) map)))))
21ad0f7b
SM
61 event)
62 ;; The looping behavior was taken from lmenu's popup-menu-popup
63 (while (and map (setq event (x-popup-menu position map)))
64 ;; Strangely x-popup-menu returns a list.
65 ;; mouse-major-mode-menu was using a weird:
66 ;; (key-binding (apply 'vector (append '(menu-bar) menu-prefix events)))
67 (let ((cmd (lookup-key map (apply 'vector event))))
68 (setq map nil)
69 ;; Clear out echoing, which perhaps shows a prefix arg.
70 (message "")
71 (when cmd
72 (if (keymapp cmd)
73 ;; Try again but with the submap.
74 (setq map cmd)
75 (setq prefix-arg prefix)
76 ;; mouse-major-mode-menu was using `command-execute' instead.
77 (call-interactively cmd)))))))
78
6a16c4cb 79(defun mouse-major-mode-menu (event prefix)
b98e5762
DL
80 "Pop up a mode-specific menu of mouse commands.
81Default to the Edit menu if the major mode doesn't define a menu."
95132d1c
RS
82 ;; Switch to the window clicked on, because otherwise
83 ;; the mode's commands may not make sense.
6a16c4cb 84 (interactive "@e\nP")
25f9b4bf
RS
85 ;; Let the mode update its menus first.
86 (run-hooks 'activate-menubar-hook)
b98e5762
DL
87 (let* (;; This is where mouse-major-mode-menu-prefix
88 ;; returns the prefix we should use (after menu-bar).
89 ;; It is either nil or (SOME-SYMBOL).
90 (mouse-major-mode-menu-prefix nil)
91 ;; Keymap from which to inherit; may be null.
92 (ancestor (mouse-major-mode-menu-1
93 (and (current-local-map)
94 (lookup-key (current-local-map) [menu-bar]))))
95 ;; Make a keymap in which our last command leads to a menu or
96 ;; default to the edit menu.
97 (newmap (if ancestor
98 (make-sparse-keymap (concat mode-name " Mode"))
99 menu-bar-edit-menu))
100 result)
101 (if ancestor
102 ;; Make our menu inherit from the desired keymap which we want
103 ;; to display as the menu now.
104 (set-keymap-parent newmap ancestor))
21ad0f7b
SM
105 (popup-menu newmap event prefix)))
106
95132d1c
RS
107
108;; Compute and cache the equivalent keys in MENU and all its submenus.
d5c847bb
KH
109;;;(defun mouse-major-mode-menu-compute-equiv-keys (menu)
110;;; (and (eq (car menu) 'keymap)
111;;; (x-popup-menu nil menu))
112;;; (while menu
113;;; (and (consp (car menu))
114;;; (consp (cdr (car menu)))
115;;; (let ((tail (cdr (car menu))))
116;;; (while (and (consp tail)
117;;; (not (eq (car tail) 'keymap)))
118;;; (setq tail (cdr tail)))
119;;; (if (consp tail)
120;;; (mouse-major-mode-menu-compute-equiv-keys tail))))
121;;; (setq menu (cdr menu))))
95132d1c
RS
122
123;; Given a mode's menu bar keymap,
124;; if it defines exactly one menu bar menu,
125;; return just that menu.
126;; Otherwise return a menu for all of them.
127(defun mouse-major-mode-menu-1 (menubar)
128 (if menubar
129 (let ((tail menubar)
130 submap)
131 (while tail
132 (if (consp (car tail))
133 (if submap
134 (setq submap t)
d5c847bb 135 (setq submap (car tail))))
95132d1c 136 (setq tail (cdr tail)))
d5c847bb 137 (if (eq submap t)
d3e458b0 138 menubar
d5c847bb 139 (setq mouse-major-mode-menu-prefix (list (car submap)))
a45423d8 140 (lookup-key menubar (vector (car submap)))))))
de420e82
DL
141
142(defun mouse-popup-menubar (event prefix)
143 "Pops up a menu equiavlent to the menu bar a keyboard EVENT with PREFIX.
144The contents are the items that would be in the menu bar whether or
145not it is actually displayed."
146 (interactive "@e \nP")
147 (run-hooks 'activate-menubar-hook)
148 (let* ((local-menu (lookup-key (current-local-map) [menu-bar]))
149 (global-menu (lookup-key global-map [menu-bar])))
150 ;; Supplying the list is faster than making a new map.
151 (popup-menu (list global-menu local-menu) event prefix)))
152
153(defun mouse-popup-menubar-stuff (event prefix)
154 "Popup a menu like either `mouse-major-mode-menu' or `mouse-popup-menubar'.
155Use the former if the menu bar is showing, otherwise the latter."
156 (interactive "@e \nP")
157 (if (zerop (assoc-default 'menu-bar-lines (frame-parameters) 'eq 0))
158 (mouse-popup-menubar event prefix)
159 (mouse-major-mode-menu event prefix)))
95132d1c 160\f
544e7e73
RS
161;; Commands that operate on windows.
162
d65147f6
KH
163(defun mouse-minibuffer-check (event)
164 (let ((w (posn-window (event-start event))))
165 (and (window-minibuffer-p w)
166 (not (minibuffer-window-active-p w))
33c448cd
RS
167 (error "Minibuffer window is not active")))
168 ;; Give temporary modes such as isearch a chance to turn off.
169 (run-hooks 'mouse-leave-buffer-hook))
d65147f6 170
cc0a8174 171(defun mouse-delete-window (click)
947da0c4 172 "Delete the window you click on.
a926a0fa
RS
173If the frame has just one window, bury the current buffer instead.
174This command must be bound to a mouse click."
ec558adc 175 (interactive "e")
a926a0fa
RS
176 (if (one-window-p t)
177 (bury-buffer)
178 (mouse-minibuffer-check click)
179 (delete-window (posn-window (event-start click)))))
cc0a8174 180
3c2dd2c0
RS
181(defun mouse-select-window (click)
182 "Select the window clicked on; don't move point."
183 (interactive "e")
d65147f6 184 (mouse-minibuffer-check click)
3c2dd2c0
RS
185 (let ((oframe (selected-frame))
186 (frame (window-frame (posn-window (event-start click)))))
187 (select-window (posn-window (event-start click)))
188 (raise-frame frame)
189 (select-frame frame)
190 (or (eq frame oframe)
e1877477 191 (set-mouse-position (selected-frame) (1- (frame-width)) 0))))
3c2dd2c0 192
b0f3a26b
JB
193(defun mouse-tear-off-window (click)
194 "Delete the window clicked on, and create a new frame displaying its buffer."
195 (interactive "e")
d65147f6 196 (mouse-minibuffer-check click)
b0f3a26b
JB
197 (let* ((window (posn-window (event-start click)))
198 (buf (window-buffer window))
01a911e3 199 (frame (make-frame)))
b0f3a26b
JB
200 (select-frame frame)
201 (switch-to-buffer buf)
202 (delete-window window)))
203
b5370f03 204(defun mouse-delete-other-windows ()
947da0c4 205 "Delete all window except the one you click on."
b5370f03 206 (interactive "@")
cc0a8174 207 (delete-other-windows))
72ea54a4 208
cc0a8174
JB
209(defun mouse-split-window-vertically (click)
210 "Select Emacs window mouse is on, then split it vertically in half.
211The window is split at the line clicked on.
212This command must be bound to a mouse click."
947da0c4 213 (interactive "@e")
d65147f6 214 (mouse-minibuffer-check click)
b5370f03
JB
215 (let ((start (event-start click)))
216 (select-window (posn-window start))
85d6b80b 217 (let ((new-height (1+ (cdr (posn-col-row (event-end click)))))
5ba2dc3f
JB
218 (first-line window-min-height)
219 (last-line (- (window-height) window-min-height)))
220 (if (< last-line first-line)
0a50b993 221 (error "Window too short to split")
5ba2dc3f
JB
222 (split-window-vertically
223 (min (max new-height first-line) last-line))))))
cc0a8174 224
947da0c4
RS
225(defun mouse-split-window-horizontally (click)
226 "Select Emacs window mouse is on, then split it horizontally in half.
227The window is split at the column clicked on.
228This command must be bound to a mouse click."
229 (interactive "@e")
d65147f6 230 (mouse-minibuffer-check click)
5ba2dc3f
JB
231 (let ((start (event-start click)))
232 (select-window (posn-window start))
233 (let ((new-width (1+ (car (posn-col-row (event-end click)))))
234 (first-col window-min-width)
235 (last-col (- (window-width) window-min-width)))
236 (if (< last-col first-col)
0a50b993 237 (error "Window too narrow to split")
5ba2dc3f
JB
238 (split-window-horizontally
239 (min (max new-width first-col) last-col))))))
947da0c4 240
b0d22e20
GM
241(defun mouse-drag-mode-line-1 (start-event mode-line-p)
242 "Change the height of a window by dragging on the mode or header line.
243START-EVENT is the starting mouse-event of the drag action.
244MODE-LINE-P non-nil means a mode line is dragged."
33c448cd
RS
245 ;; Give temporary modes such as isearch a chance to turn off.
246 (run-hooks 'mouse-leave-buffer-hook)
544e7e73
RS
247 (let ((done nil)
248 (echo-keystrokes 0)
249 (start-event-frame (window-frame (car (car (cdr start-event)))))
250 (start-event-window (car (car (cdr start-event))))
251 (start-nwindows (count-windows t))
252 (old-selected-window (selected-window))
253 should-enlarge-minibuffer
254 event mouse minibuffer y top bot edges wconfig params growth)
255 (setq params (frame-parameters))
951e0427 256 (setq minibuffer (cdr (assq 'minibuffer params)))
544e7e73
RS
257 (track-mouse
258 (progn
259 ;; enlarge-window only works on the selected window, so
260 ;; we must select the window where the start event originated.
261 ;; unwind-protect will restore the old selected window later.
262 (select-window start-event-window)
263 ;; if this is the bottommost ordinary window, then to
264 ;; move its modeline the minibuffer must be enlarged.
265 (setq should-enlarge-minibuffer
266 (and minibuffer
b0d22e20 267 mode-line-p
544e7e73
RS
268 (not (one-window-p t))
269 (= (nth 1 (window-edges minibuffer))
270 (nth 3 (window-edges)))))
271 ;; loop reading events and sampling the position of
272 ;; the mouse.
273 (while (not done)
274 (setq event (read-event)
275 mouse (mouse-position))
276 ;; do nothing if
277 ;; - there is a switch-frame event.
278 ;; - the mouse isn't in the frame that we started in
279 ;; - the mouse isn't in any Emacs frame
280 ;; drag if
281 ;; - there is a mouse-movement event
282 ;; - there is a scroll-bar-movement event
283 ;; (same as mouse movement for our purposes)
284 ;; quit if
285 ;; - there is a keyboard event or some other unknown event
286 ;; unknown event.
287 (cond ((integerp event)
288 (setq done t))
289 ((eq (car event) 'switch-frame)
290 nil)
291 ((not (memq (car event)
292 '(mouse-movement scroll-bar-movement)))
293 (if (consp event)
294 (setq unread-command-events
295 (cons event unread-command-events)))
296 (setq done t))
297 ((not (eq (car mouse) start-event-frame))
298 nil)
299 ((null (car (cdr mouse)))
300 nil)
301 (t
302 (setq y (cdr (cdr mouse))
303 edges (window-edges)
304 top (nth 1 edges)
305 bot (nth 3 edges))
b0d22e20 306
544e7e73 307 ;; compute size change needed
b0d22e20
GM
308 (cond (mode-line-p
309 ;; Scale back a move that would make the
310 ;; window too short.
311 (when (< (- y top -1) window-min-height)
312 (setq y (+ top window-min-height -1)))
313 (setq growth (- y bot -1)))
314 (t
315 (when (< (- bot y -1) window-min-height)
316 (setq y (- bot window-min-height -1)))
317 (setq growth (- top y -1))))
318 (setq wconfig (current-window-configuration))
319
951e0427
RS
320 ;; Check for an error case.
321 (if (and (/= growth 0)
322 (not minibuffer)
323 (one-window-p t))
324 (error "Attempt to resize sole window"))
b0d22e20 325
544e7e73
RS
326 ;; grow/shrink minibuffer?
327 (if should-enlarge-minibuffer
328 (progn
329 ;; yes. briefly select minibuffer so
330 ;; enlarge-window will affect the
331 ;; correct window.
332 (select-window minibuffer)
333 ;; scale back shrinkage if it would
334 ;; make the minibuffer less than 1
335 ;; line tall.
336 (if (and (> growth 0)
337 (< (- (window-height minibuffer)
338 growth)
339 1))
340 (setq growth (1- (window-height minibuffer))))
341 (enlarge-window (- growth))
342 (select-window start-event-window))
343 ;; no. grow/shrink the selected window
99d48056 344 ;; (message "growth = %d" growth)
544e7e73 345 (enlarge-window growth))
b0d22e20 346
544e7e73
RS
347 ;; if this window's growth caused another
348 ;; window to be deleted because it was too
349 ;; short, rescind the change.
350 ;;
351 ;; if size change caused space to be stolen
352 ;; from a window above this one, rescind the
a45423d8 353 ;; change, but only if we didn't grow/shrink
544e7e73
RS
354 ;; the minibuffer. minibuffer size changes
355 ;; can cause all windows to shrink... no way
356 ;; around it.
357 (if (or (/= start-nwindows (count-windows t))
358 (and (not should-enlarge-minibuffer)
b0d22e20 359 mode-line-p
544e7e73
RS
360 (/= top (nth 1 (window-edges)))))
361 (set-window-configuration wconfig)))))))))
b0d22e20
GM
362
363(defun mouse-drag-mode-line (start-event)
364 "Change the height of a window by dragging on the mode line."
365 (interactive "e")
366 (mouse-drag-mode-line-1 start-event t))
367
368(defun mouse-drag-header-line (start-event)
369 "Change the height of a window by dragging on the header line."
370 (interactive "e")
371 (mouse-drag-mode-line-1 start-event nil))
372
544e7e73 373\f
08a1c178
RS
374(defun mouse-drag-vertical-line (start-event)
375 "Change the width of a window by dragging on the vertical line."
376 (interactive "e")
377 ;; Give temporary modes such as isearch a chance to turn off.
378 (run-hooks 'mouse-leave-buffer-hook)
5d6a85e0
RS
379 (let* ((done nil)
380 (echo-keystrokes 0)
381 (start-event-frame (window-frame (car (car (cdr start-event)))))
382 (start-event-window (car (car (cdr start-event))))
383 (start-nwindows (count-windows t))
384 (old-selected-window (selected-window))
385 event mouse x left right edges wconfig growth
386 (which-side
387 (or (cdr (assq 'vertical-scroll-bars (frame-parameters start-event-frame)))
388 'right)))
08a1c178
RS
389 (if (one-window-p t)
390 (error "Attempt to resize sole ordinary window"))
4e363e7e
KH
391 (if (eq which-side 'right)
392 (if (= (nth 2 (window-edges start-event-window))
393 (frame-width start-event-frame))
394 (error "Attempt to drag rightmost scrollbar"))
395 (if (= (nth 0 (window-edges start-event-window)) 0)
396 (error "Attempt to drag leftmost scrollbar")))
08a1c178
RS
397 (track-mouse
398 (progn
399 ;; enlarge-window only works on the selected window, so
400 ;; we must select the window where the start event originated.
401 ;; unwind-protect will restore the old selected window later.
402 (select-window start-event-window)
403 ;; loop reading events and sampling the position of
404 ;; the mouse.
405 (while (not done)
406 (setq event (read-event)
407 mouse (mouse-position))
408 ;; do nothing if
409 ;; - there is a switch-frame event.
410 ;; - the mouse isn't in the frame that we started in
411 ;; - the mouse isn't in any Emacs frame
412 ;; drag if
413 ;; - there is a mouse-movement event
414 ;; - there is a scroll-bar-movement event
415 ;; (same as mouse movement for our purposes)
416 ;; quit if
417 ;; - there is a keyboard event or some other unknown event
418 ;; unknown event.
419 (cond ((integerp event)
420 (setq done t))
421 ((eq (car event) 'switch-frame)
422 nil)
423 ((not (memq (car event)
424 '(mouse-movement scroll-bar-movement)))
425 (if (consp event)
426 (setq unread-command-events
427 (cons event unread-command-events)))
428 (setq done t))
429 ((not (eq (car mouse) start-event-frame))
430 nil)
431 ((null (car (cdr mouse)))
432 nil)
433 (t
b0ea497f
KH
434 (save-selected-window
435 ;; If the scroll bar is on the window's left,
436 ;; adjust the window on the left.
4e363e7e
KH
437 (unless (eq which-side 'right)
438 (select-window (previous-window)))
b0ea497f 439 (setq x (- (car (cdr mouse))
4e363e7e 440 (if (eq which-side 'right) 0 2))
b0ea497f
KH
441 edges (window-edges)
442 left (nth 0 edges)
443 right (nth 2 edges))
444 ;; scale back a move that would make the
445 ;; window too thin.
446 (if (< (- x left -1) window-min-width)
447 (setq x (+ left window-min-width -1)))
448 ;; compute size change needed
449 (setq growth (- x right -1)
450 wconfig (current-window-configuration))
451 (enlarge-window growth t)
452 ;; if this window's growth caused another
453 ;; window to be deleted because it was too
454 ;; thin, rescind the change.
455 ;;
456 ;; if size change caused space to be stolen
457 ;; from a window to the left of this one,
458 ;; rescind the change.
459 (if (or (/= start-nwindows (count-windows t))
460 (/= left (nth 0 (window-edges))))
461 (set-window-configuration wconfig))))))))))
08a1c178 462\f
2a5fa27b 463(defun mouse-set-point (event)
cc0a8174 464 "Move point to the position clicked on with the mouse.
2a5fa27b 465This should be bound to a mouse click event type."
ec558adc 466 (interactive "e")
d65147f6 467 (mouse-minibuffer-check event)
2a5fa27b
RS
468 ;; Use event-end in case called from mouse-drag-region.
469 ;; If EVENT is a click, event-end and event-start give same value.
470 (let ((posn (event-end event)))
0a50b993
RS
471 (if (not (windowp (posn-window posn)))
472 (error "Cursor not in text area of window"))
b5370f03
JB
473 (select-window (posn-window posn))
474 (if (numberp (posn-point posn))
475 (goto-char (posn-point posn)))))
cc0a8174 476
e6c2f5d4
RS
477(defvar mouse-last-region-beg nil)
478(defvar mouse-last-region-end nil)
479(defvar mouse-last-region-tick nil)
480
481(defun mouse-region-match ()
482 "Return non-nil if there's an active region that was set with the mouse."
483 (and (mark t) mark-active
484 (eq mouse-last-region-beg (region-beginning))
485 (eq mouse-last-region-end (region-end))
486 (eq mouse-last-region-tick (buffer-modified-tick))))
487
652ccd35 488(defun mouse-set-region (click)
e37de120 489 "Set the region to the text dragged over, and copy to kill ring.
2a5fa27b 490This should be bound to a mouse drag event."
652ccd35 491 (interactive "e")
d65147f6 492 (mouse-minibuffer-check click)
652ccd35
RS
493 (let ((posn (event-start click))
494 (end (event-end click)))
495 (select-window (posn-window posn))
496 (if (numberp (posn-point posn))
497 (goto-char (posn-point posn)))
fcfc3c63 498 ;; If mark is highlighted, no need to bounce the cursor.
33a35434
KH
499 ;; On X, we highlight while dragging, thus once again no need to bounce.
500 (or transient-mark-mode
b86b9918 501 (memq (framep (selected-frame)) '(x pc w32))
fcfc3c63 502 (sit-for 1))
652ccd35 503 (push-mark)
1cc8a3f4 504 (set-mark (point))
652ccd35 505 (if (numberp (posn-point end))
e37de120
RS
506 (goto-char (posn-point end)))
507 ;; Don't set this-command to kill-region, so that a following
508 ;; C-w will not double the text in the kill ring.
91a6bc10 509 ;; Ignore last-command so we don't append to a preceding kill.
1fa01bcd 510 (let (this-command last-command deactivate-mark)
e6c2f5d4
RS
511 (copy-region-as-kill (mark) (point)))
512 (mouse-set-region-1)))
513
514(defun mouse-set-region-1 ()
515 (setq mouse-last-region-beg (region-beginning))
516 (setq mouse-last-region-end (region-end))
517 (setq mouse-last-region-tick (buffer-modified-tick)))
652ccd35 518
3b558d41 519(defcustom mouse-scroll-delay 0.25
600c6e3a
JB
520 "*The pause between scroll steps caused by mouse drags, in seconds.
521If you drag the mouse beyond the edge of a window, Emacs scrolls the
522window to bring the text beyond that edge into view, with a delay of
523this many seconds between scroll steps. Scrolling stops when you move
524the mouse back into the window, or release the button.
525This variable's value may be non-integral.
3b558d41
RS
526Setting this to zero causes Emacs to scroll as fast as it can."
527 :type 'number
528 :group 'mouse)
600c6e3a 529
3b558d41 530(defcustom mouse-scroll-min-lines 1
a3d6bb97
RS
531 "*The minimum number of lines scrolled by dragging mouse out of window.
532Moving the mouse out the top or bottom edge of the window begins
533scrolling repeatedly. The number of lines scrolled per repetition
534is normally equal to the number of lines beyond the window edge that
535the mouse has moved. However, it always scrolls at least the number
3b558d41
RS
536of lines specified by this variable."
537 :type 'integer
538 :group 'mouse)
08a1c178 539
e919a622
RS
540(defun mouse-scroll-subr (window jump &optional overlay start)
541 "Scroll the window WINDOW, JUMP lines at a time, until new input arrives.
600c6e3a
JB
542If OVERLAY is an overlay, let it stretch from START to the far edge of
543the newly visible text.
544Upon exit, point is at the far edge of the newly visible text."
08a1c178
RS
545 (cond
546 ((and (> jump 0) (< jump mouse-scroll-min-lines))
547 (setq jump mouse-scroll-min-lines))
548 ((and (< jump 0) (< (- jump) mouse-scroll-min-lines))
549 (setq jump (- mouse-scroll-min-lines))))
4e399a53
RS
550 (let ((opoint (point)))
551 (while (progn
552 (goto-char (window-start window))
553 (if (not (zerop (vertical-motion jump window)))
554 (progn
555 (set-window-start window (point))
556 (if (natnump jump)
0320e66f
RS
557 (if (window-end window)
558 (progn
559 (goto-char (window-end window))
560 ;; window-end doesn't reflect the window's new
561 ;; start position until the next redisplay.
562 (vertical-motion (1- jump) window))
563 (vertical-motion (- (window-height window) 2)))
4e399a53
RS
564 (goto-char (window-start window)))
565 (if overlay
566 (move-overlay overlay start (point)))
567 ;; Now that we have scrolled WINDOW properly,
568 ;; put point back where it was for the redisplay
569 ;; so that we don't mess up the selected window.
570 (or (eq window (selected-window))
571 (goto-char opoint))
d2287ded 572 (sit-for mouse-scroll-delay)))))
4e399a53
RS
573 (or (eq window (selected-window))
574 (goto-char opoint))))
fcfc3c63 575
dc269e81 576;; Create an overlay and immediately delete it, to get "overlay in no buffer".
600c6e3a 577(defvar mouse-drag-overlay (make-overlay 1 1))
dc269e81 578(delete-overlay mouse-drag-overlay)
600c6e3a
JB
579(overlay-put mouse-drag-overlay 'face 'region)
580
dd524dbd 581(defvar mouse-selection-click-count 0)
eb6ff46f 582
c8c5bd24
RS
583(defvar mouse-selection-click-count-buffer nil)
584
600c6e3a 585(defun mouse-drag-region (start-event)
bcd5aef1 586 "Set the region to the text that the mouse is dragged over.
78210c95
RS
587Highlight the drag area as you move the mouse.
588This must be bound to a button-down mouse event.
d017deb2
RS
589In Transient Mark mode, the highlighting remains as long as the mark
590remains active. Otherwise, it remains until the next input event."
bcd5aef1 591 (interactive "e")
d65147f6 592 (mouse-minibuffer-check start-event)
4c9afcbe
RS
593 (let* ((echo-keystrokes 0)
594 (start-posn (event-start start-event))
600c6e3a
JB
595 (start-point (posn-point start-posn))
596 (start-window (posn-window start-posn))
b846d039 597 (start-frame (window-frame start-window))
1853aa6b 598 (start-hscroll (window-hscroll start-window))
600c6e3a
JB
599 (bounds (window-edges start-window))
600 (top (nth 1 bounds))
601 (bottom (if (window-minibuffer-p start-window)
602 (nth 3 bounds)
603 ;; Don't count the mode line.
e37de120
RS
604 (1- (nth 3 bounds))))
605 (click-count (1- (event-click-count start-event))))
eb6ff46f 606 (setq mouse-selection-click-count click-count)
c8c5bd24 607 (setq mouse-selection-click-count-buffer (current-buffer))
b80f1928 608 (mouse-set-point start-event)
08a1c178
RS
609 ;; In case the down click is in the middle of some intangible text,
610 ;; use the end of that text, and put it in START-POINT.
611 (if (< (point) start-point)
612 (goto-char start-point))
613 (setq start-point (point))
e37de120
RS
614 (let ((range (mouse-start-end start-point start-point click-count)))
615 (move-overlay mouse-drag-overlay (car range) (nth 1 range)
616 (window-buffer start-window)))
f767385c 617 (deactivate-mark)
08a1c178
RS
618 ;; end-of-range is used only in the single-click case.
619 ;; It is the place where the drag has reached so far
620 ;; (but not outside the window where the drag started).
d5c847bb 621 (let (event end end-point last-end-point (end-of-range (point)))
bcd5aef1 622 (track-mouse
600c6e3a 623 (while (progn
b846d039
JB
624 (setq event (read-event))
625 (or (mouse-movement-p event)
626 (eq (car-safe event) 'switch-frame)))
b846d039
JB
627 (if (eq (car-safe event) 'switch-frame)
628 nil
629 (setq end (event-end event)
630 end-point (posn-point end))
3617aa76 631 (if (numberp end-point)
d5c847bb 632 (setq last-end-point end-point))
b846d039
JB
633
634 (cond
b846d039
JB
635 ;; Are we moving within the original window?
636 ((and (eq (posn-window end) start-window)
637 (integer-or-marker-p end-point))
08a1c178
RS
638 ;; Go to START-POINT first, so that when we move to END-POINT,
639 ;; if it's in the middle of intangible text,
640 ;; point jumps in the direction away from START-POINT.
641 (goto-char start-point)
b846d039 642 (goto-char end-point)
08a1c178
RS
643 (if (zerop (% click-count 3))
644 (setq end-of-range (point)))
e37de120
RS
645 (let ((range (mouse-start-end start-point (point) click-count)))
646 (move-overlay mouse-drag-overlay (car range) (nth 1 range))))
b846d039 647
50e527bc
KH
648 (t
649 (let ((mouse-row (cdr (cdr (mouse-position)))))
b846d039 650 (cond
50e527bc 651 ((null mouse-row))
b846d039 652 ((< mouse-row top)
e919a622 653 (mouse-scroll-subr start-window (- mouse-row top)
f9278a75
RS
654 mouse-drag-overlay start-point)
655 ;; Without this, point tends to jump back to the starting
656 ;; position where the mouse button was pressed down.
657 (setq end-of-range (overlay-start mouse-drag-overlay)))
d2287ded 658 ((>= mouse-row bottom)
e919a622 659 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
ce8c2809 660 mouse-drag-overlay start-point)
f9278a75 661 (setq end-of-range (overlay-end mouse-drag-overlay))))))))))
2e3329a5
RS
662 ;; In case we did not get a mouse-motion event
663 ;; for the final move of the mouse before a drag event
664 ;; pretend that we did get one.
665 (when (and (memq 'drag (event-modifiers (car-safe event)))
666 (setq end (event-end event)
667 end-point (posn-point end))
668 (eq (posn-window end) start-window)
669 (integer-or-marker-p end-point))
670
671 ;; Go to START-POINT first, so that when we move to END-POINT,
672 ;; if it's in the middle of intangible text,
673 ;; point jumps in the direction away from START-POINT.
674 (goto-char start-point)
675 (goto-char end-point)
676 (if (zerop (% click-count 3))
677 (setq end-of-range (point)))
678 (let ((range (mouse-start-end start-point (point) click-count)))
679 (move-overlay mouse-drag-overlay (car range) (nth 1 range))))
680
4e399a53 681 (if (consp event)
e37de120 682 (let ((fun (key-binding (vector (car event)))))
bfbcf12e
RS
683 ;; Run the binding of the terminating up-event, if possible.
684 ;; In the case of a multiple click, it gives the wrong results,
685 ;; because it would fail to set up a region.
bb3aa835
RS
686 (if (not (= (overlay-start mouse-drag-overlay)
687 (overlay-end mouse-drag-overlay)))
688 (let* ((stop-point
689 (if (numberp (posn-point (event-end event)))
690 (posn-point (event-end event))
691 last-end-point))
692 ;; The end that comes from where we ended the drag.
693 ;; Point goes here.
694 (region-termination
695 (if (and stop-point (< stop-point start-point))
696 (overlay-start mouse-drag-overlay)
44dc5252 697 (overlay-end mouse-drag-overlay)))
bb3aa835
RS
698 ;; The end that comes from where we started the drag.
699 ;; Mark goes there.
700 (region-commencement
701 (- (+ (overlay-end mouse-drag-overlay)
702 (overlay-start mouse-drag-overlay))
703 region-termination))
704 last-command this-command)
705 (push-mark region-commencement t t)
706 (goto-char region-termination)
1fa01bcd
RS
707 ;; Don't let copy-region-as-kill set deactivate-mark.
708 (let (deactivate-mark)
709 (copy-region-as-kill (point) (mark t)))
bb3aa835
RS
710 (let ((buffer (current-buffer)))
711 (mouse-show-mark)
712 ;; mouse-show-mark can call read-event,
713 ;; and that means the Emacs server could switch buffers
714 ;; under us. If that happened,
715 ;; avoid trying to use the region.
716 (and (mark t) mark-active
717 (eq buffer (current-buffer))
718 (mouse-set-region-1))))
719 (delete-overlay mouse-drag-overlay)
720 ;; Run the binding of the terminating up-event.
f45aab65 721 (when (and (functionp fun)
1853aa6b
GM
722 (= start-hscroll (window-hscroll start-window)))
723 (setq unread-command-events
724 (cons event unread-command-events)))))
e6c2f5d4 725 (delete-overlay mouse-drag-overlay)))))
e37de120
RS
726\f
727;; Commands to handle xterm-style multiple clicks.
600c6e3a 728
e37de120
RS
729(defun mouse-skip-word (dir)
730 "Skip over word, over whitespace, or over identical punctuation.
731If DIR is positive skip forward; if negative, skip backward."
732 (let* ((char (following-char))
733 (syntax (char-to-string (char-syntax char))))
258e3295
KH
734 (cond ((string= syntax "w")
735 ;; Here, we can't use skip-syntax-forward/backward because
736 ;; they don't pay attention to word-separating-categories,
737 ;; and thus they will skip over a true word boundary. So,
738 ;; we simularte the original behaviour by using
739 ;; forward-word.
740 (if (< dir 0)
741 (if (not (looking-at "\\<"))
742 (forward-word -1))
743 (if (or (looking-at "\\<") (not (looking-at "\\>")))
744 (forward-word 1))))
745 ((string= syntax " ")
08a1c178
RS
746 (if (< dir 0)
747 (skip-syntax-backward syntax)
748 (skip-syntax-forward syntax)))
749 ((string= syntax "_")
750 (if (< dir 0)
751 (skip-syntax-backward "w_")
752 (skip-syntax-forward "w_")))
753 ((< dir 0)
754 (while (and (not (bobp)) (= (preceding-char) char))
755 (forward-char -1)))
756 (t
757 (while (and (not (eobp)) (= (following-char) char))
758 (forward-char 1))))))
e37de120
RS
759
760;; Return a list of region bounds based on START and END according to MODE.
761;; If MODE is 0 then set point to (min START END), mark to (max START END).
762;; If MODE is 1 then set point to start of word at (min START END),
763;; mark to end of word at (max START END).
764;; If MODE is 2 then do the same for lines.
eb6ff46f 765(defun mouse-start-end (start end mode)
e37de120
RS
766 (if (> start end)
767 (let ((temp start))
768 (setq start end
769 end temp)))
9a974c88 770 (setq mode (mod mode 3))
e37de120
RS
771 (cond ((= mode 0)
772 (list start end))
773 ((and (= mode 1)
774 (= start end)
1ec71583 775 (char-after start)
e37de120 776 (= (char-syntax (char-after start)) ?\())
6f482eec
RS
777 (list start
778 (save-excursion
779 (goto-char start)
780 (forward-sexp 1)
781 (point))))
e37de120
RS
782 ((and (= mode 1)
783 (= start end)
1ec71583 784 (char-after start)
e37de120
RS
785 (= (char-syntax (char-after start)) ?\)))
786 (list (save-excursion
787 (goto-char (1+ start))
d89a4a47
RS
788 (backward-sexp 1)
789 (point))
e37de120 790 (1+ start)))
53770877
RS
791 ((and (= mode 1)
792 (= start end)
793 (char-after start)
794 (= (char-syntax (char-after start)) ?\"))
795 (let ((open (or (eq start (point-min))
796 (save-excursion
797 (goto-char (- start 1))
798 (looking-at "\\s(\\|\\s \\|\\s>")))))
799 (if open
800 (list start
801 (save-excursion
802 (condition-case nil
803 (progn
804 (goto-char start)
805 (forward-sexp 1)
806 (point))
807 (error end))))
f1017d55 808 (list (save-excursion
53770877
RS
809 (condition-case nil
810 (progn
811 (goto-char (1+ start))
812 (backward-sexp 1)
813 (point))
f1017d55
RS
814 (error end)))
815 (1+ start)))))
e37de120
RS
816 ((= mode 1)
817 (list (save-excursion
818 (goto-char start)
819 (mouse-skip-word -1)
820 (point))
821 (save-excursion
822 (goto-char end)
823 (mouse-skip-word 1)
824 (point))))
825 ((= mode 2)
826 (list (save-excursion
827 (goto-char start)
828 (beginning-of-line 1)
829 (point))
830 (save-excursion
831 (goto-char end)
832 (forward-line 1)
833 (point))))))
e66feb07 834\f
3f26b32a
RS
835;; Subroutine: set the mark where CLICK happened,
836;; but don't do anything else.
837(defun mouse-set-mark-fast (click)
d65147f6 838 (mouse-minibuffer-check click)
3f26b32a
RS
839 (let ((posn (event-start click)))
840 (select-window (posn-window posn))
841 (if (numberp (posn-point posn))
842 (push-mark (posn-point posn) t t))))
843
98aac09d
MB
844(defun mouse-undouble-last-event (events)
845 (let* ((index (1- (length events)))
846 (last (nthcdr index events))
847 (event (car last))
848 (basic (event-basic-type event))
397a88f3
RS
849 (old-modifiers (event-modifiers event))
850 (modifiers (delq 'double (delq 'triple (copy-sequence old-modifiers))))
98aac09d
MB
851 (new
852 (if (consp event)
7132500b
RS
853 ;; Use reverse, not nreverse, since event-modifiers
854 ;; does not copy the list it returns.
3bb846b8 855 (cons (event-convert-list (reverse (cons basic modifiers)))
98aac09d
MB
856 (cdr event))
857 event)))
858 (setcar last new)
397a88f3
RS
859 (if (and (not (equal modifiers old-modifiers))
860 (key-binding (apply 'vector events)))
98aac09d
MB
861 t
862 (setcar last event)
863 nil)))
864
3f26b32a 865;; Momentarily show where the mark is, if highlighting doesn't show it.
7aeb7370
RS
866
867(defvar mouse-region-delete-keys '([delete])
868 "List of keys which shall cause the mouse region to be deleted.")
869
3f26b32a 870(defun mouse-show-mark ()
98aac09d 871 (if transient-mark-mode
d0d57043
EZ
872 (delete-overlay mouse-drag-overlay)
873 (let ((inhibit-quit t)
874 (echo-keystrokes 0)
875 event events key ignore
876 x-lost-selection-hooks)
877 (add-hook 'x-lost-selection-hooks
878 (lambda (seltype)
879 (if (eq seltype 'PRIMARY)
880 (progn (setq ignore t)
881 (throw 'mouse-show-mark t)))))
882 (move-overlay mouse-drag-overlay (point) (mark t))
883 (catch 'mouse-show-mark
884 ;; In this loop, execute scroll bar and switch-frame events.
885 ;; Also ignore down-events that are undefined.
886 (while (progn (setq event (read-event))
887 (setq events (append events (list event)))
888 (setq key (apply 'vector events))
889 (or (and (consp event)
890 (eq (car event) 'switch-frame))
891 (and (consp event)
892 (eq (posn-point (event-end event))
893 'vertical-scroll-bar))
894 (and (memq 'down (event-modifiers event))
895 (not (key-binding key))
896 (not (mouse-undouble-last-event events))
897 (not (member key mouse-region-delete-keys)))))
898 (and (consp event)
899 (or (eq (car event) 'switch-frame)
900 (eq (posn-point (event-end event))
901 'vertical-scroll-bar))
902 (let ((keys (vector 'vertical-scroll-bar event)))
903 (and (key-binding keys)
904 (progn
905 (call-interactively (key-binding keys)
906 nil keys)
907 (setq events nil)))))))
908 ;; If we lost the selection, just turn off the highlighting.
909 (if ignore
910 nil
911 ;; For certain special keys, delete the region.
912 (if (member key mouse-region-delete-keys)
913 (delete-region (overlay-start mouse-drag-overlay)
914 (overlay-end mouse-drag-overlay))
915 ;; Otherwise, unread the key so it gets executed normally.
916 (setq unread-command-events
917 (nconc events unread-command-events))))
918 (setq quit-flag nil)
919 (delete-overlay mouse-drag-overlay))
920 (save-excursion
921 (goto-char (mark t))
922 (sit-for 1))))
3f26b32a 923
cc0a8174
JB
924(defun mouse-set-mark (click)
925 "Set mark at the position clicked on with the mouse.
926Display cursor at that position for a second.
927This must be bound to a mouse click."
ec558adc 928 (interactive "e")
f598fb03
RS
929 (mouse-minibuffer-check click)
930 (select-window (posn-window (event-start click)))
931 ;; We don't use save-excursion because that preserves the mark too.
72ea54a4
RS
932 (let ((point-save (point)))
933 (unwind-protect
cc0a8174 934 (progn (mouse-set-point click)
897897e3
RS
935 (push-mark nil t t)
936 (or transient-mark-mode
937 (sit-for 1)))
72ea54a4
RS
938 (goto-char point-save))))
939
cc0a8174
JB
940(defun mouse-kill (click)
941 "Kill the region between point and the mouse click.
942The text is saved in the kill ring, as with \\[kill-region]."
ec558adc 943 (interactive "e")
d65147f6 944 (mouse-minibuffer-check click)
142c7672
KH
945 (let* ((posn (event-start click))
946 (click-posn (posn-point posn)))
947 (select-window (posn-window posn))
bd307392
JB
948 (if (numberp click-posn)
949 (kill-region (min (point) click-posn)
950 (max (point) click-posn)))))
72ea54a4 951
87ef29fd
JB
952(defun mouse-yank-at-click (click arg)
953 "Insert the last stretch of killed text at the position clicked on.
0e57ab65
GM
954Also move point to one end of the text thus inserted (normally the end),
955and set mark at the beginning..
50f58001
RS
956Prefix arguments are interpreted as with \\[yank].
957If `mouse-yank-at-point' is non-nil, insert at point
958regardless of where you click."
ec558adc 959 (interactive "e\nP")
33c448cd
RS
960 ;; Give temporary modes such as isearch a chance to turn off.
961 (run-hooks 'mouse-leave-buffer-hook)
50f58001 962 (or mouse-yank-at-point (mouse-set-point click))
d89a4a47 963 (setq this-command 'yank)
a814e9df 964 (setq mouse-selection-click-count 0)
87ef29fd
JB
965 (yank arg))
966
967(defun mouse-kill-ring-save (click)
cc0a8174
JB
968 "Copy the region between point and the mouse click in the kill ring.
969This does not delete the region; it acts like \\[kill-ring-save]."
ec558adc 970 (interactive "e")
3f26b32a 971 (mouse-set-mark-fast click)
6452d8a6
RS
972 (let (this-command last-command)
973 (kill-ring-save (point) (mark t)))
3f26b32a 974 (mouse-show-mark))
72ea54a4 975
dbc4e1c1
JB
976;;; This function used to delete the text between point and the mouse
977;;; whenever it was equal to the front of the kill ring, but some
978;;; people found that confusing.
979
980;;; A list (TEXT START END), describing the text and position of the last
981;;; invocation of mouse-save-then-kill.
982(defvar mouse-save-then-kill-posn nil)
983
26d280b9 984(defun mouse-save-then-kill-delete-region (beg end)
9a974c88
RS
985 ;; We must make our own undo boundaries
986 ;; because they happen automatically only for the current buffer.
987 (undo-boundary)
dd524dbd
RS
988 (if (or (= beg end) (eq buffer-undo-list t))
989 ;; If we have no undo list in this buffer,
990 ;; just delete.
991 (delete-region beg end)
992 ;; Delete, but make the undo-list entry share with the kill ring.
993 ;; First, delete just one char, so in case buffer is being modified
994 ;; for the first time, the undo list records that fact.
8faa9707 995 (let (before-change-functions after-change-functions)
2f4b15ef
RS
996 (delete-region beg
997 (+ beg (if (> end beg) 1 -1))))
dd524dbd
RS
998 (let ((buffer-undo-list buffer-undo-list))
999 ;; Undo that deletion--but don't change the undo list!
8faa9707 1000 (let (before-change-functions after-change-functions)
2f4b15ef 1001 (primitive-undo 1 buffer-undo-list))
dd524dbd
RS
1002 ;; Now delete the rest of the specified region,
1003 ;; but don't record it.
1004 (setq buffer-undo-list t)
9a974c88
RS
1005 (if (/= (length (car kill-ring)) (- (max end beg) (min end beg)))
1006 (error "Lossage in mouse-save-then-kill-delete-region"))
dd524dbd
RS
1007 (delete-region beg end))
1008 (let ((tail buffer-undo-list))
1009 ;; Search back in buffer-undo-list for the string
1010 ;; that came from deleting one character.
1011 (while (and tail (not (stringp (car (car tail)))))
1012 (setq tail (cdr tail)))
1013 ;; Replace it with an entry for the entire deleted text.
1014 (and tail
9a974c88
RS
1015 (setcar tail (cons (car kill-ring) (min beg end))))))
1016 (undo-boundary))
eb6ff46f 1017
947da0c4 1018(defun mouse-save-then-kill (click)
40a45a9f
RS
1019 "Save text to point in kill ring; the second time, kill the text.
1020If the text between point and the mouse is the same as what's
1021at the front of the kill ring, this deletes the text.
1022Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
eb6ff46f
RS
1023which prepares for a second click to delete the text.
1024
1025If you have selected words or lines, this command extends the
1026selection through the word or line clicked on. If you do this
1027again in a different position, it extends the selection again.
1028If you do this twice in the same position, the selection is killed."
947da0c4 1029 (interactive "e")
53016bea
RS
1030 (let ((before-scroll
1031 (with-current-buffer (window-buffer (posn-window (event-start click)))
1032 point-before-scroll)))
b64548c7
RS
1033 (mouse-minibuffer-check click)
1034 (let ((click-posn (posn-point (event-start click)))
1035 ;; Don't let a subsequent kill command append to this one:
1036 ;; prevent setting this-command to kill-region.
1037 (this-command this-command))
c8c5bd24
RS
1038 (if (and (save-excursion
1039 (set-buffer (window-buffer (posn-window (event-start click))))
1040 (and (mark t) (> (mod mouse-selection-click-count 3) 0)
1041 ;; Don't be fooled by a recent click in some other buffer.
1042 (eq mouse-selection-click-count-buffer
1043 (current-buffer)))))
b64548c7
RS
1044 (if (not (and (eq last-command 'mouse-save-then-kill)
1045 (equal click-posn
1046 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
1047 ;; Find both ends of the object selected by this click.
1048 (let* ((range
1049 (mouse-start-end click-posn click-posn
1050 mouse-selection-click-count)))
1051 ;; Move whichever end is closer to the click.
1052 ;; That's what xterm does, and it seems reasonable.
1053 (if (< (abs (- click-posn (mark t)))
1054 (abs (- click-posn (point))))
1055 (set-mark (car range))
1056 (goto-char (nth 1 range)))
1057 ;; We have already put the old region in the kill ring.
1058 ;; Replace it with the extended region.
1059 ;; (It would be annoying to make a separate entry.)
1060 (kill-new (buffer-substring (point) (mark t)) t)
e6c2f5d4 1061 (mouse-set-region-1)
b64548c7
RS
1062 ;; Arrange for a repeated mouse-3 to kill this region.
1063 (setq mouse-save-then-kill-posn
1064 (list (car kill-ring) (point) click-posn))
1065 (mouse-show-mark))
1066 ;; If we click this button again without moving it,
1067 ;; that time kill.
bcde3748 1068 (mouse-save-then-kill-delete-region (mark) (point))
b64548c7 1069 (setq mouse-selection-click-count 0)
dd524dbd 1070 (setq mouse-save-then-kill-posn nil))
b64548c7
RS
1071 (if (and (eq last-command 'mouse-save-then-kill)
1072 mouse-save-then-kill-posn
1073 (eq (car mouse-save-then-kill-posn) (car kill-ring))
1074 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
1075 ;; If this is the second time we've called
1076 ;; mouse-save-then-kill, delete the text from the buffer.
1077 (progn
1078 (mouse-save-then-kill-delete-region (point) (mark))
1079 ;; After we kill, another click counts as "the first time".
1080 (setq mouse-save-then-kill-posn nil))
c8f264ae
RS
1081 ;; This is not a repetition.
1082 ;; We are adjusting an old selection or creating a new one.
b64548c7
RS
1083 (if (or (and (eq last-command 'mouse-save-then-kill)
1084 mouse-save-then-kill-posn)
1085 (and mark-active transient-mark-mode)
1086 (and (memq last-command
1087 '(mouse-drag-region mouse-set-region))
1088 (or mark-even-if-inactive
1089 (not transient-mark-mode))))
1090 ;; We have a selection or suitable region, so adjust it.
1091 (let* ((posn (event-start click))
1092 (new (posn-point posn)))
1093 (select-window (posn-window posn))
1094 (if (numberp new)
1095 (progn
1096 ;; Move whichever end of the region is closer to the click.
1097 ;; That is what xterm does, and it seems reasonable.
1098 (if (< (abs (- new (point))) (abs (- new (mark t))))
1099 (goto-char new)
1100 (set-mark new))
1101 (setq deactivate-mark nil)))
bcde3748
RS
1102 (kill-new (buffer-substring (point) (mark t)) t)
1103 (mouse-show-mark))
b64548c7
RS
1104 ;; Set the mark where point is, then move where clicked.
1105 (mouse-set-mark-fast click)
1106 (if before-scroll
1107 (goto-char before-scroll))
1108 (exchange-point-and-mark)
c8f264ae 1109 (kill-new (buffer-substring (point) (mark t)))
d0d57043 1110 (mouse-show-mark))
e6c2f5d4 1111 (mouse-set-region-1)
b64548c7
RS
1112 (setq mouse-save-then-kill-posn
1113 (list (car kill-ring) (point) click-posn)))))))
e66feb07
RS
1114\f
1115(global-set-key [M-mouse-1] 'mouse-start-secondary)
1116(global-set-key [M-drag-mouse-1] 'mouse-set-secondary)
1117(global-set-key [M-down-mouse-1] 'mouse-drag-secondary)
1118(global-set-key [M-mouse-3] 'mouse-secondary-save-then-kill)
9a974c88 1119(global-set-key [M-mouse-2] 'mouse-yank-secondary)
e66feb07
RS
1120
1121;; An overlay which records the current secondary selection
1122;; or else is deleted when there is no secondary selection.
1123;; May be nil.
1124(defvar mouse-secondary-overlay nil)
1125
a94c7fcc
RS
1126(defvar mouse-secondary-click-count 0)
1127
e66feb07
RS
1128;; A marker which records the specified first end for a secondary selection.
1129;; May be nil.
1130(defvar mouse-secondary-start nil)
1131
1132(defun mouse-start-secondary (click)
1133 "Set one end of the secondary selection to the position clicked on.
1134Use \\[mouse-secondary-save-then-kill] to set the other end
1135and complete the secondary selection."
1136 (interactive "e")
d65147f6 1137 (mouse-minibuffer-check click)
e66feb07 1138 (let ((posn (event-start click)))
230aaa73
RS
1139 (save-excursion
1140 (set-buffer (window-buffer (posn-window posn)))
1141 ;; Cancel any preexisting secondary selection.
1142 (if mouse-secondary-overlay
1143 (delete-overlay mouse-secondary-overlay))
1144 (if (numberp (posn-point posn))
1145 (progn
1146 (or mouse-secondary-start
1147 (setq mouse-secondary-start (make-marker)))
1148 (move-marker mouse-secondary-start (posn-point posn)))))))
e66feb07
RS
1149
1150(defun mouse-set-secondary (click)
1151 "Set the secondary selection to the text that the mouse is dragged over.
1152This must be bound to a mouse drag event."
1153 (interactive "e")
d65147f6 1154 (mouse-minibuffer-check click)
e66feb07
RS
1155 (let ((posn (event-start click))
1156 beg
1157 (end (event-end click)))
230aaa73
RS
1158 (save-excursion
1159 (set-buffer (window-buffer (posn-window posn)))
1160 (if (numberp (posn-point posn))
1161 (setq beg (posn-point posn)))
1162 (if mouse-secondary-overlay
1163 (move-overlay mouse-secondary-overlay beg (posn-point end))
1164 (setq mouse-secondary-overlay (make-overlay beg (posn-point end))))
1165 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))))
947da0c4 1166
d89a4a47 1167(defun mouse-drag-secondary (start-event)
e66feb07 1168 "Set the secondary selection to the text that the mouse is dragged over.
d89a4a47 1169Highlight the drag area as you move the mouse.
efc10c97
RS
1170This must be bound to a button-down mouse event.
1171The function returns a non-nil value if it creates a secondary selection."
e66feb07 1172 (interactive "e")
d65147f6 1173 (mouse-minibuffer-check start-event)
4c9afcbe
RS
1174 (let* ((echo-keystrokes 0)
1175 (start-posn (event-start start-event))
d89a4a47
RS
1176 (start-point (posn-point start-posn))
1177 (start-window (posn-window start-posn))
1178 (start-frame (window-frame start-window))
1179 (bounds (window-edges start-window))
1180 (top (nth 1 bounds))
1181 (bottom (if (window-minibuffer-p start-window)
1182 (nth 3 bounds)
1183 ;; Don't count the mode line.
1184 (1- (nth 3 bounds))))
1185 (click-count (1- (event-click-count start-event))))
1186 (save-excursion
1187 (set-buffer (window-buffer start-window))
a94c7fcc 1188 (setq mouse-secondary-click-count click-count)
d89a4a47
RS
1189 (or mouse-secondary-overlay
1190 (setq mouse-secondary-overlay
1191 (make-overlay (point) (point))))
26d280b9 1192 (overlay-put mouse-secondary-overlay 'face 'secondary-selection)
9a974c88 1193 (if (> (mod click-count 3) 0)
26d280b9
RS
1194 ;; Double or triple press: make an initial selection
1195 ;; of one word or line.
d89a4a47
RS
1196 (let ((range (mouse-start-end start-point start-point click-count)))
1197 (set-marker mouse-secondary-start nil)
1198 (move-overlay mouse-secondary-overlay 1 1
1199 (window-buffer start-window))
1200 (move-overlay mouse-secondary-overlay (car range) (nth 1 range)
1201 (window-buffer start-window)))
26d280b9 1202 ;; Single-press: cancel any preexisting secondary selection.
d89a4a47
RS
1203 (or mouse-secondary-start
1204 (setq mouse-secondary-start (make-marker)))
1205 (set-marker mouse-secondary-start start-point)
1206 (delete-overlay mouse-secondary-overlay))
1207 (let (event end end-point)
1208 (track-mouse
1209 (while (progn
1210 (setq event (read-event))
1211 (or (mouse-movement-p event)
1212 (eq (car-safe event) 'switch-frame)))
1213
1214 (if (eq (car-safe event) 'switch-frame)
1215 nil
1216 (setq end (event-end event)
1217 end-point (posn-point end))
1218 (cond
d89a4a47
RS
1219 ;; Are we moving within the original window?
1220 ((and (eq (posn-window end) start-window)
1221 (integer-or-marker-p end-point))
d89a4a47
RS
1222 (let ((range (mouse-start-end start-point end-point
1223 click-count)))
0136e1e3
RS
1224 (if (or (/= start-point end-point)
1225 (null (marker-position mouse-secondary-start)))
1226 (progn
1227 (set-marker mouse-secondary-start nil)
1228 (move-overlay mouse-secondary-overlay
1229 (car range) (nth 1 range))))))
3b0aebe9
RS
1230 (t
1231 (let ((mouse-row (cdr (cdr (mouse-position)))))
1232 (cond
1233 ((null mouse-row))
1234 ((< mouse-row top)
e919a622
RS
1235 (mouse-scroll-subr start-window (- mouse-row top)
1236 mouse-secondary-overlay start-point))
d2287ded 1237 ((>= mouse-row bottom)
e919a622 1238 (mouse-scroll-subr start-window (1+ (- mouse-row bottom))
3b0aebe9 1239 mouse-secondary-overlay start-point)))))))))
d89a4a47 1240
4e399a53 1241 (if (consp event)
d89a4a47
RS
1242 (if (marker-position mouse-secondary-start)
1243 (save-window-excursion
1244 (delete-overlay mouse-secondary-overlay)
9a974c88 1245 (x-set-selection 'SECONDARY nil)
d89a4a47
RS
1246 (select-window start-window)
1247 (save-excursion
1248 (goto-char mouse-secondary-start)
efc10c97
RS
1249 (sit-for 1)
1250 nil))
9a974c88
RS
1251 (x-set-selection
1252 'SECONDARY
1253 (buffer-substring (overlay-start mouse-secondary-overlay)
1254 (overlay-end mouse-secondary-overlay)))))))))
e66feb07 1255
9a974c88 1256(defun mouse-yank-secondary (click)
50f58001
RS
1257 "Insert the secondary selection at the position clicked on.
1258Move point to the end of the inserted text.
1259If `mouse-yank-at-point' is non-nil, insert at point
1260regardless of where you click."
9a974c88 1261 (interactive "e")
33c448cd
RS
1262 ;; Give temporary modes such as isearch a chance to turn off.
1263 (run-hooks 'mouse-leave-buffer-hook)
50f58001
RS
1264 (or mouse-yank-at-point (mouse-set-point click))
1265 (insert (x-get-selection 'SECONDARY)))
9a974c88 1266
7e6404f6 1267(defun mouse-kill-secondary ()
9a974c88
RS
1268 "Kill the text in the secondary selection.
1269This is intended more as a keyboard command than as a mouse command
1270but it can work as either one.
1271
1272The current buffer (in case of keyboard use), or the buffer clicked on,
1273must be the one that the secondary selection is in. This requirement
1274is to prevent accidents."
7e6404f6
RS
1275 (interactive)
1276 (let* ((keys (this-command-keys))
1277 (click (elt keys (1- (length keys)))))
1278 (or (eq (overlay-buffer mouse-secondary-overlay)
1279 (if (listp click)
1280 (window-buffer (posn-window (event-start click)))
1281 (current-buffer)))
1282 (error "Select or click on the buffer where the secondary selection is")))
9dfab550
RS
1283 (let (this-command)
1284 (save-excursion
1285 (set-buffer (overlay-buffer mouse-secondary-overlay))
1286 (kill-region (overlay-start mouse-secondary-overlay)
1287 (overlay-end mouse-secondary-overlay))))
e66feb07 1288 (delete-overlay mouse-secondary-overlay)
9dfab550 1289;;; (x-set-selection 'SECONDARY nil)
e66feb07
RS
1290 (setq mouse-secondary-overlay nil))
1291
1292(defun mouse-secondary-save-then-kill (click)
d89a4a47 1293 "Save text to point in kill ring; the second time, kill the text.
7bbe2cc7
RS
1294You must use this in a buffer where you have recently done \\[mouse-start-secondary].
1295If the text between where you did \\[mouse-start-secondary] and where
1296you use this command matches the text at the front of the kill ring,
1297this command deletes the text.
e66feb07 1298Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
7bbe2cc7 1299which prepares for a second click with this command to delete the text.
d89a4a47 1300
7bbe2cc7
RS
1301If you have already made a secondary selection in that buffer,
1302this command extends or retracts the selection to where you click.
1303If you do this again in a different position, it extends or retracts
1304again. If you do this twice in the same position, it kills the selection."
e66feb07 1305 (interactive "e")
d65147f6 1306 (mouse-minibuffer-check click)
d89a4a47
RS
1307 (let ((posn (event-start click))
1308 (click-posn (posn-point (event-start click)))
e66feb07
RS
1309 ;; Don't let a subsequent kill command append to this one:
1310 ;; prevent setting this-command to kill-region.
1311 (this-command this-command))
9a974c88
RS
1312 (or (eq (window-buffer (posn-window posn))
1313 (or (and mouse-secondary-overlay
1314 (overlay-buffer mouse-secondary-overlay))
1315 (if mouse-secondary-start
1316 (marker-buffer mouse-secondary-start))))
1317 (error "Wrong buffer"))
1318 (save-excursion
1319 (set-buffer (window-buffer (posn-window posn)))
a94c7fcc 1320 (if (> (mod mouse-secondary-click-count 3) 0)
9a974c88
RS
1321 (if (not (and (eq last-command 'mouse-secondary-save-then-kill)
1322 (equal click-posn
1323 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
1324 ;; Find both ends of the object selected by this click.
1325 (let* ((range
1326 (mouse-start-end click-posn click-posn
a94c7fcc 1327 mouse-secondary-click-count)))
9a974c88
RS
1328 ;; Move whichever end is closer to the click.
1329 ;; That's what xterm does, and it seems reasonable.
1330 (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay)))
1331 (abs (- click-posn (overlay-end mouse-secondary-overlay))))
1332 (move-overlay mouse-secondary-overlay (car range)
1333 (overlay-end mouse-secondary-overlay))
d89a4a47
RS
1334 (move-overlay mouse-secondary-overlay
1335 (overlay-start mouse-secondary-overlay)
1336 (nth 1 range)))
9a974c88
RS
1337 ;; We have already put the old region in the kill ring.
1338 ;; Replace it with the extended region.
1339 ;; (It would be annoying to make a separate entry.)
f69140fd
KH
1340 (kill-new (buffer-substring
1341 (overlay-start mouse-secondary-overlay)
1342 (overlay-end mouse-secondary-overlay)) t)
9a974c88
RS
1343 ;; Arrange for a repeated mouse-3 to kill this region.
1344 (setq mouse-save-then-kill-posn
1345 (list (car kill-ring) (point) click-posn)))
1346 ;; If we click this button again without moving it,
1347 ;; that time kill.
d89a4a47 1348 (progn
9a974c88
RS
1349 (mouse-save-then-kill-delete-region
1350 (overlay-start mouse-secondary-overlay)
1351 (overlay-end mouse-secondary-overlay))
1352 (setq mouse-save-then-kill-posn nil)
a94c7fcc 1353 (setq mouse-secondary-click-count 0)
9a974c88
RS
1354 (delete-overlay mouse-secondary-overlay)))
1355 (if (and (eq last-command 'mouse-secondary-save-then-kill)
1356 mouse-save-then-kill-posn
1357 (eq (car mouse-save-then-kill-posn) (car kill-ring))
1358 (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
1359 ;; If this is the second time we've called
1360 ;; mouse-secondary-save-then-kill, delete the text from the buffer.
1361 (progn
1362 (mouse-save-then-kill-delete-region
1363 (overlay-start mouse-secondary-overlay)
1364 (overlay-end mouse-secondary-overlay))
1365 (setq mouse-save-then-kill-posn nil)
1366 (delete-overlay mouse-secondary-overlay))
1367 (if (overlay-start mouse-secondary-overlay)
1368 ;; We have a selection, so adjust it.
1369 (progn
1370 (if (numberp click-posn)
1371 (progn
1372 ;; Move whichever end of the region is closer to the click.
1373 ;; That is what xterm does, and it seems reasonable.
1374 (if (< (abs (- click-posn (overlay-start mouse-secondary-overlay)))
1375 (abs (- click-posn (overlay-end mouse-secondary-overlay))))
1376 (move-overlay mouse-secondary-overlay click-posn
1377 (overlay-end mouse-secondary-overlay))
d89a4a47
RS
1378 (move-overlay mouse-secondary-overlay
1379 (overlay-start mouse-secondary-overlay)
1380 click-posn))
9a974c88 1381 (setq deactivate-mark nil)))
0136e1e3 1382 (if (eq last-command 'mouse-secondary-save-then-kill)
f69140fd
KH
1383 ;; If the front of the kill ring comes from
1384 ;; an immediately previous use of this command,
1385 ;; replace it with the extended region.
1386 ;; (It would be annoying to make a separate entry.)
1387 (kill-new (buffer-substring
0136e1e3 1388 (overlay-start mouse-secondary-overlay)
f69140fd 1389 (overlay-end mouse-secondary-overlay)) t)
1fa01bcd
RS
1390 (let (deactivate-mark)
1391 (copy-region-as-kill (overlay-start mouse-secondary-overlay)
1392 (overlay-end mouse-secondary-overlay)))))
9a974c88
RS
1393 (if mouse-secondary-start
1394 ;; All we have is one end of a selection,
1395 ;; so put the other end here.
1396 (let ((start (+ 0 mouse-secondary-start)))
1397 (kill-ring-save start click-posn)
1398 (if mouse-secondary-overlay
1399 (move-overlay mouse-secondary-overlay start click-posn)
1400 (setq mouse-secondary-overlay (make-overlay start click-posn)))
1401 (overlay-put mouse-secondary-overlay 'face 'secondary-selection))))
1402 (setq mouse-save-then-kill-posn
1403 (list (car kill-ring) (point) click-posn))))
fb28fd5b
RS
1404 (if (overlay-buffer mouse-secondary-overlay)
1405 (x-set-selection 'SECONDARY
9a974c88
RS
1406 (buffer-substring
1407 (overlay-start mouse-secondary-overlay)
1408 (overlay-end mouse-secondary-overlay)))))))
e66feb07 1409\f
0d9be91c 1410(defcustom mouse-buffer-menu-maxlen 20
f1107960
RS
1411 "*Number of buffers in one pane (submenu) of the buffer menu.
1412If we have lots of buffers, divide them into groups of
0d9be91c 1413`mouse-buffer-menu-maxlen' and make a pane (or submenu) for each one."
3b558d41
RS
1414 :type 'integer
1415 :group 'mouse)
f1107960 1416
3ca87c7b
RS
1417(defcustom mouse-buffer-menu-mode-mult 4
1418 "*Group the buffers by the major mode groups on \\[mouse-buffer-menu]?
1419This number which determines (in a hairy way) whether \\[mouse-buffer-menu]
1420will split the buffer menu by the major modes (see
1421`mouse-buffer-menu-mode-groups') or just by menu length.
1422Set to 1 (or even 0!) if you want to group by major mode always, and to
1423a large number if you prefer a mixed multitude. The default is 4."
1424 :type 'integer
1425 :group 'mouse
1426 :version "20.3")
1427
284a88a3
RS
1428(defvar mouse-buffer-menu-mode-groups
1429 '(("Info\\|Help\\|Apropos\\|Man" . "Help")
1430 ("\\bVM\\b\\|\\bMH\\b\\|Message\\|Mail\\|Group\\|Score\\|Summary\\|Article"
1431 . "Mail/News")
1432 ("\\<C\\>" . "C")
1433 ("ObjC" . "C")
1434 ("Text" . "Text")
1435 ("Outline" . "Text")
1436 ("Lisp" . "Lisp"))
1437 "How to group various major modes together in \\[mouse-buffer-menu].
1438Each element has the form (REGEXP . GROUPNAME).
1439If the major mode's name string matches REGEXP, use GROUPNAME instead.")
1440
8b34e79d 1441(defun mouse-buffer-menu (event)
2d82f7b9
RS
1442 "Pop up a menu of buffers for selection with the mouse.
1443This switches buffers in the window that you clicked on,
1444and selects that window."
ec558adc 1445 (interactive "e")
d65147f6 1446 (mouse-minibuffer-check event)
3ca87c7b 1447 (let ((buffers (buffer-list)) alist menu split-by-major-mode sum-of-squares)
284a88a3
RS
1448 ;; Make an alist of elements that look like (MENU-ITEM . BUFFER).
1449 (let ((tail buffers))
1450 (while tail
1451 ;; Divide all buffers into buckets for various major modes.
1452 ;; Each bucket looks like (MODE NAMESTRING BUFFERS...).
1453 (with-current-buffer (car tail)
1454 (let* ((adjusted-major-mode major-mode) elt)
1455 (let ((tail mouse-buffer-menu-mode-groups))
1456 (while tail
1457 (if (string-match (car (car tail)) mode-name)
1458 (setq adjusted-major-mode (cdr (car tail))))
1459 (setq tail (cdr tail))))
1460 (setq elt (assoc adjusted-major-mode split-by-major-mode))
1461 (if (null elt)
1462 (setq elt (list adjusted-major-mode
1463 (if (stringp adjusted-major-mode)
1464 adjusted-major-mode
1465 mode-name))
1466 split-by-major-mode (cons elt split-by-major-mode)))
1467 (or (memq (car tail) (cdr (cdr elt)))
1468 (setcdr (cdr elt) (cons (car tail) (cdr (cdr elt)))))))
1469 (setq tail (cdr tail))))
1470 ;; Compute the sum of squares of sizes of the major-mode buckets.
1471 (let ((tail split-by-major-mode))
1472 (setq sum-of-squares 0)
1473 (while tail
1474 (setq sum-of-squares
1475 (+ sum-of-squares
3ca87c7b 1476 (let ((len (length (cdr (cdr (car tail)))))) (* len len))))
284a88a3 1477 (setq tail (cdr tail))))
3ca87c7b
RS
1478 (if (< (* sum-of-squares mouse-buffer-menu-mode-mult)
1479 (* (length buffers) (length buffers)))
284a88a3
RS
1480 ;; Subdividing by major modes really helps, so let's do it.
1481 (let (subdivided-menus (buffers-left (length buffers)))
1482 ;; Sort the list to put the most popular major modes first.
1483 (setq split-by-major-mode
1484 (sort split-by-major-mode
1485 (function (lambda (elt1 elt2)
1486 (> (length elt1) (length elt2))))))
1487 ;; Make a separate submenu for each major mode
1488 ;; that has more than one buffer,
1489 ;; unless all the remaining buffers are less than 1/10 of them.
1490 (while (and split-by-major-mode
1491 (and (> (length (car split-by-major-mode)) 3)
1492 (> (* buffers-left 10) (length buffers))))
1493 (setq subdivided-menus
1494 (cons (cons
1495 (nth 1 (car split-by-major-mode))
1496 (mouse-buffer-menu-alist
1497 (cdr (cdr (car split-by-major-mode)))))
1498 subdivided-menus))
1499 (setq buffers-left
1500 (- buffers-left (length (cdr (car split-by-major-mode)))))
1501 (setq split-by-major-mode (cdr split-by-major-mode)))
1502 ;; If any major modes are left over,
1503 ;; make a single submenu for them.
1504 (if split-by-major-mode
1505 (setq subdivided-menus
1506 (cons (cons
1507 "Others"
1508 (mouse-buffer-menu-alist
3ca87c7b
RS
1509 ;; we don't need split-by-major-mode any
1510 ;; more, so we can ditch it with nconc.
1511 (apply 'nconc (mapcar 'cddr split-by-major-mode))))
284a88a3 1512 subdivided-menus)))
3ca87c7b 1513 (setq menu (cons "Buffer Menu" (nreverse subdivided-menus))))
284a88a3
RS
1514 (progn
1515 (setq alist (mouse-buffer-menu-alist buffers))
1516 (setq menu (cons "Buffer Menu"
1517 (mouse-buffer-menu-split "Select Buffer" alist)))))
2d82f7b9
RS
1518 (let ((buf (x-popup-menu event menu))
1519 (window (posn-window (event-start event))))
3ca87c7b 1520 (when buf
c0bb9f3b 1521 (or (framep window) (select-window window))
3ca87c7b 1522 (switch-to-buffer buf)))))
284a88a3
RS
1523
1524(defun mouse-buffer-menu-alist (buffers)
1525 (let (tail
1526 (maxlen 0)
1527 head)
1528 (setq buffers
1529 (sort buffers
1530 (function (lambda (elt1 elt2)
1531 (string< (buffer-name elt1) (buffer-name elt2))))))
1532 (setq tail buffers)
1533 (while tail
1534 (or (eq ?\ (aref (buffer-name (car tail)) 0))
1535 (setq maxlen
1536 (max maxlen
1537 (length (buffer-name (car tail))))))
1538 (setq tail (cdr tail)))
1539 (setq tail buffers)
1540 (while tail
1541 (let ((elt (car tail)))
1542 (if (/= (aref (buffer-name elt) 0) ?\ )
1543 (setq head
1544 (cons
1545 (cons
1546 (format
1547 (format "%%%ds %%s%%s %%s" maxlen)
1548 (buffer-name elt)
1549 (if (buffer-modified-p elt) "*" " ")
1550 (save-excursion
1551 (set-buffer elt)
1552 (if buffer-read-only "%" " "))
1553 (or (buffer-file-name elt)
1554 (save-excursion
1555 (set-buffer elt)
1556 (if list-buffers-directory
1557 (expand-file-name
1558 list-buffers-directory)))
1559 ""))
1560 elt)
1561 head))))
1562 (setq tail (cdr tail)))
1563 ;; Compensate for the reversal that the above loop does.
1564 (nreverse head)))
1565
1566(defun mouse-buffer-menu-split (title alist)
1567 ;; If we have lots of buffers, divide them into groups of 20
1568 ;; and make a pane (or submenu) for each one.
0d9be91c 1569 (if (> (length alist) (/ (* mouse-buffer-menu-maxlen 3) 2))
284a88a3
RS
1570 (let ((alist alist) sublists next
1571 (i 1))
1572 (while alist
0d9be91c 1573 ;; Pull off the next mouse-buffer-menu-maxlen buffers
284a88a3 1574 ;; and make them the next element of sublist.
0d9be91c 1575 (setq next (nthcdr mouse-buffer-menu-maxlen alist))
284a88a3 1576 (if next
0d9be91c 1577 (setcdr (nthcdr (1- mouse-buffer-menu-maxlen) alist)
284a88a3
RS
1578 nil))
1579 (setq sublists (cons (cons (format "Buffers %d" i) alist)
1580 sublists))
1581 (setq i (1+ i))
1582 (setq alist next))
1583 (nreverse sublists))
1584 ;; Few buffers--put them all in one pane.
1585 (list (cons title alist))))
72ea54a4 1586\f
5ba2dc3f 1587;;; These need to be rewritten for the new scroll bar implementation.
dbc4e1c1
JB
1588
1589;;;!! ;; Commands for the scroll bar.
1590;;;!!
1591;;;!! (defun mouse-scroll-down (click)
1592;;;!! (interactive "@e")
1593;;;!! (scroll-down (1+ (cdr (mouse-coords click)))))
1594;;;!!
1595;;;!! (defun mouse-scroll-up (click)
1596;;;!! (interactive "@e")
1597;;;!! (scroll-up (1+ (cdr (mouse-coords click)))))
1598;;;!!
1599;;;!! (defun mouse-scroll-down-full ()
1600;;;!! (interactive "@")
1601;;;!! (scroll-down nil))
1602;;;!!
1603;;;!! (defun mouse-scroll-up-full ()
1604;;;!! (interactive "@")
1605;;;!! (scroll-up nil))
1606;;;!!
1607;;;!! (defun mouse-scroll-move-cursor (click)
1608;;;!! (interactive "@e")
1609;;;!! (move-to-window-line (1+ (cdr (mouse-coords click)))))
1610;;;!!
1611;;;!! (defun mouse-scroll-absolute (event)
1612;;;!! (interactive "@e")
1613;;;!! (let* ((pos (car event))
1614;;;!! (position (car pos))
1615;;;!! (length (car (cdr pos))))
1616;;;!! (if (<= length 0) (setq length 1))
1617;;;!! (let* ((scale-factor (max 1 (/ length (/ 8000000 (buffer-size)))))
1618;;;!! (newpos (* (/ (* (/ (buffer-size) scale-factor)
1619;;;!! position)
1620;;;!! length)
1621;;;!! scale-factor)))
1622;;;!! (goto-char newpos)
1623;;;!! (recenter '(4)))))
1624;;;!!
1625;;;!! (defun mouse-scroll-left (click)
1626;;;!! (interactive "@e")
1627;;;!! (scroll-left (1+ (car (mouse-coords click)))))
1628;;;!!
1629;;;!! (defun mouse-scroll-right (click)
1630;;;!! (interactive "@e")
1631;;;!! (scroll-right (1+ (car (mouse-coords click)))))
1632;;;!!
1633;;;!! (defun mouse-scroll-left-full ()
1634;;;!! (interactive "@")
1635;;;!! (scroll-left nil))
1636;;;!!
1637;;;!! (defun mouse-scroll-right-full ()
1638;;;!! (interactive "@")
1639;;;!! (scroll-right nil))
1640;;;!!
1641;;;!! (defun mouse-scroll-move-cursor-horizontally (click)
1642;;;!! (interactive "@e")
1643;;;!! (move-to-column (1+ (car (mouse-coords click)))))
1644;;;!!
1645;;;!! (defun mouse-scroll-absolute-horizontally (event)
1646;;;!! (interactive "@e")
1647;;;!! (let* ((pos (car event))
1648;;;!! (position (car pos))
1649;;;!! (length (car (cdr pos))))
1650;;;!! (set-window-hscroll (selected-window) 33)))
1651;;;!!
1652;;;!! (global-set-key [scroll-bar mouse-1] 'mouse-scroll-up)
1653;;;!! (global-set-key [scroll-bar mouse-2] 'mouse-scroll-absolute)
1654;;;!! (global-set-key [scroll-bar mouse-3] 'mouse-scroll-down)
1655;;;!!
1656;;;!! (global-set-key [vertical-slider mouse-1] 'mouse-scroll-move-cursor)
1657;;;!! (global-set-key [vertical-slider mouse-2] 'mouse-scroll-move-cursor)
1658;;;!! (global-set-key [vertical-slider mouse-3] 'mouse-scroll-move-cursor)
1659;;;!!
1660;;;!! (global-set-key [thumbup mouse-1] 'mouse-scroll-up-full)
1661;;;!! (global-set-key [thumbup mouse-2] 'mouse-scroll-up-full)
1662;;;!! (global-set-key [thumbup mouse-3] 'mouse-scroll-up-full)
1663;;;!!
1664;;;!! (global-set-key [thumbdown mouse-1] 'mouse-scroll-down-full)
1665;;;!! (global-set-key [thumbdown mouse-2] 'mouse-scroll-down-full)
1666;;;!! (global-set-key [thumbdown mouse-3] 'mouse-scroll-down-full)
1667;;;!!
1668;;;!! (global-set-key [horizontal-scroll-bar mouse-1] 'mouse-scroll-left)
1669;;;!! (global-set-key [horizontal-scroll-bar mouse-2]
1670;;;!! 'mouse-scroll-absolute-horizontally)
1671;;;!! (global-set-key [horizontal-scroll-bar mouse-3] 'mouse-scroll-right)
1672;;;!!
1673;;;!! (global-set-key [horizontal-slider mouse-1]
1674;;;!! 'mouse-scroll-move-cursor-horizontally)
1675;;;!! (global-set-key [horizontal-slider mouse-2]
1676;;;!! 'mouse-scroll-move-cursor-horizontally)
1677;;;!! (global-set-key [horizontal-slider mouse-3]
1678;;;!! 'mouse-scroll-move-cursor-horizontally)
1679;;;!!
1680;;;!! (global-set-key [thumbleft mouse-1] 'mouse-scroll-left-full)
1681;;;!! (global-set-key [thumbleft mouse-2] 'mouse-scroll-left-full)
1682;;;!! (global-set-key [thumbleft mouse-3] 'mouse-scroll-left-full)
1683;;;!!
1684;;;!! (global-set-key [thumbright mouse-1] 'mouse-scroll-right-full)
1685;;;!! (global-set-key [thumbright mouse-2] 'mouse-scroll-right-full)
1686;;;!! (global-set-key [thumbright mouse-3] 'mouse-scroll-right-full)
1687;;;!!
1688;;;!! (global-set-key [horizontal-scroll-bar S-mouse-2]
1689;;;!! 'mouse-split-window-horizontally)
1690;;;!! (global-set-key [mode-line S-mouse-2]
1691;;;!! 'mouse-split-window-horizontally)
1692;;;!! (global-set-key [vertical-scroll-bar S-mouse-2]
1693;;;!! 'mouse-split-window)
6b2154de 1694\f
dbc4e1c1
JB
1695;;;!! ;;;;
1696;;;!! ;;;; Here are experimental things being tested. Mouse events
1697;;;!! ;;;; are of the form:
1698;;;!! ;;;; ((x y) window screen-part key-sequence timestamp)
1699;;;!! ;;
1700;;;!! ;;;;
1701;;;!! ;;;; Dynamically track mouse coordinates
1702;;;!! ;;;;
1703;;;!! ;;
1704;;;!! ;;(defun track-mouse (event)
1705;;;!! ;; "Track the coordinates, absolute and relative, of the mouse."
1706;;;!! ;; (interactive "@e")
1707;;;!! ;; (while mouse-grabbed
1708;;;!! ;; (let* ((pos (read-mouse-position (selected-screen)))
1709;;;!! ;; (abs-x (car pos))
1710;;;!! ;; (abs-y (cdr pos))
1711;;;!! ;; (relative-coordinate (coordinates-in-window-p
1712;;;!! ;; (list (car pos) (cdr pos))
1713;;;!! ;; (selected-window))))
1714;;;!! ;; (if (consp relative-coordinate)
1715;;;!! ;; (message "mouse: [%d %d], (%d %d)" abs-x abs-y
1716;;;!! ;; (car relative-coordinate)
1717;;;!! ;; (car (cdr relative-coordinate)))
1718;;;!! ;; (message "mouse: [%d %d]" abs-x abs-y)))))
1719;;;!!
1720;;;!! ;;
1721;;;!! ;; Dynamically put a box around the line indicated by point
1722;;;!! ;;
1723;;;!! ;;
1724;;;!! ;;(require 'backquote)
1725;;;!! ;;
1726;;;!! ;;(defun mouse-select-buffer-line (event)
1727;;;!! ;; (interactive "@e")
1728;;;!! ;; (let ((relative-coordinate
1729;;;!! ;; (coordinates-in-window-p (car event) (selected-window)))
1730;;;!! ;; (abs-y (car (cdr (car event)))))
1731;;;!! ;; (if (consp relative-coordinate)
1732;;;!! ;; (progn
1733;;;!! ;; (save-excursion
1734;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1735;;;!! ;; (x-draw-rectangle
1736;;;!! ;; (selected-screen)
1737;;;!! ;; abs-y 0
1738;;;!! ;; (save-excursion
1739;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1740;;;!! ;; (end-of-line)
1741;;;!! ;; (push-mark nil t)
1742;;;!! ;; (beginning-of-line)
1743;;;!! ;; (- (region-end) (region-beginning))) 1))
1744;;;!! ;; (sit-for 1)
1745;;;!! ;; (x-erase-rectangle (selected-screen))))))
1746;;;!! ;;
1747;;;!! ;;(defvar last-line-drawn nil)
1748;;;!! ;;(defvar begin-delim "[^ \t]")
1749;;;!! ;;(defvar end-delim "[^ \t]")
1750;;;!! ;;
1751;;;!! ;;(defun mouse-boxing (event)
1752;;;!! ;; (interactive "@e")
1753;;;!! ;; (save-excursion
1754;;;!! ;; (let ((screen (selected-screen)))
1755;;;!! ;; (while (= (x-mouse-events) 0)
1756;;;!! ;; (let* ((pos (read-mouse-position screen))
1757;;;!! ;; (abs-x (car pos))
1758;;;!! ;; (abs-y (cdr pos))
1759;;;!! ;; (relative-coordinate
1760;;;!! ;; (coordinates-in-window-p (` ((, abs-x) (, abs-y)))
1761;;;!! ;; (selected-window)))
1762;;;!! ;; (begin-reg nil)
1763;;;!! ;; (end-reg nil)
1764;;;!! ;; (end-column nil)
1765;;;!! ;; (begin-column nil))
1766;;;!! ;; (if (and (consp relative-coordinate)
1767;;;!! ;; (or (not last-line-drawn)
1768;;;!! ;; (not (= last-line-drawn abs-y))))
1769;;;!! ;; (progn
1770;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1771;;;!! ;; (if (= (following-char) 10)
1772;;;!! ;; ()
1773;;;!! ;; (progn
1774;;;!! ;; (setq begin-reg (1- (re-search-forward end-delim)))
1775;;;!! ;; (setq begin-column (1- (current-column)))
1776;;;!! ;; (end-of-line)
1777;;;!! ;; (setq end-reg (1+ (re-search-backward begin-delim)))
1778;;;!! ;; (setq end-column (1+ (current-column)))
1779;;;!! ;; (message "%s" (buffer-substring begin-reg end-reg))
1780;;;!! ;; (x-draw-rectangle screen
1781;;;!! ;; (setq last-line-drawn abs-y)
1782;;;!! ;; begin-column
1783;;;!! ;; (- end-column begin-column) 1))))))))))
1784;;;!! ;;
1785;;;!! ;;(defun mouse-erase-box ()
1786;;;!! ;; (interactive)
1787;;;!! ;; (if last-line-drawn
1788;;;!! ;; (progn
1789;;;!! ;; (x-erase-rectangle (selected-screen))
1790;;;!! ;; (setq last-line-drawn nil))))
1791;;;!!
1792;;;!! ;;; (defun test-x-rectangle ()
1793;;;!! ;;; (use-local-mouse-map (setq rectangle-test-map (make-sparse-keymap)))
1794;;;!! ;;; (define-key rectangle-test-map mouse-motion-button-left 'mouse-boxing)
1795;;;!! ;;; (define-key rectangle-test-map mouse-button-left-up 'mouse-erase-box))
1796;;;!!
1797;;;!! ;;
1798;;;!! ;; Here is how to do double clicking in lisp. About to change.
1799;;;!! ;;
1800;;;!!
1801;;;!! (defvar double-start nil)
1802;;;!! (defconst double-click-interval 300
1803;;;!! "Max ticks between clicks")
1804;;;!!
1805;;;!! (defun double-down (event)
1806;;;!! (interactive "@e")
1807;;;!! (if double-start
1808;;;!! (let ((interval (- (nth 4 event) double-start)))
1809;;;!! (if (< interval double-click-interval)
1810;;;!! (progn
1811;;;!! (backward-up-list 1)
1812;;;!! ;; (message "Interval %d" interval)
1813;;;!! (sleep-for 1)))
1814;;;!! (setq double-start nil))
1815;;;!! (setq double-start (nth 4 event))))
1816;;;!!
1817;;;!! (defun double-up (event)
1818;;;!! (interactive "@e")
1819;;;!! (and double-start
1820;;;!! (> (- (nth 4 event ) double-start) double-click-interval)
1821;;;!! (setq double-start nil)))
1822;;;!!
1823;;;!! ;;; (defun x-test-doubleclick ()
1824;;;!! ;;; (use-local-mouse-map (setq doubleclick-test-map (make-sparse-keymap)))
1825;;;!! ;;; (define-key doubleclick-test-map mouse-button-left 'double-down)
1826;;;!! ;;; (define-key doubleclick-test-map mouse-button-left-up 'double-up))
1827;;;!!
1828;;;!! ;;
5ba2dc3f 1829;;;!! ;; This scrolls while button is depressed. Use preferable in scroll bar.
dbc4e1c1
JB
1830;;;!! ;;
1831;;;!!
1832;;;!! (defvar scrolled-lines 0)
1833;;;!! (defconst scroll-speed 1)
1834;;;!!
1835;;;!! (defun incr-scroll-down (event)
1836;;;!! (interactive "@e")
1837;;;!! (setq scrolled-lines 0)
1838;;;!! (incremental-scroll scroll-speed))
1839;;;!!
1840;;;!! (defun incr-scroll-up (event)
1841;;;!! (interactive "@e")
1842;;;!! (setq scrolled-lines 0)
1843;;;!! (incremental-scroll (- scroll-speed)))
1844;;;!!
1845;;;!! (defun incremental-scroll (n)
1846;;;!! (while (= (x-mouse-events) 0)
1847;;;!! (setq scrolled-lines (1+ (* scroll-speed scrolled-lines)))
1848;;;!! (scroll-down n)
1849;;;!! (sit-for 300 t)))
1850;;;!!
1851;;;!! (defun incr-scroll-stop (event)
1852;;;!! (interactive "@e")
1853;;;!! (message "Scrolled %d lines" scrolled-lines)
1854;;;!! (setq scrolled-lines 0)
1855;;;!! (sleep-for 1))
1856;;;!!
1857;;;!! ;;; (defun x-testing-scroll ()
1858;;;!! ;;; (let ((scrolling-map (function mouse-vertical-scroll-bar-prefix)))
1859;;;!! ;;; (define-key scrolling-map mouse-button-left 'incr-scroll-down)
1860;;;!! ;;; (define-key scrolling-map mouse-button-right 'incr-scroll-up)
1861;;;!! ;;; (define-key scrolling-map mouse-button-left-up 'incr-scroll-stop)
1862;;;!! ;;; (define-key scrolling-map mouse-button-right-up 'incr-scroll-stop)))
1863;;;!!
1864;;;!! ;;
1865;;;!! ;; Some playthings suitable for picture mode? They need work.
1866;;;!! ;;
1867;;;!!
1868;;;!! (defun mouse-kill-rectangle (event)
1869;;;!! "Kill the rectangle between point and the mouse cursor."
1870;;;!! (interactive "@e")
1871;;;!! (let ((point-save (point)))
1872;;;!! (save-excursion
1873;;;!! (mouse-set-point event)
1874;;;!! (push-mark nil t)
1875;;;!! (if (> point-save (point))
1876;;;!! (kill-rectangle (point) point-save)
1877;;;!! (kill-rectangle point-save (point))))))
1878;;;!!
1879;;;!! (defun mouse-open-rectangle (event)
1880;;;!! "Kill the rectangle between point and the mouse cursor."
1881;;;!! (interactive "@e")
1882;;;!! (let ((point-save (point)))
1883;;;!! (save-excursion
1884;;;!! (mouse-set-point event)
1885;;;!! (push-mark nil t)
1886;;;!! (if (> point-save (point))
1887;;;!! (open-rectangle (point) point-save)
1888;;;!! (open-rectangle point-save (point))))))
1889;;;!!
1890;;;!! ;; Must be a better way to do this.
1891;;;!!
1892;;;!! (defun mouse-multiple-insert (n char)
1893;;;!! (while (> n 0)
1894;;;!! (insert char)
1895;;;!! (setq n (1- n))))
1896;;;!!
1897;;;!! ;; What this could do is not finalize until button was released.
1898;;;!!
1899;;;!! (defun mouse-move-text (event)
1900;;;!! "Move text from point to cursor position, inserting spaces."
1901;;;!! (interactive "@e")
1902;;;!! (let* ((relative-coordinate
1903;;;!! (coordinates-in-window-p (car event) (selected-window))))
1904;;;!! (if (consp relative-coordinate)
1905;;;!! (cond ((> (current-column) (car relative-coordinate))
1906;;;!! (delete-char
1907;;;!! (- (car relative-coordinate) (current-column))))
1908;;;!! ((< (current-column) (car relative-coordinate))
1909;;;!! (mouse-multiple-insert
1910;;;!! (- (car relative-coordinate) (current-column)) " "))
1911;;;!! ((= (current-column) (car relative-coordinate)) (ding))))))
07a78410 1912\f
f936ae06
RS
1913;; Choose a completion with the mouse.
1914
1915(defun mouse-choose-completion (event)
49e61c42 1916 "Click on an alternative in the `*Completions*' buffer to choose it."
f936ae06 1917 (interactive "e")
33c448cd
RS
1918 ;; Give temporary modes such as isearch a chance to turn off.
1919 (run-hooks 'mouse-leave-buffer-hook)
d89a4a47 1920 (let ((buffer (window-buffer))
02680e9b
RS
1921 choice
1922 base-size)
f936ae06
RS
1923 (save-excursion
1924 (set-buffer (window-buffer (posn-window (event-start event))))
f36f4e9e
RS
1925 (if completion-reference-buffer
1926 (setq buffer completion-reference-buffer))
02680e9b 1927 (setq base-size completion-base-size)
f936ae06
RS
1928 (save-excursion
1929 (goto-char (posn-point (event-start event)))
b6be5d95 1930 (let (beg end)
9a43a594
RS
1931 (if (and (not (eobp)) (get-text-property (point) 'mouse-face))
1932 (setq end (point) beg (1+ (point))))
1933 (if (null beg)
1934 (error "No completion here"))
1935 (setq beg (previous-single-property-change beg 'mouse-face))
2f5ed2e8
RS
1936 (setq end (or (next-single-property-change end 'mouse-face)
1937 (point-max)))
b6be5d95 1938 (setq choice (buffer-substring beg end)))))
73e2025f
RS
1939 (let ((owindow (selected-window)))
1940 (select-window (posn-window (event-start event)))
874a2cbd
RS
1941 (if (and (one-window-p t 'selected-frame)
1942 (window-dedicated-p (selected-window)))
1943 ;; This is a special buffer's frame
1944 (iconify-frame (selected-frame))
1945 (or (window-dedicated-p (selected-window))
1946 (bury-buffer)))
73e2025f 1947 (select-window owindow))
02680e9b 1948 (choose-completion-string choice buffer base-size)))
f936ae06 1949\f
07a78410
RS
1950;; Font selection.
1951
0eb9fef3
RS
1952(defun font-menu-add-default ()
1953 (let* ((default (cdr (assq 'font (frame-parameters (selected-frame)))))
1954 (font-alist x-fixed-font-alist)
0d94f5ca 1955 (elt (or (assoc "Misc" font-alist) (nth 1 font-alist))))
0eb9fef3
RS
1956 (if (assoc "Default" elt)
1957 (delete (assoc "Default" elt) elt))
1958 (setcdr elt
6b8e486e 1959 (cons (list "Default" default)
0eb9fef3
RS
1960 (cdr elt)))))
1961
07a78410
RS
1962(defvar x-fixed-font-alist
1963 '("Font menu"
1964 ("Misc"
19d973e8
RS
1965 ;; For these, we specify the pixel height and width.
1966 ("fixed" "fixed")
1967 ("6x10" "-misc-fixed-medium-r-normal--10-*-*-*-c-60-iso8859-1" "6x10")
1968 ("6x12"
1969 "-misc-fixed-medium-r-semicondensed--12-*-*-*-c-60-iso8859-1" "6x12")
1970 ("6x13"
1971 "-misc-fixed-medium-r-semicondensed--13-*-*-*-c-60-iso8859-1" "6x13")
1972 ("7x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-70-iso8859-1" "7x13")
1973 ("7x14" "-misc-fixed-medium-r-normal--14-*-*-*-c-70-iso8859-1" "7x14")
1974 ("8x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-80-iso8859-1" "8x13")
1975 ("9x15" "-misc-fixed-medium-r-normal--15-*-*-*-c-90-iso8859-1" "9x15")
1976 ("10x20" "-misc-fixed-medium-r-normal--20-*-*-*-c-100-iso8859-1" "10x20")
1977 ("11x18" "-misc-fixed-medium-r-normal--18-*-*-*-c-110-iso8859-1" "11x18")
1978 ("12x24" "-misc-fixed-medium-r-normal--24-*-*-*-c-120-iso8859-1" "12x24")
fa21fdec 1979 ("")
f29c3695
RS
1980 ("clean 5x8"
1981 "-schumacher-clean-medium-r-normal--8-*-*-*-c-50-iso8859-1")
1982 ("clean 6x8"
1983 "-schumacher-clean-medium-r-normal--8-*-*-*-c-60-iso8859-1")
19d973e8
RS
1984 ("clean 8x8"
1985 "-schumacher-clean-medium-r-normal--8-*-*-*-c-80-iso8859-1")
1986 ("clean 8x10"
1987 "-schumacher-clean-medium-r-normal--10-*-*-*-c-80-iso8859-1")
1988 ("clean 8x14"
1989 "-schumacher-clean-medium-r-normal--14-*-*-*-c-80-iso8859-1")
1990 ("clean 8x16"
1991 "-schumacher-clean-medium-r-normal--16-*-*-*-c-80-iso8859-1")
fa21fdec 1992 ("")
29a3028d 1993 ("sony 8x16" "-sony-fixed-medium-r-normal--16-*-*-*-c-80-iso8859-1")
07a78410
RS
1994;;; We don't seem to have these; who knows what they are.
1995;;; ("fg-18" "fg-18")
1996;;; ("fg-25" "fg-25")
29a3028d
DL
1997 ("lucidasanstypewriter-12" "-b&h-lucidatypewriter-medium-r-normal-sans-*-120-*-*-*-*-iso8859-1")
1998 ("lucidasanstypewriter-bold-14" "-b&h-lucidatypewriter-bold-r-normal-sans-*-140-*-*-*-*-iso8859-1")
1999 ("lucidasanstypewriter-bold-24"
2000 "-b&h-lucidatypewriter-bold-r-normal-sans-*-240-*-*-*-*-iso8859-1")
07a78410
RS
2001;;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
2002;;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
29a3028d 2003 )
07a78410 2004 ("Courier"
19d973e8 2005 ;; For these, we specify the point height.
82c048a9
RS
2006 ("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1")
2007 ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1")
2008 ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1")
2009 ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1")
2010 ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1")
2011 ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1")
2012 ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1")
2013 ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1")
2014 ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1")
2015 ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1")
2016 ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1")
2017 ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1")
2018 ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1")
2019 ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1")
2020 ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1")
2021 ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1")
2022 ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1")
2023 ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1")
2024 ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1")
2025 ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1")
2026 ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1")
2027 ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1")
2028 ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1")
2029 ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1"))
07a78410
RS
2030 )
2031 "X fonts suitable for use in Emacs.")
2032
1900a92b 2033(defun mouse-set-font (&rest fonts)
51a02226 2034 "Select an emacs font from a list of known good fonts and fontsets."
07a78410 2035 (interactive
51a02226
KH
2036 (x-popup-menu
2037 last-nonmenu-event
2038 ;; Append list of fontsets currently defined.
2039 (append x-fixed-font-alist (list (generate-fontset-menu)))))
df4de8c6
KH
2040 (if fonts
2041 (let (font)
2042 (while fonts
2043 (condition-case nil
2044 (progn
3fadec1a 2045 (set-default-font (car fonts))
df4de8c6
KH
2046 (setq font (car fonts))
2047 (setq fonts nil))
3fadec1a
RS
2048 (error
2049 (setq fonts (cdr fonts)))))
df4de8c6 2050 (if (null font)
3fadec1a 2051 (error "Font not found")))))
cc0a8174
JB
2052\f
2053;;; Bindings for mouse commands.
2054
fcfc3c63 2055(define-key global-map [down-mouse-1] 'mouse-drag-region)
dbc4e1c1 2056(global-set-key [mouse-1] 'mouse-set-point)
dbc4e1c1 2057(global-set-key [drag-mouse-1] 'mouse-set-region)
fcfc3c63 2058
e37de120
RS
2059;; These are tested for in mouse-drag-region.
2060(global-set-key [double-mouse-1] 'mouse-set-point)
2061(global-set-key [triple-mouse-1] 'mouse-set-point)
2062
dbc4e1c1
JB
2063(global-set-key [mouse-2] 'mouse-yank-at-click)
2064(global-set-key [mouse-3] 'mouse-save-then-kill)
8b34e79d 2065
dbc4e1c1
JB
2066;; By binding these to down-going events, we let the user use the up-going
2067;; event to make the selection, saving a click.
08a1c178
RS
2068(global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
2069(if (not (eq system-type 'ms-dos))
2070 (global-set-key [S-down-mouse-1] 'mouse-set-font))
eef805d7 2071;; C-down-mouse-2 is bound in facemenu.el.
de420e82 2072(global-set-key [C-down-mouse-3] 'mouse-popup-menubar-stuff)
95132d1c 2073
07a78410 2074
8b34e79d
RS
2075;; Replaced with dragging mouse-1
2076;; (global-set-key [S-mouse-1] 'mouse-set-mark)
947da0c4 2077
3c2dd2c0 2078(global-set-key [mode-line mouse-1] 'mouse-select-window)
544e7e73
RS
2079(global-set-key [mode-line drag-mouse-1] 'mouse-select-window)
2080(global-set-key [mode-line down-mouse-1] 'mouse-drag-mode-line)
b0d22e20 2081(global-set-key [header-line down-mouse-1] 'mouse-drag-header-line)
3c2dd2c0 2082(global-set-key [mode-line mouse-2] 'mouse-delete-other-windows)
dbc4e1c1 2083(global-set-key [mode-line mouse-3] 'mouse-delete-window)
3c2dd2c0 2084(global-set-key [mode-line C-mouse-2] 'mouse-split-window-horizontally)
9926ab64 2085(global-set-key [vertical-scroll-bar C-mouse-2] 'mouse-split-window-vertically)
b6522df6 2086(global-set-key [vertical-line C-mouse-2] 'mouse-split-window-vertically)
08a1c178
RS
2087(global-set-key [vertical-line down-mouse-1] 'mouse-drag-vertical-line)
2088(global-set-key [vertical-line mouse-1] 'mouse-select-window)
49116ac0
JB
2089
2090(provide 'mouse)
2091
2fe85227
DL
2092;; This file contains the functionality of the old mldrag.el.
2093(defalias 'mldrag-drag-mode-line 'mouse-drag-mode-line)
2094(defalias 'mldrag-drag-vertical-line 'mouse-drag-vertical-line)
342a1e7b
SM
2095(make-obsolete 'mldrag-drag-mode-line 'mouse-drag-mode-line "21.1")
2096(make-obsolete 'mldrag-drag-vertical-line 'mouse-drag-vertical-line "21.1")
2fe85227
DL
2097(provide 'mldrag)
2098
6594deb0 2099;;; mouse.el ends here