edit.forth: formatting improvements

FossilOrigin-Name: 9cb858a5ce01af65656553e56d54e525ec2e9707febc830a92e92a638c260101
This commit is contained in:
crc 2019-05-14 11:29:09 +00:00
parent 1beb845cf9
commit f8567fd50f
2 changed files with 30 additions and 28 deletions

View file

@ -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

View file

@ -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<n>
~~~
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