1 ;;; mouse.el --- window system-independent mouse support
3 ;; Copyright (C) 1993-1995, 1999-2011 Free Software Foundation, Inc.
6 ;; Keywords: hardware, mouse
9 ;; This file is part of GNU Emacs.
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 3 of the License, or
14 ;; (at your option) any later version.
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.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; This package provides various useful commands (including help
27 ;; system access) through the mouse. All this code assumes that mouse
28 ;; interpretation has been abstracted into Emacs input events.
30 ;; The code is rather X-dependent.
34 ;;; Utility functions.
36 ;; Indent track-mouse like progn.
37 (put 'track-mouse
'lisp-indent-function
0)
39 (defcustom mouse-yank-at-point nil
40 "If non-nil, mouse yank commands yank at point instead of at click."
44 (defcustom mouse-drag-copy-region nil
45 "If non-nil, copy to kill-ring upon mouse adjustments of the region.
47 This affects `mouse-save-then-kill' (\\[mouse-save-then-kill]) in
48 addition to mouse drags."
53 (defcustom mouse-1-click-follows-link
450
54 "Non-nil means that clicking Mouse-1 on a link follows the link.
56 With the default setting, an ordinary Mouse-1 click on a link
57 performs the same action as Mouse-2 on that link, while a longer
58 Mouse-1 click \(hold down the Mouse-1 button for more than 450
59 milliseconds) performs the original Mouse-1 binding \(which
60 typically sets point where you click the mouse).
62 If value is an integer, the time elapsed between pressing and
63 releasing the mouse button determines whether to follow the link
64 or perform the normal Mouse-1 action (typically set point).
65 The absolute numeric value specifices the maximum duration of a
66 \"short click\" in milliseconds. A positive value means that a
67 short click follows the link, and a longer click performs the
68 normal action. A negative value gives the opposite behavior.
70 If value is `double', a double click follows the link.
72 Otherwise, a single Mouse-1 click unconditionally follows the link.
74 Note that dragging the mouse never follows the link.
76 This feature only works in modes that specifically identify
77 clickable text as links, so it may not work with some external
78 packages. See `mouse-on-link-p' for details."
80 :type
'(choice (const :tag
"Disabled" nil
)
81 (const :tag
"Double click" double
)
82 (number :tag
"Single click time limit" :value
450)
83 (other :tag
"Single click" t
))
86 (defcustom mouse-1-click-in-non-selected-windows t
87 "If non-nil, a Mouse-1 click also follows links in non-selected windows.
89 If nil, a Mouse-1 click on a link in a non-selected window performs
90 the normal mouse-1 binding, typically selects the window and sets
91 point at the click position."
98 ;; Provide a mode-specific menu on a mouse button.
100 (defun popup-menu (menu &optional position prefix
)
101 "Popup the given menu and call the selected option.
102 MENU can be a keymap, an easymenu-style menu or a list of keymaps as for
104 POSITION can be a click event or ((XOFFSET YOFFSET) WINDOW) and defaults to
105 the current mouse position.
106 PREFIX is the prefix argument (if any) to pass to the command."
108 ((keymapp menu
) menu
)
109 ((and (listp menu
) (keymapp (car menu
))) menu
)
110 (t (let* ((map (easy-menu-create-menu (car menu
) (cdr menu
)))
111 (filter (when (symbolp map
)
112 (plist-get (get map
'menu-prop
) :filter
))))
113 (if filter
(funcall filter
(symbol-function map
)) map
)))))
116 (let ((mp (mouse-pixel-position)))
117 (setq position
(list (list (cadr mp
) (cddr mp
)) (car mp
)))))
118 ;; The looping behavior was taken from lmenu's popup-menu-popup
119 (while (and map
(setq event
120 ;; map could be a prefix key, in which case
121 ;; we need to get its function cell
123 (x-popup-menu position
(indirect-function map
))))
124 ;; Strangely x-popup-menu returns a list.
125 ;; mouse-major-mode-menu was using a weird:
126 ;; (key-binding (apply 'vector (append '(menu-bar) menu-prefix events)))
128 (if (and (not (keymapp map
)) (listp map
))
129 ;; We were given a list of keymaps. Search them all
130 ;; in sequence until a first binding is found.
131 (let ((mouse-click (apply 'vector event
))
133 (while (and map
(null binding
))
134 (setq binding
(lookup-key (car map
) mouse-click
))
135 (if (numberp binding
) ; `too long'
137 (setq map
(cdr map
)))
139 ;; We were given a single keymap.
140 (lookup-key map
(apply 'vector event
))))
141 ;; Clear out echoing, which perhaps shows a prefix arg.
143 ;; Maybe try again but with the submap.
144 (setq map
(if (keymapp cmd
) cmd
)))
145 ;; If the user did not cancel by refusing to select,
146 ;; and if the result is a command, run it.
147 (when (and (null map
) (commandp cmd
))
148 (setq prefix-arg prefix
)
149 ;; `setup-specified-language-environment', for instance,
150 ;; expects this to be set from a menu keymap.
151 (setq last-command-event
(car (last event
)))
152 ;; mouse-major-mode-menu was using `command-execute' instead.
153 (call-interactively cmd
))))
155 (defun minor-mode-menu-from-indicator (indicator)
156 "Show menu for minor mode specified by INDICATOR.
157 Interactively, INDICATOR is read using completion.
158 If there is no menu defined for the minor mode, then create one with
159 items `Turn Off' and `Help'."
161 (list (completing-read
162 "Minor mode indicator: "
163 (describe-minor-mode-completion-table-for-indicator))))
164 (let* ((minor-mode (lookup-minor-mode-from-indicator indicator
))
165 (mm-fun (or (get minor-mode
:minor-mode-function
) minor-mode
)))
166 (unless minor-mode
(error "Cannot find minor mode for `%s'" indicator
))
167 (let* ((map (cdr-safe (assq minor-mode minor-mode-map-alist
)))
168 (menu (and (keymapp map
) (lookup-key map
[menu-bar
]))))
171 (mouse-menu-non-singleton menu
)
174 (turn-off menu-item
"Turn Off minor mode" ,mm-fun
)
175 (help menu-item
"Help for minor mode"
176 (lambda () (interactive)
177 (describe-function ',mm-fun
))))))
180 (defun mouse-minor-mode-menu (event)
181 "Show minor-mode menu for EVENT on minor modes area of the mode line."
183 (let ((indicator (car (nth 4 (car (cdr event
))))))
184 (minor-mode-menu-from-indicator indicator
)))
186 (defun mouse-menu-major-mode-map ()
187 (run-hooks 'activate-menubar-hook
'menu-bar-update-hook
)
188 (let* (;; Keymap from which to inherit; may be null.
189 (ancestor (mouse-menu-non-singleton
190 (and (current-local-map)
191 (local-key-binding [menu-bar
]))))
192 ;; Make a keymap in which our last command leads to a menu or
193 ;; default to the edit menu.
195 (make-sparse-keymap (concat (format-mode-line mode-name
)
200 (set-keymap-parent newmap ancestor
))
203 (defun mouse-menu-non-singleton (menubar)
204 "Return menu keybar MENUBAR, or a lone submenu inside it.
205 If MENUBAR defines exactly one submenu, return just that submenu.
206 Otherwise, return MENUBAR."
210 (lambda (k v
) (setq submap
(if submap t
(cons k v
))))
211 (keymap-canonicalize menubar
))
214 (lookup-key menubar
(vector (car submap
)))))))
216 (defun mouse-menu-bar-map ()
217 "Return a keymap equivalent to the menu bar.
218 The contents are the items that would be in the menu bar whether or
219 not it is actually displayed."
220 (run-hooks 'activate-menubar-hook
'menu-bar-update-hook
)
221 (let* ((local-menu (and (current-local-map)
222 (lookup-key (current-local-map) [menu-bar
])))
223 (global-menu (lookup-key global-map
[menu-bar
]))
224 ;; If a keymap doesn't have a prompt string (a lazy
225 ;; programmer didn't bother to provide one), create it and
226 ;; insert it into the keymap; each keymap gets its own
227 ;; prompt. This is required for non-toolkit versions to
228 ;; display non-empty menu pane names.
232 (let* ((minor-mode (car menu
))
234 (title-or-map (cadr menu
)))
235 (or (stringp title-or-map
)
239 (capitalize (subst-char-in-string
245 (minor-mode-key-binding [menu-bar
])))
246 (local-title-or-map (and local-menu
(cadr local-menu
)))
247 (global-title-or-map (cadr global-menu
)))
248 (or (null local-menu
)
249 (stringp local-title-or-map
)
250 (setq local-menu
(cons 'keymap
251 (cons (concat (format-mode-line mode-name
)
254 (or (stringp global-title-or-map
)
255 (setq global-menu
(cons 'keymap
257 (cdr global-menu
)))))
258 ;; Supplying the list is faster than making a new map.
259 ;; FIXME: We have a problem here: we have to use the global/local/minor
260 ;; so they're displayed in the expected order, but later on in the command
261 ;; loop, they're actually looked up in the opposite order.
267 (defun mouse-major-mode-menu (event &optional prefix
)
268 "Pop up a mode-specific menu of mouse commands.
269 Default to the Edit menu if the major mode doesn't define a menu."
270 (interactive "@e\nP")
271 (run-hooks 'activate-menubar-hook
'menu-bar-update-hook
)
272 (popup-menu (mouse-menu-major-mode-map) event prefix
))
273 (make-obsolete 'mouse-major-mode-menu
'mouse-menu-major-mode-map
"23.1")
275 (defun mouse-popup-menubar (event prefix
)
276 "Pop up a menu equivalent to the menu bar for keyboard EVENT with PREFIX.
277 The contents are the items that would be in the menu bar whether or
278 not it is actually displayed."
279 (interactive "@e \nP")
280 (run-hooks 'activate-menubar-hook
'menu-bar-update-hook
)
281 (popup-menu (mouse-menu-bar-map) event prefix
))
282 (make-obsolete 'mouse-popup-menubar
'mouse-menu-bar-map
"23.1")
284 (defun mouse-popup-menubar-stuff (event prefix
)
285 "Popup a menu like either `mouse-major-mode-menu' or `mouse-popup-menubar'.
286 Use the former if the menu bar is showing, otherwise the latter."
287 (interactive "@e\nP")
288 (run-hooks 'activate-menubar-hook
'menu-bar-update-hook
)
290 (if (zerop (or (frame-parameter nil
'menu-bar-lines
) 0))
292 (mouse-menu-major-mode-map))
294 (make-obsolete 'mouse-popup-menubar-stuff nil
"23.1")
296 ;; Commands that operate on windows.
298 (defun mouse-minibuffer-check (event)
299 (let ((w (posn-window (event-start event
))))
300 (and (window-minibuffer-p w
)
301 (not (minibuffer-window-active-p w
))
302 (error "Minibuffer window is not active")))
303 ;; Give temporary modes such as isearch a chance to turn off.
304 (run-hooks 'mouse-leave-buffer-hook
))
306 (defun mouse-delete-window (click)
307 "Delete the window you click on.
308 Do nothing if the frame has just one window.
309 This command must be bound to a mouse click."
311 (unless (one-window-p t
)
312 (mouse-minibuffer-check click
)
313 (delete-window (posn-window (event-start click
)))))
315 (defun mouse-select-window (click)
316 "Select the window clicked on; don't move point."
318 (mouse-minibuffer-check click
)
319 (let ((oframe (selected-frame))
320 (frame (window-frame (posn-window (event-start click
)))))
321 (select-window (posn-window (event-start click
)))
324 (or (eq frame oframe
)
325 (set-mouse-position (selected-frame) (1- (frame-width)) 0))))
327 (defun mouse-tear-off-window (click)
328 "Delete the window clicked on, and create a new frame displaying its buffer."
330 (mouse-minibuffer-check click
)
331 (let* ((window (posn-window (event-start click
)))
332 (buf (window-buffer window
))
333 (frame (make-frame)))
335 (switch-to-buffer buf
)
336 (delete-window window
)))
338 (defun mouse-delete-other-windows ()
339 "Delete all windows except the one you click on."
341 (delete-other-windows))
343 (defun mouse-split-window-vertically (click)
344 "Select Emacs window mouse is on, then split it vertically in half.
345 The window is split at the line clicked on.
346 This command must be bound to a mouse click."
348 (mouse-minibuffer-check click
)
349 (let ((start (event-start click
)))
350 (select-window (posn-window start
))
351 (let ((new-height (1+ (cdr (posn-col-row (event-end click
)))))
352 (first-line window-min-height
)
353 (last-line (- (window-height) window-min-height
)))
354 (if (< last-line first-line
)
355 (error "Window too short to split")
356 (split-window-vertically
357 (min (max new-height first-line
) last-line
))))))
359 (defun mouse-split-window-horizontally (click)
360 "Select Emacs window mouse is on, then split it horizontally in half.
361 The window is split at the column clicked on.
362 This command must be bound to a mouse click."
364 (mouse-minibuffer-check click
)
365 (let ((start (event-start click
)))
366 (select-window (posn-window start
))
367 (let ((new-width (1+ (car (posn-col-row (event-end click
)))))
368 (first-col window-min-width
)
369 (last-col (- (window-width) window-min-width
)))
370 (if (< last-col first-col
)
371 (error "Window too narrow to split")
372 (split-window-horizontally
373 (min (max new-width first-col
) last-col
))))))
375 (defun mouse-drag-window-above (window)
376 "Return the (or a) window directly above WINDOW.
377 That means one whose bottom edge is at the same height as WINDOW's top edge."
378 (let ((start-top (nth 1 (window-edges window
)))
379 (start-left (nth 0 (window-edges window
)))
380 (start-right (nth 2 (window-edges window
)))
381 (start-window window
)
383 (setq window
(previous-window window
0))
384 (while (and (not above-window
) (not (eq window start-window
)))
385 (let ((left (nth 0 (window-edges window
)))
386 (right (nth 2 (window-edges window
))))
387 (when (and (= (+ (window-height window
) (nth 1 (window-edges window
)))
389 (or (and (<= left start-left
) (<= start-right right
))
390 (and (<= start-left left
) (<= left start-right
))
391 (and (<= start-left right
) (<= right start-right
))))
392 (setq above-window window
)))
393 (setq window
(previous-window window
)))
396 (defun mouse-drag-move-window-bottom (window growth
)
397 "Move the bottom of WINDOW up or down by GROWTH lines.
398 Move it down if GROWTH is positive, or up if GROWTH is negative.
399 If this would make WINDOW too short,
400 shrink the window or windows above it to make room."
402 (adjust-window-trailing-edge window growth nil
)
405 (defsubst mouse-drag-move-window-top
(window growth
)
406 "Move the top of WINDOW up or down by GROWTH lines.
407 Move it down if GROWTH is positive, or up if GROWTH is negative.
408 If this would make WINDOW too short, shrink the window or windows
409 above it to make room."
410 ;; Moving the top of WINDOW is actually moving the bottom of the
412 (let ((window-above (mouse-drag-window-above window
)))
414 (mouse-drag-move-window-bottom window-above
(- growth
)))))
416 (defun mouse-drag-mode-line-1 (start-event mode-line-p
)
417 "Change the height of a window by dragging on the mode or header line.
418 START-EVENT is the starting mouse-event of the drag action.
419 MODE-LINE-P non-nil means dragging a mode line; nil means a header line."
420 ;; Give temporary modes such as isearch a chance to turn off.
421 (run-hooks 'mouse-leave-buffer-hook
)
424 (start (event-start start-event
))
425 (start-event-window (posn-window start
))
426 (start-event-frame (window-frame start-event-window
))
427 (start-nwindows (count-windows t
))
428 (on-link (and mouse-1-click-follows-link
429 (or mouse-1-click-in-non-selected-windows
430 (eq (posn-window start
) (selected-window)))
431 (mouse-on-link-p start
)))
432 (minibuffer (frame-parameter nil
'minibuffer
))
433 should-enlarge-minibuffer event mouse y top bot edges wconfig growth
)
436 ;; if this is the bottommost ordinary window, then to
437 ;; move its modeline the minibuffer must be enlarged.
438 (setq should-enlarge-minibuffer
441 (not (one-window-p t
))
442 (= (nth 1 (window-edges minibuffer
))
443 (nth 3 (window-edges start-event-window
)))))
445 ;; loop reading events and sampling the position of
448 (setq event
(read-event)
449 mouse
(mouse-position))
452 ;; - there is a switch-frame event.
453 ;; - the mouse isn't in the frame that we started in
454 ;; - the mouse isn't in any Emacs frame
456 ;; - there is a mouse-movement event
457 ;; - there is a scroll-bar-movement event
458 ;; (same as mouse movement for our purposes)
460 ;; - there is a keyboard event or some other unknown event.
461 (cond ((not (consp event
))
464 ((memq (car event
) '(switch-frame select-window
))
467 ((not (memq (car event
) '(mouse-movement scroll-bar-movement
)))
469 ;; Do not unread a drag-mouse-1 event since it will cause the
470 ;; selection of the window above when dragging the modeline
471 ;; above the selected window.
472 (unless (eq (car event
) 'drag-mouse-1
)
473 (push event unread-command-events
)))
476 ((not (eq (car mouse
) start-event-frame
))
479 ((null (car (cdr mouse
)))
483 (setq y
(cdr (cdr mouse
))
484 edges
(window-edges start-event-window
)
488 ;; compute size change needed
490 (setq growth
(- y bot -
1)))
492 (when (< (- bot y
) window-min-height
)
493 (setq y
(- bot window-min-height
)))
494 ;; The window's top includes the header line!
495 (setq growth
(- top y
))))
496 (setq wconfig
(current-window-configuration))
498 ;; Check for an error case.
499 (when (and (/= growth
0)
502 (error "Attempt to resize sole window"))
504 ;; If we ever move, make sure we don't mistakenly treat
505 ;; some unexpected `mouse-1' final event as a sign that
506 ;; this whole drag was nothing more than a click.
507 (if (/= growth
0) (setq on-link nil
))
509 ;; grow/shrink minibuffer?
510 (if should-enlarge-minibuffer
511 (unless resize-mini-windows
512 (mouse-drag-move-window-bottom start-event-window growth
))
513 ;; no. grow/shrink the selected window
514 ;(message "growth = %d" growth)
516 (mouse-drag-move-window-bottom start-event-window growth
)
517 (mouse-drag-move-window-top start-event-window growth
)))
519 ;; if this window's growth caused another
520 ;; window to be deleted because it was too
521 ;; short, rescind the change.
523 ;; if size change caused space to be stolen
524 ;; from a window above this one, rescind the
525 ;; change, but only if we didn't grow/shrink
526 ;; the minibuffer. minibuffer size changes
527 ;; can cause all windows to shrink... no way
529 (when (or (/= start-nwindows
(count-windows t
))
530 (and (not should-enlarge-minibuffer
)
535 ;; Choose right window.
536 start-event-window
)))))
537 (set-window-configuration wconfig
)))))
539 ;; Presumably if this was just a click, the last event should
540 ;; be `mouse-1', whereas if this did move the mouse, it should be
541 ;; a `drag-mouse-1'. In any case `on-link' would have been nulled
542 ;; above if there had been any significant mouse movement.
543 (when (and on-link
(eq 'mouse-1
(car-safe event
)))
544 (push (cons 'mouse-2
(cdr event
)) unread-command-events
))))))
546 (defun mouse-drag-mode-line (start-event)
547 "Change the height of a window by dragging on the mode line."
549 (mouse-drag-mode-line-1 start-event t
))
551 (defun mouse-drag-header-line (start-event)
552 "Change the height of a window by dragging on the header line.
553 Windows whose header-lines are at the top of the frame cannot be
554 resized by dragging their header-line."
556 ;; Changing the window's size by dragging its header-line when the
557 ;; header-line is at the top of the frame is somewhat strange,
558 ;; because the header-line doesn't move, so don't do it.
559 (let* ((start (event-start start-event
))
560 (window (posn-window start
))
561 (frame (window-frame window
))
562 (first-window (frame-first-window frame
)))
563 (unless (or (eq window first-window
)
564 (= (nth 1 (window-edges window
))
565 (nth 1 (window-edges first-window
))))
566 (mouse-drag-mode-line-1 start-event nil
))))
569 (defun mouse-drag-vertical-line-rightward-window (window)
570 "Return a window that is immediately to the right of WINDOW, or nil."
571 (let ((bottom (nth 3 (window-inside-edges window
)))
572 (left (nth 0 (window-inside-edges window
)))
574 (try (previous-window window
)))
575 (while (not (eq try window
))
576 (let ((try-top (nth 1 (window-inside-edges try
)))
577 (try-bottom (nth 3 (window-inside-edges try
)))
578 (try-right (nth 2 (window-inside-edges try
))))
579 (if (and (< try-top bottom
)
580 (>= try-bottom bottom
)
582 (or (null best-right
) (> try-right best-right
)))
583 (setq best-right try-right best try
)))
584 (setq try
(previous-window try
)))
587 (defun mouse-drag-vertical-line (start-event)
588 "Change the width of a window by dragging on the vertical line."
590 ;; Give temporary modes such as isearch a chance to turn off.
591 (run-hooks 'mouse-leave-buffer-hook
)
594 (start-event-frame (window-frame (car (car (cdr start-event
)))))
595 (start-event-window (car (car (cdr start-event
))))
596 event mouse x left right edges growth
598 (or (cdr (assq 'vertical-scroll-bars
(frame-parameters start-event-frame
)))
602 (error "Attempt to resize sole ordinary window"))
603 ((and (eq which-side
'right
)
604 (>= (nth 2 (window-inside-edges start-event-window
))
605 (frame-width start-event-frame
)))
606 (error "Attempt to drag rightmost scrollbar"))
607 ((and (eq which-side
'left
)
608 (= (nth 0 (window-inside-edges start-event-window
)) 0))
609 (error "Attempt to drag leftmost scrollbar")))
612 ;; loop reading events and sampling the position of
615 (setq event
(read-event)
616 mouse
(mouse-position))
618 ;; - there is a switch-frame event.
619 ;; - the mouse isn't in the frame that we started in
620 ;; - the mouse isn't in any Emacs frame
622 ;; - there is a mouse-movement event
623 ;; - there is a scroll-bar-movement event
624 ;; (same as mouse movement for our purposes)
626 ;; - there is a keyboard event or some other unknown event
628 (cond ((integerp event
)
630 ((memq (car event
) '(switch-frame select-window
))
632 ((not (memq (car event
)
633 '(mouse-movement scroll-bar-movement
)))
635 (setq unread-command-events
636 (cons event unread-command-events
)))
638 ((not (eq (car mouse
) start-event-frame
))
640 ((null (car (cdr mouse
)))
644 ;; If the scroll bar is on the window's left,
645 ;; adjust the window on the left.
646 (if (eq which-side
'right
)
648 (mouse-drag-vertical-line-rightward-window
649 start-event-window
))))
650 (setq x
(- (car (cdr mouse
))
651 (if (eq which-side
'right
) 0 2))
652 edges
(window-edges window
)
655 ;; scale back a move that would make the
657 (if (< (- x left -
1) window-min-width
)
658 (setq x
(+ left window-min-width -
1)))
659 ;; compute size change needed
660 (setq growth
(- x right -
1))
662 (adjust-window-trailing-edge window growth t
)
665 (defun mouse-set-point (event)
666 "Move point to the position clicked on with the mouse.
667 This should be bound to a mouse click event type."
669 (mouse-minibuffer-check event
)
670 ;; Use event-end in case called from mouse-drag-region.
671 ;; If EVENT is a click, event-end and event-start give same value.
672 (posn-set-point (event-end event
)))
674 (defvar mouse-last-region-beg nil
)
675 (defvar mouse-last-region-end nil
)
676 (defvar mouse-last-region-tick nil
)
678 (defun mouse-region-match ()
679 "Return non-nil if there's an active region that was set with the mouse."
680 (and (mark t
) mark-active
681 (eq mouse-last-region-beg
(region-beginning))
682 (eq mouse-last-region-end
(region-end))
683 (eq mouse-last-region-tick
(buffer-modified-tick))))
685 (defun mouse-set-region (click)
686 "Set the region to the text dragged over, and copy to kill ring.
687 This should be bound to a mouse drag event."
689 (mouse-minibuffer-check click
)
690 (select-window (posn-window (event-start click
)))
691 (let ((beg (posn-point (event-start click
)))
692 (end (posn-point (event-end click
))))
693 (and mouse-drag-copy-region
(integerp beg
) (integerp end
)
694 ;; Don't set this-command to `kill-region', so a following
695 ;; C-w won't double the text in the kill ring. Ignore
696 ;; `last-command' so we don't append to a preceding kill.
697 (let (this-command last-command deactivate-mark
)
698 (copy-region-as-kill beg end
)))
699 (if (numberp beg
) (goto-char beg
))
700 ;; On a text terminal, bounce the cursor.
701 (or transient-mark-mode
706 (if (numberp end
) (goto-char end
))
707 (mouse-set-region-1)))
709 (defun mouse-set-region-1 ()
710 ;; Set transient-mark-mode for a little while.
711 (unless (eq (car-safe transient-mark-mode
) 'only
)
712 (setq transient-mark-mode
714 (unless (eq transient-mark-mode
'lambda
)
715 transient-mark-mode
))))
716 (setq mouse-last-region-beg
(region-beginning))
717 (setq mouse-last-region-end
(region-end))
718 (setq mouse-last-region-tick
(buffer-modified-tick)))
720 (defcustom mouse-scroll-delay
0.25
721 "The pause between scroll steps caused by mouse drags, in seconds.
722 If you drag the mouse beyond the edge of a window, Emacs scrolls the
723 window to bring the text beyond that edge into view, with a delay of
724 this many seconds between scroll steps. Scrolling stops when you move
725 the mouse back into the window, or release the button.
726 This variable's value may be non-integral.
727 Setting this to zero causes Emacs to scroll as fast as it can."
731 (defcustom mouse-scroll-min-lines
1
732 "The minimum number of lines scrolled by dragging mouse out of window.
733 Moving the mouse out the top or bottom edge of the window begins
734 scrolling repeatedly. The number of lines scrolled per repetition
735 is normally equal to the number of lines beyond the window edge that
736 the mouse has moved. However, it always scrolls at least the number
737 of lines specified by this variable."
741 (defun mouse-scroll-subr (window jump
&optional overlay start
)
742 "Scroll the window WINDOW, JUMP lines at a time, until new input arrives.
743 If OVERLAY is an overlay, let it stretch from START to the far edge of
744 the newly visible text.
745 Upon exit, point is at the far edge of the newly visible text."
747 ((and (> jump
0) (< jump mouse-scroll-min-lines
))
748 (setq jump mouse-scroll-min-lines
))
749 ((and (< jump
0) (< (- jump
) mouse-scroll-min-lines
))
750 (setq jump
(- mouse-scroll-min-lines
))))
751 (let ((opoint (point)))
753 (goto-char (window-start window
))
754 (if (not (zerop (vertical-motion jump window
)))
756 (set-window-start window
(point))
758 (if (window-end window
)
760 (goto-char (window-end window
))
761 ;; window-end doesn't reflect the window's new
762 ;; start position until the next redisplay.
763 (vertical-motion (1- jump
) window
))
764 (vertical-motion (- (window-height window
) 2)))
765 (goto-char (window-start window
)))
767 (move-overlay overlay start
(point)))
768 ;; Now that we have scrolled WINDOW properly,
769 ;; put point back where it was for the redisplay
770 ;; so that we don't mess up the selected window.
771 (or (eq window
(selected-window))
773 (sit-for mouse-scroll-delay
)))))
774 (or (eq window
(selected-window))
775 (goto-char opoint
))))
777 (defvar mouse-selection-click-count
0)
779 (defvar mouse-selection-click-count-buffer nil
)
781 (defun mouse-drag-region (start-event)
782 "Set the region to the text that the mouse is dragged over.
783 Highlight the drag area as you move the mouse.
784 This must be bound to a button-down mouse event.
785 In Transient Mark mode, the highlighting remains as long as the mark
786 remains active. Otherwise, it remains until the next input event.
788 If the click is in the echo area, display the `*Messages*' buffer."
790 (let ((w (posn-window (event-start start-event
))))
791 (if (and (window-minibuffer-p w
)
792 (not (minibuffer-window-active-p w
)))
794 ;; Swallow the up-event.
796 (set-buffer (get-buffer-create "*Messages*"))
797 (goto-char (point-max))
798 (display-buffer (current-buffer)))
799 ;; Give temporary modes such as isearch a chance to turn off.
800 (run-hooks 'mouse-leave-buffer-hook
)
801 (mouse-drag-track start-event t
))))
804 (defun mouse-posn-property (pos property
)
805 "Look for a property at click position.
806 POS may be either a buffer position or a click position like
807 those returned from `event-start'. If the click position is on
808 a string, the text property PROPERTY is examined.
809 If this is nil or the click is not on a string, then
810 the corresponding buffer position is searched for PROPERTY.
811 If PROPERTY is encountered in one of those places,
812 its value is returned."
814 (let ((w (posn-window pos
)) (pt (posn-point pos
))
815 (str (posn-string pos
)))
817 (get-text-property (cdr str
) property
(car str
)))
819 (get-char-property pt property w
))))
820 (get-char-property pos property
)))
822 (defun mouse-on-link-p (pos)
823 "Return non-nil if POS is on a link in the current buffer.
824 POS must be a buffer position in the current buffer or a mouse
825 event location in the selected window (see `event-start').
826 However, if `mouse-1-click-in-non-selected-windows' is non-nil,
827 POS may be a mouse event location in any window.
829 A clickable link is identified by one of the following methods:
831 - If the character at POS has a non-nil `follow-link' text or
832 overlay property, the value of that property determines what to do.
834 - If there is a local key-binding or a keybinding at position POS
835 for the `follow-link' event, the binding of that event determines
838 The resulting value determine whether POS is inside a link:
840 - If the value is `mouse-face', POS is inside a link if there
841 is a non-nil `mouse-face' property at POS. Return t in this case.
843 - If the value is a function, FUNC, POS is inside a link if
844 the call \(FUNC POS) returns non-nil. Return the return value
845 from that call. Arg is \(posn-point POS) if POS is a mouse event.
847 - Otherwise, return the value itself.
849 The return value is interpreted as follows:
851 - If it is a string, the mouse-1 event is translated into the
852 first character of the string, i.e. the action of the mouse-1
853 click is the local or global binding of that character.
855 - If it is a vector, the mouse-1 event is translated into the
856 first element of that vector, i.e. the action of the mouse-1
857 click is the local or global binding of that event.
859 - Otherwise, the mouse-1 event is translated into a mouse-2 event
860 at the same position."
862 (and (or (not (consp pos
))
863 mouse-1-click-in-non-selected-windows
864 (eq (selected-window) (posn-window pos
)))
865 (or (mouse-posn-property pos
'follow-link
)
866 (key-binding [follow-link
] nil t pos
)))))
868 ((eq action
'mouse-face
)
869 (and (mouse-posn-property pos
'mouse-face
) t
))
871 ;; FIXME: This seems questionable if the click is not in a buffer.
872 ;; Should we instead decide that `action' takes a `posn'?
874 (with-current-buffer (window-buffer (posn-window pos
))
875 (funcall action
(posn-point pos
)))
876 (funcall action pos
)))
879 (defun mouse-fixup-help-message (msg)
880 "Fix help message MSG for `mouse-1-click-follows-link'."
882 (if (and mouse-1-click-follows-link
884 (string-match-p "\\`mouse-2" msg
)
885 (setq mp
(mouse-pixel-position))
886 (consp (setq pos
(cdr mp
)))
887 (car pos
) (>= (car pos
) 0)
888 (cdr pos
) (>= (cdr pos
) 0)
889 (setq pos
(posn-at-x-y (car pos
) (cdr pos
) (car mp
)))
890 (windowp (posn-window pos
)))
891 (with-current-buffer (window-buffer (posn-window pos
))
892 (if (mouse-on-link-p pos
)
895 ((eq mouse-1-click-follows-link
'double
) "double-")
896 ((and (integerp mouse-1-click-follows-link
)
897 (< mouse-1-click-follows-link
0)) "Long ")
899 "mouse-1" (substring msg
7)))))))
902 (defun mouse-drag-track (start-event &optional
903 do-mouse-drag-region-post-process
)
904 "Track mouse drags by highlighting area between point and cursor.
905 The region will be defined with mark and point.
906 DO-MOUSE-DRAG-REGION-POST-PROCESS should only be used by
907 `mouse-drag-region'."
908 (mouse-minibuffer-check start-event
)
909 (setq mouse-selection-click-count-buffer
(current-buffer))
911 (let* ((original-window (selected-window))
912 ;; We've recorded what we needed from the current buffer and
913 ;; window, now let's jump to the place of the event, where things
915 (_ (mouse-set-point start-event
))
917 (start-posn (event-start start-event
))
918 (start-point (posn-point start-posn
))
919 (start-window (posn-window start-posn
))
920 (start-window-start (window-start start-window
))
921 (start-hscroll (window-hscroll start-window
))
922 (bounds (window-edges start-window
))
923 (make-cursor-line-fully-visible nil
)
925 (bottom (if (window-minibuffer-p start-window
)
927 ;; Don't count the mode line.
928 (1- (nth 3 bounds
))))
929 (on-link (and mouse-1-click-follows-link
930 (or mouse-1-click-in-non-selected-windows
931 (eq start-window original-window
))
932 ;; Use start-point before the intangibility
933 ;; treatment, in case we click on a link inside an
935 (mouse-on-link-p start-posn
)))
936 (click-count (1- (event-click-count start-event
)))
937 (remap-double-click (and on-link
938 (eq mouse-1-click-follows-link
'double
)
940 ;; Suppress automatic hscrolling, because that is a nuisance
941 ;; when setting point near the right fringe (but see below).
942 (automatic-hscrolling-saved automatic-hscrolling
)
943 (automatic-hscrolling nil
)
946 (setq mouse-selection-click-count click-count
)
947 ;; In case the down click is in the middle of some intangible text,
948 ;; use the end of that text, and put it in START-POINT.
949 (if (< (point) start-point
)
950 (goto-char start-point
))
951 (setq start-point
(point))
952 (if remap-double-click
953 (setq click-count
0))
955 ;; Activate the region, using `mouse-start-end' to determine where
956 ;; to put point and mark (e.g., double-click will select a word).
957 (setq transient-mark-mode
958 (if (eq transient-mark-mode
'lambda
)
960 (cons 'only transient-mark-mode
)))
961 (let ((range (mouse-start-end start-point start-point click-count
)))
962 (push-mark (nth 0 range
) t t
)
963 (goto-char (nth 1 range
)))
965 ;; Track the mouse until we get a non-movement event.
968 (setq event
(read-event))
969 (or (mouse-movement-p event
)
970 (memq (car-safe event
) '(switch-frame select-window
))))
971 (unless (memq (car-safe event
) '(switch-frame select-window
))
972 ;; Automatic hscrolling did not occur during the call to
973 ;; `read-event'; but if the user subsequently drags the
974 ;; mouse, go ahead and hscroll.
975 (let ((automatic-hscrolling automatic-hscrolling-saved
))
977 (setq end
(event-end event
)
978 end-point
(posn-point end
))
979 (if (and (eq (posn-window end
) start-window
)
980 (integer-or-marker-p end-point
))
981 (mouse--drag-set-mark-and-point start-point
982 end-point click-count
)
983 (let ((mouse-row (cdr (cdr (mouse-position)))))
987 (mouse-scroll-subr start-window
(- mouse-row top
)
989 ((>= mouse-row bottom
)
990 (mouse-scroll-subr start-window
(1+ (- mouse-row bottom
))
991 nil start-point
))))))))
993 ;; Handle the terminating event if possible.
995 ;; Ensure that point is on the end of the last event.
996 (when (and (setq end-point
(posn-point (event-end event
)))
997 (eq (posn-window end
) start-window
)
998 (integer-or-marker-p end-point
)
999 (/= start-point end-point
))
1000 (mouse--drag-set-mark-and-point start-point
1001 end-point click-count
))
1003 ;; Find its binding.
1004 (let* ((fun (key-binding (vector (car event
))))
1005 (do-multi-click (and (> (event-click-count event
) 0)
1007 (not (memq fun
'(mouse-set-point
1008 mouse-set-region
))))))
1009 (if (and (/= (mark) (point))
1010 (not do-multi-click
))
1012 ;; If point has moved, finish the drag.
1013 (let* (last-command this-command
)
1014 (and mouse-drag-copy-region
1015 do-mouse-drag-region-post-process
1016 (let (deactivate-mark)
1017 (copy-region-as-kill (mark) (point)))))
1019 ;; If point hasn't moved, run the binding of the
1020 ;; terminating up-event.
1022 (goto-char start-point
)
1024 (when (and (functionp fun
)
1025 (= start-hscroll
(window-hscroll start-window
))
1026 ;; Don't run the up-event handler if the window
1027 ;; start changed in a redisplay after the
1028 ;; mouse-set-point for the down-mouse event at
1029 ;; the beginning of this function. When the
1030 ;; window start has changed, the up-mouse event
1031 ;; contains a different position due to the new
1032 ;; window contents, and point is set again.
1034 (= (window-start start-window
)
1035 start-window-start
)))
1037 (= start-point
(point))
1038 (mouse--remap-link-click-p start-event event
))
1039 ;; If we rebind to mouse-2, reselect previous selected
1040 ;; window, so that the mouse-2 event runs in the same
1041 ;; situation as if user had clicked it directly. Fixes
1042 ;; the bug reported by juri@jurta.org on 2005-12-27.
1043 (if (or (vectorp on-link
) (stringp on-link
))
1044 (setq event
(aref on-link
0))
1045 (select-window original-window
)
1046 (setcar event
'mouse-2
)
1047 ;; If this mouse click has never been done by the
1048 ;; user, it doesn't have the necessary property to be
1049 ;; interpreted correctly.
1050 (put 'mouse-2
'event-kind
'mouse-click
)))
1051 (push event unread-command-events
)))))))
1053 (defun mouse--drag-set-mark-and-point (start click click-count
)
1054 (let* ((range (mouse-start-end start click click-count
))
1056 (end (nth 1 range
)))
1057 (cond ((eq (mark) beg
)
1068 (defun mouse--remap-link-click-p (start-event end-event
)
1069 (or (and (eq mouse-1-click-follows-link
'double
)
1070 (= (event-click-count start-event
) 2))
1072 (not (eq mouse-1-click-follows-link
'double
))
1073 (= (event-click-count start-event
) 1)
1074 (= (event-click-count end-event
) 1)
1075 (or (not (integerp mouse-1-click-follows-link
))
1076 (let ((t0 (posn-timestamp (event-start start-event
)))
1077 (t1 (posn-timestamp (event-end end-event
))))
1078 (and (integerp t0
) (integerp t1
)
1079 (if (> mouse-1-click-follows-link
0)
1080 (<= (- t1 t0
) mouse-1-click-follows-link
)
1081 (< (- t0 t1
) mouse-1-click-follows-link
))))))))
1084 ;; Commands to handle xterm-style multiple clicks.
1085 (defun mouse-skip-word (dir)
1086 "Skip over word, over whitespace, or over identical punctuation.
1087 If DIR is positive skip forward; if negative, skip backward."
1088 (let* ((char (following-char))
1089 (syntax (char-to-string (char-syntax char
))))
1090 (cond ((string= syntax
"w")
1091 ;; Here, we can't use skip-syntax-forward/backward because
1092 ;; they don't pay attention to word-separating-categories,
1093 ;; and thus they will skip over a true word boundary. So,
1094 ;; we simulate the original behavior by using forward-word.
1096 (if (not (looking-at "\\<"))
1098 (if (or (looking-at "\\<") (not (looking-at "\\>")))
1100 ((string= syntax
" ")
1102 (skip-syntax-backward syntax
)
1103 (skip-syntax-forward syntax
)))
1104 ((string= syntax
"_")
1106 (skip-syntax-backward "w_")
1107 (skip-syntax-forward "w_")))
1109 (while (and (not (bobp)) (= (preceding-char) char
))
1112 (while (and (not (eobp)) (= (following-char) char
))
1113 (forward-char 1))))))
1115 (defun mouse-start-end (start end mode
)
1116 "Return a list of region bounds based on START and END according to MODE.
1117 If MODE is 0 then set point to (min START END), mark to (max START END).
1118 If MODE is 1 then set point to start of word at (min START END),
1119 mark to end of word at (max START END).
1120 If MODE is 2 then do the same for lines."
1125 (setq mode
(mod mode
3))
1131 (= (char-syntax (char-after start
)) ?\
())
1140 (= (char-syntax (char-after start
)) ?\
)))
1141 (list (save-excursion
1142 (goto-char (1+ start
))
1149 (= (char-syntax (char-after start
)) ?
\"))
1150 (let ((open (or (eq start
(point-min))
1152 (goto-char (- start
1))
1153 (looking-at "\\s(\\|\\s \\|\\s>")))))
1163 (list (save-excursion
1166 (goto-char (1+ start
))
1172 (list (save-excursion
1174 (mouse-skip-word -
1)
1181 (list (save-excursion
1183 (line-beginning-position 1))
1189 ;; Subroutine: set the mark where CLICK happened,
1190 ;; but don't do anything else.
1191 (defun mouse-set-mark-fast (click)
1192 (mouse-minibuffer-check click
)
1193 (let ((posn (event-start click
)))
1194 (select-window (posn-window posn
))
1195 (if (numberp (posn-point posn
))
1196 (push-mark (posn-point posn
) t t
))))
1198 (defun mouse-undouble-last-event (events)
1199 (let* ((index (1- (length events
)))
1200 (last (nthcdr index events
))
1202 (basic (event-basic-type event
))
1203 (old-modifiers (event-modifiers event
))
1204 (modifiers (delq 'double
(delq 'triple
(copy-sequence old-modifiers
))))
1207 ;; Use reverse, not nreverse, since event-modifiers
1208 ;; does not copy the list it returns.
1209 (cons (event-convert-list (reverse (cons basic modifiers
)))
1213 (if (and (not (equal modifiers old-modifiers
))
1214 (key-binding (apply 'vector events
)))
1219 ;; Momentarily show where the mark is, if highlighting doesn't show it.
1221 (defun mouse-set-mark (click)
1222 "Set mark at the position clicked on with the mouse.
1223 Display cursor at that position for a second.
1224 This must be bound to a mouse click."
1226 (mouse-minibuffer-check click
)
1227 (select-window (posn-window (event-start click
)))
1228 ;; We don't use save-excursion because that preserves the mark too.
1229 (let ((point-save (point)))
1231 (progn (mouse-set-point click
)
1233 (or transient-mark-mode
1235 (goto-char point-save
))))
1237 (defun mouse-kill (click)
1238 "Kill the region between point and the mouse click.
1239 The text is saved in the kill ring, as with \\[kill-region]."
1241 (mouse-minibuffer-check click
)
1242 (let* ((posn (event-start click
))
1243 (click-posn (posn-point posn
)))
1244 (select-window (posn-window posn
))
1245 (if (numberp click-posn
)
1246 (kill-region (min (point) click-posn
)
1247 (max (point) click-posn
)))))
1249 (defun mouse-yank-at-click (click arg
)
1250 "Insert the last stretch of killed text at the position clicked on.
1251 Also move point to one end of the text thus inserted (normally the end),
1252 and set mark at the beginning.
1253 Prefix arguments are interpreted as with \\[yank].
1254 If `mouse-yank-at-point' is non-nil, insert at point
1255 regardless of where you click."
1256 (interactive "e\nP")
1257 ;; Give temporary modes such as isearch a chance to turn off.
1258 (run-hooks 'mouse-leave-buffer-hook
)
1259 (when select-active-regions
1260 ;; Without this, confusing things happen upon e.g. inserting into
1261 ;; the middle of an active region.
1263 (or mouse-yank-at-point
(mouse-set-point click
))
1264 (setq this-command
'yank
)
1265 (setq mouse-selection-click-count
0)
1268 (defun mouse-yank-primary (click)
1269 "Insert the primary selection at the position clicked on.
1270 Move point to the end of the inserted text.
1271 If `mouse-yank-at-point' is non-nil, insert at point
1272 regardless of where you click."
1274 ;; Give temporary modes such as isearch a chance to turn off.
1275 (run-hooks 'mouse-leave-buffer-hook
)
1276 ;; Without this, confusing things happen upon e.g. inserting into
1277 ;; the middle of an active region.
1278 (when select-active-regions
1279 (let (select-active-regions)
1281 (or mouse-yank-at-point
(mouse-set-point click
))
1284 ((eq system-type
'windows-nt
)
1285 ;; MS-Windows emulates PRIMARY in x-get-selection, but not
1286 ;; in x-get-selection-value (the latter only accesses the
1287 ;; clipboard). So try PRIMARY first, in case they selected
1288 ;; something with the mouse in the current Emacs session.
1289 (or (x-get-selection 'PRIMARY
)
1290 (x-get-selection-value)))
1291 ((fboundp 'x-get-selection-value
) ; MS-DOS and X.
1292 ;; On X, x-get-selection-value supports more formats and
1293 ;; encodings, so use it in preference to x-get-selection.
1294 (or (x-get-selection-value)
1295 (x-get-selection 'PRIMARY
)))
1296 ;; FIXME: What about xterm-mouse-mode etc.?
1298 (x-get-selection 'PRIMARY
)))))
1301 (error "No selection is available"))))
1303 (defun mouse-kill-ring-save (click)
1304 "Copy the region between point and the mouse click in the kill ring.
1305 This does not delete the region; it acts like \\[kill-ring-save]."
1307 (mouse-set-mark-fast click
)
1308 (let (this-command last-command
)
1309 (kill-ring-save (point) (mark t
))))
1311 ;; This function used to delete the text between point and the mouse
1312 ;; whenever it was equal to the front of the kill ring, but some
1313 ;; people found that confusing.
1315 ;; The position of the last invocation of `mouse-save-then-kill'.
1316 (defvar mouse-save-then-kill-posn nil
)
1318 (defun mouse-save-then-kill-delete-region (beg end
)
1319 ;; We must make our own undo boundaries
1320 ;; because they happen automatically only for the current buffer.
1322 (if (or (= beg end
) (eq buffer-undo-list t
))
1323 ;; If we have no undo list in this buffer,
1325 (delete-region beg end
)
1326 ;; Delete, but make the undo-list entry share with the kill ring.
1327 ;; First, delete just one char, so in case buffer is being modified
1328 ;; for the first time, the undo list records that fact.
1329 (let (before-change-functions after-change-functions
)
1331 (+ beg
(if (> end beg
) 1 -
1))))
1332 (let ((buffer-undo-list buffer-undo-list
))
1333 ;; Undo that deletion--but don't change the undo list!
1334 (let (before-change-functions after-change-functions
)
1335 (primitive-undo 1 buffer-undo-list
))
1336 ;; Now delete the rest of the specified region,
1337 ;; but don't record it.
1338 (setq buffer-undo-list t
)
1339 (if (/= (length (car kill-ring
)) (- (max end beg
) (min end beg
)))
1340 (error "Lossage in mouse-save-then-kill-delete-region"))
1341 (delete-region beg end
))
1342 (let ((tail buffer-undo-list
))
1343 ;; Search back in buffer-undo-list for the string
1344 ;; that came from deleting one character.
1345 (while (and tail
(not (stringp (car (car tail
)))))
1346 (setq tail
(cdr tail
)))
1347 ;; Replace it with an entry for the entire deleted text.
1349 (setcar tail
(cons (car kill-ring
) (min beg end
))))))
1352 (defun mouse-save-then-kill (click)
1353 "Set the region according to CLICK; the second time, kill it.
1354 CLICK should be a mouse click event.
1356 If the region is inactive, activate it temporarily. Set mark at
1357 the original point, and move point to the position of CLICK.
1359 If the region is already active, adjust it. Normally, do this by
1360 moving point or mark, whichever is closer, to CLICK. But if you
1361 have selected whole words or lines, move point or mark to the
1362 word or line boundary closest to CLICK instead.
1364 If `mouse-drag-copy-region' is non-nil, this command also saves the
1365 new region to the kill ring (replacing the previous kill if the
1366 previous region was just saved to the kill ring).
1368 If this command is called a second consecutive time with the same
1369 CLICK position, kill the region (or delete it
1370 if `mouse-drag-copy-region' is non-nil)"
1372 (mouse-minibuffer-check click
)
1373 (let* ((posn (event-start click
))
1374 (click-pt (posn-point posn
))
1375 (window (posn-window posn
))
1376 (buf (window-buffer window
))
1377 ;; Don't let a subsequent kill command append to this one.
1378 (this-command this-command
)
1379 ;; Check if the user has multi-clicked to select words/lines.
1381 (if (and (eq mouse-selection-click-count-buffer buf
)
1382 (with-current-buffer buf
(mark t
)))
1383 mouse-selection-click-count
1386 ((not (numberp click-pt
)) nil
)
1387 ;; If the user clicked without moving point, kill the region.
1388 ;; This also resets `mouse-selection-click-count'.
1389 ((and (eq last-command
'mouse-save-then-kill
)
1390 (eq click-pt mouse-save-then-kill-posn
)
1391 (eq window
(selected-window)))
1392 (if mouse-drag-copy-region
1393 ;; Region already saved in the previous click;
1394 ;; don't make a duplicate entry, just delete.
1395 (delete-region (mark t
) (point))
1396 (kill-region (mark t
) (point)))
1397 (setq mouse-selection-click-count
0)
1398 (setq mouse-save-then-kill-posn nil
))
1400 ;; Otherwise, if there is a suitable region, adjust it by moving
1401 ;; one end (whichever is closer) to CLICK-PT.
1402 ((or (with-current-buffer buf
(region-active-p))
1403 (and (eq window
(selected-window))
1405 (or (and (eq last-command
'mouse-save-then-kill
)
1406 mouse-save-then-kill-posn
)
1407 (and (memq last-command
'(mouse-drag-region
1409 (or mark-even-if-inactive
1410 (not transient-mark-mode
))))))
1411 (select-window window
)
1412 (let* ((range (mouse-start-end click-pt click-pt click-count
)))
1413 (if (< (abs (- click-pt
(mark t
)))
1414 (abs (- click-pt
(point))))
1415 (set-mark (car range
))
1416 (goto-char (nth 1 range
)))
1417 (setq deactivate-mark nil
)
1418 (mouse-set-region-1)
1419 (when mouse-drag-copy-region
1420 ;; Region already copied to kill-ring once, so replace.
1421 (kill-new (filter-buffer-substring (mark t
) (point)) t
))
1422 ;; Arrange for a repeated mouse-3 to kill the region.
1423 (setq mouse-save-then-kill-posn click-pt
)))
1425 ;; Otherwise, set the mark where point is and move to CLICK-PT.
1427 (select-window window
)
1428 (mouse-set-mark-fast click
)
1429 (let ((before-scroll (with-current-buffer buf point-before-scroll
)))
1430 (if before-scroll
(goto-char before-scroll
)))
1431 (exchange-point-and-mark)
1432 (mouse-set-region-1)
1433 (when mouse-drag-copy-region
1434 (kill-new (filter-buffer-substring (mark t
) (point))))
1435 (setq mouse-save-then-kill-posn click-pt
)))))
1438 (global-set-key [M-mouse-1
] 'mouse-start-secondary
)
1439 (global-set-key [M-drag-mouse-1
] 'mouse-set-secondary
)
1440 (global-set-key [M-down-mouse-1
] 'mouse-drag-secondary
)
1441 (global-set-key [M-mouse-3
] 'mouse-secondary-save-then-kill
)
1442 (global-set-key [M-mouse-2
] 'mouse-yank-secondary
)
1444 (defconst mouse-secondary-overlay
1445 (let ((ol (make-overlay (point-min) (point-min))))
1447 (overlay-put ol
'face
'secondary-selection
)
1449 "An overlay which records the current secondary selection.
1450 It is deleted when there is no secondary selection.")
1452 (defvar mouse-secondary-click-count
0)
1454 ;; A marker which records the specified first end for a secondary selection.
1456 (defvar mouse-secondary-start nil
)
1458 (defun mouse-start-secondary (click)
1459 "Set one end of the secondary selection to the position clicked on.
1460 Use \\[mouse-secondary-save-then-kill] to set the other end
1461 and complete the secondary selection."
1463 (mouse-minibuffer-check click
)
1464 (let ((posn (event-start click
)))
1465 (with-current-buffer (window-buffer (posn-window posn
))
1466 ;; Cancel any preexisting secondary selection.
1467 (delete-overlay mouse-secondary-overlay
)
1468 (if (numberp (posn-point posn
))
1470 (or mouse-secondary-start
1471 (setq mouse-secondary-start
(make-marker)))
1472 (move-marker mouse-secondary-start
(posn-point posn
)))))))
1474 (defun mouse-set-secondary (click)
1475 "Set the secondary selection to the text that the mouse is dragged over.
1476 This must be bound to a mouse drag event."
1478 (mouse-minibuffer-check click
)
1479 (let ((posn (event-start click
))
1481 (end (event-end click
)))
1482 (with-current-buffer (window-buffer (posn-window posn
))
1483 (if (numberp (posn-point posn
))
1484 (setq beg
(posn-point posn
)))
1485 (move-overlay mouse-secondary-overlay beg
(posn-point end
))
1488 (buffer-substring (overlay-start mouse-secondary-overlay
)
1489 (overlay-end mouse-secondary-overlay
))))))
1491 (defun mouse-drag-secondary (start-event)
1492 "Set the secondary selection to the text that the mouse is dragged over.
1493 Highlight the drag area as you move the mouse.
1494 This must be bound to a button-down mouse event.
1495 The function returns a non-nil value if it creates a secondary selection."
1497 (mouse-minibuffer-check start-event
)
1498 (let* ((echo-keystrokes 0)
1499 (start-posn (event-start start-event
))
1500 (start-point (posn-point start-posn
))
1501 (start-window (posn-window start-posn
))
1502 (bounds (window-edges start-window
))
1503 (top (nth 1 bounds
))
1504 (bottom (if (window-minibuffer-p start-window
)
1506 ;; Don't count the mode line.
1507 (1- (nth 3 bounds
))))
1508 (click-count (1- (event-click-count start-event
))))
1509 (with-current-buffer (window-buffer start-window
)
1510 (setq mouse-secondary-click-count click-count
)
1511 (if (> (mod click-count
3) 0)
1512 ;; Double or triple press: make an initial selection
1513 ;; of one word or line.
1514 (let ((range (mouse-start-end start-point start-point click-count
)))
1515 (set-marker mouse-secondary-start nil
)
1516 (move-overlay mouse-secondary-overlay
(car range
) (nth 1 range
)
1517 (window-buffer start-window
)))
1518 ;; Single-press: cancel any preexisting secondary selection.
1519 (or mouse-secondary-start
1520 (setq mouse-secondary-start
(make-marker)))
1521 (set-marker mouse-secondary-start start-point
)
1522 (delete-overlay mouse-secondary-overlay
))
1523 (let (event end end-point
)
1526 (setq event
(read-event))
1527 (or (mouse-movement-p event
)
1528 (memq (car-safe event
) '(switch-frame select-window
))))
1530 (if (memq (car-safe event
) '(switch-frame select-window
))
1532 (setq end
(event-end event
)
1533 end-point
(posn-point end
))
1535 ;; Are we moving within the original window?
1536 ((and (eq (posn-window end
) start-window
)
1537 (integer-or-marker-p end-point
))
1538 (let ((range (mouse-start-end start-point end-point
1540 (if (or (/= start-point end-point
)
1541 (null (marker-position mouse-secondary-start
)))
1543 (set-marker mouse-secondary-start nil
)
1544 (move-overlay mouse-secondary-overlay
1545 (car range
) (nth 1 range
))))))
1547 (let ((mouse-row (cdr (cdr (mouse-position)))))
1551 (mouse-scroll-subr start-window
(- mouse-row top
)
1552 mouse-secondary-overlay start-point
))
1553 ((>= mouse-row bottom
)
1554 (mouse-scroll-subr start-window
(1+ (- mouse-row bottom
))
1555 mouse-secondary-overlay start-point
)))))))))
1558 (if (marker-position mouse-secondary-start
)
1559 (save-window-excursion
1560 (delete-overlay mouse-secondary-overlay
)
1561 (x-set-selection 'SECONDARY nil
)
1562 (select-window start-window
)
1564 (goto-char mouse-secondary-start
)
1569 (buffer-substring (overlay-start mouse-secondary-overlay
)
1570 (overlay-end mouse-secondary-overlay
)))))))))
1572 (defun mouse-yank-secondary (click)
1573 "Insert the secondary selection at the position clicked on.
1574 Move point to the end of the inserted text.
1575 If `mouse-yank-at-point' is non-nil, insert at point
1576 regardless of where you click."
1578 ;; Give temporary modes such as isearch a chance to turn off.
1579 (run-hooks 'mouse-leave-buffer-hook
)
1580 (or mouse-yank-at-point
(mouse-set-point click
))
1581 (let ((secondary (x-get-selection 'SECONDARY
)))
1584 (error "No secondary selection"))))
1586 (defun mouse-kill-secondary ()
1587 "Kill the text in the secondary selection.
1588 This is intended more as a keyboard command than as a mouse command
1589 but it can work as either one.
1591 The current buffer (in case of keyboard use), or the buffer clicked on,
1592 must be the one that the secondary selection is in. This requirement
1593 is to prevent accidents."
1595 (let* ((keys (this-command-keys))
1596 (click (elt keys
(1- (length keys
)))))
1597 (or (eq (overlay-buffer mouse-secondary-overlay
)
1599 (window-buffer (posn-window (event-start click
)))
1601 (error "Select or click on the buffer where the secondary selection is")))
1603 (with-current-buffer (overlay-buffer mouse-secondary-overlay
)
1604 (kill-region (overlay-start mouse-secondary-overlay
)
1605 (overlay-end mouse-secondary-overlay
))))
1606 (delete-overlay mouse-secondary-overlay
))
1608 (defun mouse-secondary-save-then-kill (click)
1609 "Set the secondary selection and save it to the kill ring.
1610 The second time, kill it. CLICK should be a mouse click event.
1612 If you have not called `mouse-start-secondary' in the clicked
1613 buffer, activate the secondary selection and set it between point
1614 and the click position CLICK.
1616 Otherwise, adjust the bounds of the secondary selection.
1617 Normally, do this by moving its beginning or end, whichever is
1618 closer, to CLICK. But if you have selected whole words or lines,
1619 adjust to the word or line boundary closest to CLICK instead.
1621 If this command is called a second consecutive time with the same
1622 CLICK position, kill the secondary selection."
1624 (mouse-minibuffer-check click
)
1625 (let* ((posn (event-start click
))
1626 (click-pt (posn-point posn
))
1627 (window (posn-window posn
))
1628 (buf (window-buffer window
))
1629 ;; Don't let a subsequent kill command append to this one.
1630 (this-command this-command
)
1631 ;; Check if the user has multi-clicked to select words/lines.
1633 (if (eq (overlay-buffer mouse-secondary-overlay
) buf
)
1634 mouse-secondary-click-count
1636 (beg (overlay-start mouse-secondary-overlay
))
1637 (end (overlay-end mouse-secondary-overlay
)))
1640 ((not (numberp click-pt
)) nil
)
1642 ;; If the secondary selection is not active in BUF, activate it.
1643 ((not (eq buf
(or (overlay-buffer mouse-secondary-overlay
)
1644 (if mouse-secondary-start
1645 (marker-buffer mouse-secondary-start
)))))
1646 (select-window window
)
1647 (setq mouse-secondary-start
(make-marker))
1648 (move-marker mouse-secondary-start
(point))
1649 (move-overlay mouse-secondary-overlay
(point) click-pt buf
)
1650 (kill-ring-save (point) click-pt
))
1652 ;; If the user clicked without moving point, delete the secondary
1653 ;; selection. This also resets `mouse-secondary-click-count'.
1654 ((and (eq last-command
'mouse-secondary-save-then-kill
)
1655 (eq click-pt mouse-save-then-kill-posn
)
1656 (eq window
(selected-window)))
1657 (mouse-save-then-kill-delete-region beg end
)
1658 (delete-overlay mouse-secondary-overlay
)
1659 (setq mouse-secondary-click-count
0)
1660 (setq mouse-save-then-kill-posn nil
))
1662 ;; Otherwise, if there is a suitable secondary selection overlay,
1663 ;; adjust it by moving one end (whichever is closer) to CLICK-PT.
1664 ((and beg
(eq buf
(overlay-buffer mouse-secondary-overlay
)))
1665 (let* ((range (mouse-start-end click-pt click-pt click-count
)))
1666 (if (< (abs (- click-pt beg
))
1667 (abs (- click-pt end
)))
1668 (move-overlay mouse-secondary-overlay
(car range
) end
)
1669 (move-overlay mouse-secondary-overlay beg
(nth 1 range
))))
1670 (setq deactivate-mark nil
)
1671 (if (eq last-command
'mouse-secondary-save-then-kill
)
1672 ;; If the front of the kill ring comes from an immediately
1673 ;; previous use of this command, replace the entry.
1675 (buffer-substring (overlay-start mouse-secondary-overlay
)
1676 (overlay-end mouse-secondary-overlay
))
1678 (let (deactivate-mark)
1679 (copy-region-as-kill (overlay-start mouse-secondary-overlay
)
1680 (overlay-end mouse-secondary-overlay
))))
1681 (setq mouse-save-then-kill-posn click-pt
))
1683 ;; Otherwise, set the secondary selection overlay.
1685 (select-window window
)
1686 (if mouse-secondary-start
1687 ;; All we have is one end of a selection, so put the other
1689 (let ((start (+ 0 mouse-secondary-start
)))
1690 (kill-ring-save start click-pt
)
1691 (move-overlay mouse-secondary-overlay start click-pt
)))
1692 (setq mouse-save-then-kill-posn click-pt
))))
1694 ;; Finally, set the window system's secondary selection.
1696 (and (overlay-buffer mouse-secondary-overlay
)
1697 (setq str
(buffer-substring (overlay-start mouse-secondary-overlay
)
1698 (overlay-end mouse-secondary-overlay
)))
1700 (x-set-selection 'SECONDARY str
))))
1703 (defcustom mouse-buffer-menu-maxlen
20
1704 "Number of buffers in one pane (submenu) of the buffer menu.
1705 If we have lots of buffers, divide them into groups of
1706 `mouse-buffer-menu-maxlen' and make a pane (or submenu) for each one."
1710 (defcustom mouse-buffer-menu-mode-mult
4
1711 "Group the buffers by the major mode groups on \\[mouse-buffer-menu]?
1712 This number which determines (in a hairy way) whether \\[mouse-buffer-menu]
1713 will split the buffer menu by the major modes (see
1714 `mouse-buffer-menu-mode-groups') or just by menu length.
1715 Set to 1 (or even 0!) if you want to group by major mode always, and to
1716 a large number if you prefer a mixed multitude. The default is 4."
1721 (defvar mouse-buffer-menu-mode-groups
1722 (mapcar (lambda (arg) (cons (purecopy (car arg
)) (purecopy (cdr arg
))))
1723 '(("Info\\|Help\\|Apropos\\|Man" .
"Help")
1724 ("\\bVM\\b\\|\\bMH\\b\\|Message\\|Mail\\|Group\\|Score\\|Summary\\|Article"
1729 ("Outline" .
"Text")
1730 ("\\(HT\\|SG\\|X\\|XHT\\)ML" .
"SGML")
1731 ("log\\|diff\\|vc\\|cvs\\|Annotate" .
"Version Control") ; "Change Management"?
1732 ("Threads\\|Memory\\|Disassembly\\|Breakpoints\\|Frames\\|Locals\\|Registers\\|Inferior I/O\\|Debugger"
1735 "How to group various major modes together in \\[mouse-buffer-menu].
1736 Each element has the form (REGEXP . GROUPNAME).
1737 If the major mode's name string matches REGEXP, use GROUPNAME instead.")
1739 (defun mouse-buffer-menu (event)
1740 "Pop up a menu of buffers for selection with the mouse.
1741 This switches buffers in the window that you clicked on,
1742 and selects that window."
1744 (mouse-minibuffer-check event
)
1745 (let ((buffers (buffer-list)) alist menu split-by-major-mode sum-of-squares
)
1746 ;; Make an alist of elements that look like (MENU-ITEM . BUFFER).
1747 (dolist (buf buffers
)
1748 ;; Divide all buffers into buckets for various major modes.
1749 ;; Each bucket looks like (MODE NAMESTRING BUFFERS...).
1750 (with-current-buffer buf
1751 (let* ((adjusted-major-mode major-mode
) elt
)
1752 (dolist (group mouse-buffer-menu-mode-groups
)
1753 (when (string-match (car group
) (format-mode-line mode-name
))
1754 (setq adjusted-major-mode
(cdr group
))))
1755 (setq elt
(assoc adjusted-major-mode split-by-major-mode
))
1757 (setq elt
(list adjusted-major-mode
1758 (if (stringp adjusted-major-mode
)
1760 (format-mode-line mode-name nil nil buf
)))
1761 split-by-major-mode
(cons elt split-by-major-mode
)))
1762 (or (memq buf
(cdr (cdr elt
)))
1763 (setcdr (cdr elt
) (cons buf
(cdr (cdr elt
))))))))
1764 ;; Compute the sum of squares of sizes of the major-mode buckets.
1765 (let ((tail split-by-major-mode
))
1766 (setq sum-of-squares
0)
1768 (setq sum-of-squares
1770 (let ((len (length (cdr (cdr (car tail
)))))) (* len len
))))
1771 (setq tail
(cdr tail
))))
1772 (if (< (* sum-of-squares mouse-buffer-menu-mode-mult
)
1773 (* (length buffers
) (length buffers
)))
1774 ;; Subdividing by major modes really helps, so let's do it.
1775 (let (subdivided-menus (buffers-left (length buffers
)))
1776 ;; Sort the list to put the most popular major modes first.
1777 (setq split-by-major-mode
1778 (sort split-by-major-mode
1779 (function (lambda (elt1 elt2
)
1780 (> (length elt1
) (length elt2
))))))
1781 ;; Make a separate submenu for each major mode
1782 ;; that has more than one buffer,
1783 ;; unless all the remaining buffers are less than 1/10 of them.
1784 (while (and split-by-major-mode
1785 (and (> (length (car split-by-major-mode
)) 3)
1786 (> (* buffers-left
10) (length buffers
))))
1787 (let ((this-mode-list (mouse-buffer-menu-alist
1788 (cdr (cdr (car split-by-major-mode
))))))
1790 (setq subdivided-menus
1792 (nth 1 (car split-by-major-mode
))
1794 subdivided-menus
))))
1796 (- buffers-left
(length (cdr (car split-by-major-mode
)))))
1797 (setq split-by-major-mode
(cdr split-by-major-mode
)))
1798 ;; If any major modes are left over,
1799 ;; make a single submenu for them.
1800 (if split-by-major-mode
1802 (mouse-buffer-menu-alist
1803 ;; we don't need split-by-major-mode any more,
1804 ;; so we can ditch it with nconc.
1805 (apply 'nconc
(mapcar 'cddr split-by-major-mode
)))))
1807 (setq subdivided-menus
1808 (cons (cons "Others" others-list
)
1809 subdivided-menus
)))))
1810 (setq menu
(cons "Buffer Menu" (nreverse subdivided-menus
))))
1812 (setq alist
(mouse-buffer-menu-alist buffers
))
1813 (setq menu
(cons "Buffer Menu"
1814 (mouse-buffer-menu-split "Select Buffer" alist
)))))
1815 (let ((buf (x-popup-menu event menu
))
1816 (window (posn-window (event-start event
))))
1819 (if (framep window
) (frame-selected-window window
)
1821 (switch-to-buffer buf
)))))
1823 (defun mouse-buffer-menu-alist (buffers)
1829 (function (lambda (elt1 elt2
)
1830 (string< (buffer-name elt1
) (buffer-name elt2
))))))
1833 (or (eq ?\s
(aref (buffer-name (car tail
)) 0))
1836 (length (buffer-name (car tail
))))))
1837 (setq tail
(cdr tail
)))
1840 (let ((elt (car tail
)))
1841 (if (/= (aref (buffer-name elt
) 0) ?\s
)
1846 (format "%%-%ds %%s%%s %%s" maxlen
)
1848 (if (buffer-modified-p elt
) "*" " ")
1849 (with-current-buffer elt
1850 (if buffer-read-only
"%" " "))
1851 (or (buffer-file-name elt
)
1852 (with-current-buffer elt
1853 (if list-buffers-directory
1855 list-buffers-directory
)))
1859 (setq tail
(cdr tail
)))
1860 ;; Compensate for the reversal that the above loop does.
1863 (defun mouse-buffer-menu-split (title alist
)
1864 ;; If we have lots of buffers, divide them into groups of 20
1865 ;; and make a pane (or submenu) for each one.
1866 (if (> (length alist
) (/ (* mouse-buffer-menu-maxlen
3) 2))
1867 (let ((alist alist
) sublists next
1870 ;; Pull off the next mouse-buffer-menu-maxlen buffers
1871 ;; and make them the next element of sublist.
1872 (setq next
(nthcdr mouse-buffer-menu-maxlen alist
))
1874 (setcdr (nthcdr (1- mouse-buffer-menu-maxlen
) alist
)
1876 (setq sublists
(cons (cons (format "Buffers %d" i
) alist
)
1880 (nreverse sublists
))
1881 ;; Few buffers--put them all in one pane.
1882 (list (cons title alist
))))
1884 (define-obsolete-function-alias
1885 'mouse-choose-completion
'choose-completion
"23.2")
1889 (defun font-menu-add-default ()
1890 (let* ((default (cdr (assq 'font
(frame-parameters (selected-frame)))))
1891 (font-alist x-fixed-font-alist
)
1892 (elt (or (assoc "Misc" font-alist
) (nth 1 font-alist
))))
1893 (if (assoc "Default" elt
)
1894 (delete (assoc "Default" elt
) elt
))
1896 (cons (list "Default" default
)
1899 (defvar x-fixed-font-alist
1901 (purecopy "Font Menu")
1905 (lambda (arg) (cons (purecopy (car arg
)) (purecopy (cdr arg
))))
1906 ;; For these, we specify the pixel height and width.
1908 ("6x10" "-misc-fixed-medium-r-normal--10-*-*-*-c-60-iso8859-1" "6x10")
1910 "-misc-fixed-medium-r-semicondensed--12-*-*-*-c-60-iso8859-1" "6x12")
1912 "-misc-fixed-medium-r-semicondensed--13-*-*-*-c-60-iso8859-1" "6x13")
1913 ("7x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-70-iso8859-1" "7x13")
1914 ("7x14" "-misc-fixed-medium-r-normal--14-*-*-*-c-70-iso8859-1" "7x14")
1915 ("8x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-80-iso8859-1" "8x13")
1916 ("9x15" "-misc-fixed-medium-r-normal--15-*-*-*-c-90-iso8859-1" "9x15")
1917 ("10x20" "-misc-fixed-medium-r-normal--20-*-*-*-c-100-iso8859-1" "10x20")
1918 ("11x18" "-misc-fixed-medium-r-normal--18-*-*-*-c-110-iso8859-1" "11x18")
1919 ("12x24" "-misc-fixed-medium-r-normal--24-*-*-*-c-120-iso8859-1" "12x24")
1922 "-schumacher-clean-medium-r-normal--8-*-*-*-c-50-iso8859-1")
1924 "-schumacher-clean-medium-r-normal--8-*-*-*-c-60-iso8859-1")
1926 "-schumacher-clean-medium-r-normal--8-*-*-*-c-80-iso8859-1")
1928 "-schumacher-clean-medium-r-normal--10-*-*-*-c-80-iso8859-1")
1930 "-schumacher-clean-medium-r-normal--14-*-*-*-c-80-iso8859-1")
1932 "-schumacher-clean-medium-r-normal--16-*-*-*-c-80-iso8859-1")
1934 ("sony 8x16" "-sony-fixed-medium-r-normal--16-*-*-*-c-80-iso8859-1")
1935 ;; We don't seem to have these; who knows what they are.
1936 ;; ("fg-18" "fg-18")
1937 ;; ("fg-25" "fg-25")
1938 ("lucidasanstypewriter-12" "-b&h-lucidatypewriter-medium-r-normal-sans-*-120-*-*-*-*-iso8859-1")
1939 ("lucidasanstypewriter-bold-14" "-b&h-lucidatypewriter-bold-r-normal-sans-*-140-*-*-*-*-iso8859-1")
1940 ("lucidasanstypewriter-bold-24"
1941 "-b&h-lucidatypewriter-bold-r-normal-sans-*-240-*-*-*-*-iso8859-1")
1942 ;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
1943 ;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
1947 (purecopy "Courier")
1949 (lambda (arg) (cons (purecopy (car arg
)) (purecopy (cdr arg
))))
1950 ;; For these, we specify the point height.
1951 '(("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1")
1952 ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1")
1953 ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1")
1954 ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1")
1955 ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1")
1956 ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1")
1957 ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1")
1958 ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1")
1959 ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1")
1960 ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1")
1961 ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1")
1962 ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1")
1963 ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1")
1964 ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1")
1965 ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1")
1966 ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1")
1967 ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1")
1968 ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1")
1969 ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1")
1970 ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1")
1971 ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1")
1972 ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1")
1973 ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1")
1974 ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1")
1976 "X fonts suitable for use in Emacs.")
1978 (declare-function generate-fontset-menu
"fontset" ())
1980 (defun mouse-select-font ()
1981 "Prompt for a font name, using `x-popup-menu', and return it."
1983 (unless (display-multi-font-p)
1984 (error "Cannot change fonts on this display"))
1987 (if (listp last-nonmenu-event
)
1989 (list '(0 0) (selected-window)))
1990 (append x-fixed-font-alist
1991 (list (generate-fontset-menu))))))
1993 (declare-function text-scale-mode
"face-remap")
1995 (defun mouse-set-font (&rest fonts
)
1996 "Set the default font for the selected frame.
1997 The argument FONTS is a list of font names; the first valid font
1998 in this list is used.
2000 When called interactively, pop up a menu and allow the user to
2003 (progn (unless (display-multi-font-p)
2004 (error "Cannot change fonts on this display"))
2006 (if (listp last-nonmenu-event
)
2008 (list '(0 0) (selected-window)))
2009 ;; Append list of fontsets currently defined.
2010 (append x-fixed-font-alist
(list (generate-fontset-menu))))))
2016 (set-frame-font (car fonts
))
2017 (setq font
(car fonts
))
2020 (setq fonts
(cdr fonts
)))))
2022 (error "Font not found")))))
2024 (defvar mouse-appearance-menu-map nil
)
2025 (declare-function x-select-font
"xfns.c" (&optional frame ignored
)) ; USE_GTK
2026 (declare-function buffer-face-mode-invoke
"face-remap"
2027 (face arg
&optional interactive
))
2028 (declare-function font-face-attributes
"font.c" (font &optional frame
))
2030 (defun mouse-appearance-menu (event)
2031 "Show a menu for changing the default face in the current buffer."
2033 (require 'face-remap
)
2034 (when (display-multi-font-p)
2035 (with-selected-window (car (event-start event
))
2036 (if mouse-appearance-menu-map
2037 nil
; regenerate new fonts
2038 ;; Initialize mouse-appearance-menu-map
2039 (setq mouse-appearance-menu-map
2040 (make-sparse-keymap "Change Default Buffer Face"))
2041 (define-key mouse-appearance-menu-map
[face-remap-reset-base
]
2042 '(menu-item "Reset to Default" face-remap-reset-base
))
2043 (define-key mouse-appearance-menu-map
[text-scale-decrease
]
2044 '(menu-item "Decrease Buffer Text Size" text-scale-decrease
))
2045 (define-key mouse-appearance-menu-map
[text-scale-increase
]
2046 '(menu-item "Increase Buffer Text Size" text-scale-increase
))
2048 (if (functionp 'x-select-font
)
2049 (define-key mouse-appearance-menu-map
[x-select-font
]
2050 '(menu-item "Change Buffer Font..." x-select-font
))
2051 ;; If the select-font is unavailable, construct a menu.
2052 (let ((font-submenu (make-sparse-keymap "Change Text Font"))
2053 (font-alist (cdr (append x-fixed-font-alist
2054 (list (generate-fontset-menu))))))
2055 (dolist (family font-alist
)
2056 (let* ((submenu-name (car family
))
2057 (submenu-map (make-sparse-keymap submenu-name
)))
2058 (dolist (font (cdr family
))
2059 (let ((font-name (car font
))
2061 (if (string= font-name
"")
2062 (define-key submenu-map
[space]
2064 (setq font-symbol (intern (cadr font)))
2065 (define-key submenu-map (vector font-symbol)
2066 (list 'menu-item (car font) font-symbol)))))
2067 (define-key font-submenu (vector (intern submenu-name))
2068 (list 'menu-item submenu-name submenu-map))))
2069 (define-key mouse-appearance-menu-map [font-submenu]
2070 (list 'menu-item "Change Text Font" font-submenu)))))
2071 (let ((choice (x-popup-menu event mouse-appearance-menu-map)))
2072 (setq choice (nth (1- (length choice)) choice))
2073 (cond ((eq choice 'text-scale-increase)
2074 (text-scale-increase 1))
2075 ((eq choice 'text-scale-decrease)
2076 (text-scale-increase -1))
2077 ((eq choice 'face-remap-reset-base)
2079 (buffer-face-mode 0))
2081 ;; Either choice == 'x-select-font, or choice is a
2082 ;; symbol whose name is a font.
2083 (buffer-face-mode-invoke (font-face-attributes
2084 (if (eq choice 'x-select-font)
2086 (symbol-name choice)))
2088 (called-interactively-p 'interactive))))))))
2091 ;;; Bindings for mouse commands.
2093 (define-key global-map [down-mouse-1] 'mouse-drag-region)
2094 (global-set-key [mouse-1] 'mouse-set-point)
2095 (global-set-key [drag-mouse-1] 'mouse-set-region)
2097 ;; These are tested for in mouse-drag-region.
2098 (global-set-key [double-mouse-1] 'mouse-set-point)
2099 (global-set-key [triple-mouse-1] 'mouse-set-point)
2101 ;; Clicking on the fringes causes hscrolling:
2102 (global-set-key [left-fringe mouse-1] 'mouse-set-point)
2103 (global-set-key [right-fringe mouse-1] 'mouse-set-point)
2105 (global-set-key [mouse-2] 'mouse-yank-primary)
2106 ;; Allow yanking also when the corresponding cursor is "in the fringe".
2107 (global-set-key [right-fringe mouse-2] 'mouse-yank-at-click)
2108 (global-set-key [left-fringe mouse-2] 'mouse-yank-at-click)
2109 (global-set-key [mouse-3] 'mouse-save-then-kill)
2110 (global-set-key [right-fringe mouse-3] 'mouse-save-then-kill)
2111 (global-set-key [left-fringe mouse-3] 'mouse-save-then-kill)
2113 ;; By binding these to down-going events, we let the user use the up-going
2114 ;; event to make the selection, saving a click.
2115 (global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
2116 (if (not (eq system-type 'ms-dos))
2117 (global-set-key [S-down-mouse-1] 'mouse-appearance-menu))
2118 ;; C-down-mouse-2 is bound in facemenu.el.
2119 (global-set-key [C-down-mouse-3]
2120 `(menu-item ,(purecopy "Menu Bar") ignore
2122 (if (zerop (or (frame-parameter nil 'menu-bar-lines) 0))
2123 (mouse-menu-bar-map)
2124 (mouse-menu-major-mode-map)))))
2126 ;; Binding mouse-1 to mouse-select-window when on mode-, header-, or
2127 ;; vertical-line prevents Emacs from signaling an error when the mouse
2128 ;; button is released after dragging these lines, on non-toolkit
2130 (global-set-key [mode-line mouse-1] 'mouse-select-window)
2131 (global-set-key [mode-line drag-mouse-1] 'mouse-select-window)
2132 (global-set-key [mode-line down-mouse-1] 'mouse-drag-mode-line)
2133 (global-set-key [header-line down-mouse-1] 'mouse-drag-header-line)
2134 (global-set-key [header-line mouse-1] 'mouse-select-window)
2135 (global-set-key [mode-line mouse-2] 'mouse-delete-other-windows)
2136 (global-set-key [mode-line mouse-3] 'mouse-delete-window)
2137 (global-set-key [mode-line C-mouse-2] 'mouse-split-window-horizontally)
2138 (global-set-key [vertical-scroll-bar C-mouse-2] 'mouse-split-window-vertically)
2139 (global-set-key [vertical-line C-mouse-2] 'mouse-split-window-vertically)
2140 (global-set-key [vertical-line down-mouse-1] 'mouse-drag-vertical-line)
2141 (global-set-key [vertical-line mouse-1] 'mouse-select-window)
2145 ;;; mouse.el ends here