Mercurial > emacs
annotate lisp/emacs-lisp/levents.el @ 17126:f8d7263cce09
(init_syntax_once): Add trick to avoid compiler warning
of "comparison is always 1 ...".
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Fri, 28 Feb 1997 01:38:57 +0000 |
parents | 6dbe9f47c0a1 |
children | 72e538330a11 |
rev | line source |
---|---|
2232
4f9d60f7de9d
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2066
diff
changeset
|
1 ;;; levents.el --- emulate the Lucid event data type and associated functions. |
4f9d60f7de9d
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2066
diff
changeset
|
2 |
2034 | 3 ;; Copyright (C) 1993 Free Software Foundation, Inc. |
4 | |
5 ;; This file is part of GNU Emacs. | |
6 | |
7 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
8 ;; it under the terms of the GNU General Public License as published by | |
9 ;; the Free Software Foundation; either version 2, or (at your option) | |
10 ;; any later version. | |
11 | |
12 ;; GNU Emacs is distributed in the hope that it will be useful, | |
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 ;; GNU General Public License for more details. | |
16 | |
17 ;; You should have received a copy of the GNU General Public License | |
14169 | 18 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 ;; Boston, MA 02111-1307, USA. | |
2034 | 21 |
2232
4f9d60f7de9d
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2066
diff
changeset
|
22 ;;; Commentary: |
2034 | 23 |
24 ;; Things we cannot emulate in Lisp: | |
25 ;; It is not possible to emulate current-mouse-event as a variable, | |
26 ;; though it is not hard to obtain the data from (this-command-keys). | |
27 | |
28 ;; We do not have a variable unread-command-event; | |
29 ;; instead, we have the more general unread-command-events. | |
30 | |
2039
e062b4567dc6
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2034
diff
changeset
|
31 ;; Our read-key-sequence and read-char are not precisely |
e062b4567dc6
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2034
diff
changeset
|
32 ;; compatible with those in Lucid Emacs, but they should work ok. |
2034 | 33 |
34 ;;; Code: | |
35 | |
2057
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
36 (defun next-command-event (event) |
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
37 (error "You must rewrite to use `read-command-event' instead of `next-command-event'")) |
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
38 |
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
39 (defun next-event (event) |
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
40 (error "You must rewrite to use `read-event' instead of `next-event'")) |
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
41 |
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
42 (defun dispatch-event (event) |
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
43 (error "`dispatch-event' not supported")) |
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
44 |
2034 | 45 ;; Make events of type eval, menu and timeout |
46 ;; execute properly. | |
47 | |
48 (define-key global-map [menu] 'execute-eval-event) | |
49 (define-key global-map [timeout] 'execute-eval-event) | |
50 (define-key global-map [eval] 'execute-eval-event) | |
51 | |
52 (defun execute-eval-event (event) | |
53 (interactive "e") | |
54 (funcall (nth 1 event) (nth 2 event))) | |
55 | |
56 (put 'eval 'event-symbol-elements '(eval)) | |
57 (put 'menu 'event-symbol-elements '(eval)) | |
58 (put 'timeout 'event-symbol-elements '(eval)) | |
59 | |
60 (defun allocate-event () | |
61 "Returns an empty event structure. | |
62 In this emulation, it returns nil." | |
63 nil) | |
64 | |
65 (defun button-press-event-p (obj) | |
66 "True if the argument is a mouse-button-press event object." | |
67 (and (consp obj) (symbolp (car obj)) | |
68 (memq 'down (get (car obj) 'event-symbol-elements)))) | |
69 | |
70 (defun button-release-event-p (obj) | |
71 "True if the argument is a mouse-button-release event object." | |
72 (and (consp obj) (symbolp (car obj)) | |
73 (or (memq 'click (get (car obj) 'event-symbol-elements)) | |
74 (memq 'drag (get (car obj) 'event-symbol-elements))))) | |
75 | |
76 (defun character-to-event (ch &optional event) | |
77 "Converts a numeric ASCII value to an event structure, replete with | |
78 bucky bits. The character is the first argument, and the event to fill | |
79 in is the second. This function contains knowledge about what the codes | |
80 mean -- for example, the number 9 is converted to the character Tab, | |
81 not the distinct character Control-I. | |
82 | |
83 Beware that character-to-event and event-to-character are not strictly | |
84 inverse functions, since events contain much more information than the | |
85 ASCII character set can encode." | |
86 ch) | |
87 | |
88 (defun copy-event (event1 &optional event2) | |
89 "Make a copy of the given event object. | |
90 In this emulation, `copy-event' just returns its argument." | |
91 event1) | |
92 | |
93 (defun deallocate-event (event) | |
94 "Allow the given event structure to be reused. | |
95 In actual Lucid Emacs, you MUST NOT use this event object after | |
96 calling this function with it. You will lose. It is not necessary to | |
97 call this function, as event objects are garbage- collected like all | |
98 other objects; however, it may be more efficient to explicitly | |
99 deallocate events when you are sure that that is safe. | |
100 | |
101 This emulation does not actually deallocate or reuse events | |
102 except via garbage collection and `cons'." | |
103 nil) | |
104 | |
105 (defun enqueue-eval-event: (function object) | |
106 "Add an eval event to the back of the queue. | |
107 It will be the next event read after all pending events." | |
108 (setq unread-command-events | |
109 (nconc unread-command-events | |
110 (list (list 'eval function object))))) | |
111 | |
112 (defun eval-event-p (obj) | |
113 "True if the argument is an eval or menu event object." | |
114 (eq (car-safe obj) 'eval)) | |
115 | |
116 (defun event-button (event) | |
117 "Return the button-number of the given mouse-button-press event." | |
118 (let ((sym (car (get (car event) 'event-symbol-elements)))) | |
119 (cdr (assq sym '((mouse-1 . 1) (mouse-2 . 2) (mouse-3 . 3) | |
120 (mouse-4 . 4) (mouse-5 . 5)))))) | |
121 | |
122 (defun event-function (event) | |
123 "Return the callback function of the given timeout, menu, or eval event." | |
124 (nth 1 event)) | |
125 | |
126 (defun event-key (event) | |
127 "Returns the KeySym of the given key-press event. | |
128 The value is an ASCII printing character (not upper case) or a symbol." | |
129 (if (symbolp event) | |
130 (car (get event 'event-symbol-elements)) | |
131 (let ((base (logand event (1- (lsh 1 18))))) | |
132 (downcase (if (< base 32) (logior base 64) base))))) | |
133 | |
134 (defun event-object (event) | |
135 "Returns the function argument of the given timeout, menu, or eval event." | |
136 (nth 2 event)) | |
137 | |
138 (defun event-point (event) | |
139 "Returns the character position of the given mouse-related event. | |
140 If the event did not occur over a window, or did | |
141 not occur over text, then this returns nil. Otherwise, it returns an index | |
142 into the buffer visible in the event's window." | |
143 (posn-point (event-end event))) | |
144 | |
145 (defun event-process (event) | |
146 "Returns the process of the given process-output event." | |
147 (nth 1 event)) | |
148 | |
149 (defun event-timestamp (event) | |
150 "Returns the timestamp of the given event object. | |
151 In Lucid Emacs, this works for any kind of event. | |
152 In this emulation, it returns nil for non-mouse-related events." | |
153 (and (listp event) | |
154 (posn-timestamp (event-end event)))) | |
155 | |
156 (defun event-to-character (event &optional lenient) | |
157 "Returns the closest ASCII approximation to the given event object. | |
158 If the event isn't a keypress, this returns nil. | |
159 If the second argument is non-nil, then this is lenient in its | |
160 translation; it will ignore modifier keys other than control and meta, | |
161 and will ignore the shift modifier on those characters which have no | |
162 shifted ASCII equivalent (Control-Shift-A for example, will be mapped to | |
163 the same ASCII code as Control-A.) If the second arg is nil, then nil | |
164 will be returned for events which have no direct ASCII equivalent." | |
165 (if (symbolp event) | |
166 (and lenient | |
167 (cdr (assq event '((backspace . 8) (delete . 127) (tab . 9) | |
168 (return . 10) (enter . 10))))) | |
169 ;; Our interpretation is, ASCII means anything a number can represent. | |
170 (if (integerp event) | |
171 event nil))) | |
172 | |
173 (defun event-window (event) | |
174 "Returns the window of the given mouse-related event object." | |
175 (posn-window (event-end event))) | |
176 | |
177 (defun event-x (event) | |
178 "Returns the X position in characters of the given mouse-related event." | |
179 (/ (car (posn-col-row (event-end event))) | |
2066 | 180 (frame-char-width (window-frame (event-window event))))) |
2034 | 181 |
182 (defun event-x-pixel (event) | |
183 "Returns the X position in pixels of the given mouse-related event." | |
184 (car (posn-col-row (event-end event)))) | |
185 | |
186 (defun event-y (event) | |
187 "Returns the Y position in characters of the given mouse-related event." | |
188 (/ (cdr (posn-col-row (event-end event))) | |
2066 | 189 (frame-char-height (window-frame (event-window event))))) |
2034 | 190 |
191 (defun event-y-pixel (event) | |
192 "Returns the Y position in pixels of the given mouse-related event." | |
193 (cdr (posn-col-row (event-end event)))) | |
194 | |
195 (defun key-press-event-p (obj) | |
196 "True if the argument is a keyboard event object." | |
197 (or (integerp obj) | |
198 (and (symbolp obj) | |
199 (get obj 'event-symbol-elements)))) | |
200 | |
201 (defun menu-event-p (obj) | |
202 "True if the argument is a menu event object." | |
203 (eq (car-safe obj) 'menu)) | |
204 | |
205 (defun motion-event-p (obj) | |
206 "True if the argument is a mouse-motion event object." | |
207 (eq (car-safe obj) 'mouse-movement)) | |
208 | |
2057
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
209 (defun read-command-event () |
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
210 "Return the next keyboard or mouse event; execute other events. |
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
211 This is similar to the function `next-command-event' of Lucid Emacs, |
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
212 but different in that it returns the event rather than filling in |
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
213 an existing event object." |
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
214 (let (event) |
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
215 (while (progn |
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
216 (setq event (read-event)) |
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
217 (not (or (key-press-event-p event) |
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
218 (button-press-event-p event) |
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
219 (button-release-event-p event) |
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
220 (menu-event-p event)))) |
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
221 (let ((type (car-safe event))) |
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
222 (cond ((eq type 'eval) |
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
223 (funcall (nth 1 event) (nth 2 event))) |
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
224 ((eq type 'switch-frame) |
2957
ec432bd5d5b9
(event-modifiers): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents:
2232
diff
changeset
|
225 (select-frame (nth 1 event)))))) |
2057
265b81ff7eee
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
2039
diff
changeset
|
226 event)) |
2034 | 227 |
228 (defun process-event-p (obj) | |
229 "True if the argument is a process-output event object. | |
230 GNU Emacs 19 does not currently generate process-output events." | |
231 (eq (car-safe obj) 'process)) | |
232 | |
233 ;;; levents.el ends here |