diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 9e64c4c..6c8690b 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -41,6 +41,7 @@ July - September window for this release. - add sqlite3 wrapper - add unix-does-user-exist.forth - improved 99bottles.forth +- improved edit.forth - corrected an issue in mail.forth - cleanup publish-examples.forth - publish-examples.forth now uses `retro-document` to generate glossaries diff --git a/example/edit.forth b/example/edit.forth index 4e313e4..80557d8 100755 --- a/example/edit.forth +++ b/example/edit.forth @@ -39,6 +39,13 @@ sys:argc n:zero? [ 'No_file_specified! s:put nl #0 unix:exit ] if If I get here, a filename was provided. So I start by creating a few variables and constants. +Get the name of the file to edit. + +~~~ +#0 sys:argv s:keep 'SourceFile var +~~~ + + The configuration here is for two items. The number of lines from the file to show on screen, and the name of the temporary file to use when editing. @@ -46,14 +53,13 @@ file to use when editing. ~~~ #70 'COLS const #16 'MAX-LINES const -'/tmp/rre.edit 'TEMP-FILE s:const +'/tmp/hua.editor.scratch 'TEMP-FILE s:const ~~~ Next are the variables that I use to track various bits of state. ~~~ -'SourceFile var 'CurrentLine var 'LineCount var 'ShowEOL var @@ -61,12 +67,6 @@ state. 'CopiedLine d:create #1025 allot ~~~ -Get the name of the file to edit. - -~~~ -#0 sys:argv s:keep !SourceFile -~~~ - To create a new file, Hua allows for the use of `new` followed by the filename. I handle the file creation here. @@ -175,7 +175,8 @@ whitespace. The indicator can be toggled via the ~ key. :display (-) @SourceFile file:R file:open !FID clear-display header ---- skip-to - @CurrentLine MAX-LINES #2 / - #0 n:max count-lines MAX-LINES n:min [ display-line ] times drop + @CurrentLine MAX-LINES #2 / - #0 n:max count-lines MAX-LINES n:min + [ display-line ] times drop ---- @FID file:close ; ~~~ @@ -329,25 +330,25 @@ top level loop. :constrain (-) &CurrentLine #0 @LineCount n:dec v:limit ; :handler c:get - $1 [ replace-line ] case - $2 [ add-line ] case - $3 [ trim-trailing ] case - $4 [ delete-line ] case - $5 [ kill-line ] case - $~ [ @ShowEOL not !ShowEOL ] case - $c [ copy-line ] case - $v [ paste-line ] case - $< [ dedent-line ] case - $> [ indent-line ] case - $| [ code-block ] case - $[ [ goto-start ] case - $] [ goto-end ] case - $j [ &CurrentLine v:inc constrain ] case - $k [ &CurrentLine v:dec constrain ] case - $h [ &CurrentLine v:inc constrain ] case - $t [ &CurrentLine v:dec constrain ] case - $g [ goto constrain ] case - $q [ 'stty_-cbreak unix:system #0 unix:exit ] case + $1 [ replace-line ] case + $2 [ add-line ] case + $3 [ trim-trailing ] case + $4 [ delete-line ] case + $5 [ kill-line ] case + $~ [ @ShowEOL not !ShowEOL ] case + $c [ copy-line ] case + $v [ paste-line ] case + $< [ dedent-line ] case + $> [ indent-line ] case + $| [ code-block ] case + $[ [ goto-start ] case + $] [ goto-end ] case + $j [ &CurrentLine v:inc constrain ] case + $k [ &CurrentLine v:dec constrain ] case + $h [ &CurrentLine v:inc constrain ] case + $t [ &CurrentLine v:dec constrain ] case + $g [ goto constrain ] case + $q [ 'stty_-cbreak unix:system bye ] case drop ; :edit