Blob


1 .TH ACMEEVENT 1
2 .SH NAME
3 acmeevent, acme.rc \- shell script support for acme clients
4 .SH SYNOPSIS
5 .B 9p
6 .B read
7 .B acme/acme/$winid/event | acmeevent
8 .PP
9 .B
10 \&. /usr/local/plan9/lib/acme.rc
11 .PP
12 .B newwindow
13 .PP
14 .B winread
15 .I file
16 .PP
17 .B winwrite
18 .I file
19 .PP
20 .B winctl
21 .I cmd
22 .PP
23 .B windump
24 [
25 .I dumpdir
26 |
27 .B -
28 ]
29 [
30 .I dumpcmd
31 |
32 .B -
33 ]
34 .PP
35 .B winname
36 .I name
37 .PP
38 .B windel
39 [
40 .B sure
41 ]
42 .PP
43 .B winwriteevent
44 .I c1
45 .I c2
46 .I q0
47 .I q1
48 [
49 .I eq0
50 .I eq1
51 .I flag
52 .I textlen
53 .I text
54 .I chordarg
55 .I chordaddr
56 ]
57 .PP
58 .B wineventloop
59 .SH DESCRIPTION
60 .I Acmeevent
61 and
62 .I acme.rc
63 make it easy to write simple
64 .IR acme (1)
65 client programs as shell scripts.
66 .PP
67 .I Acme
68 clients read the
69 .B event
70 files
71 (see
72 .IR acme (4))
73 for the windows they control, reacting to the events.
74 The events are presented in a format that is easy to read with C programs
75 but hard to read with shell scripts.
76 .PP
77 .I Acmeevent
78 reads an
79 .IR acme (4)
80 event stream from standard input, printing a shell-friendly
81 version of the events, one per line, on standard output.
82 Each output line from
83 .I acmeevent
84 has the form:
85 .IP
86 .B event
87 .I c1
88 .I c2
89 .I q0
90 .I q1
91 .I eq0
92 .I eq1
93 .I flag
94 .I textlen
95 .I text
96 .I chordarg
97 .I chordaddr
98 .PP
99 The fields are:
100 .TP
101 .I c1
102 A character indicating the origin or cause of the action.
103 The possible causes are:
104 a write to the body or tag file
105 .RB ( E ),
106 a write to the window's other files
107 .RB ( F ),
108 input via the keyboard
109 .RB ( K ),
110 and
111 input via the mouse
112 .RB ( M ).
113 .TP
114 .I c2
115 A character indicating the type of action.
116 The possible types are:
117 text deleted from the body
118 .RB ( D ),
119 text deleted from the tag
120 .RB ( d ),
121 text inserted in the body
122 .RB ( I ),
123 text inserted in the tag
124 .RB ( i ),
125 a button 3 action in the body
126 .RB ( L ),
127 a button 3 action in the tag
128 .RB ( l ),
129 a button 2 action in the body
130 .RB ( X ),
131 and
132 a button 2 action in the tag
133 .RB ( x ).
134 .TP
135 .I q0
137 .TP
138 .I q1
140 .TP
141 .I eq0
143 .TP
144 .I eq1
146 .TP
147 .I flag
149 .TP
150 .I textlen
152 .TP
153 .I text
155 .TP
156 .I chordarg
158 .TP
159 .I chordorigin
161 .PP
162 .I Acme.rc
163 is a library of
164 .IR rc (1)
165 shell functions useful for writing acme clients.
166 .PP
167 .I Newwindow
168 creates a new acme window and sets
169 .B $winid
170 to the new window's id.
171 The other commands all use
172 .B $winid
173 to determine which window to operate on.
174 .PP
175 .I Winread
176 prints the current window's
177 .I file
178 to standard output.
179 It is equivalent to
180 .B cat
181 .BI /mnt/acme/acme/$winid/ file
182 on Plan 9.
183 Similarly,
184 .I winwrite
185 writes standard input to the current window's
186 .IR file .
187 .I Winread
188 and
189 .I winwrite
190 are useful mainly in building more complex functions.
191 .PP
192 .I Winctl
193 writes
194 .I cmd
195 to the window's
196 .B ctl
197 file.
198 The most commonly-used command is
199 .BR clean ,
200 which marks the window as clean.
201 See
202 .IR acme (4)
203 for a full list of commands.
204 .PP
205 .I Windump
206 sets the window's dump directory
207 and dump command
208 (see
209 .IR acme (4)).
210 If either argument is omitted or is
211 .BR - ,
212 that argument is not set.
213 .PP
214 .I Winname
215 sets the name displayed in the window's tag.
216 .PP
217 .I Windel
218 simulates the
219 .B Del
220 command. If the argument
221 .B sure
222 is given, it simulates the
223 .B Delete
224 command.
225 .PP
226 .I Winwriteevent
227 writes an event to the window's event file.
228 The event is in the format produced by
229 .IR acmeevent .
230 Only the first four arguments are necessary:
231 the rest are ignored.
232 Event handlers should call
233 .I winwriteevent
234 to pass unhandled button 2 or button 3 events
235 back to
236 .I acme
237 for processing.
238 .PP
239 .I Wineventloop
240 executes the current window's event file, as output by
241 .IR acmeevent .
242 It returns when the window has been deleted.
243 Before running
244 .I wineventloop ,
245 clients must define a shell function named
246 .BR event ,
247 which will be run for each incoming event,
248 as
249 .I rc
250 executes the output of
251 .IR acmeevent .
252 A typical event function need only worry about button 2 and button 3 events.
253 Those events not handled should be sent back to
254 .I acme
255 with
256 .IR winwriteevent .
257 .SH EXAMPLE
258 .IR Adict ,
259 a dictionary browser,
260 is implemented using
261 .I acmeevent
262 and
263 .IR acme.rc .
264 The
265 .I event
266 handler is:
267 .IP
268 .EX
269 .ta +4n +4n +4n +4n +4n +4n
270 fn event {
271 switch($1$2){
272 case Mx MX # button 2 - pass back to acme
273 winwriteevent $*
274 case Ml ML # button 3 - open new window on dictionary or entry
276 if(~ $dict NONE)
277 dictwin /adict/$7/ $7
278 if not
279 dictwin /adict/$dict/$7 $dict $7
280 } &
283 .EE
284 .LP
285 Note that the button 3 handler starts a subshell in which to run
286 .IR dictwin .
287 That subshell will create a new window, set its name,
288 possibly fill the window with a dictionary list or dictionary entry,
289 mark the window as clean, and run the event loop:
290 .IP
291 .EX
292 fn dictwin {
293 newwindow
294 winname $1
295 dict=$2
296 if(~ $dict NONE)
297 dict -d '?' >[2=1] | sed 1d | winwrite body
298 if(~ $#* 3)
299 dict -d $dict $3 >[2=1] | winwrite body
300 winctl clean
301 wineventloop
303 .EE
304 .LP
305 The script starts with an initial window:
306 .IP
307 .EX
308 dictwin /adict/ NONE
309 .EE
310 .LP
311 Button 3 clicking on a dictionary name in the initial window
312 will create a new empty window for that dictionary.
313 Typing and button 3 clicking on a word in that window
314 will create a new window with the dictionary's entry for that word.
315 .PP
316 See
317 .B /usr/local/plan9/bin/adict
318 for the full implementation.
319 .SH SOURCE
320 .B /usr/local/plan9/src/cmd/acmeevent.c
321 .br
322 .B /usr/local/plan9/lib/acme.rc
323 .SH SEE ALSO
324 .IR acme (1),
325 .IR acme (4),
326 .IR rc (1)
327 .SH BUGS
328 There is more that could be done to ease the writing
329 of complicated clients.