bled : a dvorak-oriented fork of the retro editor
Table of Contents
1 keymap
Key | Action |
---|---|
c | Move cursor up |
h | Move cursor left |
t | Move cursor down |
r | Move cursor right |
e | Evaluate current block |
E | Evaluate all blocks |
m | Move cursor to start of next line |
C | Move cursor to top line of block |
H | Move cursor to start of current line |
T | Move cursor to last line of block |
S | Move cursor to end of current line |
M | Center cursor on current line |
z | Exit RxE |
Esc | Switch between edit and command mode |
{ | Load "blocks" |
} | Save "blocks" |
[ | Switch to previous block |
] | Switch to next block |
2 implementation
2.1 variables, etc.
: 2/ 1 >> ; 64 constant cols 16 constant rows cols rows * constant blksz variables| buffer count | : restore ( - ) &getc :devector ok ; : get ( -c ) @buffer @ ; : next ( -c ) @count [ count -- get buffer ++ ] [ 32 restore ] if ; : replace ( - ) &next &getc :is ; : eval ( an- ) !count !buffer replace ; variables| #blocks offset blk line column mode active | : toBlock blksz * @offset + ; : thisBlock @blk toBlock ; : toLine cols * thisBlock + ;
2.2 check boundaries
( check boundaries ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ) : top ( - ) 0 !line ; : bot ( - ) rows 1- !line ; : beg ( - ) 0 !column ; : end ( - ) cols 1- !column ; : mid ( - ) rows 2/ !column ; : 1st ( - ) 0 !blk ; : bounds ( - ) @column -1 = [ end line -- ] ifTrue @column cols = [ beg line ++ ] ifTrue @line -1 = [ top blk -- ] ifTrue @line rows = [ bot blk ++ ] ifTrue @blk -1 = [ 1st ] ifTrue @blk @#blocks >= [ blk -- ] ifTrue ;
2.3 display a block
( display a block ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ) : ds/rows rows [ dup cols [ @ putc ] ^types'BUFFER each@ cols + cr ] times ; : mode? @mode [ "INS" ] [ "CMD" ] if ; : .block @column @line @blk mode? "(%s) #%d - %d:%d " puts ; : bar cols [ '- putc ] times cr ; : vb @blk toBlock ds/rows drop bar .block ; ( visualize block ? ) : (v) ( - ) clear vb ; : pos ( -cl ) @column @line ; : get ( cl-a ) toLine + ; : va ( a-va ) dup @ swap ; : c! ( a- ) '* swap ! ; : show ( va- ) dup c! (v) ! ; : display ( - ) bounds pos get va show ;
2.4 input processing
( input processing ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ) 27 constant Esc : advance? ( - ) line ++ @line rows >= [ 0 !line blk ++ ] ifTrue 0 !column ; : del ( - ) @column dup [ dup cols = [ drop !column display 0 ] [ 32 over @line get ! 1+ -1 ] if ] while ; : remap ( c-c ) dup 9 = [ drop Esc ] ifTrue dup 13 = [ drop 0 ] ifTrue dup 10 = [ drop 0 advance? display ] ifTrue ; : input ( - ) repeat display @mode 0; drop getc 0; dup Esc <> 0; drop dup 8 = [ drop column -- display ] [ pos get ! column ++ ] if again ; : rxe.in ( -c ) mode on remapping [ remapping off input ] preserve mode off ; : match ( c- ) "$$_" dup [ 2 + ! ] dip find [ @d->xt do ] &drop if ; : edit? ( c-c ) dup Esc = [ rxe.in drop ] ifTrue ;
2.5 various support bits
( various support bits ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ) : new ( - ) @offset 32 blksz @#blocks * fill ; : e ( - ) thisBlock blksz eval ; : ea ( - ) @offset @#blocks blksz * eval ; : run ( - ) active on &remap &remapKeys :is clear [ display getc edit? match @active ] while &remapKeys :devector ; : min-wh ( -nn ) rows 2 + cols ;
3 public interface
: setBlocks ( n- ) !#blocks here blksz @#blocks * allot !offset new ; : edit ( - ) min-wh push push @ch pop >= @cw pop >= and &run [ min-wh swap "requires an " puts putn "x" puts putn "or greater display, sorry!\n" puts ] if ;
4 keymap
( dvorak keymap ) : $$c line -- ; : $$C top ; : $$h column -- ; : $$H beg ; : $$t line ++ ; : $$T bot ; : $$n column ++ ; : $$N end ; : $$m $$t beg ; : $$M mid ; : $$d del ; : $$[ blk -- ; : $$] blk ++ ; : $${ @offset "blocks" ^files'slurp drop ; : $$} @offset @#blocks @blksz * "blocks" ^files'spew drop ; : $$e active off e ; : $$E active off ea ; : $$z active off ;
5 OUTPUT bled.rx
needs files' chain: editor' {{ <<private>> ---reveal--- <<public>> }} 128 setBlocks ;chain global with editor'