Mercurial > emacs
comparison lisp/mouse.el @ 1363:f34d8e4d1d7b
* mouse.el: Begin adapting this to the new event format.
(event-window, event-point, mouse-coords, mouse-timestamp):
Removed.
(event-start, event-end, posn-window, posn-point, posn-col-row,
posn-timestamp): New accessors; these are defsubsts.
(mouse-delete-window, mouse-delete-other-windows,
mouse-split-window-vertically, mouse-set-point): Rewritten to use
the new accessors.
* mouse.el: Remove hack of binding down-mouse-1.
* mouse.el (mouse-movement-p): Add docstring for this.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Wed, 07 Oct 1992 20:46:31 +0000 |
parents | 467833df795b |
children | 4005f73e5712 |
comparison
equal
deleted
inserted
replaced
1362:4bea5980f778 | 1363:f34d8e4d1d7b |
---|---|
22 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 22 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
23 | 23 |
24 | 24 |
25 ;;; Utility functions. | 25 ;;; Utility functions. |
26 | 26 |
27 (defun mouse-movement-p (event) | 27 (defsubst mouse-movement-p (object) |
28 (and (consp event) | 28 "Return non-nil if OBJECT is a mouse movement event." |
29 (eq (car event) 'mouse-movement))) | 29 (and (consp object) |
30 | 30 (eq (car object) 'mouse-movement))) |
31 (defun event-window (event) (nth 1 event)) | 31 |
32 (defun event-point (event) (nth 2 event)) | 32 (defsubst event-start (event) |
33 (defun mouse-coords (event) (nth 3 event)) | 33 "Return the starting position of EVENT. |
34 (defun mouse-timestamp (event) (nth 4 event)) | 34 If EVENT is a mouse press or a mouse click, this returns the location |
35 of the event. | |
36 If EVENT is a drag, this returns the drag's starting position. | |
37 The return value is of the form | |
38 (WINDOW BUFFER-POSITION (COL . ROW) TIMESTAMP) | |
39 The `posn-' functions access elements of such lists." | |
40 (nth 1 event)) | |
41 | |
42 (defsubst event-end (event) | |
43 "Return the ending location of EVENT. EVENT should be a drag event. | |
44 The return value is of the form | |
45 (WINDOW BUFFER-POSITION (COL . ROW) TIMESTAMP) | |
46 The `posn-' functions access elements of such lists." | |
47 (nth 2 event)) | |
48 | |
49 (defsubst posn-window (position) | |
50 "Return the window in POSITION. | |
51 POSITION should be a list of the form | |
52 (WINDOW BUFFER-POSITION (COL . ROW) TIMESTAMP) | |
53 as returned by the `event-start' and `event-end' functions." | |
54 (nth 0 position)) | |
55 | |
56 (defsubst posn-point (position) | |
57 "Return the buffer location in POSITION. | |
58 POSITION should be a list of the form | |
59 (WINDOW BUFFER-POSITION (COL . ROW) TIMESTAMP) | |
60 as returned by the `event-start' and `event-end' functions." | |
61 (nth 1 position)) | |
62 | |
63 (defsubst posn-col-row (position) | |
64 "Return the row and column in POSITION. | |
65 POSITION should be a list of the form | |
66 (WINDOW BUFFER-POSITION (COL . ROW) TIMESTAMP) | |
67 as returned by the `event-start' and `event-end' functions." | |
68 (nth 2 position)) | |
69 | |
70 (defsubst posn-timestamp (position) | |
71 "Return the timestamp of POSITION. | |
72 POSITION should be a list of the form | |
73 (WINDOW BUFFER-POSITION (COL . ROW) TIMESTAMP) | |
74 nas returned by the `event-start' and `event-end' functions." | |
75 (nth 3 position)) | |
35 | 76 |
36 ;;; Indent track-mouse like progn. | 77 ;;; Indent track-mouse like progn. |
37 (put 'track-mouse 'lisp-indent-function 0) | 78 (put 'track-mouse 'lisp-indent-function 0) |
38 | 79 |
39 | 80 |
40 (defun mouse-delete-window (click) | 81 (defun mouse-delete-window (click) |
41 "Delete the window you click on. | 82 "Delete the window you click on. |
42 This must be bound to a mouse click." | 83 This must be bound to a mouse click." |
43 (interactive "e") | 84 (interactive "e") |
44 (delete-window (event-window click))) | 85 (delete-window (posn-window (event-start click)))) |
45 | 86 |
46 (defun mouse-delete-other-windows (click) | 87 (defun mouse-delete-other-windows () |
47 "Delete all window except the one you click on." | 88 "Delete all window except the one you click on." |
48 (interactive "@e") | 89 (interactive "@") |
49 (delete-other-windows)) | 90 (delete-other-windows)) |
50 | 91 |
51 (defun mouse-split-window-vertically (click) | 92 (defun mouse-split-window-vertically (click) |
52 "Select Emacs window mouse is on, then split it vertically in half. | 93 "Select Emacs window mouse is on, then split it vertically in half. |
53 The window is split at the line clicked on. | 94 The window is split at the line clicked on. |
54 This command must be bound to a mouse click." | 95 This command must be bound to a mouse click." |
55 (interactive "@e") | 96 (interactive "@e") |
56 (split-window-vertically (1+ (cdr (mouse-coords click))))) | 97 (let ((start (event-start click))) |
98 (select-window (posn-window start)) | |
99 (split-window-vertically (1+ (cdr (posn-col-row click)))))) | |
57 | 100 |
58 (defun mouse-split-window-horizontally (click) | 101 (defun mouse-split-window-horizontally (click) |
59 "Select Emacs window mouse is on, then split it horizontally in half. | 102 "Select Emacs window mouse is on, then split it horizontally in half. |
60 The window is split at the column clicked on. | 103 The window is split at the column clicked on. |
61 This command must be bound to a mouse click." | 104 This command must be bound to a mouse click." |
64 | 107 |
65 (defun mouse-set-point (click) | 108 (defun mouse-set-point (click) |
66 "Move point to the position clicked on with the mouse. | 109 "Move point to the position clicked on with the mouse. |
67 This must be bound to a mouse click." | 110 This must be bound to a mouse click." |
68 (interactive "e") | 111 (interactive "e") |
69 (select-window (event-window click)) | 112 (let ((posn (event-start click))) |
70 (if (numberp (event-point click)) | 113 (select-window (posn-window posn)) |
71 (goto-char (event-point click)))) | 114 (if (numberp (posn-point posn)) |
115 (goto-char (posn-point posn))))) | |
72 | 116 |
73 (defun mouse-set-mark (click) | 117 (defun mouse-set-mark (click) |
74 "Set mark at the position clicked on with the mouse. | 118 "Set mark at the position clicked on with the mouse. |
75 Display cursor at that position for a second. | 119 Display cursor at that position for a second. |
76 This must be bound to a mouse click." | 120 This must be bound to a mouse click." |
184 | 228 |
185 (defun mouse-scroll-left (click) | 229 (defun mouse-scroll-left (click) |
186 (interactive "@e") | 230 (interactive "@e") |
187 (scroll-left (1+ (car (mouse-coords click))))) | 231 (scroll-left (1+ (car (mouse-coords click))))) |
188 | 232 |
189 (defun mouse-scroll-right (ncolumns) | 233 (defun mouse-scroll-right (click) |
190 (interactive "@e") | 234 (interactive "@e") |
191 (scroll-right (1+ (car (mouse-coords click))))) | 235 (scroll-right (1+ (car (mouse-coords click))))) |
192 | 236 |
193 (defun mouse-scroll-left-full () | 237 (defun mouse-scroll-left-full () |
194 (interactive "@") | 238 (interactive "@") |
536 | 580 |
537 ;; This won't be needed once the drag and down events | 581 ;; This won't be needed once the drag and down events |
538 ;; are properly implemented. | 582 ;; are properly implemented. |
539 (global-set-key [mouse-1] 'mouse-set-point) | 583 (global-set-key [mouse-1] 'mouse-set-point) |
540 | 584 |
541 (global-set-key [down-mouse-1] 'mouse-set-point) | |
542 (global-set-key [drag-mouse-1] 'mouse-set-mark) | 585 (global-set-key [drag-mouse-1] 'mouse-set-mark) |
543 (global-set-key [mouse-2] 'mouse-yank-at-click) | 586 (global-set-key [mouse-2] 'mouse-yank-at-click) |
544 (global-set-key [mouse-3] 'mouse-save-then-kill) | 587 (global-set-key [mouse-3] 'mouse-save-then-kill) |
545 | 588 |
546 (global-set-key [C-mouse-1] 'mouse-buffer-menu) | 589 (global-set-key [C-mouse-1] 'mouse-buffer-menu) |