******************************************************************************* * * * Topsoft Editor. * * Copyright Topsoft Inc. 1987. * * All rights reserved. * * Version 7.1. * * * ******************************************************************************* * Permission is granted to copy, distribute and/or modify this document * under the terms of the GNU Free Documentation License, Version 1.3 or * any later version published by the Free Software Foundation, with no * Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. * Visit the site http://www.gnu.org/licenses/fdl.html for a copy of the * license. * This file contains information concerning the Topsoft Editor. In particular * the existing command sequences are described, a few macro examples are given * and a description of the macro facilities is presented. This file has been * constructed as a very preliminary source of information. * Input characters. The Editor expects all characters in the initial file to * be Ascii characters in the range 0-127 (Control-@ - delete). In addition * no lines should be longer than 300 characters. Also the output of the * Editor will be conform to these rules. * Characters outside this range will be transformed into a two character * sequence. The sequence is Control-Q followed by the character stripped * of bit 7. Thus 0xE1 is transformed into the two byte sequence 0x11 0x61. * Note that Control-Q is the usual X-on character. Since during Editor * operations Control-S and Control-Q are retained in their usual X-off/ * X-on function they are not to be used in command strings anyway. * Terminals capable of sending characters in the range 128-255 may use * these for commands by denoting them accordingly in the command strings. * For example 244 would be denoted as \Qt (t=0x74=116=244-128=0xF4-0x80). * Similarly 130 is denoted as \Q\B (\B = Control-B = 0x2). * Also in INIT, BELL and EXIT strings this notation may be used. It then * results in sending characters with bit 7 set to the terminal. * Terminal Initialization and Exit strings, Command and Macro definitions. * Legal Entries: * Nn="str1" * Command redefinition. * NX="str2"="....." * Macro definition. X=Upper case or number. * For INIT, BELL and EXIT: see notes on \Q use. * INIT="string" * Initialization string. * BELL="string" * Alarm sequence. For most cases string=\G will do. * EXIT="string" * Exit string. * TIME=# * #=adjustment time to system usage in hours. * The ascii strings allow also control characters by means of the following * escape convention using the backslash: * \X = Control-X, \! = Control-\, \\ = \ * In addition: two subsequent quotes are interpreted as one: "" = ". * Delete (0x7F) is denoted by \d. * The two character sequence Nn defines the command to be redefined. * Existing sequences and the corresponding default values are given below. * * str1 may not contain more than 5 characters (a control character counts * as 1). It must start with a control character. No existing command code * must coincide with the leading characters. For example, given that * Escape control-Z is a command for search direction reversion no sequence * should start with \[\Z. Note that \[ = control [ = Escape. ******************************************************************************* * * * Specification of Editor Commands. * * * ******************************************************************************* * These are commands emitted by the terminal and to be understood by * the Editor as specified. By changing the appropriate entries below * one can adapt the Editor to the terminal. For example, if the cursor * up key of the terminal emits the (Ansi standard) sequence "Esc [ A" * then replace the line for Cu to be: * * Cu="\[[A" * * In addition, one can change the other commands to sequences emitted * by function keys, assuming that these cannot be programmed. Note that * such keys can often be programmed by sending a string to the terminal, * which string may be specified in the INIT string. Possible resettings * may be specified in the EXIT string. * * Remember that Esc = Control-[, thus Esc = \[ in the code below. * * There is one command that can not be altered, namely the "emergency exit" * command, which is Esc Control-C (i.e. "\[\C"). Commands containig this as * the first two characters lead to exit. At the very lowest level the * Editor will abort if this emergency exit signal is seen twice in succession. * Cursor movements. Cu="\P" * Cursor up Cl="\H" * Cursor left Cd="\N" * Cursor down Cr="\F" * Cursor right Bw="\A" * One word backwards Fw="\W" * One word forwards Co="\^" * Position to column * The last command must be followed by a number followed by return. The * cursor positions to the column corresponding to the number. If the * number is larger than the number of characters in the line the cursor * is positioned at the end of the line. * The cursor right and cursor left commands do not move the cursor beyond * a newline mark. If that is wanted macro's must be made. Below examples * showing that are given. * Screen positioning. * Line number oriented. General positioning: \@ n followed by return. * n is a number. Special symbols: . = line number of cursor position, * $ = number of last line, * # = line number of mark. * In addition .+n and .-n (also for $, #) are allowed. * Thus for example '\@ 1 return' brings up the very first part of the * file, and '\@ $ return' the very last. Ln="\@" * Position screen to line number. * For leafing through a file: Sp="\[\N" * Next screen. This is actually Esc Cd. Sn="\[\P" * Previous; Esc Cu. * Delete operations. Df="\D" * Delete character forward, including newlines. Db="\d" * Delete character backward, including newlines. Dn="\[\D" * Delete forward, not newline. Nd="\[\d" * Delete backwards, not newline. Dl="\K" * Delete line Dr="\_" * Restore last delete * Take-buffer operations. Tc="\T" * Take one character Tl="\Y" * Take one line Pt="\V" * Put contents of take-buffer Eb="\[\V" * Empty the take-buffer * Mark and positioning operations * Note the use of \] instead of \[ in the mark operations. Ms="\]\M" * Set mark Me="\]\_" * Erase mark Mg="\]\J" * Go to mark Mx="\]\[\J" * Exchange cursor and mark Pu="\[+" * Push position counter on position stack Po="\[-" * Pop position stack and bring up the corresponding screen * Insertion operations. * Anything not starting with a control character is inserted in the file * at the location of the cursor. Control characers can be inserted too by * preceeding them with a special character (escape character). Ec="\!" * Escape character (Control \) * A string of more than one character can be inserted. Then no screen * updating is done while reading the string. The string must be * terminated by \M or \J (return or line feed) which is not inserted. * Also one may open several lines at the same time, i.e. insert several * newlines in one go. The number of newlines is asked for. * These operation are mainly intended for use with macro's. Is="\[\I" * To be followed by string and return. Insert string. In="\[I" * To be followed by number and return. Insert newlines. * Selection operations. A portion of the file may be selected by delimiting * that portion with cursor and mark. This selection is done with the * 'Highlight' command. Through questions and answers the selection may be * deleted, put in the take buffer, be subject to pattern replacement, or * be formatted (filling up of lines as much as possible given a certain * number of columns). Hs="\U" * Highlight selection * Pattern operations. * Two different patterns may be defined, pattern A and pattern B. * Note: defining pattern A has in addition two other consequences, namely * (i) the search options are reset to +A and (ii) a search follows. * If a search with other options is needed put the pattern in B, * exchange, set options and search. Pa="\[a" * Define pattern A and Search Pb="\[b" * Define pattern B Px="\[x" * Exchange patterns A and B * Pattern searches and replacements. There are three kinds of searches, * namely the exclusive search, the non-exclusive search and the single * character search. In the exclusive search the pattern is only recognized * if delimited on both sides by a special (i.e. not alpha-numeric) character. * Typically, if the pattern searched for is 'the' then the exclusive search * will not recognize this pattern in words such as 'these' or 'theater'. The * non-exclusive search finds them all. * The single character search will stop on encountering any one of the * characters in string A. Also class searches can be done, by including * certain control characters in the string: * Control-@ (\@): stop on control character. Note: newline (\J) and tab * (\I) are control characters. * Control-A (\A): stop on numeric character. * Control-B (\B): stop on upper case character. * Control-C (\C): stop on lower case character. * Control-D (\D): stop on anything else. * Control-E (\E): stop on end file. * * Pattern A is the one used in search operations. In principle pattern B * is the replacement pattern in replacement operations. B may be empty. * The period (.) requires special attention. In Assembly language the period * may or may not be part of the names. In normal text it is not. * By default the period is treated as non-special, in fact as an upper case * character. If it should be treated as non-alpha-numeric an option may * be set. Ps="\Z" * Pattern search (both forward and backward) Pn="\[z" * Toggle Exclusive/Non-Exclusive/Single mode. Pr="\[\Z" * Toggle direction of the search. Pe="\[." * Toggle period interpretation. * String replacement. * Replacements in limited portions of the file can be done with the * selection operation Hs (Highlight selection). Rx="\R" * Search exclusive, replace once. Dr applies. Ra="\[\R" * Search non-exclusive, replace once. Dr applies. Ax="\[r" * Search exclusive and replace in the whole file. An="\[R" * Search non-exclusive, replace all. * File operations. Gf="\G" * Get external file and insert at cursor location Ef="\[\G" * Write present file into temporary file. Get external file. * Next occurence of this command the original file is * put back, overwriting the other. However, the take buffer * is unchanged during these operations, and may be used to * transport pieces. Wf="\[W" * Write the file (destination asked for) Wb="\[w" * Write the take-buffer (destination asked for) Qu="\C" * Quit. File destination is asked for. * Newline mapping. In Unix type files the newline character \n is represented * by 0x0A = Control-J. This corresponds to the line feed character of most * terminals. The return key (carriage return) gives Control-M. Normally this * is to correspond to a newline. Here two characters that map onto the Unix * newline can be specified. Na="\M" * Newline character a. Becomes \n=\J=0x0A in the text. Nb="\M" * Newline character b. Becomes \n=\J=0x0A in the text. * There are some commands that must be terminated by a carriage return * (for example Co, position to a column number). That has nothing to do * with text occurences. The editor accepts both \M (return) and \J * (line feed) for that. They need not to coincide with either Na or Nb. * Miscellaneous. No="\Q" * Do nothing. These are the Xon/Xoff characters, Np="\S" * should normally not get to the Editor. Td="\[t" * Define tab entry. Te="\[e" * Toggles tab entry mode (E in first line if on). Ov="\[o" * Toggles overstrike mode (O). Fo="\[f" * Toggles folding of lower into upper case characters (F). Cn="\[c" * Toggles highlight control characters (C). So="\[s" * Followed by one or more of OEFC+-.AXS. Sets the * option (O=overstrike, E=entries formatted, F=fold * lower to upper case, +=search forward, -=backward, * .=period not considered alphanumeric, A=non-exclusive, * X=exclusive, S=single character search). * May be preceeded by _ where meaningful to switch the * option off. Le="\[l" * Enter/exit learning mode. When in learning mode all * characters typed from input are copied into a macro * named @@ (not a name to be used elsewhere). The code * for that macro is like the one for Le (this one) except * that upper case and lower case are interchanged. Thus * here "\[L". When subsequently calling this macro (by * typing \[L) the sequence is simply repeated. Any * subsequent \M (return) leads to another repeat. Any * other input aborts the repeating. * A constant problem is the difficulty arising with * such automatic procedures if one meets occasional * situations slightly different from the first defining * one. In particular, forward and backward deletes * when rubbing out newlines may create large problems. * For this reason, when in defining or repeating mode * the delete character definitions are interchanged. * Thus delete backwards including newlines becomes * delete backwards not including newlines. Similar * for the forward character delete. Mr="\[m" * Read run-time macro. See macro description below. INIT=" " * Initiating sequence. Blank here. BELL="\G" * Alarm signal. EXIT=" " * Exit sequence. TIME=0 * No time difference. ******************************************************************************* * * * Available commands in alphabetical order. * * * ******************************************************************************* * An \[R Replace all * Ax \[r Replace all exclusive * Bw \A One word back. * Cd \N Cursor down * Cl \H Cursor left * Cn \[c Toggle highlight control characters. * Co \[\^ Position to column * Cr \F Cursor right * Cu \P Cursor up * Db \d Backward delete, including newlines * Df \D Delete character in front, including newl. * Dl \K Delete line * Dn \[\D Forward delete, not newline * Dr \_ Restore latest delete * Eb \[\V Empty buffer * Ec \! Escape character * Ef \[\G Exchange file * Fo \[f Fold lower case to upper case * Fw \W One word forward. * Gf \G Get file * Hs \U Highlight selection * In \[I Insert newlines * Is \[\I Insert sequence (not including terminating \n) * Le \[l Start/end learning. * Ln \@ Line number positioning. * Me \]\_ Erase mark * Mg \]\J Go to mark * Mr \[m Macro reading * Ms \]\M Set mark * Mx \]\[\J Exchange with mark * Na \J Newline 1 * Nb \M Newline 2 * Nd \[\d Backward delete, not newlines * Ov \[o Toggle overstrike mode * Pa \[a Define pattern a * Pb \[b Define pattern b * Pe \[. Period special toggle * Pn \[z Toggle search mode * Po \[- Pop position counter * Pr \[\Z Reverse pattern search. * Ps \Z Pattern search * Pt \V Put buffer * Pu \[+ Push position counter * Px \[x Exchange patterns * Qu \C Quit * Ra \[\R Replace string non-exclusive once * Rx \R Replace string exclusive once * Sn \[\P Previous screen * So \[s Set option * Sp \[\N Next screen * Tc \T Take character * Td \[t Tab definition * Te \[e Tab entry/exit * Tl \Y Take line * Wb \[w Write take buffer * Wf \[W Write file * Macro definition. General format: * * MM="str"=...;...; * ...;...; ;end * * One may refer to known commands and macro's by quoting the two letter code * for that command. * * Below follows a number of examples. OL="\O"=Na;Cu;end * Macro: open line. C1="\[F"=Co;put("1\M");end * Cursor to column 1. CE="\[E"=Co;put("400\M");end * Cursor to end of line. BF="\B"=Ln;put("1\M");C1;end * Macro: begin file. Use \M or \J here. EF="\[\B"=Ln;put("$\M");CE;end * Macro: end file. RS="\L"=Ln;put(".\M");end * Refresh screen. RT="\["""= r0=" "; r1=""""; * Translating raw text to \X notation. r2="\!"; r3="\d"; r4=0x40; * until " (not "") encountered. 0: r7=ic; if (r7=r1) goto 4f; if(r70)goto 0b; * Give string. put("\M") Cd; C1; end * End string. Position next line. MX="\[2"= r7=79; C1; * Position to col 1. In; put("5\J"); MA; * Insert 5 newl. Write first line. put("*"); r3=-2; r3=r3+r7; Is; * Insert string: * begin, blanks, * 0: put(" "); r3=r3-1; if(r3>0)goto 0b; put("*\M"); Cd; C1; 1: r0="\M"; r1="\I"; * Set r0 and r1 to newline and tab. 0: r3=ic; * Get character from input to r3. if(r3=r1)r3=" "; * If tab, replace by blank. if(r3=r0)goto 7f; put(r3); goto 0b; * If newline go to 7, else back to 0. 7: r3=cn; if(r3=1)goto 4f; * r3=column number. If 1 go to 4f. Ms; r4=-3; r4=r4+r7; r4=r4-r3; * Set mark. Compute blanks to be put r5=r4; r5=r5/2; r4=r4-r5; * before (r4), after (r5) the string. C1; Is; put("*"); * Col 1. Insert * and leading bl. 2: if(r5<0)goto 6f; put(" "); r5=r5-1; goto 2b; 6: put("\M"); Mg; Me; * Go to mark. Erase mark. Is; * Insert string 3: if(r4<0)goto 6f; put(" "); r4=r4-1;goto 3b; 6: put("*\M") Na; goto 1b; * and final *. Go back to 1. 4: C1; Is; * Position to col 1. Insert string. put("*"); r3=-2; r3=r3+r7; * Make line: *, blans, *. 0: put(" "); r3=r3-1; if(r3>0) goto 0b; put("*\M"); Cd; C1; MA; end * Write final line. * Writing time and date. TI="\[3"= Is; put(ti); put("\M"); end * Write date/time. * Rub forward till character (asked for) seen or end line or end file. RF="\[4"= r0=ic; r1="\J"; r2="\E"; 0: r3=sc; if(r3=r0)goto1f; if(r3=r1)goto 1f; if(r3=r2)goto 1f; Df; goto 0b; 1: st; end * Search in forward direction till character (asked) seen. * Note the use of pattern B, to avoid option resetting (done if pattern A). AD="\[5"= r1="\M"; r0=ic; * Allow abort by straight return. if(r1=r0)goto 3f; * Get input characer. So; put("S+\M"); * Set options. Search direction r1 Pb; put(r0); put("\\J\\E\M"); * Define pattern. Px; Ps; st; end * Exchange patterns, search. * Macro to order lines alphabetically with respect to the first two * characters. Execution stops at the end of the file, or when meeting * an empty line. OA="\[O"= r7="\J"; r6="\E"; * Remember position first by 'Push'. 0: Cd; C1; Pu; r0=sc; * Get first two characters in r0,r1. if(r0=r7)goto 7f; if(r0=r6)goto 7f; * Stop if empty line or end file. Cr; r1=sc; Cl; r4=0; 1: Cd; C1; r2=sc; * Inspect next line. If smaller set if(r2=r7)goto 6f; if(r2=r6)goto 6f; * mark, replace r0,r1 with r2,r3. Cr; r3=sc; Cl; if(r2 or =, and x as before: 0-4, r0-r7, ic, sc, and cn. * # is a positive number < 128 in ascii, hex or decimal notation. * If the condition is met the statement is executed. * Example: r3 = "X"; if(r3 = sc) put(a3); * Note: a put() here must be byte size. In case of a put("string") only the * first character is not transmitted if the condition is not met. * Thus: * if(r3=4)put("Ha !"); * leads to transmission to the Editor of Ha ! if the condition is true, else * only a ! is sent. * ******************************************************************************* * * * Runtime macro definition. * * * ******************************************************************************* * Extra Macro's may be defined at runtime. One simply types them in somewhere * in the text, and when the macro seems correct delimit the appropriate area * with cursor and mark. A subsequent Mr command ( \[m above) enters the macro * in the macro table. If it existed already it is redefined provided it was * the last one. After that it may be invoked, but it will not be saved. * It may of course be saved by explicitly writing the same piece to some * outside file. In fact, this is the easiest way to produce and test a macro. * * Step mode. When following up the column position command Co with a macro * command hat starts with Esc (\[) the Macro interpreter is put in step mode. * This means that the request for the continuation signal (\@) is made much * more frequently. Any other character aborts the macro. This can be used to * debug a macro sequence. For this to work the macro command sequence must * start with escape (\[). Preceeding the macro call with a column position * command leads then to step mode. This can not be done when already in a * macro.