|
|
1.1 root 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: _e_d_i_t_f), values (_e_d_i_t_v), properties (_e_d_i_t_p), and
44: expressions (_e_d_i_t_e). The beginner is advised to
45: start with the following (very basic) commands: _o_k,
46: _u_n_d_o, _p, #, 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: 9
61:
62: 9The 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: _S_C_O_P_E _O_F _A_T_T_E_N_T_I_O_N _C_O_M_M_A_N_D _S_U_M_M_A_R_Y
85:
86: _n (_n>_0) . Makes the nth element of the current expression be
87: the new current expression.
88:
89: -_n (_n>_0). Makes the nth element from the end of the current
90: expression be the new current expression.
91:
92: _0. 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: _u_p . 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: !_0 . Goes back to the next higher left parenthesis.
103:
104: ^ . Makes the top level expression be the current expres-
105: sion.
106:
107: _n_x . Makes the current expression be the next expression.
108:
109: (_n_x _n) equivalent to n nx commands.
110:
111: !_n_x . 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: _b_k . Makes the current expression be the previous expres-
116: sion in the next higher expression.
117:
118: (_n_t_h _n) _n>_0 . Makes the list starting with the nth element
119: of the current expression be the current expression.
120:
121: (_n_t_h $) - _g_e_n_e_r_a_l_i_z_e_d _n_t_h _c_o_m_m_a_n_d. 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: (_b_e_l_o_w _c_o_m _x) . 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: (_n_e_x _x) . same as (_b_e_l_o_w _x) followed by nx. For example,
151: if you are deep inside of a selectq clause, you can advance
152: to the next clause with (_n_e_x _s_e_l_e_c_t_q).
153:
154: _n_e_x. The atomic form of _n_e_x is useful if you will be
155: performing repeated executions of (_n_e_x _x). By simply
156: marking the chain corresponding to x, you can use _n_e_x 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 _p_a_t matches with x if:
168:
169: ____________________________________________________________
170:
171: _P_A_T_T_E_R_N _S_P_E_C_I_F_I_C_A_T_I_O_N _S_U_M_M_A_R_Y
172:
173: - _p_a_t is _e_q to x.
174:
175: - _p_a_t is &.
176:
177: - _p_a_t is a number and equal to x.
178:
179: - if (car _p_a_t) is the atom *any*, (cdr _p_a_t) is a list of
180: patterns, and _p_a_t matches x if and only if one of the pat-
181: terns on (cdr _p_a_t) matches x.
182:
183: - if _p_a_t is a literal atom or string, and (nthchar _p_a_t -1)
184: is @, then _p_a_t matches with any literal atom or string which
185: has the same initial characters as _p_a_t, e.g. ver@ matches
186: with verylongatom, as well as "verylongstring".
187:
188: - if (car _p_a_t) is the atom --, _p_a_t matches x if (a) (cdr
189: _p_a_t)=nil, i.e. _p_a_t=(--), 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 _p_a_t) 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 _p_a_t) is the atom ==, _p_a_t matches x if and only if
211: (cdr _p_a_t) is _e_q 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 _e_q to existing structure.) - otherwise if x is a
215: list, _p_a_t matches x if (car _p_a_t) matches (car x), and (cdr
216: _p_a_t) 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: _S_E_A_R_C_H _C_O_M_M_A_N_D _S_U_M_M_A_R_Y
236:
237: _f _p_a_t_t_e_r_n . 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: (_f _p_a_t_t_e_r_n _n). Finds the next instance of pattern.
243:
244: (_f _p_a_t_t_e_r_n _t). 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: (_f _p_a_t_t_e_r_n _n) _n>_0. 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: (_f _p_a_t_t_e_r_n) _o_r (_f _p_a_t_t_e_r_n _n_i_l). only matches with elements
253: at the top level of the current expression. If the current
254: expression is (_p_r_o_g _n_i_l (_s_e_t_q _x (_c_o_n_d & &)) (_c_o_n_d &) ...) 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: (_s_e_c_o_n_d . $) . 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: (_t_h_i_r_d . $) . Similar to second.
276:
277: (_f_s _p_a_t_t_e_r_n_1 ... _p_a_t_t_e_r_n_n) . 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: (_f= _e_x_p_r_e_s_s_i_o_n _x) . Searches for a structure eq to expres-
283: sion.
284:
285: (_o_r_f _p_a_t_t_e_r_n_1 ... _p_a_t_t_e_r_n_n) . Searches for an expression
286: that is matched by either pattern1 or ... patternn.
287:
288: _b_f _p_a_t_t_e_r_n . backwards find. If the current expression is
289: (_p_r_o_g _n_i_l (_s_e_t_q _x (_s_e_t_q _y (_l_i_s_t _z))) (_c_o_n_d ((_s_e_t_q _w --) --))
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: (_b_f _p_a_t_t_e_r_n _t). 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 (_r_e_t_u_r_n) after ^ prog -1) will
346: go to the top, find the first prog, and insert a
347: (_r_e_t_u_r_n) 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: _L_O_C_A_T_I_O_N _C_O_M_M_A_N_D _S_U_M_M_A_R_Y
369:
370: (_l_c . $) . Provides a way of explicitly invoking the loca-
371: tion operation. (lc cond 2 3) will perform search.
372:
373: (_l_c_l . $) . Same as lc except search is confined to current
374: expression. To find a cond containing a _r_e_t_u_r_n, one might
375: use the location specification (cond (lcl _r_e_t_u_r_n) ) 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: _E_D_I_T _C_H_A_I_N _C_O_M_M_A_N_D _S_U_M_M_A_R_Y
406:
407: _m_a_r_k . 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: (_ _p_a_t_t_e_r_n) . 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: \_p . 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: _P_R_I_N_T_I_N_G _C_O_M_M_A_N_D _S_U_M_M_A_R_Y
445:
446: _p 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: 9
456:
457: 9 Printed: July 21, 1983
458:
459:
460:
461:
462:
463:
464:
465: The LISP Editor 16-8
466:
467:
468: _p_p . pretty-prints the current expression.
469:
470: _p_p*. 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: _u_n_d_o.
481:
482:
483: ____________________________________________________________
484:
485: _S_T_R_U_C_T_U_R_E _M_O_D_I_F_I_C_A_T_I_O_N _C_O_M_M_A_N_D _S_U_M_M_A_R_Y
486:
487: # [_e_d_i_t_o_r _c_o_m_m_a_n_d_s] (n) n>1 deletes the corresponding ele-
488: ment from the current expression.
489:
490: (_n _e_1 ... _e_m) _n,_m>_1 replaces the nth element in the current
491: expression with e1 ... em.
492:
493: (-_n _e_1 ... _e_m) _n,_m>_1 inserts e1 ... em before the n ele-
494: ment in the current expression.
495:
496: (_n _e_1 ... _e_m) (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: (_a _e_1 ... _e_m) . inserts e1 ... em after the current
501: expression (or after its first element if it is a tail).
502:
503: (_b _e_1 ... _e_m) . 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: (: _e_1 ... _e_m) . replaces the current expression by e1 ...
508: em. If the current expression is a tail then replace its
509: first element.
510:
511: _d_e_l_e_t_e _o_r (:) . deletes the current expression, or if the
512: current expression is a tail, deletes its first element.
513:
514: (_d_e_l_e_t_e . $). does a (lc . $) followed by delete. current
515: edit chain is not changed.
516:
517: (_i_n_s_e_r_t _e_1 ... _e_m _b_e_f_o_r_e . $) . similar to (lc. $) fol-
518: lowed by (b e1 ... em).
519:
520: (_i_n_s_e_r_t _e_1 ... _e_m _a_f_t_e_r . $). 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: (_i_n_s_e_r_t _e_1 ... _e_m _f_o_r . $). similar to insert before
537: except uses : for b.
538:
539: (_r_e_p_l_a_c_e $ _w_i_t_h _e_1 ... _e_m) . here $ is the segment of the
540: command between replace and with.
541:
542: (_c_h_a_n_g_e $ _t_o _e_1 ... _e_m) . same as replace with.
543: ____________________________________________________________
544:
545:
546:
547:
548:
549: 16.6. Extraction and Embedding Commands
550:
551: ____________________________________________________________
552:
553: _E_X_T_R_A_C_T_I_O_N _A_N_D _E_M_B_E_D_D_I_N_G _C_O_M_M_A_N_D _S_U_M_M_A_R_Y
554:
555: (_x_t_r . $) . replaces the original current expression with
556: the expression that is current after performing (lcl . $).
557:
558: (_m_b_d _x) . 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: (_e_x_t_r_a_c_t $_1 _f_r_o_m $_2) . 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: (_e_m_b_e_d $ _i_n . _x) . 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 _r_e_t_u_r_n), (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: 9
587:
588: 9 Printed: July 21, 1983
589:
590:
591:
592:
593:
594:
595:
596: The LISP Editor 16-10
597:
598:
599: ____________________________________________________________
600:
601: _M_O_V_E _A_N_D _C_O_P_Y _C_O_M_M_A_N_D _S_U_M_M_A_R_Y
602:
603: (_m_o_v_e $_1 _t_o _c_o_m . $_2) . ($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: (_m_v _c_o_m . $) . is the same as (move here to com . $).
613:
614: (_c_o_p_y $_1 _t_o _c_o_m . $_2) is like move except that the source
615: expression is not deleted.
616:
617: (_c_p _c_o_m . $). 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: _P_A_R_E_N_T_H_E_S_E_S _M_O_V_I_N_G _C_O_M_M_A_N_D _S_U_M_M_A_R_Y
635:
636: (_b_i _n _m) . 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: (_b_o _n) . 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: (_l_i _n) . 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: (_l_o _n) . 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: (_r_i _n _m) . 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: (_r_o _n) . 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: (_r _x _y) 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: (_s_w _n _m) 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: 9
718:
719: 9 Printed: July 21, 1983
720:
721:
722:
723:
724:
725:
726:
727: The LISP Editor 16-12
728:
729:
730: ____________________________________________________________
731:
732: _T_O _A_N_D _T_H_R_U _C_O_M_M_A_N_D _S_U_M_M_A_R_Y
733:
734: ($_1 _t_o $_2) . same as thru except last element not
735: included.
736:
737: ($_1 _t_o). same as ($1 thru -1)
738:
739: ($_1 _t_h_r_u $_2) . 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: ($_1 _t_h_r_u). same as ($_1 _t_h_r_u -_1).
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: _U_N_D_O _C_O_M_M_A_N_D _S_U_M_M_A_R_Y
765:
766: _u_n_d_o . 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: !_u_n_d_o . undoes all modifications performed during this
773: editing session, i.e., this call to the editor.
774:
775: _u_n_b_l_o_c_k . 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: _t_e_s_t . 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: _u_n_d_o_l_s_t [_v_a_l_u_e]. 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: _E_V_A_L_U_A_T_I_O_N _C_O_M_M_A_N_D _S_U_M_M_A_R_Y
816:
817: _e . 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: (_e _x) evaluates x, and prints the result. (e x t) same
822: as (e x) but does not print.
823:
824: (_i _c _x_1 ... _x_n) 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: (_c_o_m_s _x_1 ... _x_n) . 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: (_c_o_m_s_q _c_o_m_1 ... _c_o_m_n) . 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: _T_E_S_T_I_N_G _C_O_M_M_A_N_D _S_U_M_M_A_R_Y
875:
876: (_i_f _x) 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: (_l_p . _c_o_m_s) . 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: (_l_p_q . _c_o_m_s) same as lp but does not print n occurrences.
894:
895: (_o_r_r _c_o_m_s_1 ... _c_o_m_s_n) . 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: (_m _c . _c_o_m_s) 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: (_b_i_n_d . _c_o_m_s) 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: _u_s_e_r_m_a_c_r_o_s [_v_a_l_u_e]. 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: _e_d_i_t_c_o_m_s_l [_v_a_l_u_e]. 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: _M_I_S_C_E_L_L_A_N_E_O_U_S _E_D_I_T_O_R _C_O_M_M_A_N_D _S_U_M_M_A_R_Y
1027:
1028: _o_k . Exits from the editor.
1029:
1030: _n_i_l . Unless preceded by f or bf, is always a null opera-
1031: tion.
1032:
1033: _t_t_y: . 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: _s_t_o_p . 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: _t_l . tl calls (top-level). to return to the editor just
1068: use the _r_e_t_u_r_n top-level command.
1069:
1070: _r_e_p_a_c_k . permits the 'editing' of an atom or string.
1071:
1072: (_r_e_p_a_c_k $) does (lc . $) followed by repack, e.g. (repack
1073: this@).
1074:
1075: (_m_a_k_e_f_n _f_o_r_m _a_r_g_s _n _m) . 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: (_m_a_k_e_f_n _f_o_r_m _a_r_g_s _n). same as (makefn form args n n).
1082:
1083: (_s _v_a_r . $) . 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: 9
1113:
1114: 9 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: 9
1310:
1311: 9 Printed: July 21, 1983
1312:
1313:
1314:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.