Mercurial > hg > xemacs-beta
comparison lisp/mouse.el @ 272:c5d627a313b1 r21-0b34
Import from CVS: tag r21-0b34
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:28:48 +0200 |
parents | 084402c475ba |
children | 7df0dd720c89 |
comparison
equal
deleted
inserted
replaced
271:c7b7086b0a39 | 272:c5d627a313b1 |
---|---|
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | 18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
20 ;; General Public License for more details. | 20 ;; General Public License for more details. |
21 | 21 |
22 ;; You should have received a copy of the GNU General Public License | 22 ;; You should have received a copy of the GNU General Public License |
23 ;; along with XEmacs; see the file COPYING. If not, write to the | 23 ;; along with XEmacs; see the file COPYING. If not, write to the |
24 ;; Free Software Foundation, 59 Temple Place - Suite 330, | 24 ;; Free Software Foundation, 59 Temple Place - Suite 330, |
25 ;; Boston, MA 02111-1307, USA. | 25 ;; Boston, MA 02111-1307, USA. |
26 | 26 |
27 ;;; Synched up with: Not synched with FSF. Almost completely divergent. | 27 ;;; Synched up with: Not synched with FSF. Almost completely divergent. |
28 | 28 |
146 (and (not mouse-yank-at-point) | 146 (and (not mouse-yank-at-point) |
147 (mouse-set-point event)) | 147 (mouse-set-point event)) |
148 (funcall mouse-yank-function)) | 148 (funcall mouse-yank-function)) |
149 | 149 |
150 (defun click-inside-extent-p (click extent) | 150 (defun click-inside-extent-p (click extent) |
151 "Returns non-nil if the button event is within the bounds of the primary | 151 "Return non-nil if the button event is within the primary selection-extent. |
152 selection-extent, nil otherwise." | 152 Return nil otherwise." |
153 ;; stig@hackvan.com | 153 ;; stig@hackvan.com |
154 (let ((ewin (event-window click)) | 154 (let ((ewin (event-window click)) |
155 (epnt (event-point click))) | 155 (epnt (event-point click))) |
156 (and ewin | 156 (and ewin |
157 epnt | 157 epnt |
166 (or (click-inside-extent-p click primary-selection-extent) | 166 (or (click-inside-extent-p click primary-selection-extent) |
167 (click-inside-extent-p click zmacs-region-extent) | 167 (click-inside-extent-p click zmacs-region-extent) |
168 )) | 168 )) |
169 | 169 |
170 (defun point-inside-extent-p (extent) | 170 (defun point-inside-extent-p (extent) |
171 "Returns non-nil if the point is within or just after the bounds of the | 171 "Return t if point is within the bounds of the primary selection extent. |
172 primary selection-extent, nil otherwise." | 172 Return t is point is at the end position of the extent. |
173 Return nil otherwise." | |
173 ;; stig@hackvan.com | 174 ;; stig@hackvan.com |
174 (and extent | 175 (and extent |
175 (eq (current-buffer) | 176 (eq (current-buffer) |
176 (extent-object extent)) | 177 (extent-object extent)) |
177 (> (point) (extent-start-position extent)) | 178 (> (point) (extent-start-position extent)) |
178 (>= (extent-end-position extent) (point)))) | 179 (>= (extent-end-position extent) (point)))) |
179 | 180 |
180 (defun point-inside-selection-p () | 181 (defun point-inside-selection-p () |
181 ;; by Stig@hackvan.com | 182 ;; by Stig@hackvan.com |
182 (or (point-inside-extent-p primary-selection-extent) | 183 (or (point-inside-extent-p primary-selection-extent) |
183 (point-inside-extent-p zmacs-region-extent))) | 184 (point-inside-extent-p zmacs-region-extent))) |
184 | 185 |
185 (defun mouse-drag-or-yank (event) | 186 (defun mouse-drag-or-yank (event) |
186 "Either drag or paste the current selection. If the variable | 187 "Either drag or paste the current selection. |
187 `mouse-yank-at-point' is non-nil, then moves the cursor to the location of | 188 If the variable `mouse-yank-at-point' is non-nil, |
188 the click before pasting. | 189 move the cursor to the location of the click before pasting. |
189 This functions has to be improved. Until now it is just a (working) test." | 190 This functions has to be improved. Currently it is just a (working) test." |
190 ;; by Oliver Graf <ograf@fga.de> | 191 ;; by Oliver Graf <ograf@fga.de> |
191 (interactive "e") | 192 (interactive "e") |
192 (if (click-inside-extent-p event zmacs-region-extent) | 193 (if (click-inside-extent-p event zmacs-region-extent) |
193 ;; okay, this is a drag | 194 ;; okay, this is a drag |
194 (cond ((featurep 'offix) | 195 (cond ((featurep 'offix) |
206 (mouse-set-point event)) | 207 (mouse-set-point event)) |
207 (funcall mouse-yank-function)) | 208 (funcall mouse-yank-function)) |
208 ) | 209 ) |
209 | 210 |
210 (defun mouse-offix-drop (event) | 211 (defun mouse-offix-drop (event) |
211 "Do something with an OffiX drop event. Inserts Text drops and | 212 "Do something with an OffiX drop event. |
212 executes appropriate commands for specific drops. | 213 Insert Text drops and execute appropriate commands for specific drops. |
213 Text drops follow the `mouse-yank-at-point' variable." | 214 Text drops follow the `mouse-yank-at-point' variable." |
214 ;; by Oliver Graf <ograf@fga.de> | 215 ;; by Oliver Graf <ograf@fga.de> |
215 (interactive "e") | 216 (interactive "e") |
216 (let ((type (car (event-drag-and-drop-data event))) | 217 (let ((type (car (event-drag-and-drop-data event))) |
217 (data (cadr (event-drag-and-drop-data event))) | 218 (data (cadr (event-drag-and-drop-data event))) |
218 (frame (event-channel event))) | 219 (frame (event-channel event))) |
251 (hexlify-buffer) | 252 (hexlify-buffer) |
252 (make-frame-visible frame)))) | 253 (make-frame-visible frame)))) |
253 (undo-boundary))) | 254 (undo-boundary))) |
254 | 255 |
255 (defun mouse-mswindows-drop (event) | 256 (defun mouse-mswindows-drop (event) |
256 "Do something with a drop event. Inserts Text drops and | 257 "Do something with a drop event. |
257 executes appropriate commands for specific drops. | 258 Insert Text drops and execute appropriate commands for specific drops. |
258 Text drops follow the `mouse-yank-at-point' variable." | 259 Text drops follow the `mouse-yank-at-point' variable." |
259 (interactive "e") | 260 (interactive "e") |
260 (let* ((type (car (event-drag-and-drop-data event))) | 261 (let* ((type (car (event-drag-and-drop-data event))) |
261 (data (cadr (event-drag-and-drop-data event))) | 262 (data (cadr (event-drag-and-drop-data event))) |
262 (frame (event-channel event)) | 263 (frame (event-channel event)) |
263 (window (if frame (event-window event) (frame-selected-window)))) | 264 (window (if frame (event-window event) (frame-selected-window)))) |
305 It's also fantastic for debugging regular expressions." | 306 It's also fantastic for debugging regular expressions." |
306 ;; by Stig@hackvan.com | 307 ;; by Stig@hackvan.com |
307 (interactive "e\nP") | 308 (interactive "e\nP") |
308 (let (exp val result-str) | 309 (let (exp val result-str) |
309 (setq exp (save-window-excursion | 310 (setq exp (save-window-excursion |
310 (save-excursion | 311 (save-excursion |
311 (mouse-set-point click) | 312 (mouse-set-point click) |
312 (save-excursion | 313 (save-excursion |
313 (or (looking-at "(") (forward-sexp -1)) | 314 (or (looking-at "(") (forward-sexp -1)) |
314 (read (point-marker)))))) | 315 (read (point-marker)))))) |
315 (cond ((stringp exp) | 316 (cond ((stringp exp) |
381 "Bury the buffer pointed to by the mouse, thus selecting the next one." | 382 "Bury the buffer pointed to by the mouse, thus selecting the next one." |
382 (interactive "e") | 383 (interactive "e") |
383 (save-selected-window | 384 (save-selected-window |
384 (select-window (event-window event)) | 385 (select-window (event-window event)) |
385 (bury-buffer))) | 386 (bury-buffer))) |
386 | 387 |
387 (defun mouse-unbury-buffer (event) | 388 (defun mouse-unbury-buffer (event) |
388 "Unbury and select the most recently buried buffer." | 389 "Unbury and select the most recently buried buffer." |
389 (interactive "e") | 390 (interactive "e") |
390 (save-selected-window | 391 (save-selected-window |
391 (select-window (event-window event)) | 392 (select-window (event-window event)) |
642 Default handlers are provided to implement standard selecting/positioning | 643 Default handlers are provided to implement standard selecting/positioning |
643 behavior. You can explicitly request this default behavior, and override | 644 behavior. You can explicitly request this default behavior, and override |
644 any custom-supplied handlers, by using the function `mouse-track-default' | 645 any custom-supplied handlers, by using the function `mouse-track-default' |
645 instead of `mouse-track'. | 646 instead of `mouse-track'. |
646 | 647 |
647 Default behavior is as follows: | 648 Default behavior is as follows: |
648 | 649 |
649 If you click-and-drag, the selection will be set to the region between the | 650 If you click-and-drag, the selection will be set to the region between the |
650 point of the initial click and the point at which you release the button. | 651 point of the initial click and the point at which you release the button. |
651 These positions need not be ordered. | 652 These positions need not be ordered. |
652 | 653 |
744 (defvar default-mouse-track-max-anchor nil) | 745 (defvar default-mouse-track-max-anchor nil) |
745 (defvar default-mouse-track-result nil) | 746 (defvar default-mouse-track-result nil) |
746 (defvar default-mouse-track-down-event nil) | 747 (defvar default-mouse-track-down-event nil) |
747 | 748 |
748 ;; D. Verna Feb. 17 1998 | 749 ;; D. Verna Feb. 17 1998 |
749 ;; This function used to assume that when (event-window event) differs from | 750 ;; This function used to assume that when (event-window event) differs from |
750 ;; window, we have to scroll. This is WRONG, for instance when there are | 751 ;; window, we have to scroll. This is WRONG, for instance when there are |
751 ;; toolbars on the side, in which case window-event returns nil. | 752 ;; toolbars on the side, in which case window-event returns nil. |
752 (defun default-mouse-track-set-point-in-window (event window) | 753 (defun default-mouse-track-set-point-in-window (event window) |
753 (if (event-over-modeline-p event) | 754 (if (event-over-modeline-p event) |
754 nil ;; Scroll | 755 nil ;; Scroll |
758 (if (or (not p) (not (pos-visible-in-window-p p window))) | 759 (if (or (not p) (not (pos-visible-in-window-p p window))) |
759 nil ;; Scroll | 760 nil ;; Scroll |
760 (mouse-set-point event) | 761 (mouse-set-point event) |
761 t)) | 762 t)) |
762 ;; Not over a modeline, not the same window. Check if the Y position | 763 ;; Not over a modeline, not the same window. Check if the Y position |
763 ;; is still overlapping the original window. | 764 ;; is still overlapping the original window. |
764 (let* ((edges (window-pixel-edges window)) | 765 (let* ((edges (window-pixel-edges window)) |
765 (row (event-y-pixel event)) | 766 (row (event-y-pixel event)) |
766 (text-start (nth 1 edges)) | 767 (text-start (nth 1 edges)) |
767 (text-end (+ (nth 3 edges)))) | 768 (text-end (+ (nth 3 edges)))) |
768 (if (or (< row text-start) | 769 (if (or (< row text-start) |
769 (> row text-end)) | 770 (> row text-end)) |
770 nil ;; Scroll | 771 nil ;; Scroll |
771 ;; The Y pos in overlapping the original window. Check however if | 772 ;; The Y pos in overlapping the original window. Check however if |
772 ;; the position is really visible, because there could be a | 773 ;; the position is really visible, because there could be a |
773 ;; scrollbar or a modeline at this place. | 774 ;; scrollbar or a modeline at this place. |
774 ;; Find the mean line height (height / lines nb), and approximate | 775 ;; Find the mean line height (height / lines nb), and approximate |
775 ;; the line number for Y pos. | 776 ;; the line number for Y pos. |
776 (select-window window) | 777 (select-window window) |
777 (let ((line (/ (* (- row text-start) (window-height)) | 778 (let ((line (/ (* (- row text-start) (window-height)) |
778 (- text-end text-start)))) | 779 (- text-end text-start)))) |
779 (if (not (save-excursion | 780 (if (not (save-excursion |
780 (goto-char (window-start)) | 781 (goto-char (window-start)) |
781 (pos-visible-in-window-p | 782 (pos-visible-in-window-p |
782 (point-at-bol (+ 1 line))))) | 783 (point-at-bol (+ 1 line))))) |
815 (goto-char (window-end)) | 816 (goto-char (window-end)) |
816 (vertical-motion delta) | 817 (vertical-motion delta) |
817 ;; window-end reports the end of the clipped line, even if | 818 ;; window-end reports the end of the clipped line, even if |
818 ;; scroll-on-clipped-lines is t. compensate. | 819 ;; scroll-on-clipped-lines is t. compensate. |
819 ;; (If window-end gets fixed this can be removed.) | 820 ;; (If window-end gets fixed this can be removed.) |
820 (if (not (pos-visible-in-window-p (max (1- (point)) | 821 (if (not (pos-visible-in-window-p (max (1- (point)) |
821 (point-min)))) | 822 (point-min)))) |
822 (vertical-motion -1)) | 823 (vertical-motion -1)) |
823 (condition-case () (backward-char 1) | 824 (condition-case () (backward-char 1) |
824 (error (end-of-line))))))))) | 825 (error (end-of-line))))))))) |
825 | 826 |
826 | 827 |
827 ;; This remembers the last position at which the user clicked, for the | 828 ;; This remembers the last position at which the user clicked, for the |
828 ;; benefit of mouse-track-adjust (for example, button1; scroll until the | 829 ;; benefit of mouse-track-adjust (for example, button1; scroll until the |
1079 (close-pos (save-excursion | 1080 (close-pos (save-excursion |
1080 (set-buffer (event-buffer event)) | 1081 (set-buffer (event-buffer event)) |
1081 (let ((p (event-closest-point event))) | 1082 (let ((p (event-closest-point event))) |
1082 (and p (min (max p (point-min)) (point-max)))))) | 1083 (and p (min (max p (point-min)) (point-max)))))) |
1083 extent previous-point) | 1084 extent previous-point) |
1084 | 1085 |
1085 (if (not (event-window event)) | 1086 (if (not (event-window event)) |
1086 (error "not over window?")) | 1087 (error "not over window?")) |
1087 (setq default-mouse-track-type | 1088 (setq default-mouse-track-type |
1088 (nth (mod (1- click-count) | 1089 (nth (mod (1- click-count) |
1089 (length default-mouse-track-type-list)) | 1090 (length default-mouse-track-type-list)) |
1104 ;; resolved by the usual size-and-endpoint-comparison method. | 1105 ;; resolved by the usual size-and-endpoint-comparison method. |
1105 (set-extent-priority extent (1+ mouse-highlight-priority)) | 1106 (set-extent-priority extent (1+ mouse-highlight-priority)) |
1106 (if mouse-track-rectangle-p | 1107 (if mouse-track-rectangle-p |
1107 (setq default-mouse-track-extent | 1108 (setq default-mouse-track-extent |
1108 (list default-mouse-track-extent))) | 1109 (list default-mouse-track-extent))) |
1109 | 1110 |
1110 (setq previous-point | 1111 (setq previous-point |
1111 (if (and adjust | 1112 (if (and adjust |
1112 (markerp default-mouse-track-previous-point) | 1113 (markerp default-mouse-track-previous-point) |
1113 (eq (current-buffer) | 1114 (eq (current-buffer) |
1114 (marker-buffer default-mouse-track-previous-point))) | 1115 (marker-buffer default-mouse-track-previous-point))) |
1305 (defvar mouse-track-insert-selected-region nil) | 1306 (defvar mouse-track-insert-selected-region nil) |
1306 | 1307 |
1307 (defun mouse-track-insert-drag-up-hook (event click-count) | 1308 (defun mouse-track-insert-drag-up-hook (event click-count) |
1308 (setq mouse-track-insert-selected-region | 1309 (setq mouse-track-insert-selected-region |
1309 (default-mouse-track-return-dragged-selection event))) | 1310 (default-mouse-track-return-dragged-selection event))) |
1310 | 1311 |
1311 (defun mouse-track-insert (event &optional delete) | 1312 (defun mouse-track-insert (event &optional delete) |
1312 "Make a selection with the mouse and insert it at point. | 1313 "Make a selection with the mouse and insert it at point. |
1313 This is exactly the same as the `mouse-track' command on \\[mouse-track], | 1314 This is exactly the same as the `mouse-track' command on \\[mouse-track], |
1314 except that point is not moved; the selected text is immediately inserted | 1315 except that point is not moved; the selected text is immediately inserted |
1315 after being selected\; and the selection is immediately disowned afterwards." | 1316 after being selected\; and the selection is immediately disowned afterwards." |