Commit | Line | Data |
---|---|---|
f9a8037d C |
1 | |
2 | ||
3 | ||
4 | ||
5 | ||
6 | ||
7 | ||
8 | CHAPTER 16 | |
9 | ||
10 | ||
11 | The LISP Editor | |
12 | ||
13 | ||
14 | ||
15 | ||
16 | ||
17 | ||
18 | ||
19 | 16.1. The Editors | |
20 | ||
21 | It is quite possible to use VI, Emacs or other stan- | |
22 | dard editors to edit your lisp programs, and many peo- | |
23 | ple do just that. However there is a lisp structure | |
24 | editor which is particularly good for the editing of | |
25 | lisp programs, and operates in a rather different | |
26 | fashion, namely within a lisp environment. applica- | |
27 | tion. It is handy to know how to use it for fixing | |
28 | problems without exiting from the lisp system (e.g. | |
29 | from the debugger so you can continue to execute | |
30 | rather than having to start over.) The editor is not | |
31 | quite like the top-level and debugger, in that it | |
32 | expects you to type editor commands to it. It will | |
33 | not evaluate whatever you happen to type. (There is | |
34 | an editor command to evaluate things, though.) | |
35 | ||
36 | The editor is available (assuming your system is set | |
37 | up correctly with a lisp library) by typing (load | |
38 | 'cmufncs) and (load 'cmuedit). | |
39 | ||
40 | The most frequent use of the editor is to change | |
41 | function definitions by starting the editor with one | |
42 | of the commands described in section 16.14. (see | |
43 | _\be_\bd_\bi_\bt_\bf), values (_\be_\bd_\bi_\bt_\bv), properties (_\be_\bd_\bi_\bt_\bp), and | |
44 | expressions (_\be_\bd_\bi_\bt_\be). The beginner is advised to | |
45 | start with the following (very basic) commands: _\bo_\bk, | |
46 | _\bu_\bn_\bd_\bo, _\bp, #, under which are explained two different | |
47 | basic commands which start with numbers, and f. | |
48 | ||
49 | This documentation, and the editor, were imported from | |
50 | PDP-10 CMULisp by Don Cohen. PDP-10 CMULisp is based | |
51 | on UCILisp, and the editor itself was derived from an | |
52 | early version of Interlisp. Lars Ericson, the author | |
53 | of this section, has provided this very concise sum- | |
54 | mary. Tutorial examples and implementation details | |
55 | may be found in the Interlisp Reference Manual, where | |
56 | a similar editor is described. | |
57 | ||
58 | ||
59 | ||
60 | \e9 | |
61 | ||
62 | \e9The LISP Editor 16-1 | |
63 | ||
64 | ||
65 | ||
66 | ||
67 | ||
68 | ||
69 | ||
70 | The LISP Editor 16-2 | |
71 | ||
72 | ||
73 | 16.2. Scope of Attention | |
74 | ||
75 | Attention-changing commands allow you to look at a | |
76 | different part of a Lisp expression you are editing. | |
77 | The sub-structure upon which the editor's attention is | |
78 | centered is called "the current expression". Chang- | |
79 | ing the current expression means shifting attention | |
80 | and not actually modifying any structure. | |
81 | ||
82 | ____________________________________________________________ | |
83 | ||
84 | _\bS_\bC_\bO_\bP_\bE _\bO_\bF _\bA_\bT_\bT_\bE_\bN_\bT_\bI_\bO_\bN _\bC_\bO_\bM_\bM_\bA_\bN_\bD _\bS_\bU_\bM_\bM_\bA_\bR_\bY | |
85 | ||
86 | _\bn (_\bn>_\b0) . Makes the nth element of the current expression be | |
87 | the new current expression. | |
88 | ||
89 | -_\bn (_\bn>_\b0). Makes the nth element from the end of the current | |
90 | expression be the new current expression. | |
91 | ||
92 | _\b0. Makes the next higher expression be the new correct | |
93 | expression. If the intention is to go back to the next | |
94 | higher left parenthesis, use the command !0. | |
95 | ||
96 | _\bu_\bp . If a p command would cause the editor to type ... | |
97 | before typing the current expression, (the current expres- | |
98 | sion is a tail of the next higher expression) then has no | |
99 | effect; else, up makes the old current expression the first | |
100 | element in the new current expression. | |
101 | ||
102 | !_\b0 . Goes back to the next higher left parenthesis. | |
103 | ||
104 | ^ . Makes the top level expression be the current expres- | |
105 | sion. | |
106 | ||
107 | _\bn_\bx . Makes the current expression be the next expression. | |
108 | ||
109 | (_\bn_\bx _\bn) equivalent to n nx commands. | |
110 | ||
111 | !_\bn_\bx . Makes current expression be the next expression at a | |
112 | higher level. Goes through any number of right parentheses | |
113 | to get to the next expression. | |
114 | ||
115 | _\bb_\bk . Makes the current expression be the previous expres- | |
116 | sion in the next higher expression. | |
117 | ||
118 | (_\bn_\bt_\bh _\bn) _\bn>_\b0 . Makes the list starting with the nth element | |
119 | of the current expression be the current expression. | |
120 | ||
121 | (_\bn_\bt_\bh $) - _\bg_\be_\bn_\be_\br_\ba_\bl_\bi_\bz_\be_\bd _\bn_\bt_\bh _\bc_\bo_\bm_\bm_\ba_\bn_\bd. nth locates $, and then | |
122 | backs up to the current level, where the new current expres- | |
123 | sion is the tail whose first element contains, however dee- | |
124 | ply, the expression that was the terminus of the location | |
125 | operation. | |
126 | ||
127 | ||
128 | Printed: July 21, 1983 | |
129 | ||
130 | ||
131 | ||
132 | ||
133 | ||
134 | ||
135 | ||
136 | The LISP Editor 16-3 | |
137 | ||
138 | ||
139 | :: . (pattern :: . $) e.g., (cond :: return). finds a | |
140 | cond that contains a return, at any depth. | |
141 | ||
142 | (_\bb_\be_\bl_\bo_\bw _\bc_\bo_\bm _\bx) . The below command is useful for locating a | |
143 | substructure by specifying something it contains. (below | |
144 | cond) will cause the cond clause containing the current | |
145 | expression to become the new current expression. Suppose | |
146 | you are editing a list of lists, and want to find a sublist | |
147 | that contains a foo (at any depth). Then simply executes f | |
148 | foo (below ). | |
149 | ||
150 | (_\bn_\be_\bx _\bx) . same as (_\bb_\be_\bl_\bo_\bw _\bx) followed by nx. For example, | |
151 | if you are deep inside of a selectq clause, you can advance | |
152 | to the next clause with (_\bn_\be_\bx _\bs_\be_\bl_\be_\bc_\bt_\bq). | |
153 | ||
154 | _\bn_\be_\bx. The atomic form of _\bn_\be_\bx is useful if you will be | |
155 | performing repeated executions of (_\bn_\be_\bx _\bx). By simply | |
156 | marking the chain corresponding to x, you can use _\bn_\be_\bx to | |
157 | step through the sublists. | |
158 | ____________________________________________________________ | |
159 | ||
160 | ||
161 | ||
162 | ||
163 | ||
164 | 16.3. Pattern Matching Commands | |
165 | ||
166 | Many editor commands that search take patterns. A | |
167 | pattern _\bp_\ba_\bt matches with x if: | |
168 | ||
169 | ____________________________________________________________ | |
170 | ||
171 | _\bP_\bA_\bT_\bT_\bE_\bR_\bN _\bS_\bP_\bE_\bC_\bI_\bF_\bI_\bC_\bA_\bT_\bI_\bO_\bN _\bS_\bU_\bM_\bM_\bA_\bR_\bY | |
172 | ||
173 | - _\bp_\ba_\bt is _\be_\bq to x. | |
174 | ||
175 | - _\bp_\ba_\bt is &. | |
176 | ||
177 | - _\bp_\ba_\bt is a number and equal to x. | |
178 | ||
179 | - if (car _\bp_\ba_\bt) is the atom *any*, (cdr _\bp_\ba_\bt) is a list of | |
180 | patterns, and _\bp_\ba_\bt matches x if and only if one of the pat- | |
181 | terns on (cdr _\bp_\ba_\bt) matches x. | |
182 | ||
183 | - if _\bp_\ba_\bt is a literal atom or string, and (nthchar _\bp_\ba_\bt -1) | |
184 | is @, then _\bp_\ba_\bt matches with any literal atom or string which | |
185 | has the same initial characters as _\bp_\ba_\bt, e.g. ver@ matches | |
186 | with verylongatom, as well as "verylongstring". | |
187 | ||
188 | - if (car _\bp_\ba_\bt) is the atom --, _\bp_\ba_\bt matches x if (a) (cdr | |
189 | _\bp_\ba_\bt)=nil, i.e. _\bp_\ba_\bt=(--), e.g., (a --) matches (a) (a b c) | |
190 | and (a . b) in other words, -- can match any tail of a | |
191 | list. (b) (cdr _\bp_\ba_\bt) matches with some tail of x, e.g. (a | |
192 | ||
193 | ||
194 | Printed: July 21, 1983 | |
195 | ||
196 | ||
197 | ||
198 | ||
199 | ||
200 | ||
201 | ||
202 | The LISP Editor 16-4 | |
203 | ||
204 | ||
205 | -- (&)) will match with (a b c (d)), but not (a b c d), or | |
206 | (a b c (d) e). however, note that (a -- (&) --) will match | |
207 | with (a b c (d) e). in other words, -- will match any inte- | |
208 | rior segment of a list. | |
209 | ||
210 | - if (car _\bp_\ba_\bt) is the atom ==, _\bp_\ba_\bt matches x if and only if | |
211 | (cdr _\bp_\ba_\bt) is _\be_\bq to x. (this pattern is for use by programs | |
212 | that call the editor as a subroutine, since any non-atomic | |
213 | expression in a command typed in by the user obviously can- | |
214 | not be _\be_\bq to existing structure.) - otherwise if x is a | |
215 | list, _\bp_\ba_\bt matches x if (car _\bp_\ba_\bt) matches (car x), and (cdr | |
216 | _\bp_\ba_\bt) matches (cdr x). | |
217 | ||
218 | - when searching, the pattern matching routine is called | |
219 | only to match with elements in the structure, unless the | |
220 | pattern begins with :::, in which case cdr of the pattern is | |
221 | matched against tails in the structure. (in this case, the | |
222 | tail does not have to be a proper tail, e.g. (::: a --) | |
223 | will match with the element (a b c) as well as with cdr of | |
224 | (x a b c), since (a b c) is a tail of (a b c).) | |
225 | ____________________________________________________________ | |
226 | ||
227 | ||
228 | ||
229 | ||
230 | ||
231 | 16.3.1. Commands That Search | |
232 | ||
233 | ____________________________________________________________ | |
234 | ||
235 | _\bS_\bE_\bA_\bR_\bC_\bH _\bC_\bO_\bM_\bM_\bA_\bN_\bD _\bS_\bU_\bM_\bM_\bA_\bR_\bY | |
236 | ||
237 | _\bf _\bp_\ba_\bt_\bt_\be_\br_\bn . f informs the editor that the next command is | |
238 | to be interpreted as a pattern. If no pattern is given on | |
239 | the same line as the f then the last pattern is used. f | |
240 | pattern means find the next instance of pattern. | |
241 | ||
242 | (_\bf _\bp_\ba_\bt_\bt_\be_\br_\bn _\bn). Finds the next instance of pattern. | |
243 | ||
244 | (_\bf _\bp_\ba_\bt_\bt_\be_\br_\bn _\bt). similar to f pattern, except, for example, | |
245 | if the current expression is (cond ..), f cond will look for | |
246 | the next cond, but (f cond t) will 'stay here'. | |
247 | ||
248 | (_\bf _\bp_\ba_\bt_\bt_\be_\br_\bn _\bn) _\bn>_\b0. Finds the nth place that pattern | |
249 | matches. If the current expression is (foo1 foo2 foo3), (f | |
250 | f00@ 3) will find foo3. | |
251 | ||
252 | (_\bf _\bp_\ba_\bt_\bt_\be_\br_\bn) _\bo_\br (_\bf _\bp_\ba_\bt_\bt_\be_\br_\bn _\bn_\bi_\bl). only matches with elements | |
253 | at the top level of the current expression. If the current | |
254 | expression is (_\bp_\br_\bo_\bg _\bn_\bi_\bl (_\bs_\be_\bt_\bq _\bx (_\bc_\bo_\bn_\bd & &)) (_\bc_\bo_\bn_\bd &) ...) f | |
255 | (cond --) will find the cond inside the setq, whereas (f | |
256 | (cond --)) will find the top level cond, i.e., the second | |
257 | one. | |
258 | ||
259 | ||
260 | Printed: July 21, 1983 | |
261 | ||
262 | ||
263 | ||
264 | ||
265 | ||
266 | ||
267 | ||
268 | The LISP Editor 16-5 | |
269 | ||
270 | ||
271 | (_\bs_\be_\bc_\bo_\bn_\bd . $) . same as (lc . $) followed by another (lc . | |
272 | $) except that if the first succeeds and second fails, no | |
273 | change is made to the edit chain. | |
274 | ||
275 | (_\bt_\bh_\bi_\br_\bd . $) . Similar to second. | |
276 | ||
277 | (_\bf_\bs _\bp_\ba_\bt_\bt_\be_\br_\bn_\b1 ... _\bp_\ba_\bt_\bt_\be_\br_\bn_\bn) . equivalent to f pattern1 fol- | |
278 | lowed by f pattern2 ... followed by f pattern n, so that if | |
279 | f pattern m fails, edit chain is left at place pattern m-1 | |
280 | matched. | |
281 | ||
282 | (_\bf= _\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn _\bx) . Searches for a structure eq to expres- | |
283 | sion. | |
284 | ||
285 | (_\bo_\br_\bf _\bp_\ba_\bt_\bt_\be_\br_\bn_\b1 ... _\bp_\ba_\bt_\bt_\be_\br_\bn_\bn) . Searches for an expression | |
286 | that is matched by either pattern1 or ... patternn. | |
287 | ||
288 | _\bb_\bf _\bp_\ba_\bt_\bt_\be_\br_\bn . backwards find. If the current expression is | |
289 | (_\bp_\br_\bo_\bg _\bn_\bi_\bl (_\bs_\be_\bt_\bq _\bx (_\bs_\be_\bt_\bq _\by (_\bl_\bi_\bs_\bt _\bz))) (_\bc_\bo_\bn_\bd ((_\bs_\be_\bt_\bq _\bw --) --)) | |
290 | --) f list followed by bf setq will leave the current | |
291 | expression as (setq y (list z)), as will f cond followed by | |
292 | bf setq | |
293 | ||
294 | (_\bb_\bf _\bp_\ba_\bt_\bt_\be_\br_\bn _\bt). backwards find. Search always includes | |
295 | current expression, i.e., starts at end of current expres- | |
296 | sion and works backward, then ascends and backs up, etc. | |
297 | ____________________________________________________________ | |
298 | ||
299 | ||
300 | ||
301 | ||
302 | ||
303 | 16.3.1.1. Location Specifications Many editor | |
304 | commands use a method of specifying position | |
305 | called a location specification. The meta- | |
306 | symbol $ is used to denote a location specifica- | |
307 | tion. $ is a list of commands interpreted as | |
308 | described above. $ can also be atomic, in which | |
309 | case it is interpreted as (list $). a location | |
310 | specification is a list of edit commands that | |
311 | are executed in the normal fashion with two | |
312 | exceptions. first, all commands not recognized | |
313 | by the editor are interpreted as though they had | |
314 | been preceded by f. The location specification | |
315 | (cond 2 3) specifies the 3rd element in the | |
316 | first clause of the next cond. | |
317 | ||
318 | the if command and the ## function provide a way | |
319 | of using in location specifications arbitrary | |
320 | predicates applied to elements in the current | |
321 | expression. | |
322 | ||
323 | In insert, delete, replace and change, if $ is | |
324 | ||
325 | ||
326 | Printed: July 21, 1983 | |
327 | ||
328 | ||
329 | ||
330 | ||
331 | ||
332 | ||
333 | ||
334 | The LISP Editor 16-6 | |
335 | ||
336 | ||
337 | nil (empty), the corresponding operation is per- | |
338 | formed on the current edit chain, i.e. (replace | |
339 | with (car x)) is equivalent to (:(car x)). for | |
340 | added readability, here is also permitted, e.g., | |
341 | (insert (print x) before here) will insert | |
342 | (print x) before the current expression (but not | |
343 | change the edit chain). It is perfectly legal | |
344 | to ascend to insert, replace, or delete. for | |
345 | example (insert (_\br_\be_\bt_\bu_\br_\bn) after ^ prog -1) will | |
346 | go to the top, find the first prog, and insert a | |
347 | (_\br_\be_\bt_\bu_\br_\bn) at its end, and not change the current | |
348 | edit chain. | |
349 | ||
350 | The a, b, and : commands all make special | |
351 | checks in e1 thru em for expressions of the form | |
352 | (## . coms). In this case, the expression used | |
353 | for inserting or replacing is a copy of the | |
354 | current expression after executing coms, a list | |
355 | of edit commands. (insert (## f cond -1 -1) | |
356 | after3) will make a copy of the last form in | |
357 | the last clause of the next cond, and insert it | |
358 | after the third element of the current expres- | |
359 | sion. | |
360 | ||
361 | $. In descriptions of the editor, the meta- | |
362 | symbol $ is used to denote a location specifica- | |
363 | tion. $ is a list of commands interpreted as | |
364 | described above. $ can also be atomic. | |
365 | ||
366 | ____________________________________________________________ | |
367 | ||
368 | _\bL_\bO_\bC_\bA_\bT_\bI_\bO_\bN _\bC_\bO_\bM_\bM_\bA_\bN_\bD _\bS_\bU_\bM_\bM_\bA_\bR_\bY | |
369 | ||
370 | (_\bl_\bc . $) . Provides a way of explicitly invoking the loca- | |
371 | tion operation. (lc cond 2 3) will perform search. | |
372 | ||
373 | (_\bl_\bc_\bl . $) . Same as lc except search is confined to current | |
374 | expression. To find a cond containing a _\br_\be_\bt_\bu_\br_\bn, one might | |
375 | use the location specification (cond (lcl _\br_\be_\bt_\bu_\br_\bn) ) where | |
376 | the would reverse the effects of the lcl command, and make | |
377 | the final current expression be the cond. | |
378 | ____________________________________________________________ | |
379 | ||
380 | ||
381 | ||
382 | ||
383 | ||
384 | 16.3.2. The Edit Chain The edit-chain is a list of | |
385 | which the first element is the the one you are now | |
386 | editing ("current expression"), the next element is | |
387 | what would become the current expression if you | |
388 | were to do a 0, etc., until the last element which | |
389 | is the expression that was passed to the editor. | |
390 | ||
391 | ||
392 | Printed: July 21, 1983 | |
393 | ||
394 | ||
395 | ||
396 | ||
397 | ||
398 | ||
399 | ||
400 | The LISP Editor 16-7 | |
401 | ||
402 | ||
403 | ____________________________________________________________ | |
404 | ||
405 | _\bE_\bD_\bI_\bT _\bC_\bH_\bA_\bI_\bN _\bC_\bO_\bM_\bM_\bA_\bN_\bD _\bS_\bU_\bM_\bM_\bA_\bR_\bY | |
406 | ||
407 | _\bm_\ba_\br_\bk . Adds the current edit chain to the front of the list | |
408 | marklst. | |
409 | ||
410 | _ . Makes the new edit chain be (car marklst). | |
411 | ||
412 | (_ _\bp_\ba_\bt_\bt_\be_\br_\bn) . Ascends the edit chain looking for a link | |
413 | which matches pattern. for example: | |
414 | ||
415 | __ . Similar to _ but also erases the mark. | |
416 | ||
417 | \ . Makes the edit chain be the value of unfind. unfind is | |
418 | set to the current edit chain by each command that makes a | |
419 | "big jump", i.e., a command that usually performs more than | |
420 | a single ascent or descent, namely ^, _, __, !nx, all com- | |
421 | mands that involve a search, e.g., f, lc, ::, below, et al | |
422 | and and themselves. | |
423 | if the user types f cond, and then f car, would take him | |
424 | back to the cond. another would take him back to the car, | |
425 | etc. | |
426 | ||
427 | \_\bp . Restores the edit chain to its state as of the last | |
428 | print operation. If the edit chain has not changed since | |
429 | the last printing, \p restores it to its state as of the | |
430 | printing before that one. If the user types p followed by 3 | |
431 | 2 1 p, \p will return to the first p, i.e., would be | |
432 | equivalent to 0 0 0. Another \p would then take him back to | |
433 | the second p. | |
434 | ____________________________________________________________ | |
435 | ||
436 | ||
437 | ||
438 | ||
439 | ||
440 | 16.4. Printing Commands | |
441 | ||
442 | ____________________________________________________________ | |
443 | ||
444 | _\bP_\bR_\bI_\bN_\bT_\bI_\bN_\bG _\bC_\bO_\bM_\bM_\bA_\bN_\bD _\bS_\bU_\bM_\bM_\bA_\bR_\bY | |
445 | ||
446 | _\bp Prints current expression in abbreviated form. (p m) | |
447 | prints mth element of current expression in abbreviated | |
448 | form. (p m n) prints mth element of current expression as | |
449 | though printlev were given a depth of n. (p 0 n) prints | |
450 | current expression as though printlev were given a depth of | |
451 | n. (p cond 3) will work. | |
452 | ||
453 | ? . prints the current expression as though printlev were | |
454 | given a depth of 100. | |
455 | \e9 | |
456 | ||
457 | \e9 Printed: July 21, 1983 | |
458 | ||
459 | ||
460 | ||
461 | ||
462 | ||
463 | ||
464 | ||
465 | The LISP Editor 16-8 | |
466 | ||
467 | ||
468 | _\bp_\bp . pretty-prints the current expression. | |
469 | ||
470 | _\bp_\bp*. is like pp, but forces comments to be shown. | |
471 | ____________________________________________________________ | |
472 | ||
473 | ||
474 | ||
475 | ||
476 | ||
477 | 16.5. Structure Modification Commands | |
478 | ||
479 | All structure modification commands are undoable. See | |
480 | _\bu_\bn_\bd_\bo. | |
481 | ||
482 | ||
483 | ____________________________________________________________ | |
484 | ||
485 | _\bS_\bT_\bR_\bU_\bC_\bT_\bU_\bR_\bE _\bM_\bO_\bD_\bI_\bF_\bI_\bC_\bA_\bT_\bI_\bO_\bN _\bC_\bO_\bM_\bM_\bA_\bN_\bD _\bS_\bU_\bM_\bM_\bA_\bR_\bY | |
486 | ||
487 | # [_\be_\bd_\bi_\bt_\bo_\br _\bc_\bo_\bm_\bm_\ba_\bn_\bd_\bs] (n) n>1 deletes the corresponding ele- | |
488 | ment from the current expression. | |
489 | ||
490 | (_\bn _\be_\b1 ... _\be_\bm) _\bn,_\bm>_\b1 replaces the nth element in the current | |
491 | expression with e1 ... em. | |
492 | ||
493 | (-_\bn _\be_\b1 ... _\be_\bm) _\bn,_\bm>_\b1 inserts e1 ... em before the n ele- | |
494 | ment in the current expression. | |
495 | ||
496 | (_\bn _\be_\b1 ... _\be_\bm) (the letter "n" for "next" or "nconc", not a | |
497 | number) m>1 attaches e1 ... em at the end of the current | |
498 | expression. | |
499 | ||
500 | (_\ba _\be_\b1 ... _\be_\bm) . inserts e1 ... em after the current | |
501 | expression (or after its first element if it is a tail). | |
502 | ||
503 | (_\bb _\be_\b1 ... _\be_\bm) . inserts e1 ... em before the current | |
504 | expression. to insert foo before the last element in the | |
505 | current expression, perform -1 and then (b foo). | |
506 | ||
507 | (: _\be_\b1 ... _\be_\bm) . replaces the current expression by e1 ... | |
508 | em. If the current expression is a tail then replace its | |
509 | first element. | |
510 | ||
511 | _\bd_\be_\bl_\be_\bt_\be _\bo_\br (:) . deletes the current expression, or if the | |
512 | current expression is a tail, deletes its first element. | |
513 | ||
514 | (_\bd_\be_\bl_\be_\bt_\be . $). does a (lc . $) followed by delete. current | |
515 | edit chain is not changed. | |
516 | ||
517 | (_\bi_\bn_\bs_\be_\br_\bt _\be_\b1 ... _\be_\bm _\bb_\be_\bf_\bo_\br_\be . $) . similar to (lc. $) fol- | |
518 | lowed by (b e1 ... em). | |
519 | ||
520 | (_\bi_\bn_\bs_\be_\br_\bt _\be_\b1 ... _\be_\bm _\ba_\bf_\bt_\be_\br . $). similar to insert before | |
521 | ||
522 | ||
523 | Printed: July 21, 1983 | |
524 | ||
525 | ||
526 | ||
527 | ||
528 | ||
529 | ||
530 | ||
531 | The LISP Editor 16-9 | |
532 | ||
533 | ||
534 | except uses a instead of b. | |
535 | ||
536 | (_\bi_\bn_\bs_\be_\br_\bt _\be_\b1 ... _\be_\bm _\bf_\bo_\br . $). similar to insert before | |
537 | except uses : for b. | |
538 | ||
539 | (_\br_\be_\bp_\bl_\ba_\bc_\be $ _\bw_\bi_\bt_\bh _\be_\b1 ... _\be_\bm) . here $ is the segment of the | |
540 | command between replace and with. | |
541 | ||
542 | (_\bc_\bh_\ba_\bn_\bg_\be $ _\bt_\bo _\be_\b1 ... _\be_\bm) . same as replace with. | |
543 | ____________________________________________________________ | |
544 | ||
545 | ||
546 | ||
547 | ||
548 | ||
549 | 16.6. Extraction and Embedding Commands | |
550 | ||
551 | ____________________________________________________________ | |
552 | ||
553 | _\bE_\bX_\bT_\bR_\bA_\bC_\bT_\bI_\bO_\bN _\bA_\bN_\bD _\bE_\bM_\bB_\bE_\bD_\bD_\bI_\bN_\bG _\bC_\bO_\bM_\bM_\bA_\bN_\bD _\bS_\bU_\bM_\bM_\bA_\bR_\bY | |
554 | ||
555 | (_\bx_\bt_\br . $) . replaces the original current expression with | |
556 | the expression that is current after performing (lcl . $). | |
557 | ||
558 | (_\bm_\bb_\bd _\bx) . x is a list, substitutes the current expression | |
559 | for all instances of the atom * in x, and replaces the | |
560 | current expression with the result of that substitution. | |
561 | (mbd x) : x atomic, same as (mbd (x *)). | |
562 | ||
563 | (_\be_\bx_\bt_\br_\ba_\bc_\bt $_\b1 _\bf_\br_\bo_\bm $_\b2) . extract is an editor command which | |
564 | replaces the current expression with one of its subexpres- | |
565 | sions (from any depth). ($1 is the segment between extract | |
566 | and from.) example: if the current expression is (print | |
567 | (cond ((null x) y) (t z))) then following (extract y from | |
568 | cond), the current expression will be (print y). (extract 2 | |
569 | -1 from cond), (extract y from 2), (extract 2 -1 from 2) | |
570 | will all produce the same result. | |
571 | ||
572 | (_\be_\bm_\bb_\be_\bd $ _\bi_\bn . _\bx) . embed replaces the current expression | |
573 | with a new expression which contains it as a subexpression. | |
574 | ($ is the segment between embed and in.) example: (embed | |
575 | print in setq x), (embed 3 2 in _\br_\be_\bt_\bu_\br_\bn), (embed cond 3 1 in | |
576 | (or * (null x))). | |
577 | ____________________________________________________________ | |
578 | ||
579 | ||
580 | ||
581 | ||
582 | ||
583 | 16.7. Move and Copy Commands | |
584 | ||
585 | ||
586 | \e9 | |
587 | ||
588 | \e9 Printed: July 21, 1983 | |
589 | ||
590 | ||
591 | ||
592 | ||
593 | ||
594 | ||
595 | ||
596 | The LISP Editor 16-10 | |
597 | ||
598 | ||
599 | ____________________________________________________________ | |
600 | ||
601 | _\bM_\bO_\bV_\bE _\bA_\bN_\bD _\bC_\bO_\bP_\bY _\bC_\bO_\bM_\bM_\bA_\bN_\bD _\bS_\bU_\bM_\bM_\bA_\bR_\bY | |
602 | ||
603 | (_\bm_\bo_\bv_\be $_\b1 _\bt_\bo _\bc_\bo_\bm . $_\b2) . ($1 is the segment between move and | |
604 | to.) where com is before, after, or the name of a list com- | |
605 | mand, e.g., :, n, etc. If $2 is nil, or (here), the current | |
606 | position specifies where the operation is to take place. If | |
607 | $1 is nil, the move command allows the user to specify some | |
608 | place the current expression is to be moved to. if the | |
609 | current expression is (a b d c), (move 2 to after 4) will | |
610 | make the new current expression be (a c d b). | |
611 | ||
612 | (_\bm_\bv _\bc_\bo_\bm . $) . is the same as (move here to com . $). | |
613 | ||
614 | (_\bc_\bo_\bp_\by $_\b1 _\bt_\bo _\bc_\bo_\bm . $_\b2) is like move except that the source | |
615 | expression is not deleted. | |
616 | ||
617 | (_\bc_\bp _\bc_\bo_\bm . $). is like mv except that the source expression | |
618 | is not deleted. | |
619 | ____________________________________________________________ | |
620 | ||
621 | ||
622 | ||
623 | ||
624 | ||
625 | 16.8. Parentheses Moving Commands The commands | |
626 | presented in this section permit modification of the | |
627 | list structure itself, as opposed to modifying com- | |
628 | ponents thereof. their effect can be described as | |
629 | inserting or removing a single left or right | |
630 | parenthesis, or pair of left and right parentheses. | |
631 | ||
632 | ____________________________________________________________ | |
633 | ||
634 | _\bP_\bA_\bR_\bE_\bN_\bT_\bH_\bE_\bS_\bE_\bS _\bM_\bO_\bV_\bI_\bN_\bG _\bC_\bO_\bM_\bM_\bA_\bN_\bD _\bS_\bU_\bM_\bM_\bA_\bR_\bY | |
635 | ||
636 | (_\bb_\bi _\bn _\bm) . both in. inserts parentheses before the nth | |
637 | element and after the mth element in the current expression. | |
638 | example: if the current expression is (a b (c d e) f g), | |
639 | then (bi 2 4) will modify it to be (a (b (c d e) f) g). (bi | |
640 | n) : same as (bi n n). example: if the current expression | |
641 | is (a b (c d e) f g), then (bi -2) will modify it to be (a b | |
642 | (c d e) (f) g). | |
643 | ||
644 | (_\bb_\bo _\bn) . both out. removes both parentheses from the nth | |
645 | element. example: if the current expression is (a b (c d | |
646 | e) f g), then (bo d) will modify it to be (a b c d e f g). | |
647 | ||
648 | (_\bl_\bi _\bn) . left in. inserts a left parenthesis before the | |
649 | nth element (and a matching right parenthesis at the end of | |
650 | the current expression). example: if the current expres- | |
651 | sion is (a b (c d e) f g), then (li 2) will modify it to be | |
652 | ||
653 | ||
654 | Printed: July 21, 1983 | |
655 | ||
656 | ||
657 | ||
658 | ||
659 | ||
660 | ||
661 | ||
662 | The LISP Editor 16-11 | |
663 | ||
664 | ||
665 | (a (b (c d e) f g)). | |
666 | ||
667 | (_\bl_\bo _\bn) . left out. removes a left parenthesis from the | |
668 | nth element. all elements following the nth element are | |
669 | deleted. example: if the current expression is (a b (c d e) | |
670 | f g), then (lo 3) will modify it to be (a b c d e). | |
671 | ||
672 | (_\br_\bi _\bn _\bm) . right in. move the right parenthesis at the | |
673 | end of the nth element in to after the mth element. inserts | |
674 | a right parenthesis after the mth element of the nth ele- | |
675 | ment. The rest of the nth element is brought up to the | |
676 | level of the current expression. example: if the current | |
677 | expression is (a (b c d e) f g), (ri 2 2) will modify it to | |
678 | be (a (b c) d e f g). | |
679 | ||
680 | (_\br_\bo _\bn) . right out. move the right parenthesis at the end | |
681 | of the nth element out to the end of the current expres- | |
682 | sion. removes the right parenthesis from the nth element, | |
683 | moving it to the end of the current expression. all elements | |
684 | following the nth element are moved inside of the nth | |
685 | element. example: if the current expression is (a b (c d e) | |
686 | f g), (ro 3) will modify it to be (a b (c d e f g)). | |
687 | ||
688 | (_\br _\bx _\by) replaces all instances of x by y in the current | |
689 | expression, e.g., (r caadr cadar). x can be the s- | |
690 | expression (or atom) to be substituted for, or can be a pat- | |
691 | tern which specifies that s-expression (or atom). | |
692 | ||
693 | (_\bs_\bw _\bn _\bm) switches the nth and mth elements of the current | |
694 | expression. for example, if the current expression is (list | |
695 | (cons (car x) (car y)) (cons (cdr y))), (sw 2 3) will | |
696 | modify it to be (list (cons (cdr x) (cdr y)) (cons (car x) | |
697 | (car y))). (sw car cdr) would produce the same result. | |
698 | ____________________________________________________________ | |
699 | ||
700 | ||
701 | ||
702 | ||
703 | ||
704 | 16.8.1. Using to and thru | |
705 | ||
706 | to, thru, extract, embed, delete, replace, and move | |
707 | can be made to operate on several contiguous ele- | |
708 | ments, i.e., a segment of a list, by using the to | |
709 | or thru command in their respective location | |
710 | specifications. thru and to are intended to be | |
711 | used in conjunction with extract, embed, delete, | |
712 | replace, and move. to and thru can also be used | |
713 | directly with xtr (which takes after a location | |
714 | specification), as in (xtr (2 thru 4)) (from the | |
715 | current expression). | |
716 | ||
717 | \e9 | |
718 | ||
719 | \e9 Printed: July 21, 1983 | |
720 | ||
721 | ||
722 | ||
723 | ||
724 | ||
725 | ||
726 | ||
727 | The LISP Editor 16-12 | |
728 | ||
729 | ||
730 | ____________________________________________________________ | |
731 | ||
732 | _\bT_\bO _\bA_\bN_\bD _\bT_\bH_\bR_\bU _\bC_\bO_\bM_\bM_\bA_\bN_\bD _\bS_\bU_\bM_\bM_\bA_\bR_\bY | |
733 | ||
734 | ($_\b1 _\bt_\bo $_\b2) . same as thru except last element not | |
735 | included. | |
736 | ||
737 | ($_\b1 _\bt_\bo). same as ($1 thru -1) | |
738 | ||
739 | ($_\b1 _\bt_\bh_\br_\bu $_\b2) . If the current expression is (a (b (c d) | |
740 | (e) (f g h) i) j k), following (c thru g), the current | |
741 | expression will be ((c d) (e) (f g h)). If both $1 and $2 | |
742 | are numbers, and $2 is greater than $1, then $2 counts from | |
743 | the beginning of the current expression, the same as $1. in | |
744 | other words, if the current expression is (a b c d e f g), | |
745 | (3 thru 4) means (c thru d), not (c thru f). in this case, | |
746 | the corresponding bi command is (bi 1 $2-$1+1). | |
747 | ||
748 | ($_\b1 _\bt_\bh_\br_\bu). same as ($_\b1 _\bt_\bh_\br_\bu -_\b1). | |
749 | ____________________________________________________________ | |
750 | ||
751 | ||
752 | ||
753 | ||
754 | ||
755 | 16.9. Undoing Commands each command that causes struc- | |
756 | ture modification automatically adds an entry to the | |
757 | front of undolst containing the information required | |
758 | to restore all pointers that were changed by the com- | |
759 | mand. The undo command undoes the last, i.e., most | |
760 | recent such command. | |
761 | ||
762 | ____________________________________________________________ | |
763 | ||
764 | _\bU_\bN_\bD_\bO _\bC_\bO_\bM_\bM_\bA_\bN_\bD _\bS_\bU_\bM_\bM_\bA_\bR_\bY | |
765 | ||
766 | _\bu_\bn_\bd_\bo . the undo command undoes most recent, structure | |
767 | modification command that has not yet been undone, and | |
768 | prints the name of that command, e.g., mbd undone. The edit | |
769 | chain is then exactly what it was before the 'undone' com- | |
770 | mand had been performed. | |
771 | ||
772 | !_\bu_\bn_\bd_\bo . undoes all modifications performed during this | |
773 | editing session, i.e., this call to the editor. | |
774 | ||
775 | _\bu_\bn_\bb_\bl_\bo_\bc_\bk . removes an undo-block. If executed at a non- | |
776 | blocked state, i.e., if undo or !undo could operate, types | |
777 | not blocked. | |
778 | ||
779 | _\bt_\be_\bs_\bt . adds an undo-block at the front of undolst. note | |
780 | that test together with !undo provide a 'tentative' | |
781 | mode for editing, i.e., the user can perform a number of | |
782 | changes, and then undo all of them with a single !undo | |
783 | ||
784 | ||
785 | Printed: July 21, 1983 | |
786 | ||
787 | ||
788 | ||
789 | ||
790 | ||
791 | ||
792 | ||
793 | The LISP Editor 16-13 | |
794 | ||
795 | ||
796 | command. | |
797 | ||
798 | _\bu_\bn_\bd_\bo_\bl_\bs_\bt [_\bv_\ba_\bl_\bu_\be]. each editor command that causes structure | |
799 | modification automatically adds an entry to the front of | |
800 | undolst containing the information required to restore all | |
801 | pointers that were changed by the command. | |
802 | ||
803 | ?? prints the entries on undolst. The entries are listed | |
804 | most recent entry first. | |
805 | ____________________________________________________________ | |
806 | ||
807 | ||
808 | ||
809 | ||
810 | ||
811 | 16.10. Commands that Evaluate | |
812 | ||
813 | ____________________________________________________________ | |
814 | ||
815 | _\bE_\bV_\bA_\bL_\bU_\bA_\bT_\bI_\bO_\bN _\bC_\bO_\bM_\bM_\bA_\bN_\bD _\bS_\bU_\bM_\bM_\bA_\bR_\bY | |
816 | ||
817 | _\be . only when typed in, (i.e., (insert d before e) will | |
818 | treat e as a pattern) causes the editor to call the | |
819 | lisp interpreter giving it the next input as argument. | |
820 | ||
821 | (_\be _\bx) evaluates x, and prints the result. (e x t) same | |
822 | as (e x) but does not print. | |
823 | ||
824 | (_\bi _\bc _\bx_\b1 ... _\bx_\bn) same as (c y1 ... yn) where yi=(eval xi). | |
825 | example: (i 3 (cdr foo)) will replace the 3rd element of | |
826 | the current expression with the cdr of the value of foo. (i | |
827 | n foo (car fie)) will attach the value of foo and car of the | |
828 | value of fie to the end of the current expression. (i f= | |
829 | foo t) will search for an expression eq to the value of foo. | |
830 | If c is not an atom, it is evaluated as well. | |
831 | ||
832 | (_\bc_\bo_\bm_\bs _\bx_\b1 ... _\bx_\bn) . each xi is evaluated and its value | |
833 | executed as a command. The i command is not very convenient | |
834 | for computing an entire edit command for execution, since | |
835 | it computes the command name and its arguments separately. | |
836 | also, the i command cannot be used to compute an atomic | |
837 | command. The coms and comsq commands provide more gen- | |
838 | eral ways of computing commands. (coms (cond (x (list 1 | |
839 | x)))) will replace the first element of the current expres- | |
840 | sion with the value of x if non-nil, otherwise do nothing. | |
841 | (nil as a command is a nop.) | |
842 | ||
843 | (_\bc_\bo_\bm_\bs_\bq _\bc_\bo_\bm_\b1 ... _\bc_\bo_\bm_\bn) . executes com1 ... comn. comsq is | |
844 | mainly useful in conjunction with the coms command. for | |
845 | example, suppose the user wishes to compute an entire list | |
846 | of commands for evaluation, as opposed to computing each | |
847 | command one at a time as does the coms command. he would | |
848 | then write (coms (cons (quote comsq) x)) where x computed | |
849 | ||
850 | ||
851 | Printed: July 21, 1983 | |
852 | ||
853 | ||
854 | ||
855 | ||
856 | ||
857 | ||
858 | ||
859 | The LISP Editor 16-14 | |
860 | ||
861 | ||
862 | the list of commands, e.g., (coms (cons (quote comsq) | |
863 | (get foo (quote commands)))) | |
864 | ____________________________________________________________ | |
865 | ||
866 | ||
867 | ||
868 | ||
869 | ||
870 | 16.11. Commands that Test | |
871 | ||
872 | ____________________________________________________________ | |
873 | ||
874 | _\bT_\bE_\bS_\bT_\bI_\bN_\bG _\bC_\bO_\bM_\bM_\bA_\bN_\bD _\bS_\bU_\bM_\bM_\bA_\bR_\bY | |
875 | ||
876 | (_\bi_\bf _\bx) generates an error unless the value of (eval x) is | |
877 | non-nil, i.e., if (eval x) causes an error or (eval x)=nil, | |
878 | if will cause an error. (if x coms1 coms2) if (eval x) is | |
879 | non-nil, execute coms1; if (eval x) causes an error or is | |
880 | equal to nil, execute coms2. (if x coms1) if (eval x) | |
881 | is non-nil, execute coms1; otherwise generate an error. | |
882 | ||
883 | (_\bl_\bp . _\bc_\bo_\bm_\bs) . repeatedly executes coms, a list of commands, | |
884 | until an error occurs. (lp f print (n t)) will | |
885 | attach a t at the end of every print expression. (lp f | |
886 | print (if (## 3) nil ((n t)))) will attach a t at the end | |
887 | of each print expression which does not already have a | |
888 | second argument. (i.e. the form (## 3) will cause an | |
889 | error if the edit command 3 causes an error, thereby select- | |
890 | ing ((n t)) as the list of commands to be executed. The if | |
891 | could also be written as (if (cddr (##)) nil ((n t))).). | |
892 | ||
893 | (_\bl_\bp_\bq . _\bc_\bo_\bm_\bs) same as lp but does not print n occurrences. | |
894 | ||
895 | (_\bo_\br_\br _\bc_\bo_\bm_\bs_\b1 ... _\bc_\bo_\bm_\bs_\bn) . orr begins by executing coms1, a | |
896 | list of commands. If no error occurs, orr is finished. | |
897 | otherwise, orr restores the edit chain to its original | |
898 | value, and continues by executing coms2, etc. If none of | |
899 | the command lists execute without errors, i.e., the orr | |
900 | "drops off the end", orr generates an error. otherwise, the | |
901 | edit chain is left as of the completion of the first command | |
902 | list which executes without error. | |
903 | ____________________________________________________________ | |
904 | ||
905 | ||
906 | ||
907 | ||
908 | ||
909 | 16.12. Editor Macros | |
910 | ||
911 | Many of the more sophisticated branching commands in | |
912 | the editor, such as orr, if, etc., are most often | |
913 | used in conjunction with edit macros. The macro | |
914 | feature permits the user to define new commands and | |
915 | ||
916 | ||
917 | Printed: July 21, 1983 | |
918 | ||
919 | ||
920 | ||
921 | ||
922 | ||
923 | ||
924 | ||
925 | The LISP Editor 16-15 | |
926 | ||
927 | ||
928 | thereby expand the editor's repertoire. (however, | |
929 | built in commands always take precedence over mac- | |
930 | ros, i.e., the editor's repertoire can be expanded, | |
931 | but not modified.) macros are defined by using the m | |
932 | command. | |
933 | ||
934 | (_\bm _\bc . _\bc_\bo_\bm_\bs) for c an atom, m defines c as an atomic | |
935 | command. (if a macro is redefined, its new defini- | |
936 | tion replaces its old.) executing c is then the same | |
937 | as executing the list of commands coms. macros | |
938 | can also define list commands, i.e., commands that | |
939 | take arguments. (m (c) (arg[1] ... arg[n]) . coms) c | |
940 | an atom. m defines c as a list command. executing (c | |
941 | e1 ... en) is then performed by substituting e1 | |
942 | for arg[1], ... en for arg[n] throughout coms, | |
943 | and then executing coms. a list command can be | |
944 | defined via a macro so as to take a fixed or | |
945 | indefinite number of 'arguments'. The form given | |
946 | above specified a macro with a fixed number of argu- | |
947 | ments, as indicated by its argument list. if the of | |
948 | arguments. (m (c) args . coms) c, args both atoms, | |
949 | defines c as a list command. executing (c e1 ... | |
950 | en) is performed by substituting (e1 ... en), i.e., | |
951 | cdr of the command, for args throughout coms, and then | |
952 | executing coms. | |
953 | ||
954 | (m bp bk up p) will define bp as an atomic command | |
955 | which does three things, a bk, an up, and a p. note | |
956 | that macros can use commands defined by macros as well | |
957 | as built in commands in their definitions. for | |
958 | example, suppose z is defined by (m z -1 (if (null | |
959 | (##)) nil (p))), i.e. z does a -1, and then if the | |
960 | current expression is not nil, a p. now we can define | |
961 | zz by (m zz -1 z), and zzz by (m zzz -1 -1 z) or (m | |
962 | zzz -1 zz). we could define a more general bp by (m | |
963 | (bp) (n) (bk n) up p). (bp 3) would perform (bk | |
964 | 3), followed by an up, followed by a p. The com- | |
965 | mand second can be defined as a macro by (m (2nd) x | |
966 | (orr ((lc . x) (lc . x)))). | |
967 | ||
968 | Note that for all editor commands, 'built in' com- | |
969 | mands as well as commands defined by macros, atomic | |
970 | definitions and list definitions are completely | |
971 | independent. in other words, the existence of an | |
972 | atomic definition for c in no way affects the treat- | |
973 | ment of c when it appears as car of a list command, | |
974 | and the existence of a list definition for c in no way | |
975 | affects the treatment of c when it appears as an | |
976 | atom. in particular, c can be used as the name of | |
977 | either an atomic command, or a list command, or both. | |
978 | in the latter case, two entirely different defini- | |
979 | tions can be used. note also that once c is | |
980 | defined as an atomic command via a macro definition, | |
981 | ||
982 | ||
983 | Printed: July 21, 1983 | |
984 | ||
985 | ||
986 | ||
987 | ||
988 | ||
989 | ||
990 | ||
991 | The LISP Editor 16-16 | |
992 | ||
993 | ||
994 | it will not be searched for when used in a location | |
995 | specification, unless c is preceded by an f. (insert | |
996 | -- before bp) would not search for bp, but instead | |
997 | perform a bk, an up, and a p, and then do the inser- | |
998 | tion. The corresponding also holds true for list com- | |
999 | mands. | |
1000 | ||
1001 | (_\bb_\bi_\bn_\bd . _\bc_\bo_\bm_\bs) bind is an edit command which is | |
1002 | useful mainly in macros. it binds three dummy vari- | |
1003 | ables #1, #2, #3, (initialized to nil), and then exe- | |
1004 | cutes the edit commands coms. note that these | |
1005 | bindings are only in effect while the commands are | |
1006 | being executed, and that bind can be used recursively; | |
1007 | it will rebind #1, #2, and #3 each time it is | |
1008 | invoked. | |
1009 | ||
1010 | _\bu_\bs_\be_\br_\bm_\ba_\bc_\br_\bo_\bs [_\bv_\ba_\bl_\bu_\be]. this variable contains the | |
1011 | users editing macros . if you want to save your mac- | |
1012 | ros then you should save usermacros. you should | |
1013 | probably also save editcomsl. | |
1014 | ||
1015 | _\be_\bd_\bi_\bt_\bc_\bo_\bm_\bs_\bl [_\bv_\ba_\bl_\bu_\be]. editcomsl is the list of "list | |
1016 | commands" recognized by the editor. (these are the | |
1017 | ones of the form (command arg1 arg2 ...).) | |
1018 | ||
1019 | ||
1020 | ||
1021 | ||
1022 | 16.13. Miscellaneous Editor Commands | |
1023 | ||
1024 | ____________________________________________________________ | |
1025 | ||
1026 | _\bM_\bI_\bS_\bC_\bE_\bL_\bL_\bA_\bN_\bE_\bO_\bU_\bS _\bE_\bD_\bI_\bT_\bO_\bR _\bC_\bO_\bM_\bM_\bA_\bN_\bD _\bS_\bU_\bM_\bM_\bA_\bR_\bY | |
1027 | ||
1028 | _\bo_\bk . Exits from the editor. | |
1029 | ||
1030 | _\bn_\bi_\bl . Unless preceded by f or bf, is always a null opera- | |
1031 | tion. | |
1032 | ||
1033 | _\bt_\bt_\by: . Calls the editor recursively. The user can then | |
1034 | type in commands, and have them executed. The tty: command | |
1035 | is completed when the user exits from the lower editor | |
1036 | (with ok or stop). the tty: command is extremely use- | |
1037 | ful. it enables the user to set up a complex operation, | |
1038 | and perform interactive attention-changing commands part | |
1039 | way through it. for example the command (move 3 to after | |
1040 | cond 3 p tty:) allows the user to interact, in effect, | |
1041 | within the move command. he can verify for himself | |
1042 | that the correct location has been found, or complete the | |
1043 | specification "by hand". in effect, tty: says "I'll tell you | |
1044 | what you should do when you get there." | |
1045 | ||
1046 | _\bs_\bt_\bo_\bp . exits from the editor with an error. mainly for use | |
1047 | ||
1048 | ||
1049 | Printed: July 21, 1983 | |
1050 | ||
1051 | ||
1052 | ||
1053 | ||
1054 | ||
1055 | ||
1056 | ||
1057 | The LISP Editor 16-17 | |
1058 | ||
1059 | ||
1060 | in conjunction with tty: commands that the user wants to | |
1061 | abort. since all of the commands in the editor are errset | |
1062 | protected, the user must exit from the editor via a command. | |
1063 | stop provides a way of distinguishing between a successful | |
1064 | and unsuccessful (from the user's standpoint) editing ses- | |
1065 | sion. | |
1066 | ||
1067 | _\bt_\bl . tl calls (top-level). to return to the editor just | |
1068 | use the _\br_\be_\bt_\bu_\br_\bn top-level command. | |
1069 | ||
1070 | _\br_\be_\bp_\ba_\bc_\bk . permits the 'editing' of an atom or string. | |
1071 | ||
1072 | (_\br_\be_\bp_\ba_\bc_\bk $) does (lc . $) followed by repack, e.g. (repack | |
1073 | this@). | |
1074 | ||
1075 | (_\bm_\ba_\bk_\be_\bf_\bn _\bf_\bo_\br_\bm _\ba_\br_\bg_\bs _\bn _\bm) . makes (car form) an expr with the | |
1076 | nth through mth elements of the current expression with | |
1077 | each occurrence of an element of (cdr form) replaced by | |
1078 | the corresponding element of args. The nth through mth | |
1079 | elements are replaced by form. | |
1080 | ||
1081 | (_\bm_\ba_\bk_\be_\bf_\bn _\bf_\bo_\br_\bm _\ba_\br_\bg_\bs _\bn). same as (makefn form args n n). | |
1082 | ||
1083 | (_\bs _\bv_\ba_\br . $) . sets var (using setq) to the current expres- | |
1084 | sion after performing (lc . $). (s foo) will set | |
1085 | foo to the current expression, (s foo -1 1) will set foo to | |
1086 | the first element in the last element of the current expres- | |
1087 | sion. | |
1088 | ____________________________________________________________ | |
1089 | ||
1090 | ||
1091 | ||
1092 | ||
1093 | ||
1094 | 16.14. Editor Functions | |
1095 | ||
1096 | ||
1097 | (editf s_x1 ...) | |
1098 | ||
1099 | SIDE EFFECT: edits a function. s_x1 is the name of the | |
1100 | function, any additional arguments are an | |
1101 | optional list of commands. | |
1102 | ||
1103 | RETURNS: s_x1. | |
1104 | ||
1105 | NOTE: if s_x1 is not an editable function, editf gen- | |
1106 | erates an fn not editable error. | |
1107 | ||
1108 | ||
1109 | ||
1110 | ||
1111 | ||
1112 | \e9 | |
1113 | ||
1114 | \e9 Printed: July 21, 1983 | |
1115 | ||
1116 | ||
1117 | ||
1118 | ||
1119 | ||
1120 | ||
1121 | ||
1122 | The LISP Editor 16-18 | |
1123 | ||
1124 | ||
1125 | (edite l_expr l_coms s_atm)) | |
1126 | edits an expression. its value is the last element of | |
1127 | (editl (list l_expr) l_coms s_atm nil nil). | |
1128 | ||
1129 | ||
1130 | (editracefn s_com) | |
1131 | is available to help the user debug complex edit macros, or | |
1132 | subroutine calls to the editor. editracefn is to be | |
1133 | defined by the user. whenever the value of editracefn is | |
1134 | non-nil, the editor calls the function editracefn | |
1135 | before executing each command (at any level), giving it | |
1136 | that command as its argument. editracefn is initially equal | |
1137 | to nil, and undefined. | |
1138 | ||
1139 | ||
1140 | (editv s_var [ g_com1 ... ]) | |
1141 | ||
1142 | SIDE EFFECT: similar to editf, for editing values. | |
1143 | editv sets the variable to the value | |
1144 | returned. | |
1145 | ||
1146 | RETURNS: the name of the variable whose value was | |
1147 | edited. | |
1148 | ||
1149 | ||
1150 | (editp s_x) | |
1151 | ||
1152 | SIDE EFFECT: similar to editf for editing property | |
1153 | lists. used if x is nil. | |
1154 | ||
1155 | RETURNS: the atom whose property list was edited. | |
1156 | ||
1157 | ||
1158 | (editl coms atm marklst mess) | |
1159 | ||
1160 | SIDE EFFECT: editl is the editor. its first argument | |
1161 | is the edit chain, and its value is an | |
1162 | edit chain, namely the value of l at the | |
1163 | time editl is exited. (l is a special | |
1164 | variable, and so can be examined or set by | |
1165 | edit commands. ^ is equivalent to (e | |
1166 | (setq l(last l)) t).) coms is an optional | |
1167 | list of commands. for interactive edit- | |
1168 | ing, coms is nil. in this case, editl | |
1169 | types edit and then waits for input from | |
1170 | the teletype. (if mess is not nil editl | |
1171 | types it instead of edit. for example, | |
1172 | the tty: command is essentially (setq l | |
1173 | (editl l nil nil nil (quote tty:))).) | |
1174 | exit occurs only via an ok, stop, or save | |
1175 | command. If coms is not nil, no message | |
1176 | is typed, and each member of coms is | |
1177 | treated as a command and executed. If an | |
1178 | ||
1179 | ||
1180 | Printed: July 21, 1983 | |
1181 | ||
1182 | ||
1183 | ||
1184 | ||
1185 | ||
1186 | ||
1187 | ||
1188 | The LISP Editor 16-19 | |
1189 | ||
1190 | ||
1191 | error occurs in the execution of one of | |
1192 | the commands, no error message is printed | |
1193 | , the rest of the commands are ignored, | |
1194 | and editl exits with an error, i.e., the | |
1195 | effect is the same as though a stop com- | |
1196 | mand had been executed. If all commands | |
1197 | execute successfully, editl returns the | |
1198 | current value of l. marklst is the list | |
1199 | of marks. on calls from editf, atm is the | |
1200 | name of the function being edited; on | |
1201 | calls from editv, the name of the vari- | |
1202 | able, and calls from editp, the atom of | |
1203 | which some property of its property list | |
1204 | is being edited. The property list of atm | |
1205 | is used by the save command for saving the | |
1206 | state of the edit. save will not save | |
1207 | anything if atm=nil i.e., when editing | |
1208 | arbitrary expressions via edite or editl | |
1209 | directly. | |
1210 | ||
1211 | ||
1212 | (editfns s_x [ g_coms1 ... ]) | |
1213 | fsubr function, used to perform the same editing operations | |
1214 | on several functions. editfns maps down the list of func- | |
1215 | tions, prints the name of each function, and calls the edi- | |
1216 | tor (via editf) on that function. | |
1217 | ||
1218 | EXAMPLE: editfns foofns (r fie fum)) will change every | |
1219 | fie to fum in each of the functions on | |
1220 | foofns. | |
1221 | ||
1222 | NOTE: the call to the editor is errset protected, | |
1223 | so that if the editing of one function causes an | |
1224 | error, editfns will proceed to the next func- | |
1225 | tion. in the above example, if one of the | |
1226 | functions did not contain a fie, the r command | |
1227 | would cause an error, but editing would con- | |
1228 | tinue with the next function. The value of | |
1229 | editfns is nil. | |
1230 | ||
1231 | ||
1232 | (edit4e pat y) | |
1233 | ||
1234 | SIDE EFFECT: is the pattern match routine. | |
1235 | ||
1236 | RETURNS: t if pat matches y. see edit-match for defini- | |
1237 | tion of 'match'. | |
1238 | ||
1239 | NOTE: before each search operation in the editor | |
1240 | begins, the entire pattern is scanned for | |
1241 | atoms or strings that end in at-signs. These | |
1242 | are replaced by patterns of the form (cons | |
1243 | (quote /@) (explodec atom)). from the | |
1244 | ||
1245 | ||
1246 | Printed: July 21, 1983 | |
1247 | ||
1248 | ||
1249 | ||
1250 | ||
1251 | ||
1252 | ||
1253 | ||
1254 | The LISP Editor 16-20 | |
1255 | ||
1256 | ||
1257 | standpoint of edit4e, pattern type 5, atoms or | |
1258 | strings ending in at-signs, is really "if | |
1259 | car[pat] is the atom @ (at-sign), pat will match | |
1260 | with any literal atom or string whose ini- | |
1261 | tial character codes (up to the @) are the same | |
1262 | as those in cdr[pat]." if the user wishes to | |
1263 | call edit4e directly, he must therefore convert | |
1264 | any patterns which contain atoms or strings | |
1265 | ending in at-signs to the form recognized by | |
1266 | edit4e. this can be done via the function | |
1267 | editfpat. | |
1268 | ||
1269 | (editfpat pat flg) | |
1270 | makes a copy of pat with all patterns of type 5 (see edit- | |
1271 | match) converted to the form expected by edit4e. flg should | |
1272 | be passed as nil (flg=t is for internal use by the editor). | |
1273 | ||
1274 | ||
1275 | (editfindp x pat flg) | |
1276 | ||
1277 | NOTE: Allows a program to use the edit find command as | |
1278 | a pure predicate from outside the editor. x is | |
1279 | an expression, pat a pattern. The value of edit- | |
1280 | findp is t if the command f pat would succeed, | |
1281 | nil otherwise. editfindp calls editfpat to con- | |
1282 | vert pat to the form expected by edit4e, unless | |
1283 | flg=t. if the program is applying editfindp to | |
1284 | several different expressions using the same pat- | |
1285 | tern, it will be more efficient to call editfpat | |
1286 | once, and then call editfindp with the converted | |
1287 | pattern and flg=t. | |
1288 | ||
1289 | ||
1290 | (## g_com1 ...) | |
1291 | ||
1292 | RETURNS: what the current expression would be after | |
1293 | executing the edit commands com1 ... starting | |
1294 | from the present edit chain. generates an | |
1295 | error if any of comi cause errors. The | |
1296 | current edit chain is never changed. example: | |
1297 | (i r (quote x) (## (cons ..z))) replaces all | |
1298 | x's in the current expression by the first | |
1299 | cons containing a z. | |
1300 | ||
1301 | ||
1302 | ||
1303 | ||
1304 | ||
1305 | ||
1306 | ||
1307 | ||
1308 | ||
1309 | \e9 | |
1310 | ||
1311 | \e9 Printed: July 21, 1983 | |
1312 | ||
1313 | ||
1314 |