1 ;;; mouse.el --- window system-independent mouse support.
3 ;;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
8 ;;; This file is part of GNU Emacs.
10 ;;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;;; it under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 2, or (at your option)
13 ;;; any later version.
15 ;;; GNU Emacs is distributed in the hope that it will be useful,
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
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 (defvar mouse-yank-at-point nil
40 "*If non-nil, mouse yank commands yank at point instead of at click.")
42 ;; Provide a mode-specific menu on a mouse button.
44 (defun mouse-major-mode-menu (event)
45 "Pop up a mode-specific menu of mouse commands."
46 ;; Switch to the window clicked on, because otherwise
47 ;; the mode's commands may not make sense.
49 (let ((newmap (make-sparse-keymap))
50 (unread-command-events (list event
)))
51 ;; Make a keymap in which our last command leads to a menu
52 (define-key newmap
(vector (car event
))
53 (nconc (make-sparse-keymap "Menu")
54 (mouse-major-mode-menu-1
55 (and (current-local-map)
56 (lookup-key (current-local-map) [menu-bar
])))))
57 (mouse-major-mode-menu-compute-equiv-keys newmap
)
59 ;; Make NEWMAP override the usual definition
60 ;; of the mouse button that got us here.
61 ;; Then read the user's menu choice.
62 (let ((minor-mode-map-alist
63 (cons (cons t newmap
) minor-mode-map-alist
)))
64 (lookup-key newmap
(read-key-sequence ""))))))
66 ;; Compute and cache the equivalent keys in MENU and all its submenus.
67 (defun mouse-major-mode-menu-compute-equiv-keys (menu)
68 (and (eq (car menu
) 'keymap
)
69 (x-popup-menu nil menu
))
71 (and (consp (car menu
))
72 (consp (cdr (car menu
)))
73 (let ((tail (cdr (car menu
))))
74 (while (and (consp tail
)
75 (not (eq (car tail
) 'keymap
)))
76 (setq tail
(cdr tail
)))
78 (mouse-major-mode-menu-compute-equiv-keys tail
))))
79 (setq menu
(cdr menu
))))
81 ;; Given a mode's menu bar keymap,
82 ;; if it defines exactly one menu bar menu,
83 ;; return just that menu.
84 ;; Otherwise return a menu for all of them.
85 (defun mouse-major-mode-menu-1 (menubar)
90 (if (consp (car tail
))
93 (setq submap
(cdr (car tail
)))))
94 (setq tail
(cdr tail
)))
95 (if (eq submap t
) menubar
98 ;; Commands that operate on windows.
100 (defun mouse-minibuffer-check (event)
101 (let ((w (posn-window (event-start event
))))
102 (and (window-minibuffer-p w
)
103 (not (minibuffer-window-active-p w
))
104 (error "Minibuffer window is not active")))
105 ;; Give temporary modes such as isearch a chance to turn off.
106 (run-hooks 'mouse-leave-buffer-hook
))
108 (defun mouse-delete-window (click)
109 "Delete the window you click on.
110 This must be bound to a mouse click."
112 (mouse-minibuffer-check click
)
113 (delete-window (posn-window (event-start click
))))
115 (defun mouse-select-window (click)
116 "Select the window clicked on; don't move point."
118 (mouse-minibuffer-check click
)
119 (let ((oframe (selected-frame))
120 (frame (window-frame (posn-window (event-start click
)))))
121 (select-window (posn-window (event-start click
)))
124 (or (eq frame oframe
)
125 (set-mouse-position (selected-frame) (1- (frame-width)) 0))
128 (defun mouse-tear-off-window (click)
129 "Delete the window clicked on, and create a new frame displaying its buffer."
131 (mouse-minibuffer-check click
)
132 (let* ((window (posn-window (event-start click
)))
133 (buf (window-buffer window
))
134 (frame (make-frame)))
136 (switch-to-buffer buf
)
137 (delete-window window
)))
139 (defun mouse-delete-other-windows ()
140 "Delete all window except the one you click on."
142 (delete-other-windows))
144 (defun mouse-split-window-vertically (click)
145 "Select Emacs window mouse is on, then split it vertically in half.
146 The window is split at the line clicked on.
147 This command must be bound to a mouse click."
149 (mouse-minibuffer-check click
)
150 (let ((start (event-start click
)))
151 (select-window (posn-window start
))
152 (let ((new-height (1+ (cdr (posn-col-row (event-end click
)))))
153 (first-line window-min-height
)
154 (last-line (- (window-height) window-min-height
)))
155 (if (< last-line first-line
)
156 (error "Window too short to split")
157 (split-window-vertically
158 (min (max new-height first-line
) last-line
))))))
160 (defun mouse-split-window-horizontally (click)
161 "Select Emacs window mouse is on, then split it horizontally in half.
162 The window is split at the column clicked on.
163 This command must be bound to a mouse click."
165 (mouse-minibuffer-check click
)
166 (let ((start (event-start click
)))
167 (select-window (posn-window start
))
168 (let ((new-width (1+ (car (posn-col-row (event-end click
)))))
169 (first-col window-min-width
)
170 (last-col (- (window-width) window-min-width
)))
171 (if (< last-col first-col
)
172 (error "Window too narrow to split")
173 (split-window-horizontally
174 (min (max new-width first-col
) last-col
))))))
176 (defun mouse-drag-mode-line (start-event)
177 "Change the height of a window by dragging on the mode line."
179 ;; Give temporary modes such as isearch a chance to turn off.
180 (run-hooks 'mouse-leave-buffer-hook
)
183 (start-event-frame (window-frame (car (car (cdr start-event
)))))
184 (start-event-window (car (car (cdr start-event
))))
185 (start-nwindows (count-windows t
))
186 (old-selected-window (selected-window))
187 should-enlarge-minibuffer
188 event mouse minibuffer y top bot edges wconfig params growth
)
189 (setq params
(frame-parameters))
190 (if (and (not (setq minibuffer
(cdr (assq 'minibuffer params
))))
192 (error "Attempt to resize sole window"))
195 ;; enlarge-window only works on the selected window, so
196 ;; we must select the window where the start event originated.
197 ;; unwind-protect will restore the old selected window later.
198 (select-window start-event-window
)
199 ;; if this is the bottommost ordinary window, then to
200 ;; move its modeline the minibuffer must be enlarged.
201 (setq should-enlarge-minibuffer
203 (not (one-window-p t
))
204 (= (nth 1 (window-edges minibuffer
))
205 (nth 3 (window-edges)))))
206 ;; loop reading events and sampling the position of
209 (setq event
(read-event)
210 mouse
(mouse-position))
212 ;; - there is a switch-frame event.
213 ;; - the mouse isn't in the frame that we started in
214 ;; - the mouse isn't in any Emacs frame
216 ;; - there is a mouse-movement event
217 ;; - there is a scroll-bar-movement event
218 ;; (same as mouse movement for our purposes)
220 ;; - there is a keyboard event or some other unknown event
222 (cond ((integerp event
)
224 ((eq (car event
) 'switch-frame
)
226 ((not (memq (car event
)
227 '(mouse-movement scroll-bar-movement
)))
229 (setq unread-command-events
230 (cons event unread-command-events
)))
232 ((not (eq (car mouse
) start-event-frame
))
234 ((null (car (cdr mouse
)))
237 (setq y
(cdr (cdr mouse
))
241 ;; scale back a move that would make the
243 (cond ((< (- y top -
1) window-min-height
)
244 (setq y
(+ top window-min-height -
1))))
245 ;; compute size change needed
246 (setq growth
(- y bot -
1)
247 wconfig
(current-window-configuration))
248 ;; grow/shrink minibuffer?
249 (if should-enlarge-minibuffer
251 ;; yes. briefly select minibuffer so
252 ;; enlarge-window will affect the
254 (select-window minibuffer
)
255 ;; scale back shrinkage if it would
256 ;; make the minibuffer less than 1
258 (if (and (> growth
0)
259 (< (- (window-height minibuffer
)
262 (setq growth
(1- (window-height minibuffer
))))
263 (enlarge-window (- growth
))
264 (select-window start-event-window
))
265 ;; no. grow/shrink the selected window
266 (enlarge-window growth
))
267 ;; if this window's growth caused another
268 ;; window to be deleted because it was too
269 ;; short, rescind the change.
271 ;; if size change caused space to be stolen
272 ;; from a window above this one, rescind the
273 ;; change, but only if we didn't grow/srhink
274 ;; the minibuffer. minibuffer size changes
275 ;; can cause all windows to shrink... no way
277 (if (or (/= start-nwindows
(count-windows t
))
278 (and (not should-enlarge-minibuffer
)
279 (/= top
(nth 1 (window-edges)))))
280 (set-window-configuration wconfig
)))))))))
282 (defun mouse-set-point (event)
283 "Move point to the position clicked on with the mouse.
284 This should be bound to a mouse click event type."
286 (mouse-minibuffer-check event
)
287 ;; Use event-end in case called from mouse-drag-region.
288 ;; If EVENT is a click, event-end and event-start give same value.
289 (let ((posn (event-end event
)))
290 (if (not (windowp (posn-window posn
)))
291 (error "Cursor not in text area of window"))
292 (select-window (posn-window posn
))
293 (if (numberp (posn-point posn
))
294 (goto-char (posn-point posn
)))))
296 (defvar mouse-last-region-beg nil
)
297 (defvar mouse-last-region-end nil
)
298 (defvar mouse-last-region-tick nil
)
300 (defun mouse-region-match ()
301 "Return non-nil if there's an active region that was set with the mouse."
302 (and (mark t
) mark-active
303 (eq mouse-last-region-beg
(region-beginning))
304 (eq mouse-last-region-end
(region-end))
305 (eq mouse-last-region-tick
(buffer-modified-tick))))
307 (defun mouse-set-region (click)
308 "Set the region to the text dragged over, and copy to kill ring.
309 This should be bound to a mouse drag event."
311 (mouse-minibuffer-check click
)
312 (let ((posn (event-start click
))
313 (end (event-end click
)))
314 (select-window (posn-window posn
))
315 (if (numberp (posn-point posn
))
316 (goto-char (posn-point posn
)))
317 ;; If mark is highlighted, no need to bounce the cursor.
318 (or (and transient-mark-mode
319 (framep (selected-frame)))
323 (if (numberp (posn-point end
))
324 (goto-char (posn-point end
)))
325 ;; Don't set this-command to kill-region, so that a following
326 ;; C-w will not double the text in the kill ring.
328 (copy-region-as-kill (mark) (point)))
329 (mouse-set-region-1)))
331 (defun mouse-set-region-1 ()
332 (setq mouse-last-region-beg
(region-beginning))
333 (setq mouse-last-region-end
(region-end))
334 (setq mouse-last-region-tick
(buffer-modified-tick)))
336 (defvar mouse-scroll-delay
0.25
337 "*The pause between scroll steps caused by mouse drags, in seconds.
338 If you drag the mouse beyond the edge of a window, Emacs scrolls the
339 window to bring the text beyond that edge into view, with a delay of
340 this many seconds between scroll steps. Scrolling stops when you move
341 the mouse back into the window, or release the button.
342 This variable's value may be non-integral.
343 Setting this to zero causes Emacs to scroll as fast as it can.")
345 (defun mouse-scroll-subr (window jump
&optional overlay start
)
346 "Scroll the window WINDOW, JUMP lines at a time, until new input arrives.
347 If OVERLAY is an overlay, let it stretch from START to the far edge of
348 the newly visible text.
349 Upon exit, point is at the far edge of the newly visible text."
350 (let ((opoint (point)))
352 (goto-char (window-start window
))
353 (if (not (zerop (vertical-motion jump window
)))
355 (set-window-start window
(point))
358 (goto-char (window-end window
))
359 ;; window-end doesn't reflect the window's new
360 ;; start position until the next redisplay. Hurrah.
361 (vertical-motion (1- jump
) window
))
362 (goto-char (window-start window
)))
364 (move-overlay overlay start
(point)))
365 ;; Now that we have scrolled WINDOW properly,
366 ;; put point back where it was for the redisplay
367 ;; so that we don't mess up the selected window.
368 (or (eq window
(selected-window))
370 (sit-for mouse-scroll-delay
)))))
371 (or (eq window
(selected-window))
372 (goto-char opoint
))))
374 (defvar mouse-drag-overlay
(make-overlay 1 1))
375 (overlay-put mouse-drag-overlay
'face
'region
)
377 (defvar mouse-selection-click-count
0)
379 (defun mouse-drag-region (start-event)
380 "Set the region to the text that the mouse is dragged over.
381 Highlight the drag area as you move the mouse.
382 This must be bound to a button-down mouse event.
383 In Transient Mark mode, the highlighting remains once you
384 release the mouse button. Otherwise, it does not."
386 (mouse-minibuffer-check start-event
)
387 (let* ((start-posn (event-start start-event
))
388 (start-point (posn-point start-posn
))
389 (start-window (posn-window start-posn
))
390 (start-frame (window-frame start-window
))
391 (bounds (window-edges start-window
))
393 (bottom (if (window-minibuffer-p start-window
)
395 ;; Don't count the mode line.
396 (1- (nth 3 bounds
))))
397 (click-count (1- (event-click-count start-event
))))
398 (setq mouse-selection-click-count click-count
)
399 (mouse-set-point start-event
)
400 (let ((range (mouse-start-end start-point start-point click-count
)))
401 (move-overlay mouse-drag-overlay
(car range
) (nth 1 range
)
402 (window-buffer start-window
)))
404 (let (event end end-point
)
407 (setq event
(read-event))
408 (or (mouse-movement-p event
)
409 (eq (car-safe event
) 'switch-frame
)))
410 (if (eq (car-safe event
) 'switch-frame
)
412 (setq end
(event-end event
)
413 end-point
(posn-point end
))
416 ;; Are we moving within the original window?
417 ((and (eq (posn-window end
) start-window
)
418 (integer-or-marker-p end-point
))
419 (goto-char end-point
)
420 (let ((range (mouse-start-end start-point
(point) click-count
)))
421 (move-overlay mouse-drag-overlay
(car range
) (nth 1 range
))))
424 (let ((mouse-row (cdr (cdr (mouse-position)))))
428 (mouse-scroll-subr start-window
(- mouse-row top
)
429 mouse-drag-overlay start-point
))
430 ((>= mouse-row bottom
)
431 (mouse-scroll-subr start-window
(1+ (- mouse-row bottom
))
432 mouse-drag-overlay start-point
)))))))))
434 (let ((fun (key-binding (vector (car event
)))))
435 ;; Run the binding of the terminating up-event, if possible.
436 ;; In the case of a multiple click, it gives the wrong results,
437 ;; because it would fail to set up a region.
438 (if (and (= (mod mouse-selection-click-count
3) 0) (fboundp fun
))
440 (setq this-command fun
)
441 ;; Delete the overlay before calling the function,
442 ;; because delete-overlay increases buffer-modified-tick.
443 (delete-overlay mouse-drag-overlay
)
445 (if (not (= (overlay-start mouse-drag-overlay
)
446 (overlay-end mouse-drag-overlay
)))
447 (let (last-command this-command
)
448 (push-mark (overlay-start mouse-drag-overlay
) t t
)
449 (goto-char (overlay-end mouse-drag-overlay
))
450 (delete-overlay mouse-drag-overlay
)
451 (copy-region-as-kill (point) (mark t
))
452 (mouse-set-region-1))
453 (goto-char (overlay-end mouse-drag-overlay
))
454 (setq this-command
'mouse-set-point
)
455 (delete-overlay mouse-drag-overlay
))))
456 (delete-overlay mouse-drag-overlay
)))))
458 ;; Commands to handle xterm-style multiple clicks.
460 (defun mouse-skip-word (dir)
461 "Skip over word, over whitespace, or over identical punctuation.
462 If DIR is positive skip forward; if negative, skip backward."
463 (let* ((char (following-char))
464 (syntax (char-to-string (char-syntax char
))))
465 (if (or (string= syntax
"w") (string= syntax
" "))
467 (skip-syntax-backward syntax
)
468 (skip-syntax-forward syntax
))
470 (while (and (not (bobp)) (= (preceding-char) char
))
472 (while (and (not (eobp)) (= (following-char) char
))
473 (forward-char 1))))))
475 ;; Return a list of region bounds based on START and END according to MODE.
476 ;; If MODE is 0 then set point to (min START END), mark to (max START END).
477 ;; If MODE is 1 then set point to start of word at (min START END),
478 ;; mark to end of word at (max START END).
479 ;; If MODE is 2 then do the same for lines.
480 (defun mouse-start-end (start end mode
)
485 (setq mode
(mod mode
3))
491 (= (char-syntax (char-after start
)) ?\
())
500 (= (char-syntax (char-after start
)) ?\
)))
501 (list (save-excursion
502 (goto-char (1+ start
))
507 (list (save-excursion
516 (list (save-excursion
518 (beginning-of-line 1)
525 ;; Subroutine: set the mark where CLICK happened,
526 ;; but don't do anything else.
527 (defun mouse-set-mark-fast (click)
528 (mouse-minibuffer-check click
)
529 (let ((posn (event-start click
)))
530 (select-window (posn-window posn
))
531 (if (numberp (posn-point posn
))
532 (push-mark (posn-point posn
) t t
))))
534 ;; Momentarily show where the mark is, if highlighting doesn't show it.
535 (defun mouse-show-mark ()
536 (or transient-mark-mode
541 (defun mouse-set-mark (click)
542 "Set mark at the position clicked on with the mouse.
543 Display cursor at that position for a second.
544 This must be bound to a mouse click."
546 (mouse-minibuffer-check click
)
547 (select-window (posn-window (event-start click
)))
548 ;; We don't use save-excursion because that preserves the mark too.
549 (let ((point-save (point)))
551 (progn (mouse-set-point click
)
553 (or transient-mark-mode
555 (goto-char point-save
))))
557 (defun mouse-kill (click)
558 "Kill the region between point and the mouse click.
559 The text is saved in the kill ring, as with \\[kill-region]."
561 (mouse-minibuffer-check click
)
562 (let* ((posn (event-start click
))
563 (click-posn (posn-point posn
)))
564 (select-window (posn-window posn
))
565 (if (numberp click-posn
)
566 (kill-region (min (point) click-posn
)
567 (max (point) click-posn
)))))
569 (defun mouse-yank-at-click (click arg
)
570 "Insert the last stretch of killed text at the position clicked on.
571 Also move point to one end of the text thus inserted (normally the end).
572 Prefix arguments are interpreted as with \\[yank].
573 If `mouse-yank-at-point' is non-nil, insert at point
574 regardless of where you click."
576 ;; Give temporary modes such as isearch a chance to turn off.
577 (run-hooks 'mouse-leave-buffer-hook
)
578 (or mouse-yank-at-point
(mouse-set-point click
))
579 (setq this-command
'yank
)
582 (defun mouse-kill-ring-save (click)
583 "Copy the region between point and the mouse click in the kill ring.
584 This does not delete the region; it acts like \\[kill-ring-save]."
586 (mouse-set-mark-fast click
)
587 (let (this-command last-command
)
588 (kill-ring-save (point) (mark t
)))
591 ;;; This function used to delete the text between point and the mouse
592 ;;; whenever it was equal to the front of the kill ring, but some
593 ;;; people found that confusing.
595 ;;; A list (TEXT START END), describing the text and position of the last
596 ;;; invocation of mouse-save-then-kill.
597 (defvar mouse-save-then-kill-posn nil
)
599 (defun mouse-save-then-kill-delete-region (beg end
)
600 ;; We must make our own undo boundaries
601 ;; because they happen automatically only for the current buffer.
603 (if (or (= beg end
) (eq buffer-undo-list t
))
604 ;; If we have no undo list in this buffer,
606 (delete-region beg end
)
607 ;; Delete, but make the undo-list entry share with the kill ring.
608 ;; First, delete just one char, so in case buffer is being modified
609 ;; for the first time, the undo list records that fact.
610 (let (before-change-function after-change-function
611 before-change-functions after-change-functions
)
613 (+ beg
(if (> end beg
) 1 -
1))))
614 (let ((buffer-undo-list buffer-undo-list
))
615 ;; Undo that deletion--but don't change the undo list!
616 (let (before-change-function after-change-function
617 before-change-functions after-change-functions
)
618 (primitive-undo 1 buffer-undo-list
))
619 ;; Now delete the rest of the specified region,
620 ;; but don't record it.
621 (setq buffer-undo-list t
)
622 (if (/= (length (car kill-ring
)) (- (max end beg
) (min end beg
)))
623 (error "Lossage in mouse-save-then-kill-delete-region"))
624 (delete-region beg end
))
625 (let ((tail buffer-undo-list
))
626 ;; Search back in buffer-undo-list for the string
627 ;; that came from deleting one character.
628 (while (and tail
(not (stringp (car (car tail
)))))
629 (setq tail
(cdr tail
)))
630 ;; Replace it with an entry for the entire deleted text.
632 (setcar tail
(cons (car kill-ring
) (min beg end
))))))
635 (defun mouse-save-then-kill (click)
636 "Save text to point in kill ring; the second time, kill the text.
637 If the text between point and the mouse is the same as what's
638 at the front of the kill ring, this deletes the text.
639 Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
640 which prepares for a second click to delete the text.
642 If you have selected words or lines, this command extends the
643 selection through the word or line clicked on. If you do this
644 again in a different position, it extends the selection again.
645 If you do this twice in the same position, the selection is killed."
647 (let ((before-scroll point-before-scroll
))
648 (mouse-minibuffer-check click
)
649 (let ((click-posn (posn-point (event-start click
)))
650 ;; Don't let a subsequent kill command append to this one:
651 ;; prevent setting this-command to kill-region.
652 (this-command this-command
))
653 (if (and (mark t
) (> (mod mouse-selection-click-count
3) 0))
654 (if (not (and (eq last-command
'mouse-save-then-kill
)
656 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn
))))))
657 ;; Find both ends of the object selected by this click.
659 (mouse-start-end click-posn click-posn
660 mouse-selection-click-count
)))
661 ;; Move whichever end is closer to the click.
662 ;; That's what xterm does, and it seems reasonable.
663 (if (< (abs (- click-posn
(mark t
)))
664 (abs (- click-posn
(point))))
665 (set-mark (car range
))
666 (goto-char (nth 1 range
)))
667 ;; We have already put the old region in the kill ring.
668 ;; Replace it with the extended region.
669 ;; (It would be annoying to make a separate entry.)
670 (kill-new (buffer-substring (point) (mark t
)) t
)
672 ;; Arrange for a repeated mouse-3 to kill this region.
673 (setq mouse-save-then-kill-posn
674 (list (car kill-ring
) (point) click-posn
))
676 ;; If we click this button again without moving it,
678 (mouse-save-then-kill-delete-region (point) (mark))
679 (setq mouse-selection-click-count
0)
680 (setq mouse-save-then-kill-posn nil
))
681 (if (and (eq last-command
'mouse-save-then-kill
)
682 mouse-save-then-kill-posn
683 (eq (car mouse-save-then-kill-posn
) (car kill-ring
))
684 (equal (cdr mouse-save-then-kill-posn
) (list (point) click-posn
)))
685 ;; If this is the second time we've called
686 ;; mouse-save-then-kill, delete the text from the buffer.
688 (mouse-save-then-kill-delete-region (point) (mark))
689 ;; After we kill, another click counts as "the first time".
690 (setq mouse-save-then-kill-posn nil
))
691 (if (or (and (eq last-command
'mouse-save-then-kill
)
692 mouse-save-then-kill-posn
)
693 (and mark-active transient-mark-mode
)
694 (and (memq last-command
695 '(mouse-drag-region mouse-set-region
))
696 (or mark-even-if-inactive
697 (not transient-mark-mode
))))
698 ;; We have a selection or suitable region, so adjust it.
699 (let* ((posn (event-start click
))
700 (new (posn-point posn
)))
701 (select-window (posn-window posn
))
704 ;; Move whichever end of the region is closer to the click.
705 ;; That is what xterm does, and it seems reasonable.
706 (if (< (abs (- new
(point))) (abs (- new
(mark t
))))
709 (setq deactivate-mark nil
)))
710 (kill-new (buffer-substring (point) (mark t
)) t
))
711 ;; Set the mark where point is, then move where clicked.
712 (mouse-set-mark-fast click
)
714 (goto-char before-scroll
))
715 (exchange-point-and-mark)
716 (kill-ring-save (point) (mark t
)))
719 (setq mouse-save-then-kill-posn
720 (list (car kill-ring
) (point) click-posn
)))))))
722 (global-set-key [M-mouse-1
] 'mouse-start-secondary
)
723 (global-set-key [M-drag-mouse-1
] 'mouse-set-secondary
)
724 (global-set-key [M-down-mouse-1
] 'mouse-drag-secondary
)
725 (global-set-key [M-mouse-3
] 'mouse-secondary-save-then-kill
)
726 (global-set-key [M-mouse-2
] 'mouse-yank-secondary
)
728 ;; An overlay which records the current secondary selection
729 ;; or else is deleted when there is no secondary selection.
731 (defvar mouse-secondary-overlay nil
)
733 (defvar mouse-secondary-click-count
0)
735 ;; A marker which records the specified first end for a secondary selection.
737 (defvar mouse-secondary-start nil
)
739 (defun mouse-start-secondary (click)
740 "Set one end of the secondary selection to the position clicked on.
741 Use \\[mouse-secondary-save-then-kill] to set the other end
742 and complete the secondary selection."
744 (mouse-minibuffer-check click
)
745 (let ((posn (event-start click
)))
747 (set-buffer (window-buffer (posn-window posn
)))
748 ;; Cancel any preexisting secondary selection.
749 (if mouse-secondary-overlay
750 (delete-overlay mouse-secondary-overlay
))
751 (if (numberp (posn-point posn
))
753 (or mouse-secondary-start
754 (setq mouse-secondary-start
(make-marker)))
755 (move-marker mouse-secondary-start
(posn-point posn
)))))))
757 (defun mouse-set-secondary (click)
758 "Set the secondary selection to the text that the mouse is dragged over.
759 This must be bound to a mouse drag event."
761 (mouse-minibuffer-check click
)
762 (let ((posn (event-start click
))
764 (end (event-end click
)))
766 (set-buffer (window-buffer (posn-window posn
)))
767 (if (numberp (posn-point posn
))
768 (setq beg
(posn-point posn
)))
769 (if mouse-secondary-overlay
770 (move-overlay mouse-secondary-overlay beg
(posn-point end
))
771 (setq mouse-secondary-overlay
(make-overlay beg
(posn-point end
))))
772 (overlay-put mouse-secondary-overlay
'face
'secondary-selection
))))
774 (defun mouse-drag-secondary (start-event)
775 "Set the secondary selection to the text that the mouse is dragged over.
776 Highlight the drag area as you move the mouse.
777 This must be bound to a button-down mouse event."
779 (mouse-minibuffer-check start-event
)
780 (let* ((start-posn (event-start start-event
))
781 (start-point (posn-point start-posn
))
782 (start-window (posn-window start-posn
))
783 (start-frame (window-frame start-window
))
784 (bounds (window-edges start-window
))
786 (bottom (if (window-minibuffer-p start-window
)
788 ;; Don't count the mode line.
789 (1- (nth 3 bounds
))))
790 (click-count (1- (event-click-count start-event
))))
792 (set-buffer (window-buffer start-window
))
793 (setq mouse-secondary-click-count click-count
)
794 (or mouse-secondary-overlay
795 (setq mouse-secondary-overlay
796 (make-overlay (point) (point))))
797 (overlay-put mouse-secondary-overlay
'face
'secondary-selection
)
798 (if (> (mod click-count
3) 0)
799 ;; Double or triple press: make an initial selection
800 ;; of one word or line.
801 (let ((range (mouse-start-end start-point start-point click-count
)))
802 (set-marker mouse-secondary-start nil
)
803 (move-overlay mouse-secondary-overlay
1 1
804 (window-buffer start-window
))
805 (move-overlay mouse-secondary-overlay
(car range
) (nth 1 range
)
806 (window-buffer start-window
)))
807 ;; Single-press: cancel any preexisting secondary selection.
808 (or mouse-secondary-start
809 (setq mouse-secondary-start
(make-marker)))
810 (set-marker mouse-secondary-start start-point
)
811 (delete-overlay mouse-secondary-overlay
))
812 (let (event end end-point
)
815 (setq event
(read-event))
816 (or (mouse-movement-p event
)
817 (eq (car-safe event
) 'switch-frame
)))
819 (if (eq (car-safe event
) 'switch-frame
)
821 (setq end
(event-end event
)
822 end-point
(posn-point end
))
824 ;; Are we moving within the original window?
825 ((and (eq (posn-window end
) start-window
)
826 (integer-or-marker-p end-point
))
827 (let ((range (mouse-start-end start-point end-point
829 (if (or (/= start-point end-point
)
830 (null (marker-position mouse-secondary-start
)))
832 (set-marker mouse-secondary-start nil
)
833 (move-overlay mouse-secondary-overlay
834 (car range
) (nth 1 range
))))))
836 (let ((mouse-row (cdr (cdr (mouse-position)))))
840 (mouse-scroll-subr start-window
(- mouse-row top
)
841 mouse-secondary-overlay start-point
))
842 ((>= mouse-row bottom
)
843 (mouse-scroll-subr start-window
(1+ (- mouse-row bottom
))
844 mouse-secondary-overlay start-point
)))))))))
847 ;;; (eq (get (event-basic-type event) 'event-kind) 'mouse-click)
848 ;;; (eq (posn-window (event-end event)) start-window)
849 ;;; (numberp (posn-point (event-end event)))
850 (if (marker-position mouse-secondary-start
)
851 (save-window-excursion
852 (delete-overlay mouse-secondary-overlay
)
853 (x-set-selection 'SECONDARY nil
)
854 (select-window start-window
)
856 (goto-char mouse-secondary-start
)
860 (buffer-substring (overlay-start mouse-secondary-overlay
)
861 (overlay-end mouse-secondary-overlay
)))))))))
863 (defun mouse-yank-secondary (click)
864 "Insert the secondary selection at the position clicked on.
865 Move point to the end of the inserted text.
866 If `mouse-yank-at-point' is non-nil, insert at point
867 regardless of where you click."
869 ;; Give temporary modes such as isearch a chance to turn off.
870 (run-hooks 'mouse-leave-buffer-hook
)
871 (or mouse-yank-at-point
(mouse-set-point click
))
872 (insert (x-get-selection 'SECONDARY
)))
874 (defun mouse-kill-secondary ()
875 "Kill the text in the secondary selection.
876 This is intended more as a keyboard command than as a mouse command
877 but it can work as either one.
879 The current buffer (in case of keyboard use), or the buffer clicked on,
880 must be the one that the secondary selection is in. This requirement
881 is to prevent accidents."
883 (let* ((keys (this-command-keys))
884 (click (elt keys
(1- (length keys
)))))
885 (or (eq (overlay-buffer mouse-secondary-overlay
)
887 (window-buffer (posn-window (event-start click
)))
889 (error "Select or click on the buffer where the secondary selection is")))
892 (set-buffer (overlay-buffer mouse-secondary-overlay
))
893 (kill-region (overlay-start mouse-secondary-overlay
)
894 (overlay-end mouse-secondary-overlay
))))
895 (delete-overlay mouse-secondary-overlay
)
896 ;;; (x-set-selection 'SECONDARY nil)
897 (setq mouse-secondary-overlay nil
))
899 (defun mouse-secondary-save-then-kill (click)
900 "Save text to point in kill ring; the second time, kill the text.
901 You must use this in a buffer where you have recently done \\[mouse-start-secondary].
902 If the text between where you did \\[mouse-start-secondary] and where
903 you use this command matches the text at the front of the kill ring,
904 this command deletes the text.
905 Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
906 which prepares for a second click with this command to delete the text.
908 If you have already made a secondary selection in that buffer,
909 this command extends or retracts the selection to where you click.
910 If you do this again in a different position, it extends or retracts
911 again. If you do this twice in the same position, it kills the selection."
913 (mouse-minibuffer-check click
)
914 (let ((posn (event-start click
))
915 (click-posn (posn-point (event-start click
)))
916 ;; Don't let a subsequent kill command append to this one:
917 ;; prevent setting this-command to kill-region.
918 (this-command this-command
))
919 (or (eq (window-buffer (posn-window posn
))
920 (or (and mouse-secondary-overlay
921 (overlay-buffer mouse-secondary-overlay
))
922 (if mouse-secondary-start
923 (marker-buffer mouse-secondary-start
))))
924 (error "Wrong buffer"))
926 (set-buffer (window-buffer (posn-window posn
)))
927 (if (> (mod mouse-secondary-click-count
3) 0)
928 (if (not (and (eq last-command
'mouse-secondary-save-then-kill
)
930 (car (cdr-safe (cdr-safe mouse-save-then-kill-posn
))))))
931 ;; Find both ends of the object selected by this click.
933 (mouse-start-end click-posn click-posn
934 mouse-secondary-click-count
)))
935 ;; Move whichever end is closer to the click.
936 ;; That's what xterm does, and it seems reasonable.
937 (if (< (abs (- click-posn
(overlay-start mouse-secondary-overlay
)))
938 (abs (- click-posn
(overlay-end mouse-secondary-overlay
))))
939 (move-overlay mouse-secondary-overlay
(car range
)
940 (overlay-end mouse-secondary-overlay
))
941 (move-overlay mouse-secondary-overlay
942 (overlay-start mouse-secondary-overlay
)
944 ;; We have already put the old region in the kill ring.
945 ;; Replace it with the extended region.
946 ;; (It would be annoying to make a separate entry.)
947 (kill-new (buffer-substring
948 (overlay-start mouse-secondary-overlay
)
949 (overlay-end mouse-secondary-overlay
)) t
)
950 ;; Arrange for a repeated mouse-3 to kill this region.
951 (setq mouse-save-then-kill-posn
952 (list (car kill-ring
) (point) click-posn
)))
953 ;; If we click this button again without moving it,
956 (mouse-save-then-kill-delete-region
957 (overlay-start mouse-secondary-overlay
)
958 (overlay-end mouse-secondary-overlay
))
959 (setq mouse-save-then-kill-posn nil
)
960 (setq mouse-secondary-click-count
0)
961 (delete-overlay mouse-secondary-overlay
)))
962 (if (and (eq last-command
'mouse-secondary-save-then-kill
)
963 mouse-save-then-kill-posn
964 (eq (car mouse-save-then-kill-posn
) (car kill-ring
))
965 (equal (cdr mouse-save-then-kill-posn
) (list (point) click-posn
)))
966 ;; If this is the second time we've called
967 ;; mouse-secondary-save-then-kill, delete the text from the buffer.
969 (mouse-save-then-kill-delete-region
970 (overlay-start mouse-secondary-overlay
)
971 (overlay-end mouse-secondary-overlay
))
972 (setq mouse-save-then-kill-posn nil
)
973 (delete-overlay mouse-secondary-overlay
))
974 (if (overlay-start mouse-secondary-overlay
)
975 ;; We have a selection, so adjust it.
977 (if (numberp click-posn
)
979 ;; Move whichever end of the region is closer to the click.
980 ;; That is what xterm does, and it seems reasonable.
981 (if (< (abs (- click-posn
(overlay-start mouse-secondary-overlay
)))
982 (abs (- click-posn
(overlay-end mouse-secondary-overlay
))))
983 (move-overlay mouse-secondary-overlay click-posn
984 (overlay-end mouse-secondary-overlay
))
985 (move-overlay mouse-secondary-overlay
986 (overlay-start mouse-secondary-overlay
)
988 (setq deactivate-mark nil
)))
989 (if (eq last-command
'mouse-secondary-save-then-kill
)
990 ;; If the front of the kill ring comes from
991 ;; an immediately previous use of this command,
992 ;; replace it with the extended region.
993 ;; (It would be annoying to make a separate entry.)
994 (kill-new (buffer-substring
995 (overlay-start mouse-secondary-overlay
)
996 (overlay-end mouse-secondary-overlay
)) t
)
997 (copy-region-as-kill (overlay-start mouse-secondary-overlay
)
998 (overlay-end mouse-secondary-overlay
))))
999 (if mouse-secondary-start
1000 ;; All we have is one end of a selection,
1001 ;; so put the other end here.
1002 (let ((start (+ 0 mouse-secondary-start
)))
1003 (kill-ring-save start click-posn
)
1004 (if mouse-secondary-overlay
1005 (move-overlay mouse-secondary-overlay start click-posn
)
1006 (setq mouse-secondary-overlay
(make-overlay start click-posn
)))
1007 (overlay-put mouse-secondary-overlay
'face
'secondary-selection
))))
1008 (setq mouse-save-then-kill-posn
1009 (list (car kill-ring
) (point) click-posn
))))
1010 (if (overlay-buffer mouse-secondary-overlay
)
1011 (x-set-selection 'SECONDARY
1013 (overlay-start mouse-secondary-overlay
)
1014 (overlay-end mouse-secondary-overlay
)))))))
1016 (defun mouse-buffer-menu (event)
1017 "Pop up a menu of buffers for selection with the mouse.
1018 This switches buffers in the window that you clicked on,
1019 and selects that window."
1021 (mouse-minibuffer-check event
)
1024 (cons "Select Buffer"
1025 (let ((tail (buffer-list))
1029 (or (eq ?\
(aref (buffer-name (car tail
)) 0))
1032 (length (buffer-name (car tail
))))))
1033 (setq tail
(cdr tail
)))
1034 (setq tail
(buffer-list))
1036 (let ((elt (car tail
)))
1037 (if (not (string-match "^ "
1043 (format "%%%ds %%s%%s %%s" maxbuf
)
1045 (if (buffer-modified-p elt
) "*" " ")
1048 (if buffer-read-only
"%" " "))
1049 (or (buffer-file-name elt
)
1052 (if list-buffers-directory
1054 list-buffers-directory
)))
1058 (setq tail
(cdr tail
)))
1060 (let ((buf (x-popup-menu event menu
))
1061 (window (posn-window (event-start event
))))
1064 (or (framep window
) (select-window window
))
1065 (switch-to-buffer buf
))))))
1067 ;;; These need to be rewritten for the new scroll bar implementation.
1069 ;;;!! ;; Commands for the scroll bar.
1071 ;;;!! (defun mouse-scroll-down (click)
1072 ;;;!! (interactive "@e")
1073 ;;;!! (scroll-down (1+ (cdr (mouse-coords click)))))
1075 ;;;!! (defun mouse-scroll-up (click)
1076 ;;;!! (interactive "@e")
1077 ;;;!! (scroll-up (1+ (cdr (mouse-coords click)))))
1079 ;;;!! (defun mouse-scroll-down-full ()
1080 ;;;!! (interactive "@")
1081 ;;;!! (scroll-down nil))
1083 ;;;!! (defun mouse-scroll-up-full ()
1084 ;;;!! (interactive "@")
1085 ;;;!! (scroll-up nil))
1087 ;;;!! (defun mouse-scroll-move-cursor (click)
1088 ;;;!! (interactive "@e")
1089 ;;;!! (move-to-window-line (1+ (cdr (mouse-coords click)))))
1091 ;;;!! (defun mouse-scroll-absolute (event)
1092 ;;;!! (interactive "@e")
1093 ;;;!! (let* ((pos (car event))
1094 ;;;!! (position (car pos))
1095 ;;;!! (length (car (cdr pos))))
1096 ;;;!! (if (<= length 0) (setq length 1))
1097 ;;;!! (let* ((scale-factor (max 1 (/ length (/ 8000000 (buffer-size)))))
1098 ;;;!! (newpos (* (/ (* (/ (buffer-size) scale-factor)
1101 ;;;!! scale-factor)))
1102 ;;;!! (goto-char newpos)
1103 ;;;!! (recenter '(4)))))
1105 ;;;!! (defun mouse-scroll-left (click)
1106 ;;;!! (interactive "@e")
1107 ;;;!! (scroll-left (1+ (car (mouse-coords click)))))
1109 ;;;!! (defun mouse-scroll-right (click)
1110 ;;;!! (interactive "@e")
1111 ;;;!! (scroll-right (1+ (car (mouse-coords click)))))
1113 ;;;!! (defun mouse-scroll-left-full ()
1114 ;;;!! (interactive "@")
1115 ;;;!! (scroll-left nil))
1117 ;;;!! (defun mouse-scroll-right-full ()
1118 ;;;!! (interactive "@")
1119 ;;;!! (scroll-right nil))
1121 ;;;!! (defun mouse-scroll-move-cursor-horizontally (click)
1122 ;;;!! (interactive "@e")
1123 ;;;!! (move-to-column (1+ (car (mouse-coords click)))))
1125 ;;;!! (defun mouse-scroll-absolute-horizontally (event)
1126 ;;;!! (interactive "@e")
1127 ;;;!! (let* ((pos (car event))
1128 ;;;!! (position (car pos))
1129 ;;;!! (length (car (cdr pos))))
1130 ;;;!! (set-window-hscroll (selected-window) 33)))
1132 ;;;!! (global-set-key [scroll-bar mouse-1] 'mouse-scroll-up)
1133 ;;;!! (global-set-key [scroll-bar mouse-2] 'mouse-scroll-absolute)
1134 ;;;!! (global-set-key [scroll-bar mouse-3] 'mouse-scroll-down)
1136 ;;;!! (global-set-key [vertical-slider mouse-1] 'mouse-scroll-move-cursor)
1137 ;;;!! (global-set-key [vertical-slider mouse-2] 'mouse-scroll-move-cursor)
1138 ;;;!! (global-set-key [vertical-slider mouse-3] 'mouse-scroll-move-cursor)
1140 ;;;!! (global-set-key [thumbup mouse-1] 'mouse-scroll-up-full)
1141 ;;;!! (global-set-key [thumbup mouse-2] 'mouse-scroll-up-full)
1142 ;;;!! (global-set-key [thumbup mouse-3] 'mouse-scroll-up-full)
1144 ;;;!! (global-set-key [thumbdown mouse-1] 'mouse-scroll-down-full)
1145 ;;;!! (global-set-key [thumbdown mouse-2] 'mouse-scroll-down-full)
1146 ;;;!! (global-set-key [thumbdown mouse-3] 'mouse-scroll-down-full)
1148 ;;;!! (global-set-key [horizontal-scroll-bar mouse-1] 'mouse-scroll-left)
1149 ;;;!! (global-set-key [horizontal-scroll-bar mouse-2]
1150 ;;;!! 'mouse-scroll-absolute-horizontally)
1151 ;;;!! (global-set-key [horizontal-scroll-bar mouse-3] 'mouse-scroll-right)
1153 ;;;!! (global-set-key [horizontal-slider mouse-1]
1154 ;;;!! 'mouse-scroll-move-cursor-horizontally)
1155 ;;;!! (global-set-key [horizontal-slider mouse-2]
1156 ;;;!! 'mouse-scroll-move-cursor-horizontally)
1157 ;;;!! (global-set-key [horizontal-slider mouse-3]
1158 ;;;!! 'mouse-scroll-move-cursor-horizontally)
1160 ;;;!! (global-set-key [thumbleft mouse-1] 'mouse-scroll-left-full)
1161 ;;;!! (global-set-key [thumbleft mouse-2] 'mouse-scroll-left-full)
1162 ;;;!! (global-set-key [thumbleft mouse-3] 'mouse-scroll-left-full)
1164 ;;;!! (global-set-key [thumbright mouse-1] 'mouse-scroll-right-full)
1165 ;;;!! (global-set-key [thumbright mouse-2] 'mouse-scroll-right-full)
1166 ;;;!! (global-set-key [thumbright mouse-3] 'mouse-scroll-right-full)
1168 ;;;!! (global-set-key [horizontal-scroll-bar S-mouse-2]
1169 ;;;!! 'mouse-split-window-horizontally)
1170 ;;;!! (global-set-key [mode-line S-mouse-2]
1171 ;;;!! 'mouse-split-window-horizontally)
1172 ;;;!! (global-set-key [vertical-scroll-bar S-mouse-2]
1173 ;;;!! 'mouse-split-window)
1176 ;;;!! ;;;; Here are experimental things being tested. Mouse events
1177 ;;;!! ;;;; are of the form:
1178 ;;;!! ;;;; ((x y) window screen-part key-sequence timestamp)
1181 ;;;!! ;;;; Dynamically track mouse coordinates
1184 ;;;!! ;;(defun track-mouse (event)
1185 ;;;!! ;; "Track the coordinates, absolute and relative, of the mouse."
1186 ;;;!! ;; (interactive "@e")
1187 ;;;!! ;; (while mouse-grabbed
1188 ;;;!! ;; (let* ((pos (read-mouse-position (selected-screen)))
1189 ;;;!! ;; (abs-x (car pos))
1190 ;;;!! ;; (abs-y (cdr pos))
1191 ;;;!! ;; (relative-coordinate (coordinates-in-window-p
1192 ;;;!! ;; (list (car pos) (cdr pos))
1193 ;;;!! ;; (selected-window))))
1194 ;;;!! ;; (if (consp relative-coordinate)
1195 ;;;!! ;; (message "mouse: [%d %d], (%d %d)" abs-x abs-y
1196 ;;;!! ;; (car relative-coordinate)
1197 ;;;!! ;; (car (cdr relative-coordinate)))
1198 ;;;!! ;; (message "mouse: [%d %d]" abs-x abs-y)))))
1201 ;;;!! ;; Dynamically put a box around the line indicated by point
1204 ;;;!! ;;(require 'backquote)
1206 ;;;!! ;;(defun mouse-select-buffer-line (event)
1207 ;;;!! ;; (interactive "@e")
1208 ;;;!! ;; (let ((relative-coordinate
1209 ;;;!! ;; (coordinates-in-window-p (car event) (selected-window)))
1210 ;;;!! ;; (abs-y (car (cdr (car event)))))
1211 ;;;!! ;; (if (consp relative-coordinate)
1213 ;;;!! ;; (save-excursion
1214 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1215 ;;;!! ;; (x-draw-rectangle
1216 ;;;!! ;; (selected-screen)
1218 ;;;!! ;; (save-excursion
1219 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1220 ;;;!! ;; (end-of-line)
1221 ;;;!! ;; (push-mark nil t)
1222 ;;;!! ;; (beginning-of-line)
1223 ;;;!! ;; (- (region-end) (region-beginning))) 1))
1224 ;;;!! ;; (sit-for 1)
1225 ;;;!! ;; (x-erase-rectangle (selected-screen))))))
1227 ;;;!! ;;(defvar last-line-drawn nil)
1228 ;;;!! ;;(defvar begin-delim "[^ \t]")
1229 ;;;!! ;;(defvar end-delim "[^ \t]")
1231 ;;;!! ;;(defun mouse-boxing (event)
1232 ;;;!! ;; (interactive "@e")
1233 ;;;!! ;; (save-excursion
1234 ;;;!! ;; (let ((screen (selected-screen)))
1235 ;;;!! ;; (while (= (x-mouse-events) 0)
1236 ;;;!! ;; (let* ((pos (read-mouse-position screen))
1237 ;;;!! ;; (abs-x (car pos))
1238 ;;;!! ;; (abs-y (cdr pos))
1239 ;;;!! ;; (relative-coordinate
1240 ;;;!! ;; (coordinates-in-window-p (` ((, abs-x) (, abs-y)))
1241 ;;;!! ;; (selected-window)))
1242 ;;;!! ;; (begin-reg nil)
1243 ;;;!! ;; (end-reg nil)
1244 ;;;!! ;; (end-column nil)
1245 ;;;!! ;; (begin-column nil))
1246 ;;;!! ;; (if (and (consp relative-coordinate)
1247 ;;;!! ;; (or (not last-line-drawn)
1248 ;;;!! ;; (not (= last-line-drawn abs-y))))
1250 ;;;!! ;; (move-to-window-line (car (cdr relative-coordinate)))
1251 ;;;!! ;; (if (= (following-char) 10)
1254 ;;;!! ;; (setq begin-reg (1- (re-search-forward end-delim)))
1255 ;;;!! ;; (setq begin-column (1- (current-column)))
1256 ;;;!! ;; (end-of-line)
1257 ;;;!! ;; (setq end-reg (1+ (re-search-backward begin-delim)))
1258 ;;;!! ;; (setq end-column (1+ (current-column)))
1259 ;;;!! ;; (message "%s" (buffer-substring begin-reg end-reg))
1260 ;;;!! ;; (x-draw-rectangle screen
1261 ;;;!! ;; (setq last-line-drawn abs-y)
1262 ;;;!! ;; begin-column
1263 ;;;!! ;; (- end-column begin-column) 1))))))))))
1265 ;;;!! ;;(defun mouse-erase-box ()
1266 ;;;!! ;; (interactive)
1267 ;;;!! ;; (if last-line-drawn
1269 ;;;!! ;; (x-erase-rectangle (selected-screen))
1270 ;;;!! ;; (setq last-line-drawn nil))))
1272 ;;;!! ;;; (defun test-x-rectangle ()
1273 ;;;!! ;;; (use-local-mouse-map (setq rectangle-test-map (make-sparse-keymap)))
1274 ;;;!! ;;; (define-key rectangle-test-map mouse-motion-button-left 'mouse-boxing)
1275 ;;;!! ;;; (define-key rectangle-test-map mouse-button-left-up 'mouse-erase-box))
1278 ;;;!! ;; Here is how to do double clicking in lisp. About to change.
1281 ;;;!! (defvar double-start nil)
1282 ;;;!! (defconst double-click-interval 300
1283 ;;;!! "Max ticks between clicks")
1285 ;;;!! (defun double-down (event)
1286 ;;;!! (interactive "@e")
1287 ;;;!! (if double-start
1288 ;;;!! (let ((interval (- (nth 4 event) double-start)))
1289 ;;;!! (if (< interval double-click-interval)
1291 ;;;!! (backward-up-list 1)
1292 ;;;!! ;; (message "Interval %d" interval)
1293 ;;;!! (sleep-for 1)))
1294 ;;;!! (setq double-start nil))
1295 ;;;!! (setq double-start (nth 4 event))))
1297 ;;;!! (defun double-up (event)
1298 ;;;!! (interactive "@e")
1299 ;;;!! (and double-start
1300 ;;;!! (> (- (nth 4 event ) double-start) double-click-interval)
1301 ;;;!! (setq double-start nil)))
1303 ;;;!! ;;; (defun x-test-doubleclick ()
1304 ;;;!! ;;; (use-local-mouse-map (setq doubleclick-test-map (make-sparse-keymap)))
1305 ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left 'double-down)
1306 ;;;!! ;;; (define-key doubleclick-test-map mouse-button-left-up 'double-up))
1309 ;;;!! ;; This scrolls while button is depressed. Use preferable in scroll bar.
1312 ;;;!! (defvar scrolled-lines 0)
1313 ;;;!! (defconst scroll-speed 1)
1315 ;;;!! (defun incr-scroll-down (event)
1316 ;;;!! (interactive "@e")
1317 ;;;!! (setq scrolled-lines 0)
1318 ;;;!! (incremental-scroll scroll-speed))
1320 ;;;!! (defun incr-scroll-up (event)
1321 ;;;!! (interactive "@e")
1322 ;;;!! (setq scrolled-lines 0)
1323 ;;;!! (incremental-scroll (- scroll-speed)))
1325 ;;;!! (defun incremental-scroll (n)
1326 ;;;!! (while (= (x-mouse-events) 0)
1327 ;;;!! (setq scrolled-lines (1+ (* scroll-speed scrolled-lines)))
1328 ;;;!! (scroll-down n)
1329 ;;;!! (sit-for 300 t)))
1331 ;;;!! (defun incr-scroll-stop (event)
1332 ;;;!! (interactive "@e")
1333 ;;;!! (message "Scrolled %d lines" scrolled-lines)
1334 ;;;!! (setq scrolled-lines 0)
1335 ;;;!! (sleep-for 1))
1337 ;;;!! ;;; (defun x-testing-scroll ()
1338 ;;;!! ;;; (let ((scrolling-map (function mouse-vertical-scroll-bar-prefix)))
1339 ;;;!! ;;; (define-key scrolling-map mouse-button-left 'incr-scroll-down)
1340 ;;;!! ;;; (define-key scrolling-map mouse-button-right 'incr-scroll-up)
1341 ;;;!! ;;; (define-key scrolling-map mouse-button-left-up 'incr-scroll-stop)
1342 ;;;!! ;;; (define-key scrolling-map mouse-button-right-up 'incr-scroll-stop)))
1345 ;;;!! ;; Some playthings suitable for picture mode? They need work.
1348 ;;;!! (defun mouse-kill-rectangle (event)
1349 ;;;!! "Kill the rectangle between point and the mouse cursor."
1350 ;;;!! (interactive "@e")
1351 ;;;!! (let ((point-save (point)))
1352 ;;;!! (save-excursion
1353 ;;;!! (mouse-set-point event)
1354 ;;;!! (push-mark nil t)
1355 ;;;!! (if (> point-save (point))
1356 ;;;!! (kill-rectangle (point) point-save)
1357 ;;;!! (kill-rectangle point-save (point))))))
1359 ;;;!! (defun mouse-open-rectangle (event)
1360 ;;;!! "Kill the rectangle between point and the mouse cursor."
1361 ;;;!! (interactive "@e")
1362 ;;;!! (let ((point-save (point)))
1363 ;;;!! (save-excursion
1364 ;;;!! (mouse-set-point event)
1365 ;;;!! (push-mark nil t)
1366 ;;;!! (if (> point-save (point))
1367 ;;;!! (open-rectangle (point) point-save)
1368 ;;;!! (open-rectangle point-save (point))))))
1370 ;;;!! ;; Must be a better way to do this.
1372 ;;;!! (defun mouse-multiple-insert (n char)
1373 ;;;!! (while (> n 0)
1375 ;;;!! (setq n (1- n))))
1377 ;;;!! ;; What this could do is not finalize until button was released.
1379 ;;;!! (defun mouse-move-text (event)
1380 ;;;!! "Move text from point to cursor position, inserting spaces."
1381 ;;;!! (interactive "@e")
1382 ;;;!! (let* ((relative-coordinate
1383 ;;;!! (coordinates-in-window-p (car event) (selected-window))))
1384 ;;;!! (if (consp relative-coordinate)
1385 ;;;!! (cond ((> (current-column) (car relative-coordinate))
1387 ;;;!! (- (car relative-coordinate) (current-column))))
1388 ;;;!! ((< (current-column) (car relative-coordinate))
1389 ;;;!! (mouse-multiple-insert
1390 ;;;!! (- (car relative-coordinate) (current-column)) " "))
1391 ;;;!! ((= (current-column) (car relative-coordinate)) (ding))))))
1393 ;; Choose a completion with the mouse.
1395 (defun mouse-choose-completion (event)
1396 "Click on an alternative in the `*Completions*' buffer to choose it."
1398 ;; Give temporary modes such as isearch a chance to turn off.
1399 (run-hooks 'mouse-leave-buffer-hook
)
1400 (let ((buffer (window-buffer))
1404 (set-buffer (window-buffer (posn-window (event-start event
))))
1405 (if completion-reference-buffer
1406 (setq buffer completion-reference-buffer
))
1407 (setq base-size completion-base-size
)
1409 (goto-char (posn-point (event-start event
)))
1411 (if (and (not (eobp)) (get-text-property (point) 'mouse-face
))
1412 (setq end
(point) beg
(1+ (point))))
1414 (error "No completion here"))
1415 (setq beg
(previous-single-property-change beg
'mouse-face
))
1416 (setq end
(or (next-single-property-change end
'mouse-face
)
1418 (setq choice
(buffer-substring beg end
)))))
1419 (let ((owindow (selected-window)))
1420 (select-window (posn-window (event-start event
)))
1421 (if (and (one-window-p t
'selected-frame
)
1422 (window-dedicated-p (selected-window)))
1423 ;; This is a special buffer's frame
1424 (iconify-frame (selected-frame))
1425 (or (window-dedicated-p (selected-window))
1427 (select-window owindow
))
1428 (choose-completion-string choice buffer base-size
)))
1432 (defun font-menu-add-default ()
1433 (let* ((default (cdr (assq 'font
(frame-parameters (selected-frame)))))
1434 (font-alist x-fixed-font-alist
)
1435 (elt (or (assoc "Misc" font-alist
) (nth 1 font-alist
))))
1436 (if (assoc "Default" elt
)
1437 (delete (assoc "Default" elt
) elt
))
1439 (cons (list "Default"
1440 (cdr (assq 'font
(frame-parameters (selected-frame)))))
1443 (defvar x-fixed-font-alist
1446 ;; For these, we specify the pixel height and width.
1448 ("6x10" "-misc-fixed-medium-r-normal--10-*-*-*-c-60-iso8859-1" "6x10")
1450 "-misc-fixed-medium-r-semicondensed--12-*-*-*-c-60-iso8859-1" "6x12")
1452 "-misc-fixed-medium-r-semicondensed--13-*-*-*-c-60-iso8859-1" "6x13")
1453 ("7x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-70-iso8859-1" "7x13")
1454 ("7x14" "-misc-fixed-medium-r-normal--14-*-*-*-c-70-iso8859-1" "7x14")
1455 ("8x13" "-misc-fixed-medium-r-normal--13-*-*-*-c-80-iso8859-1" "8x13")
1456 ("9x15" "-misc-fixed-medium-r-normal--15-*-*-*-c-90-iso8859-1" "9x15")
1457 ("10x20" "-misc-fixed-medium-r-normal--20-*-*-*-c-100-iso8859-1" "10x20")
1458 ("11x18" "-misc-fixed-medium-r-normal--18-*-*-*-c-110-iso8859-1" "11x18")
1459 ("12x24" "-misc-fixed-medium-r-normal--24-*-*-*-c-120-iso8859-1" "12x24")
1462 "-schumacher-clean-medium-r-normal--8-*-*-*-c-50-iso8859-1")
1464 "-schumacher-clean-medium-r-normal--8-*-*-*-c-60-iso8859-1")
1466 "-schumacher-clean-medium-r-normal--8-*-*-*-c-80-iso8859-1")
1468 "-schumacher-clean-medium-r-normal--10-*-*-*-c-80-iso8859-1")
1470 "-schumacher-clean-medium-r-normal--14-*-*-*-c-80-iso8859-1")
1472 "-schumacher-clean-medium-r-normal--16-*-*-*-c-80-iso8859-1")
1474 ("sony 8x16" "-sony-fixed-medium-r-normal--16-*-*-*-c-80-iso8859-1"))
1475 ;;; We don't seem to have these; who knows what they are.
1476 ;;; ("fg-18" "fg-18")
1477 ;;; ("fg-25" "fg-25")
1478 ;;; ("lucidasanstypewriter-12" "lucidasanstypewriter-12")
1479 ;;; ("lucidasanstypewriter-bold-14" "lucidasanstypewriter-bold-14")
1480 ;;; ("lucidasanstypewriter-bold-24" "lucidasanstypewriter-bold-24")
1481 ;;; ("lucidatypewriter-bold-r-24" "-b&h-lucidatypewriter-bold-r-normal-sans-24-240-75-75-m-140-iso8859-1")
1482 ;;; ("fixed-medium-20" "-misc-fixed-medium-*-*-*-20-*-*-*-*-*-*-*")
1484 ;; For these, we specify the point height.
1485 ("8" "-adobe-courier-medium-r-normal--*-80-*-*-m-*-iso8859-1")
1486 ("10" "-adobe-courier-medium-r-normal--*-100-*-*-m-*-iso8859-1")
1487 ("12" "-adobe-courier-medium-r-normal--*-120-*-*-m-*-iso8859-1")
1488 ("14" "-adobe-courier-medium-r-normal--*-140-*-*-m-*-iso8859-1")
1489 ("18" "-adobe-courier-medium-r-normal--*-180-*-*-m-*-iso8859-1")
1490 ("24" "-adobe-courier-medium-r-normal--*-240-*-*-m-*-iso8859-1")
1491 ("8 bold" "-adobe-courier-bold-r-normal--*-80-*-*-m-*-iso8859-1")
1492 ("10 bold" "-adobe-courier-bold-r-normal--*-100-*-*-m-*-iso8859-1")
1493 ("12 bold" "-adobe-courier-bold-r-normal--*-120-*-*-m-*-iso8859-1")
1494 ("14 bold" "-adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1")
1495 ("18 bold" "-adobe-courier-bold-r-normal--*-180-*-*-m-*-iso8859-1")
1496 ("24 bold" "-adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1")
1497 ("8 slant" "-adobe-courier-medium-o-normal--*-80-*-*-m-*-iso8859-1")
1498 ("10 slant" "-adobe-courier-medium-o-normal--*-100-*-*-m-*-iso8859-1")
1499 ("12 slant" "-adobe-courier-medium-o-normal--*-120-*-*-m-*-iso8859-1")
1500 ("14 slant" "-adobe-courier-medium-o-normal--*-140-*-*-m-*-iso8859-1")
1501 ("18 slant" "-adobe-courier-medium-o-normal--*-180-*-*-m-*-iso8859-1")
1502 ("24 slant" "-adobe-courier-medium-o-normal--*-240-*-*-m-*-iso8859-1")
1503 ("8 bold slant" "-adobe-courier-bold-o-normal--*-80-*-*-m-*-iso8859-1")
1504 ("10 bold slant" "-adobe-courier-bold-o-normal--*-100-*-*-m-*-iso8859-1")
1505 ("12 bold slant" "-adobe-courier-bold-o-normal--*-120-*-*-m-*-iso8859-1")
1506 ("14 bold slant" "-adobe-courier-bold-o-normal--*-140-*-*-m-*-iso8859-1")
1507 ("18 bold slant" "-adobe-courier-bold-o-normal--*-180-*-*-m-*-iso8859-1")
1508 ("24 bold slant" "-adobe-courier-bold-o-normal--*-240-*-*-m-*-iso8859-1"))
1510 "X fonts suitable for use in Emacs.")
1512 (defun mouse-set-font (&rest fonts
)
1513 "Select an emacs font from a list of known good fonts"
1515 (x-popup-menu last-nonmenu-event x-fixed-font-alist
))
1521 (set-default-font (car fonts
))
1522 (setq font
(car fonts
))
1525 (setq fonts
(cdr fonts
)))))
1527 (error "Font not found")))))
1529 ;;; Bindings for mouse commands.
1531 (define-key global-map
[down-mouse-1
] 'mouse-drag-region
)
1532 (global-set-key [mouse-1
] 'mouse-set-point
)
1533 (global-set-key [drag-mouse-1
] 'mouse-set-region
)
1535 ;; These are tested for in mouse-drag-region.
1536 (global-set-key [double-mouse-1
] 'mouse-set-point
)
1537 (global-set-key [triple-mouse-1
] 'mouse-set-point
)
1539 (global-set-key [mouse-2
] 'mouse-yank-at-click
)
1540 (global-set-key [mouse-3
] 'mouse-save-then-kill
)
1542 ;; By binding these to down-going events, we let the user use the up-going
1543 ;; event to make the selection, saving a click.
1544 (global-set-key [C-down-mouse-1
] 'mouse-set-font
)
1545 ;; C-down-mouse-2 is bound in facemenu.el.
1546 (global-set-key [C-down-mouse-3
] 'mouse-major-mode-menu
)
1549 ;; Replaced with dragging mouse-1
1550 ;; (global-set-key [S-mouse-1] 'mouse-set-mark)
1552 (global-set-key [mode-line mouse-1
] 'mouse-select-window
)
1553 (global-set-key [mode-line drag-mouse-1
] 'mouse-select-window
)
1554 (global-set-key [mode-line down-mouse-1
] 'mouse-drag-mode-line
)
1555 (global-set-key [mode-line mouse-2
] 'mouse-delete-other-windows
)
1556 (global-set-key [mode-line mouse-3
] 'mouse-delete-window
)
1557 (global-set-key [mode-line C-mouse-2
] 'mouse-split-window-horizontally
)
1558 (global-set-key [vertical-scroll-bar C-mouse-2
] 'mouse-split-window-vertically
)
1559 (global-set-key [vertical-line C-mouse-2
] 'mouse-split-window-vertically
)
1563 ;;; mouse.el ends here