comparison lisp/mouse.el @ 2799:93a5aef19835

(mouse-drag-region): New command, on down-mouse-1.
author Richard M. Stallman <rms@gnu.org>
date Sat, 15 May 1993 19:52:01 +0000
parents f63bcaae7cd0
children 02c75b605550
comparison
equal deleted inserted replaced
2798:e2f296263868 2799:93a5aef19835
97 (if (numberp (posn-point posn)) 97 (if (numberp (posn-point posn))
98 (goto-char (posn-point posn))))) 98 (goto-char (posn-point posn)))))
99 99
100 (defun mouse-set-region (click) 100 (defun mouse-set-region (click)
101 "Set the region to the text that the mouse is dragged over. 101 "Set the region to the text that the mouse is dragged over.
102 This must be bound to a mouse click." 102 This must be bound to a mouse drag event."
103 (interactive "e") 103 (interactive "e")
104 (let ((posn (event-start click)) 104 (let ((posn (event-start click))
105 (end (event-end click))) 105 (end (event-end click)))
106 (select-window (posn-window posn)) 106 (select-window (posn-window posn))
107 (if (numberp (posn-point posn)) 107 (if (numberp (posn-point posn))
108 (goto-char (posn-point posn))) 108 (goto-char (posn-point posn)))
109 (sit-for 1) 109 ;; If mark is highlighted, no need to bounce the cursor.
110 (or (and transient-mark-mode
111 (eq (framep (selected-frame)) 'x))
112 (sit-for 1))
110 (push-mark) 113 (push-mark)
111 (if (numberp (posn-point end)) 114 (if (numberp (posn-point end))
112 (goto-char (posn-point end))))) 115 (goto-char (posn-point end)))))
116
117 (defun mouse-drag-region (click)
118 "Set the region to the text that the mouse is dragged over.
119 This must be bound to a button-down mouse event."
120 (interactive "e")
121 (let ((posn (event-start click))
122 done event (mark-active nil))
123 (select-window (posn-window posn))
124 ;; Set point temporarily, so user sees where it is.
125 (if (numberp (posn-point posn))
126 (goto-char (posn-point posn)))
127 ;; Turn off the old mark when we set up an empty region.
128 (setq deactivate-mark t)))
129
130 ;;;Nice hack, but too slow.
131 ;;;(defun mouse-drag-region-1 (click)
132 ;;; "Set the region to the text that the mouse is dragged over.
133 ;;;This must be bound to a button-down mouse event."
134 ;;; (interactive "e")
135 ;;; (let (newmark)
136 ;;; (let ((posn (event-start click))
137 ;;; done event omark (mark-active t))
138 ;;; (select-window (posn-window posn))
139 ;;; (setq omark (and mark-active (mark)))
140 ;;; (if (numberp (posn-point posn))
141 ;;; (goto-char (posn-point posn)))
142 ;;; ;; Set mark temporarily, so highlighting does what we want.
143 ;;; (set-marker (mark-marker) (point))
144 ;;; (track-mouse
145 ;;; (while (not done)
146 ;;; (setq event (read-event))
147 ;;; (if (eq (car-safe event) 'mouse-movement)
148 ;;; (goto-char (posn-point (event-start event)))
149 ;;; ;; Exit when we get the drag event; ignore that event.
150 ;;; (setq done t))))
151 ;;; (if (/= (mark) (point))
152 ;;; (setq newmark (mark)))
153 ;;; ;; Restore previous mark status.
154 ;;; (if omark (set-marker (mark-marker) omark)))
155 ;;; ;; Now, if we dragged, set the mark at the proper place.
156 ;;; (if newmark
157 ;;; (push-mark newmark t)
158 ;;; ;; Turn off the old mark when we set up an empty region.
159 ;;; (setq deactivate-mark t))))
113 160
114 (defun mouse-set-mark (click) 161 (defun mouse-set-mark (click)
115 "Set mark at the position clicked on with the mouse. 162 "Set mark at the position clicked on with the mouse.
116 Display cursor at that position for a second. 163 Display cursor at that position for a second.
117 This must be bound to a mouse click." 164 This must be bound to a mouse click."
601 (modify-frame-parameters (selected-frame) 648 (modify-frame-parameters (selected-frame)
602 (list (cons 'font font))))) 649 (list (cons 'font font)))))
603 650
604 ;;; Bindings for mouse commands. 651 ;;; Bindings for mouse commands.
605 652
606 ;; This won't be needed once the drag and down events 653 (define-key global-map [down-mouse-1] 'mouse-drag-region)
607 ;; are properly implemented.
608 (global-set-key [mouse-1] 'mouse-set-point) 654 (global-set-key [mouse-1] 'mouse-set-point)
609
610 (global-set-key [drag-mouse-1] 'mouse-set-region) 655 (global-set-key [drag-mouse-1] 'mouse-set-region)
656
611 (global-set-key [mouse-2] 'mouse-yank-at-click) 657 (global-set-key [mouse-2] 'mouse-yank-at-click)
612 (global-set-key [mouse-3] 'mouse-save-then-kill) 658 (global-set-key [mouse-3] 'mouse-save-then-kill)
613 659
614 ;; By binding these to down-going events, we let the user use the up-going 660 ;; By binding these to down-going events, we let the user use the up-going
615 ;; event to make the selection, saving a click. 661 ;; event to make the selection, saving a click.