EDITORS AND EDITOR
Editors are very personal. Most people find that the first editor they learned to use is the only type of editor to use.
But there are many different editors of a number of different types. The modern word processors are very powerful editors. The one being used to write this has more commands than MVP-FORTH. It has taken years to learn it and the revisions are more frustrating than helpful. The result is that an old version is being used.
In MVP-FORTH, all you need is to be able to write to the FORTH screens. Each screen has only 16 lines of 64 characters on each line. You do not need all of the power of a full blown word processor.
You have already been shown how to use the rudimentary editor which is included in the MVP-FORTH kernel.75 LIST 75 CLEAR 0 PP ( THIS IS LINE 0 ) FLUSH
This sequence will allow you to develop programs in screens and test them with a minimum change in your previous habits. The initial translation of the EXPERT-2 System to MVP-FORTH was done with this rudimentary editor even though several types of FORTH editors were available. It includes the necessary and sufficient tools to progress very rapidly. Why would you want anything more complicated?
Well, there are a few things you would like to be able to do without having to type an entire line over. You would like to be able to find character strings and replace them. You would like to be able to insert and delete strings and whole lines and have the rest of the text expand and contract as necessary. Yes, something more than the rudimentary editor is available. But you will have to learn some more FORTH functions.
Charles Moore, who created FORTH because of the constraint of speed, created an editor. In his hands, screen editing can be done with amazing speed. If you are interested in speed, you might find it worth while taking a look at the capabilities of his editor.
Sam Daniels wrote an implementation of Charles Moore's editor and placed it in the public domain. It was published in FORTH DIMENSIONS, Vol III No. 3. That editor has been translated to MVP-FORTH. It has been compiled into your implementation of FORTH. You have the source code both in hard copy with your MVP-FORTH system documentation, and on the MVP-FORTH screen's disk.
You will find many examples of FORTH functions in the source code. Do take some time to look at them. They will serve as models for developing a number of unrelated applications.
The first thing you will notice is that when you bring up your MVP-FORTH, none of the editor commands seem to work. Frustrating! The reason is trivial. Your run time MVP-FORTH dictionary is not burdened with the vocabulary necessary for the editor unless you need it.
Invoke the editor by executing EDITOR. Now suddenly you will find that the editor functions are available. Every time you LOAD a screen as you test a program during development, you will leave the EDITOR vocabulary. So you will have to invoke the editor again if you need it.
Well, what can you do with the EDITOR vocabulary? Once you have LISTed a screen, you can relist that screen with a single character command, L . This command finds the number of the current screen in the MVP-FORTH variable, SCR , and executes LIST. You have seen this definition earlier.: L SCR @ LIST [COMPILE] EDITOR ;
You might even want to add this to your rudimentary editor by adding the definition to your MVP-FORTH vocabulary.
As you make changes you can always redisplay the revised screen with this command. The problem of displaying an image would be greatly simplified if all displays were memory mapped in your system. Unfortunately, this is not the case. In fact, the variety of monitors which connect to your system with an RS-232 line are each different and few are memory mapped as far as your system is concerned.
You will find that the functions of this EDITOR vocabulary will work on any system. Having learned the few commands you will use, you will be able to move from system to system with completely different hardware. No new learning curve for each.
When you list a screen while in the EDITOR, you will be shown one of the lines below the screen with a caret mark, in the line. Occasionally, you will get a message: NOT ON CURRENT SCREEN. This means that the pointer to the location of the cursor is larger than 1023, the number of characters possible on a screen. You can then tell the system the line you would like to place the cursor on.0 T
This will type out the 0 line of the current screen. It will show you what you have written on the index line of screen 75, if that is where you are. You will also see a caret at the beginning of the line. That is where the cursor is currently located.
Using a simple command, P , for put, you can now replace the text which is on the selected line.0 T P ( THIS IS LINE 0 ) 0 PP ( THIS IS LINE 0 )
These two sequences do exactly the same thing. The name PP was adapted from P , but the character was used twice to distinguish it from the single character command. The function of P in the EDITOR requires that you first select the desired line with T , while PP requires that you tell the system the line number. It is easy enough to type a character twice once you have found it.
As a contrived example, insert something in the existing line.F IS I ON L
You will find it easier to execute these sequences than to explain them. The name F is for find. The name I is for insert. The mnemonics are good and only a single key stroke is necessary. With the EDITOR functions, a single space is used for parsing. All subsequent spaces are significant.
Add some more text to your experimental screen. Use these commands to modify them. Perhaps you will want to erase something you have found. Try the name E for erase. You can also try R for replace. All good mnemonic, single stroke functions. No control characters to associate with any of them.
One other function is most useful, TILL . This erases everything from the current cursor position through the character string which follows TILL .
These functions are even smarter than at first appears. The F and TILL use the find buffer. Once something has been placed in a buffer, use of the function without adding anything to it will use the existing contents of the buffer. The R and I functions use the insert buffer. These functions will use the existing contents of that buffer, if no new contents are given.
You can use these commands in conjunction with one another and repeatedly.
Suppose you want to go through a screen and change all occurances of DDUP to simply DUP.0 T F DDUP R DUP F R F R etc
When you get to the end of the screen you will see the find buffer displayed followed by NONE. Continuing to execute the F function will recycle through the same screen.
There are many other permutations and combinations of these commands which allow you to move rapidly through a screen. It is easier to say what you want to find than to move a cursor over the page. You can also be sure that you find every occurance of a particularly string on a screen. If you do not wish to make a change after you have placed the cursor in some location you can advance to the next location by repeating the F function.
Practice is the only way to learn these commands. There are only a few and each has a reasonably good mnemonic. You should master them quickly. While in the EDITOR, you can refresh you memory of the available commands with VLIST.
Using VLIST, you will see that the first word in the EDITOR's vocabulary is M . That is mnemonic for move. The source for the move is always on the current screen, i.e., the value stored in SCR, and the line is the one on which the cursor is currently located. You must tell the system which screen number ollowed by the line number above which you want for the destination line. The destination screen need not be different from the source screen, but you will have to tell the system that anyway.0 T 75 0 M
Suppose you are still working on screen 75. The above sequence will make a copy of line 0 on line 1. All of the other lines will be pushed down one. What was on line 15 will be pushed off the screen and lost.L
You can now see what you have done. If you are doing a number of moves you will automatically learn to follow it with an L. Perhaps that is a little cryptic for you. Once you move beyond the novice level, you will find that the commands are easy to use and very fast. Try VLIST again.
The word R, you have already learned. The word U is new. The function of U is to insert a new line below the current line. All lines are moved down one and what was on line 15 is lost.0 T U : NOOP ; U U L
The string buffer for the U command is the same as that for R and I. The function of U without a new string is to insert the contents of the insert/replace/U buffer.
Try VLIST again. The next new word is S. This is a most convenient function. It will search as much of a disk as you wish for any string you wish. The search will always begin with the current screen. It must be told the number of the ending screen. Following the command you enter the string you wish to search for.80 S LINE
All occurances of the word LINE will be displayed followed by the line number and the screen number. The power of this command is not limited to FORTH screens.
Perhaps you remember trying to find the system dictionary on one of the early screens of a system disk. Try it this way. Place a system disk in the the drive. Be sure you have a backup. You might do something you do not expect to do.0 SCR ! 10 S FORTH
You will see which block contains the directory entry FORTH. If there is an extension that will be found too. If you have an entry which has been erased you will see the location of that too. You can find and replace any string on any disk, including system disks. FORTH is powerful. It is also dangerous.
Referring back to VLIST, the next two words are primitives, so we will skip over them. The next potentially useful function is D. It is a combination of F and E. The combination is dangerous. The function will delete the string you enter without checking to be sure that is what you intended to do. You might find it more convenient to execute F . If you found what you expected you can use the E function.
Go back to your FORTH SCREENS disk.75 LIST
Suppose you have finished that screen and want to go on to the next in order.N L
The word N, is mnemonic for next. The command increments to pointer to the current screen, SCR, by one. The function of L is to list the screen pointed to by SCR. You can now edit the next screen. You would have accomplished the same thing with:76 LIST
To back up one screen you have available the function of B, mnemonic for back. The function of B is to decrement the value in the pointer SCR.
The last function crosses out the current line and moves all of the rest of the lines up one. A blank line is added to the end of the screen.8 T X
The line which is crossed out is placed into the insert/replace/U buffer. You can get it back! You can move the cursor to another line and insert the contents of the buffer under it with U.6 T U
Having crossed out line 8, you then inserted it below line 6, i.e. on line 7.
There is no end to the possible combinations you can use with these simple mnemonic commands. With the exception of TILL, all of the useful commands are simple single key words. You can move around the screen with great speed.
Along with the source code for the EDITOR vocabulary, three useful words are added to the FORTH vocabulary.
The function of WIPE is to erase the current screen.75 LIST WIPE 75 LIST75 LIST 75 CLEAR 75 LIST
Each of the above groups of commands does exactly the same thing.
The function of LINE is to leave the address of the beginning of the specified line number for various functions in the EDITOR. You could examine its function with your screen 75.75 BLOCK . 0 LINE .
You will recall that BLOCK leaves the memory address of the specified block which you displayed. In the second example you used LINE to leave the memory address of the beginning of the specified line and displayed that. You will see that the two values are the same.
The last MVP-FORTH function added with EDITOR is MATCH and its primitive <MATCH>. It would be better to implement these functions in assembly code for the specific processors. But then the function would not be portable among various systems, so we sacrifice a small amount of speed.
The function of MATCH requires an address, the length of the field in memory which you wish to search for a match, and the address and length of the string being searched for. That is perhaps a little confusing. You need two pairs of addresses and counts. The first has to do with the range to be searched. The second has to do with the location of the string being looked for.75 LIST 8 PP THIS IS A STRING 1 TEXT STR 75 BLOCK 1024 PAD COUNT MATCH
You will investigate the function of TEXT and PAD shortly. The sequence of instructions will find the location of STR as an offset in the buffer for screen 75. After executing the above series of commands, prove the statement with:EDITOR R# ! L DROP
You placed the cursor where you found the matching string and then redisplayed the screen with L. Under the new screen display you should see the cursor at the appropriate point ready for other functions. You will have to DROP the flag which MATCH leaves under the offset value.
The function of TEXT is to use the indicated value as a terminator for the input of a string of characters to a temporary location pointed to by PAD. You can test this with a simple example:1 TEXT THIS IS A TEST PAD COUNT TYPE PAD 10 DUMP
As a result of the last sequence, you will see that the first byte beginning at the location pointed to by PAD is a length byte. The function of COUNT is to fetch the length and advance the address by 1. The order needs to be reversed for the convenience of TYPE. The function of TYPE is to display the text beginning at a specified address and of a specified length.
As with many of these examples, you should be working with ALL ABOUT FORTH and your MVP-FORTH Users's Manual. Use the examples there too. The purpose of this discussion is to make learning about MVP-FORTH a little easier than just reading the glossary, source code and documentation.
There are a number of other editors available, many of which are in the public domain. You can play with them as you have time. Each is designed to meet the needs of the author. Perhaps one of the other editors will meet your needs better. However, you are encouraged to give this EDITOR a chance. It was designed for speed and convenience of an experienced user. When you become experienced with its use, you may agree. Chuck Moore still uses his.
Next Previous Contents