lib-editor

Primarily a series of routines building up from lib-edit to the final result of cmd/lsedit. But handy writing programs that need an inline editor.

The author of this library (Foxen) requests that credit is given where credit is due: Any program using these routines should note in its help or some other portion of its output as appropiate that it uses Foxen's lib-editor library.

If you're relatively new to dealing with "lists" and "ranges" you may want to take a look at the lib-stackrng and lib-lmgr libraries. In particular, by far the easiest way to deal with editor is before calling the editor, use LMGR-Getlist (from lib-lmgr) to fetch the entire "list", put any other relevant items on the stack, and call the editor.

Then, to handle "abort" and "end" properly: For abort, you simply POP off the entire list using sr-poprng (from lib-stackrng) being the easiest way. To handle "end", you need to save the new list back to the properties. I'd use LMGR-Deletelist to delete the old version of the list from the propdir, and then use LMGR-PutRange to put the new version from the stack into the properties.

EDITOR takes a bunch of strings on the stack, with a count on top, and returns a set of strings with the count, and a string on top containing the command used to exit. The two options for the top item (the exit command) is "abort" or "end". Presumably, the calling program will need to handle both appropiately: "abort", exit without make changes to the list, "end" saving changes to the list.

The format is: {strs} count -- {strs'} count' exitcmdstr

EDITORloop is more complex. it takes the strings and count [hereafter to be referred to as a range], a string containing the space seperated names of the commands it should return on [in addition to abort and end], the position in the range that you want it to set the insertion point at, and the command you want it to first execute [usually ".i"]. It lets the user edit the range until the user enters a .command that you have listed in the mask, or until they enter .end, or .abort. It returns the new range, the mask, the insertion point that the user was at when it returned, and the arguments that were given to the command that made the routine return, and the name of the command that made it return.

The format of a .command is: .cmd  startline  endline=argstr
So, overall, the input/output of the function is: {rng} mask curpos cmdstr -- {rng'} mask curpos argstr startline endline exitcmd

EDITORparse takes and returns arguments identically to EDITORloop, but only executes the command you pass it without doing any more editing on the range, before returning.

EDITORheader takes and returns no arguments, but prints out a standard message about you entering the editor. EDITOR calls this automatically.


feaelin@kemenel.org
lib-editor / Revised 2004 March 31 22:06 (Wednesday)
© 2004 Iain E. Davis

Green Web Hosting! This site hosted by DreamHost. Standards Now! Valid XHTML 1.1! Valid CSS! We rated with ICRA!