-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathediwind.fs
More file actions
364 lines (338 loc) · 10.3 KB
/
ediwind.fs
File metadata and controls
364 lines (338 loc) · 10.3 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
\ editor also 21dec97py
dos also
[defined] win32api [IF] win32api also [THEN]
[defined] xconst [IF] xconst also [THEN]
MINOS also editor
AVariable 'edifile0
[defined] forth.fb [IF] & forth.fb cell+ 'edifile0 ! [THEN]
Variable 'scr0 1 'scr0 !
Variable 'r#0 0 'r#0 !
Variable uclose uclose off
Variable edit-o
Variable do-done do-done off
Variable closing closing off
[defined] VFXforth [IF]
also Forth definitions
defer (block
defer convey
:noname true abort" VFX doesn't support blocks!" ;
dup is (block
dup is convey
drop
$10 Value l/s
c/l l/s * Value b/blk
: capacity 2 ;
: (view drop 0 ;
Variable caps
Variable loadfile
Variable fpos
Variable isfile
Variable r#
: isfile@ isfile @ ;
: .file ( file -- ) drop ;
: open ( -- ) ; \ dummy
: close ( -- ) ; \ dummy
: -eof? ( -- flag )
loadfile @ file-position throw
loadfile @ file-size throw d< ;
: readline ( buffer maxlen -- len )
loadfile @ read-line throw drop ;
: !files isfile ! ;
: purgebuf ;
: save-buffers ;
: more ( n -- ) drop ;
: searchfile ( file -- string ) ;
: str? ( file -- flag ) drop true ;
: (#load ( n >in -- ) 2drop isfile@ include-file ;
: (load 2drop true abort" VFX doesn't support blocks!" ;
editor definitions previous
Defer edicatch
[ELSE]
: purgebuf prev @ emptybuf ;
forward edicatch
[THEN]
0 AValue (scraction
forward ev-key
forward done
forward ?stamp
forward scr:view
terminal class scredit
public:
cell var edifile
cell var 'edifile
cell var scr#
cell var r#
cell var 'scr
cell var 'r#
cell var retscr
cell var actiontable
ptr shadowscr
ptr next-buffer
terminal ptr callwind
window ptr win-title
early scrslide
early !scr
early >shadow
early !window
method updated?
method update$
method title$
method .line
method slided
method showerror
class;
scredit ptr edit-buffer
scredit implements
: >shadow ( n1 n -- n2 ) dup 1 and
IF over 0= IF drop EXIT THEN 2/ 2dup > 0=
ELSE 2/ 2dup < THEN IF + ELSE - THEN ;
: 'start ( -- addr ) scr# @ edifile @ (block ;
: add-to-buffer ( -- )
edit-buffer self bind next-buffer
self F bind edit-buffer ;
: init ( action file -- )
term self bind callwind
edifile ! actiontable ! c/l l/s super init
'edifile0 @ 'edifile ! 'scr0 @ 'scr ! 'r#0 @ 'r# !
F r# @ pos ! scr @ scr# !
^ edit-o ! add-to-buffer ;
[defined] VFXForth [IF]
: updated? false ;
: update$ s" not modified" ;
: title$ ( -- addr u )
base push decimal
S" Scr # " scratch$ $!
scr# @ 0 <<# bl hold # # #S #> scratch$ $+! #>>
scratch$ $@ ;
[ELSE]
: updated? ( -- f ) 'start 4- @ $14 + wx@ 0< ;
: update$ ( -- string ) updated? 0=
IF S" not modified" EXIT THEN S" modified" ;
: title$ ( -- addr u )
base push decimal
edifile @ filename >len scratch$ $!
S" Scr # " scratch$ $+! scr# @ 0 <<# bl hold # # #S #> scratch$ $+! #>>
update$ scratch$ $+!
scratch$ $@ ;
[THEN]
: !window bind win-title ;
: (slided ( -- )
draw win-title self IF title$ win-title title! THEN
& viewport @ dpy class?
IF dpy self viewport with hspos self
IF hspos draw THEN endwith THEN ;
: slided ( -- )
(slided shadowscr self
IF scr# @ capacity >shadow shadowscr scr# !
shadowscr with (slided endwith
THEN ;
: showerror ( addr -- )
title$ >r >r s" *** " $add count $add
r> r> win-title self IF win-title title!
ELSE 2drop THEN ;
: scrslide self
TS[ isfile push edifile @ isfile ! scr# ! ?stamp slided
][ isfile push edifile @ isfile ! capacity 1 scr# @ ]TS
;
: close
shadowscr self
IF 0 shadowscr bind shadowscr 0 bind shadowscr THEN
do-done @ do-done off
closing push closing @ closing on or
0= IF edicatch false c" closed" done EXIT THEN
dpy close ;
: !scr edifile @ isfile ! scr# @ scr ! pos @ r# ! ;
: type super type update ;
: scrollup pos @ b/blk mod pos ! ;
: .line ( y -- ) >r at? r> 0 at
pos @ 'line c/l showtext at ;
: keyed ( key sh -- )
dup $40 and IF drop $100 /mod swap at EXIT THEN
$-13 and over shift-keys? IF 2drop EXIT THEN
dup 2 and IF swap tolower swap THEN
!scr $D and ev-key ;
: clicked ( x y b n -- ) dup >r super clicked
r> 4 = IF edicatch scr:view THEN ;
: dispose ( -- )
F link edit-buffer
BEGIN dup @ ^ <> WHILE
dup @ 0<> WHILE
@ >o link next-buffer o> REPEAT THEN
next-buffer self swap ! super dispose ;
class;
menu-entry class edimenu-entry
cell var item
how:
Variable action#
: do-action
scredit !scr edicatch
scredit actiontable @ action# @ cells +
perform ;
: menu-action
window innerwin self
viewport with child with
& combined @ class?
IF combined childs self op! THEN
do-action
endwith endwith ;
: clicked ( x y b n -- )
dup 0= IF 2drop 2drop EXIT THEN
super clicked item @ action# ! ;
: init ( n addr count -- )
^^ ['] menu-action simple new -rot super init item ! ;
class;
viewport class scrviewport
& child scredit asptr screen-edit
how:
: 'hslide screen-edit scrslide ;
: hglue super hglue + 0 ;
: scr#+! ( n -- ) screen-edit with
scr# @ + 0 max edifile @ isfile ! capacity 1- min
scr# ! slided endwith ;
: clicked ( x y b n -- )
over $18 and over 1 and 0= and IF \ scroll
over $10 and IF 1 scr#+! THEN
over $08 and IF -1 scr#+! THEN
over $18 and IF slided THEN
2drop 2drop
ELSE super clicked THEN ;
\ backing :: keyed
class;
: (menu" edimenu-entry new ;
: menu" '"' parse postpone SLiteral postpone (menu" ; immediate restrict
: (label" menu-label new ;
: label" '"' parse postpone SLiteral postpone (label" ; immediate restrict
: file-menu: ( -- o )
label" File System"
0 menu" Use File... &M-u"
1 menu" Make File... &M-m"
2 menu" Kill File... &M-k"
4 menu" Save &M-w"
label" Folders"
3 menu" Make Dir..."
label" Leave Editor"
6 menu" cancel changes &Esc"
8 menu" close window &C-x"
7 menu" save and leave &C-s"
9 menu" save and load &C-l"
#12 vabox new 2 borderbox ;
: edit-menu: ( flag -- o ) >r
#10 menu" Undo &C-z"
label" Searching"
#53 menu" Find &C-f"
#54 menu" Repeat &C-r"
label" Write mode"
#55 menu" Insert &C-i"
#56 menu" Overwrite &C-o"
label" Author"
#57 menu" Get ID... &C-g"
r> IF
label" Line"
#58 menu" Set Length &M-l"
#60 menu" Stamp &M-s"
#12 ELSE
#09 THEN
vabox new 2 borderbox ;
: screen-menu: ( -- o )
#12 menu" Next Scr &C-n"
#13 menu" Back Scr &C-b"
#16 menu" Shadow Scr &C-w"
#17 menu" Jump to Mark &C-a"
#18 menu" Jump to Scr... &C-j"
#19 menu" View... &C-v"
label" don't move"
#20 menu" Clear Scr &M-c"
#21 menu" Insert Scr &M-i"
#22 menu" Delete Scr &M-d"
#23 menu" Set Mark &C-m"
#11 vabox new 2 borderbox ;
: line-menu: ( -- o )
label" wag Tail of Scr"
#28 menu" Backspace Line &S-bs"
#29 menu" Delete Line &S-del"
#30 menu" Insert Line &S-ins"
#32 menu" Split Line &S-ret"
#34 menu" Linefeed &C-ret"
#24 menu" Cut to Stack &S-up"
#25 menu" Paste from Stack &S-down"
label" don't wag Tail of Scr"
#26 menu" Copy to Stack &C-down"
#31 menu" Erase Line &C-e"
#27 menu" Erase Line-rest &C-del"
#12 vabox new 2 borderbox ;
: char-menu: ( -- o )
label" wag Tail of Line"
#37 menu" Cut to Stack &S-left"
#38 menu" Paste from Stack &S-right"
label" don't wag Tail of Line"
#39 menu" Copy to Stack &C-right"
5 vabox new 2 borderbox ;
: cursor-menu: ( -- o )
label" move Cursor quick"
#51 menu" Home &home"
#52 menu" > Text-End &S-home"
#49 menu" 1/4 Line > &tab"
#50 menu" 1/8 Line < &S-tab"
5 vabox new 2 borderbox ;
: window-menu: ( -- o )
label" Open"
#59 menu" Duplicate &M-o"
#60 menu" Shadow &M-s"
3 vabox new 2 borderbox ;
: make-menu ( flag -- o )
>r ^ to ^^
file-menu: s" File " menu-title new
r@ edit-menu: s" Edit " menu-title new
screen-menu: s" Screen " menu-title new
line-menu: s" Line " menu-title new
char-menu: s" Char " menu-title new
cursor-menu: s" Cursor " menu-title new
r> IF 6
ELSE window-menu: s" Window " menu-title new 7 THEN
2fill swap 1+
hbox new vfixbox ;
: scredi-menu ( -- o ) false make-menu ;
: stredi-menu ( -- o ) true make-menu ;
: wi_open ( -- )
screen self menu-window new menu-window with
scredi-menu
1 1 scrviewport new scrviewport with
(scraction isfile@ scredit new dup >r
assign ^ r> endwith
^ swap scredit with
!window title$ endwith
assign c/l l/s geometry show
endwith ;
\ window shortcuts 02jul94py
| : pos scredit pos ; hmacro
: cur ( -- n ) pos @ ; macro
: c ( n -- ) dup cur + b/blk 0 within
abort" Border!" scredit c ;
: updated? scredit updated? ;
: curup c/l negate c ;
: curdown c/l c ;
: cursize scredit 'start cur + dup xchar+ swap - ;
: curleft scredit 'start cur + dup xchar- swap - c ;
: currite cursize c ;
: 'start scredit 'start ;
\ print buffers 27dec99py
| : .edit-buffers ( -- )
edit-buffer self
BEGIN dup WHILE cr
scredit with edifile @ .file next-buffer self endwith
REPEAT drop ;
: search-buffer ( -- o / 0 )
edit-buffer self
BEGIN dup WHILE
scredit with
next-buffer self
edifile @ isfile @ = self and
endwith ?dup IF nip EXIT THEN
REPEAT drop 0 ;
[defined] x11 [IF]
: mousexy! ( x y -- ) 2>r
window xrc dpy @ 0 window xwin @ 0 0 0 0 2r>
XWarpPointer ;
[ELSE]
: mousexy! 2drop ;
[THEN]