support moving by word

This commit is contained in:
~d6 2022-04-06 23:26:07 -04:00
parent f1f8c97537
commit 397d60693b
1 changed files with 48 additions and 14 deletions

View File

@ -44,14 +44,13 @@
( - help text ) ( - help text )
( - open file command? ) ( - open file command? )
( - close file command? ) ( - close file command? )
( - move by word/paragraph )
( - search&replace ) ( - search&replace )
|00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 ] |00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 ]
|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ] |10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ]
|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] |a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ]
( MAX file size is currently #c950, i.e. 51536 bytes ) ( MAX file size is currently #d000, i.e. 53248 bytes )
%dbg { #ff .System/debug DEO } %dbg { #ff .System/debug DEO }
%emit { .Console/write DEO } %emit { .Console/write DEO }
@ -87,7 +86,6 @@
%emit-~ { LIT2 '~ 18 DEO } %emit-~ { LIT2 '~ 18 DEO }
%quit! { #01 .System/halt DEO BRK } %quit! { #01 .System/halt DEO BRK }
%lmargin { #0006 } %lmargin { #0006 }
( zero page ) ( zero page )
@ -194,7 +192,7 @@
( the interpreter to halt. ) ( the interpreter to halt. )
@error! ( msg* -> ) @error! ( msg* -> )
emit-! sp emit-! sp
&loop LDAk #00 EQU ,&done JMP &loop LDAk #00 EQU ,&done JCN
LDAk emit INC2 ,&loop JMP LDAk emit INC2 ,&loop JMP
&done POP2 nl dbg BRK &done POP2 nl dbg BRK
@ -205,7 +203,7 @@
( TODO: enable closing/opening files with editor already running ) ( TODO: enable closing/opening files with editor already running )
@open-file ( filename* -> ) @open-file ( filename* -> )
.File/name DEO2 .File/name DEO2
#c950 .File/length DEO2 #d000 .File/length DEO2
;data .File/read DEO2 ;data .File/read DEO2
.File/success DEI2 #0000 GTH2 ,&ok JCN .File/success DEI2 #0000 GTH2 ,&ok JCN
@ -318,18 +316,20 @@
;redraw-statusbar-and-cursor JSR2 ;redraw-statusbar-and-cursor JSR2
;return JMP2 ;return JMP2
( move forward by one character )
@forward ( -> ) @forward ( -> )
;go-forward JSR2 ;return JMP2
( move forward by one character )
@go-forward ( -> )
;cur-pos JSR2 ;last-pos JSR2 GTH2 ( ;return JCN2 ) ,&noop JCN
;redraw-statusbar-and-cursor JSR2 ;redraw-statusbar-and-cursor JSR2
;cur-pos JSR2 ;last-pos JSR2 GTH2 ;return JCN2
;cur-col JSR2 ;cur-len JSR2 LTH2 ,&normal JCN ;cur-col JSR2 ;cur-len JSR2 LTH2 ,&normal JCN
#0000 .cursor/col STZ2 #0000 .cursor/col STZ2
.cursor/row LDZ2 INC2 .cursor/row STZ2 .cursor/row LDZ2 INC2 .cursor/row STZ2
;ensure-visible-cursor JSR2 ;ensure-visible-cursor JMP2
;return JMP2
&normal &normal
;cur-col JSR2 INC2 .cursor/col STZ2 ;cur-col JSR2 INC2 .cursor/col STZ2
;return JMP2 &noop JMP2r
( move backward by one character ) ( move backward by one character )
@back ( -> ) @back ( -> )
@ -365,6 +365,40 @@
;redraw-statusbar-and-cursor JSR2 ;redraw-statusbar-and-cursor JSR2
;return JMP2 ;return JMP2
@is-word-char ( c^ -> bool^ )
DUP #2f GTH OVR #3a LTH AND STH
DUP #40 GTH OVR #5b LTH AND STH ORAr
DUP #60 GTH SWP #7b LTH AND STHr ORA JMP2r
@not-word-char ( c^ -> bool^ )
;is-word-char JSR2 #00 EQU JMP2r
@forward-by-word ( -> )
;cur-pos JSR2
&first
LDAk #00 EQU ,&done JCN
LDAk ;is-word-char JSR2 ,&second JCN
INC2 ;go-forward JSR2 ,&first JMP
&second
LDAk #00 EQU ,&done JCN
LDAk ;not-word-char JSR2 ,&done JCN
INC2 ;go-forward JSR2 ,&second JMP
&done
POP2 ;return JMP2
@back-by-word ( -> )
;cur-pos JSR2 #0001 SUB2
&first
DUP2 ;data LTH2 ,&done JCN
LDAk ;is-word-char JSR2 ,&second JCN
#0001 SUB2 ;go-back JSR2 ,&first JMP
&second
DUP2 ;data LTH2 ,&done JCN
LDAk ;not-word-char JSR2 ,&done JCN
#0001 SUB2 ;go-back JSR2 ,&second JMP
&done
POP2 ;return JMP2
( center buffer view on the current line ) ( center buffer view on the current line )
@center-view @center-view
.term/rows LDZ2 INC2 #0002 DIV2 STH2k .term/rows LDZ2 INC2 #0002 DIV2 STH2k
@ -786,14 +820,14 @@
( ) ( )
( called by on-key with state/saw-esc is true ) ( called by on-key with state/saw-esc is true )
( ) ( )
( TODO: M-f and M-b for next/previous word ) ( TODO: maybe M-% for search&replace )
( M-n and M-p for next/previous paragraph )
( maybe M-% for search&replace )
@on-key-escaped ( -> ) @on-key-escaped ( -> )
#00 .state/saw-esc STZ #00 .state/saw-esc STZ
.state/key LDZ LIT '< EQU ( M-< ) ;goto-start JCN2 .state/key LDZ LIT '< EQU ( M-< ) ;goto-start JCN2
.state/key LDZ LIT '> EQU ( M-> ) ;goto-end JCN2 .state/key LDZ LIT '> EQU ( M-> ) ;goto-end JCN2
.state/key LDZ LIT 'b EQU ( M-b ) ;back-by-word JCN2
.state/key LDZ LIT 'c EQU ( M-c ) ;toggle-color JCN2 .state/key LDZ LIT 'c EQU ( M-c ) ;toggle-color JCN2
.state/key LDZ LIT 'f EQU ( M-f ) ;forward-by-word JCN2
.state/key LDZ LIT 'g EQU ( M-g ) ;goto-line JCN2 .state/key LDZ LIT 'g EQU ( M-g ) ;goto-line JCN2
.state/key LDZ LIT 's EQU ( M-s ) ;regex-search JCN2 .state/key LDZ LIT 's EQU ( M-s ) ;regex-search JCN2
.state/key LDZ LIT 't EQU ( M-t ) ;toggle-tabs JCN2 .state/key LDZ LIT 't EQU ( M-t ) ;toggle-tabs JCN2
@ -1550,4 +1584,4 @@
@filename $80 @filename $80
( actual file data to be edited ) ( actual file data to be edited )
@data $c950 @data $d000