duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit 2e3878859326350f490372b188b9f0bc188d9fd4
parent 45e0739065d568000531a9cc51f8566c20f442d2
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Sat, 28 Jan 2023 10:19:44 -0500

text/ed: add :findnext

Diffstat:
Mfs/doc/text/ed.txt | 6++++++
Mfs/text/ed.fs | 13++++++++-----
2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/fs/doc/text/ed.txt b/fs/doc/text/ed.txt @@ -113,6 +113,9 @@ Words: Find occurence of "str" in buffer, starting from current position. If found, position is moved to that occurence. If not, position stays unchanged. +:findnext ( self -- ) + Repeat the last :find. + :print ( n self -- ) Print "n" lines, starting from current line, to stdio. @@ -183,6 +186,9 @@ O ( "...\n" -- ) f ( "...\n" -- ) Find typed string in buffer. +n ( -- ) + Repeat the last find + d ( n -- ) Delete "n" lines starting from the current one. diff --git a/fs/text/ed.fs b/fs/text/ed.fs @@ -30,14 +30,16 @@ extends IO struct[ Edbuf over sel over <> while ( self line ) over 1 swap to+ lpos llnext repeat ( self line ) 2drop ; - : :find ( str self -- ) >r >r \ V1=self V2=str - V2 V1 cpos V1 sel Line :range rtrimleft [str]? ( idx ) + create _findstr STR_MAXSZ allot0 + : :findnext ( self -- ) >r \ V1=self + _findstr V1 cpos 1+ V1 sel Line :range rtrimleft [str]? ( idx ) dup 0< if drop V1 sel llnext begin ( line ) \ search following lines ?dup while ( line ) - V2 over Line :range [str]? dup 0< while ( line -1 ) + _findstr over Line :range [str]? dup 0< while ( line -1 ) drop llnext repeat ( line idx ) - V1 to cpos V1 to sel V1 _updatelpos then ( ) - else V1 to+ cpos then rdrop rdrop ; + V1 to cpos V1 to sel r> _updatelpos then ( ) + else r> to+ cpos then ; + : :find ( str self -- ) swap _findstr strmove :findnext ; : _newline ( self -- line ) Line SZ swap buf Arena :allot dup Line SZ 0 fill ; @@ -154,6 +156,7 @@ Edbuf :new structbind Edbuf edbuf : dl ( n -- ) edbuf :dellines ?s ; : i console :readline edbuf :puts ?s ; : f console :readline edbuf :find ?s ; +: n edbuf :findnext ?s ; : o edbuf :appendline i ; : O edbuf :insertline i ; : edload ( -- )