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