1 \ SAVE-INPUT and RESTORE-INPUT
3 anew task-save-input.fth
7 : save-buffer ( -- column source-id 2 ) >in @ source-id 2 ;
9 : restore-column ( column -- flag )
16 \ Return the file-position of the beginning of the current line in
17 \ file SOURCE-ID. Assume that the current line is stored in SOURCE
18 \ and that the current file-position is at an end-of-line (or
20 : line-start-position ( -- ud )
21 source-id file-position throw
22 \ unless at end-of-file, subtract newline
23 source-id file-size throw 2over d= 0= IF 1 s>d d- THEN
24 \ subtract line length
28 : save-file ( column line filepos:ud source-id 5 -- )
36 : restore-file ( column line filepos:ud -- flag )
37 source-id reposition-file IF 2drop true exit THEN
38 refill 0= IF 2drop true exit THEN
43 : ndrop ( n*x n -- ) 0 ?do drop loop ;
48 \ EVALUATE >IN SourceID=(-1) 2
49 \ keyboard >IN SourceID=(0) 2
50 \ file >IN lineNumber filePos SourceID=(fileID) 5
51 : SAVE-INPUT ( -- column {line filepos}? source-id n )
53 -1 of save-buffer endof
54 0 of save-buffer endof
59 : RESTORE-INPUT ( column {line filepos}? source-id n -- flag )
60 over source-id <> IF ndrop true exit THEN
63 -1 of restore-column endof
64 0 of restore-column endof
65 drop restore-file exit