From 6d93de7ecd5b6489fced0b76162f3c0ec217452f Mon Sep 17 00:00:00 2001 From: crc Date: Sun, 3 Feb 2019 22:45:12 +0000 Subject: [PATCH] editor improvements from Kiyoshi FossilOrigin-Name: 7a31037a55020c31bf0ae5e926304760eae297d5a777153ad8f241c696d7f4a9 --- example/edit.forth | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/example/edit.forth b/example/edit.forth index 5b91183..7e7dbe4 100755 --- a/example/edit.forth +++ b/example/edit.forth @@ -119,7 +119,8 @@ This just displays the separator bars. ~~~ :---- (-) - COLS [ $- c:put ] times nl ; + #7 [ $- c:put ] times + #0 COLS #10 / [ dup n:put #9 [ $- c:put ] times n:inc ] times n:put nl ; ~~~ Next, a word to display the header. Currently just the name of @@ -196,7 +197,7 @@ to aid in later readability. @FID file:close here TEMP-FILE file:slurp here @SourceFile file:spew ; -:current? (n-nf) +:current (ns-nsf) over @CurrentLine eq? ; ~~~ @@ -217,8 +218,9 @@ Then a word to discard the current line, removing it from the file. And the inverse, a word to inject a new line into the file. ~~~ -:add-line (-) - [ current? [ ASCII:LF @FID file:write ] if file:s:put n:inc ] process-lines ; +:add-line (-) + [ current? [ file:s:put ASCII:LF @FID file:write ] + [ file:s:put ] choose n:inc ] process-lines CurrentLine v:inc ; ~~~ Replacing a line is next. Much like the `delete-line`, this @@ -239,8 +241,9 @@ file with the dummy one. [ repeat c:get dup ASCII:LF -eq? 0; drop save again ] call drop ] sip ; }} -:replace-line (-) - [ current? [ drop s:get ] if file:s:put n:inc ] process-lines ; +:replace-line (-) + [ current? [ drop #7 [ ASCII:SPACE c:put ] times s:get ] if + file:s:put n:inc ] process-lines ; ~~~ The next four are just things I find useful. They allow me to