commit 7bf8aafab05f0749e9f38f8962714fd78f13223a
parent aba53d399ab5e8c733a296379db1ea1c616ab2ca
Author: Virgil Dupras <hsoft@hardcoded.net>
Date: Sun, 15 Jan 2023 15:31:16 -0500
text/ed: implement some more movement commands
Diffstat:
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/fs/tests/text/ed.fs b/fs/tests/text/ed.fs
@@ -6,5 +6,12 @@ f" /tests/txtfile" edload
1 g
5 capture l
S" with some text\n ^\n1 / 17\n" #s=
-p
+7 capture j
+S" be\n ^\n8 / 17\n" #s=
+5 capture k
+S" (oh well maybe grow)\n ^\n3 / 17\n" #s=
+capture L
+S" (oh well maybe grow)\n ^\n3 / 17\n" #s=
+capture H
+S" (oh well maybe grow)\n^\n3 / 17\n" #s=
testend
diff --git a/fs/text/ed.fs b/fs/text/ed.fs
@@ -26,11 +26,12 @@ extends IO struct[ Edbuf
: _sel$ ( self -- )
0 over to lpos dup lines swap to sel ;
+ : _cbounds ( self -- ) dup cpos over sel Line cnt 1- max0 min swap to cpos ;
: :godown ( n self -- )
over if swap >r dup sel begin ( self line )
dup llnext if llnext over 1 swap to+ lpos else leave then
next then ( self line )
- swap to sel ;
+ over to sel _cbounds ;
: _addline ( self -- )
dup _newline over lines llappend 1 swap :godown ;
@@ -66,8 +67,9 @@ extends IO struct[ Edbuf
: :linecnt ( self -- cnt ) lines llcnt ;
: :goleft ( n self -- ) dup cpos rot - max0 swap to cpos ;
- : :goright ( n self -- ) dup cpos rot + over sel Line cnt min swap to cpos ;
+ : :goright ( n self -- ) dup cpos rot + over to cpos _cbounds ;
: :go ( n self -- ) dup _sel$ :godown ;
+ : :goup ( n self -- ) dup lpos rot - max0 swap :go ;
: _nl> ( -- ) LF stdout ;
@@ -100,6 +102,9 @@ Edbuf :new structbind Edbuf edbuf
: g ( n -- ) edbuf :go ?s ;
: h ( n -- ) edbuf :goleft ?s ;
+: H ( -- ) $10000 h ;
: l ( n -- ) edbuf :goright ?s ;
+: L ( -- ) $10000 l ;
: j ( n -- ) edbuf :godown ?s ;
+: k ( n -- ) edbuf :goup ?s ;
: p ( -- ) pagesz edbuf :print ;