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