-
Notifications
You must be signed in to change notification settings - Fork 2
/
block-024.fth
32 lines (29 loc) · 1.22 KB
/
block-024.fth
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
cols var cmd-buf cols var yank-buf
->file(fh--)(output-fp) ! ; ->stdout0 ->file ;
write-row p1 i 0 >pos s-cpy s-rtrim ztype 10 emit ;
write-blockrows for write-row next ;
w(write the block)dirty?ifblock-fn fopen-wb ?dup
if>t t@ ->file write-block t> fclose clean ->stdoutthen then;
bs8 emit ;
del-ch( -- )y@ x@ <ifx- 0 !x bs space bsthen;
app-ch( ch-- )!x+ 0 !x emit ;
clr-bufy@ x! 0 !x ;
t50 >a x>t y>t ; t6t>y t>x adrop ;
accept( str-- )t5 y! clr-buf
beginkey a!
a@ 13 = ift6 exitthen
a@ 27 = a@ 3 = or ifclr-buf t6 exitthen
a@ 8 = a@ 127 = or ifdel-chthen
a@ printable?ifa@ app-chthen
again;
q(quit)dirty?if." (use q! to quit without saving)" exitthenq! ;
wq(write and quit)w q! ;
ed-exec(A--)->cmd 3 state wc! outer ;
do-cmd ->cmd ':' emit cur-on cmd-buf accept cmd-buf ed-exec ;
yank-line yank-buf row 0 >pos s-cpy drop ;
put-line insert-line row 0 >pos yank-buf s-cpy drop dirty ;
next-blk w blk 1- 0 max ed! ; prev-blk w blk 1+ ed! ;
mv-tab-l 0 -8 mv ; mv-tab-r 0 8 mv ;
mv-cr 1 -99 mv ; mv-end! max-row 0 >row/col ;
yank/del yank-line delete-line ;
exec-line row 0 >pos ed-exec ;