-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathedit.fs
More file actions
650 lines (535 loc) · 22 KB
/
edit.fs
File metadata and controls
650 lines (535 loc) · 22 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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
/* *** Streamfile-Editor *** 01sep97py
Wie versprochen, ist hier ein voll in den Screen-Editor
eingebundener Streamfile-Editor.
Seine Features:
* Volle Tastaturkomptibilitaet
* Views aus dem Editor (auch auf im Screenfile definierte
Woerter)
Seine Nachteile:
* Nur bedingt zum Editieren von "normalen" Texten geeignet
Da ich nach wie vor Screen-Befuerworter bin, ist diese Datei
auch wie eine Screenfile formatiert, wenn auch die logischen
Einheiten nicht alle gleich lang sind. Auf alle Faelle laesst
man sich seltener hinreissen, neue logische Einheiten zu
erzeugen, da es so einfach ist, eine neue physikalische (die
Zeile) aufzumachen. */
\ Datenstrukturen 27apr91py
\ Textzeile: { NextMP | PrevMP | count.b | Text.count }
\ Allokiert wird in 16-er Schritten, angefangen bei 12 Bytes
\ fuer kurze Zeilen...
\ Stream editor widget 01sep97py
forward ?clearbuffer
Variable do!schib
Variable :done
[defined] ?head [IF] ?head @ ?head off [THEN]
scredit class stredit
\ early !cursor
public:
cell var thisline
cell var changed
cell var thisline#
early pos@
early pos!
early pos+!
early line#@
early line#!
early line#+!
early dump
early add
early maketitle
class;
[defined] ?head [IF] ?head ! [THEN]
stredit implements
Variable drawbuf
: pos@ pos @ cols @ modf ;
: pos! pos @ cols @ /f cols @ * + pos ! ;
: pos+! pos +! pos @ 0 max pos ! ;
: line#@ pos @ cols @ /f 1+ ;
: line#! 1- pos @ cols @ modf swap cols @ * + pos !
line#@ thisline# ! ;
: line#+! cols @ * pos+! line#@ thisline# ! ;
class;
: cur stredit postpone pos@ ; immediate
: pos! stredit postpone pos! ; immediate
: pos+! stredit postpone pos+! ; immediate
: line#@ stredit postpone line#@ ; immediate
: line#! stredit line#! do!schib on ;
: line#+! stredit line#+! do!schib on ;
: thisline# stredit postpone thisline# ; immediate
\ Zeile löschen, verschieben und einfügen 07may91py
: (DelLine ( lineMP -- ) @
dup 2@ dup IF @ cell+ ! ELSE 2drop THEN
2@ swap dup IF @ ! ELSE 2drop THEN ;
: MoveLine ( lineMP thisMP -- ) >r dup (DelLine
r@ @ @ ?dup IF over @ ! THEN r@ over @ cell+ !
dup r> @ !
dup @ @ dup IF @ cell+ ! ELSE 2drop THEN ;
: AddLine ( lineMP thisMP -- ) >r dup (DelLine
r@ @ cell+ @ ?dup IF over @ cell+ ! THEN
r@ over @ ! dup r> @ cell+ !
dup @ cell+ @ dup IF @ ! ELSE 2drop THEN ;
: thisline stredit postpone thisline ; immediate
: retscr stredit postpone retscr ; immediate
: retbuf stredit postpone start ; immediate
: MakeLine ( -- MP ) $18 NewHandle dup @ $18 erase ;
: (InsLine ( MP -- ) thisline @
dup 0= IF drop thisline ! ELSE MoveLine THEN ;
: InsLine ( -- ) MakeLine (InsLine ;
\ Zeile setzen 29apr91py
: Lalign ( len -- alen ) $-4 cells and 8 cells + ;
: (Line! ( addr len -- MP )
( pad place pad count ) dup Lalign NewHandle >r
( dup pos! ) r@ @ cell+ cell+ place 0. r@ @ 2!
0 r@ @ cell+ cell+ count + c! r> ;
: Line! ( addr len -- ) (Line! (InsLine ;
\ Zeile löschen 27apr91py
[defined] VFXForth [IF]
: (thisline! ( MP / 0 -- )
dup IF thisline ! EXIT THEN drop rdrop ; DoNotSin
: thisline! postpone (thisline! discard-sinline ; immediate
[ELSE]
: thisline! ( MP / 0 -- )
dup IF thisline ! EXIT THEN drop rdrop ;
[THEN]
: NextLine ( -- ) thisline @ @ @ thisline! 1 line#+! ;
: PrevLine ( -- ) thisline @ @ cell+ @ thisline! -1 line#+! ;
: +lines ( n -- lineMP ) dup 0= IF drop thisline @ EXIT THEN
>r thisline @ dup 0= IF rdrop EXIT THEN
r> dup thisline# @ 1- + over 0<
IF 0 min - negate 0 ?DO @ cell+ @ LOOP
ELSE stredit rows @ - 0 max - 0 ?DO @ @ LOOP
THEN ;
\ Text löschen 29apr91py
: Top ( -- ) \ 0 0 stredit at ;
thisline @ 0= ?EXIT thisline @
BEGIN dup @ cell+ @ dup WHILE nip REPEAT drop thisline!
1 line#! 0 pos! do!schib on ;
: Bottom ( -- ) \ stredit rows @ 1- 0 stredit at
thisline @ 0= ?EXIT thisline @ 0
BEGIN >r dup @ @ dup WHILE nip r> 1+ REPEAT
drop thisline! r> line#+!
thisline @ @ 8+ c@ pos! do!schib on ;
: DelText ( -- ) thisline @ 0= ?EXIT Top thisline @
BEGIN dup @ @ >r DisposHandle r> dup 0= UNTIL
drop thisline off ;
\ Streamfile sichern 06may91py
$2000 Constant sbuf# \ A long buffer for fast saving
Create CRLF 1 c, #lf c,
Variable epos
: SaveLine ( addr len MP handle -- ) >r >r
BEGIN r@ @ sbuf# epos @ safe/string 2 pick over > WHILE
3 pick rot 2 pick move epos off
r> dup @ sbuf# r@ write-file throw
>r safe/string REPEAT
drop swap dup epos +! move rdrop rdrop ;
\ Save Text 12may91py
: saveText ( -- )
thisline push loadfile push
line#@ >r cur >r
stredit edifile @ >r epos off
[defined] filehandle [IF]
r@ filehandle @ 0< IF r@ r/w (open throw THEN
[THEN]
0. r@ resize-file throw
sbuf# NewHandle >r Top thisline @
BEGIN dup WHILE dup @ 8+ count r> r> 2dup >r >r
SaveLine CRLF count r> r> 2dup >r >r SaveLine
@ @ REPEAT drop
r> dup @ epos @ r@ write-file >r epos off
DisposHandle r> r> flush-file
r> pos! r> line#! throw throw
stredit changed off do!schib on ;
\ Aktionen auf thisline 27apr91py
: LineLen ( -- len ) stredit cols @ 1- ;
Variable ?reformat
Forward FormatPar
: enough? ( len -- ) LineLen > ?reformat ! ;
: Line@ ( -- addr count ) thisline @ @ 8 + count ;
: SetLineLen ( len -- ) dup enough?
Lalign dup thisline @ @ 8 + c@ Lalign
<> IF thisline @ over SetHandleSize THEN drop
0 Line@ + c! ;
: +LineLen ( addlen -- ) thisline @ @ 8 + c@ + SetLineLen ;
: Liner@ ( -- addr count ) Line@ cur safe/string ;
: 'cursor ( -- addr ) Liner@ drop ;
: LineLen+! ( n -- ) >r thisline @ @ 8+ dup c@ r> + swap c!
0 Line@ + c! ?reformat @ IF FormatPar THEN ;
\ Mausknopfreaktion 10may91py
: +#Line ( n -- ) line#@ + stredit rows @ min
dup line#@ - +lines thisline! line#! ;
: mark! scredit 'r# ! scredit 'scr ! scredit 'edifile ! ;
: (mark isfile@ scr @ cur mark! ;
: (mark line#@ scr ! cur r# ! (mark ;
: str:view ( -- ) Line@ cur 2dup >
IF stredit curoff (mark word@ find! >view !view
stredit curon
ELSE 2drop drop THEN ;
: ins+ ( n -- )
stredit 'scr @ line#@ > IF dup stredit 'scr +! THEN
stredit rows +!
\ stredit child hmin +!
\ stredit child hmin @ stredit sh @ max stredit rows !
stredit resized ;
\ stredit implementation
stredit implements
: at ( r c -- ) curoff super at
line#@ thisline# @ - +lines thisline !
line#@ thisline# ! curon ;
: 'line ( n -- addr u ) cols @ /modf swap >r
thisline# @ 1- - +lines @ 8+ count r> safe/string ;
: .line ( -- )
pos@ >r 0 pos!
pos @ 'line cols @ showtext r> pos! ;
\ click and mark selection 27feb95py
: :view ( -- ) edicatch str:view ;
: paste-selection ( addr u -- ) bounds
selection HLock
?DO I c@ #lf case? IF $0D 1 ELSE 0 THEN
keyed pause LOOP
selection HUnLock ;
\ resize, glue and title$ 24may94py
: updated? changed @ ;
: title$ ( -- string ) s" " scratch$ $! edifile @ ?dup
IF [defined] filename [IF] filename >len scratch$ $+!
[ELSE] drop [THEN] THEN
S" Line # " scratch$ $+! base push decimal
line#@ 0 <<# bl hold # # # #S #> scratch$ $+! #>>
update$ scratch$ $+! scratch$ $@ ;
: maketitle edifile @ 0= ?EXIT
title$ dpy get-dpy window with title! endwith
do!schib off ;
\ Streamfile scannen 29apr91py
: dump ( xt -- ) line#@ >r pos@ >r thisline @ >r >r
Top thisline @
BEGIN dup WHILE
dup @ 8+ count r@ execute @ @ REPEAT
drop rdrop r> thisline ! r> pos! r> line#! ;
: add ( addr u -- ) Line! NextLine 1 rows +! ;
| Create readbuf $100 allot
| Create readbuf' $200 allot
: un-tab ( addr u -- addr' u' )
0 -rot bounds
?DO I c@ #tab = IF dup 8 + -8 and tuck swap
?DO bl readbuf' I + c! LOOP
ELSE I c@ over readbuf' + c! 1+ THEN
LOOP readbuf' swap ;
: loadText ( -- linelen #lines ) DelText
$100 cols ! 1 line#!
edifile @ dup isfile ! loadfile ! fpos off open c/l 0
BEGIN -eof? WHILE
dup $3F and $3F = IF pause THEN
readbuf dup $100 ReadLine dup $100 =
IF 3 FOR over c/l -trailing add
c/l safe/string NEXT 2drop 4+
ELSE un-tab
dup >r add 1+ swap r> max swap THEN
REPEAT
dup 0= IF scratch 0 Line! 1+ THEN
Top F close changed off ;
\ loadText jedenfalls liest so problemlos auch Screenfiles ein..
: assign ( file -- )
?dup 0= IF $100 1 terminal :: assign EXIT THEN
edifile @ IF edifile @ close-file throw THEN
edifile !
next-buffer self 0= IF add-to-buffer THEN
'edifile0 @ 'edifile ! 'scr0 @ 'scr ! 'r#0 @ 'r# !
F r# @ pos! scr @ scr# !
^ edit-o !
loadText rows ! 1+ cols !
gotoline ;
: init ( action -- )
term self bind callwind
actiontable ! 0 super super init
$31415926 retscr ! 1 line#! 1 thisline# !
0 pos! 0 rows ! ?clearbuffer ;
: dispose ( -- )
updated? edifile @ and IF changed off SaveText THEN
DelText line#@ super dispose invert scr ! ;
: keyed ( kb sh -- ) super keyed
do!schib @ IF maketitle THEN ;
: clicked ( x y b n -- ) dup >r super super clicked
r> 4 = IF :view THEN maketitle ;
: close ( -- ) super close do!schib off ;
class;
\ Einfügen 07may91py
: InsChar ( char -- ) dup xc-size >r
r@ +LineLen Liner@ over dup r@ + rot move xc!+ drop r> LineLen+! ;
: InsString ( addr count -- ) dup +LineLen
Liner@ >r tuck 2dup + r> move dup >r move r> LineLen+! ;
: InsSpaces ( len -- ) thisline @ @ 8+ c@ -
dup 0> IF dup +LineLen Line@ + over blank LineLen+!
ELSE drop THEN ;
: DelString ( count -- ) >r
Liner@ dup 0= IF rdrop 2drop EXIT THEN
>r dup r> r@ safe/string >r swap r> move
r> negate dup +LineLen LineLen+! ;
\ Zeile einfügen 09may91py
: >ret ( addr count -- ) retbuf @ place ;
: mod-on
stredit changed @ 0= IF do!schib on THEN
stredit changed on ;
: modify ( -- ) mod-on
line#@ retscr @ case? ?EXIT
retscr ! Line@ >ret ;
: lmodify ( -- ) modify retscr @ negate retscr ! ;
\ Line stack 11oct93py
Variable linebuffer
: ?line linebuffer @ 0= abort" line buffer empty" ;
: @line ( addr len -- ) (Line! dup
linebuffer @ ?dup IF AddLine ELSE drop THEN linebuffer ! ;
: !lineMP ( -- MP ) linebuffer @ dup @ @ linebuffer ! ;
: !line" ( -- addr len )
!lineMP dup (DelLine dup @ 8+ count pad place
DisposHandle pad count ;
\ Vorbereitung für Undo und Redo 01aug92py
\ Verlassen des Editors 30apr91py
: ??done ( -- ) stredit edifile @ 0= IF rdrop THEN ;
: edone ( tf string -- )
line#@ invert cur r# ! scr ! :done on done ;
: cdone ( -- ) ??done cancel-alert 1 = ?EXIT
stredit changed off false c" canceled" edone ;
: sdone ( -- ) ??done false c" saved" edone ;
: xdone ( -- ) ??done false stredit update$ pad place
pad edone ;
: ldone ( -- ) ??done true c" loading" edone ;
\ Cursorbewegung 04may91py
: curleft cur 0=
IF line#@ 1 = ?EXIT PrevLine Line@ nip pos!
ELSE liner@ drop dup xchar- swap - pos+! THEN ;
: currite cur LineLen >=
IF line#@ stredit rows @ = ?EXIT NextLine 0 pos!
ELSE liner@ drop dup xchar+ swap - pos+! THEN ;
\ Tabulator 07may91py
: curleft+ cur 0=
IF line#@ 1 = ?EXIT PrevLine LineLen 1- pos!
ELSE -1 pos+! THEN ;
: +tab ( -- ) $10 cur $10 modf - 0 ?DO currite LOOP ;
: -tab ( -- ) cur 8 modf negate dup 0= 8 * + negate
0 ?DO curleft+ LOOP ;
: b $F FOR PrevLine NEXT ;
: n $F FOR NextLine NEXT ;
: w line#@ 1- stredit rows @ stredit >shadow
line#@ - 1+ +#Line ;
: a stredit 'r# @ stredit 'scr @ (mark scr ! pos! gotoline ;
: mark (mark true abort" marked !" ;
: gotoline cur >r Top scr @ 1 max 1 ?DO NextLine LOOP
scr on r> pos! ;
\ Zeilen 07may91py
: linemodified stredit .line ;
: cr 0 pos! thisline @ @ @
0= IF pad 0 Line! 1 ins+ ( modified ) THEN
NextLine linemodified ;
: lineinsert ( line# -- ) drop scredit draw ;
: (linsert line#@ 1- lineinsert 1 ins+ stredit draw ;
: (split ( insspaces -- ) pad over blank dup pad +
liner@ >r swap r@ move pad over r@ +
cur >r Line! r> pos! r> DelString linemodified
cr pos! (linsert modify linemodified ;
: split 0 (split ;
: lfsplit cur (split ;
: InstLine MakeLine dup thisline @ AddLine thisline!
(linsert mod-on ;
\ Zeile löschen 09may91py
: ClrRight modify Liner@ nip negate dup +LineLen LineLen+!
LineModified ;
: ClrLine cur >r 0 pos! ClrRight r> pos! ;
: DelLine ( -- ) lmodify thisline @ dup @ @
dup 0= IF 2drop ClrLine EXIT THEN thisline!
dup (DelLine DisposHandle -1 ins+ stredit draw ;
: BackLine ( -- ) thisline @ @ cell+ @ 0= ?EXIT
PrevLine DelLine ;
\ Edi line handling 08may91py
: copyline line@ @line NextLine ;
: line>buf line@ @line DelLine ;
: !line !lineMP thisline @ AddLine
thisline @ @ cell+ @ thisline! stredit draw ;
: buf>line ?line line#@ 1- lineinsert cur >r !line
1 ins+ mod-on r> pos! ;
\ move part of the line by one char 30aug93py
: <char ; hmacro
: char> ; hmacro
\ (putchar del bs 01aug92py
: ((putchar ( char flag -- )
modify cur over invert - InsSpaces
IF char> InsChar ELSE 'cursor c! THEN
linemodified currite ;
: (putchar ( -- ) ?key imode @ ((putchar ;
: instchar ( -- ) bl true ((putchar curleft ;
: delchar ( -- ) Liner@ nip 0=
IF thisline @ @ @ 0= ?EXIT NextLine Line@ pad place
thisline @ @ @ 0=
IF thisline @ PrevLine thisline @ @ off
DisposHandle -1 ins+ true
ELSE DelLine PrevLine false THEN
cur InsSpaces pad count InsString
IF stredit draw ELSE LineModified THEN EXIT
THEN modify Liner@ drop dup xchar+ swap -
DelString 0 Liner@ + c! <char linemodified ;
: backspace ( -- ) pos @ 0= ?EXIT
curleft delchar ;
\ Character Stack 12may91py
: @char liner@ IF c@ ELSE drop bl THEN (@char ;
: copychar @char currite ;
: char>buf @char delchar ;
: buf>char ?chars 'chars 1- c@ true ((putchar
-1 #chars +! curleft ;
\ Wer suchet, der findet 13may91py
: find? ( -- n f ) 'find count dup liner@
rot over 1+ < IF 2swap 2over 2swap search >r nip - nip r>
ELSE 2drop 2drop 0. THEN ;
: s BEGIN find? IF 'find+ pos+! EXIT THEN drop
fscreen @ line#@ - ?dup
WHILE 0< IF PrevLine ELSE NextLine THEN 0 pos!
REPEAT <scrs> >last? IF >1st ELSE >last cell+ THEN
@ fscreen ! stredit show-you nofound ;
: r LineLen Line@ nip - 'insert c@ 'find c@ - < ?reformat !
'find c@ dup negate pos+! DelString
'insert count InsString stredit show-you linemodified
'insert c@ pos+! modify pause
?reformat @ IF FormatPar THEN ;
\ High level search and replace 13may91py
forward replace-it'
: >rep >cancel edicatch r s replace-it' ;
: >search >cancel edicatch s replace-it' ;
\ Replacing 03aug97py
: handle-replace ( x y -- )
screen self menu-frame new menu-frame with
noop-act 1 tributton new 1 habox new hfixbox
s" Replace?" text-label new 2 habox new
0 S[ >rep ]S S" Yes" button new dup >r
0 S[ >search ]S S" No" button new r> over >r >r
0 S[ >cancel ]S S" Cancel" button new
3 hatbox new hskip vskip
2 r> modal new 0 hskips 0 vskips 2 borderbox
( s" " ) assign show ( xwin @ grab )
focus r> widget with xywh endwith 2/ swap 2/ swap p+
2dup 1 0 clicked mousexy! endwith ;
: replace-it' ( -- )
?show_replace @ 0= IF BEGIN r s AGAIN EXIT THEN
pos push 'find c@ negate pos+!
stredit show-you stredit curpos stredit x @ stredit y @ p+
stredit dpy transback
stredit dpy dpy screenpos p+ ^ edit-o ! handle-replace ;
\ Editor's find and replace 26apr87py
: repfind ( -- ) edicatch
?findfirst fscreen @ stredit rows @ min fscreen !
<caps> @ caps ! s ?replace @ IF replace-it' THEN
stredit show-you stredit maketitle ;
: >find ( -- ) find-field get 'find place
insert-field get 'insert place
<some> @ 0= ?show_replace !
last-scr get drop 1st-scr get drop <scrs> 2!
<scrs> >last? IF cell+ THEN @ fscreen !
cancel caps push <caps> @ caps ! repfind ;
: >repl ( -- ) ?replace on >find ;
: button-field ( -- o w )
0 S[ cancel ]S s" Cancel" button new
0 S[ >find ]S s" Find:" button new dup >r
2 habox new hskip
0 S[ >repl ]S s" Replace with:" button new
2 vabox new vskip hfixbox r> ;
: text-button ( -- o w )
text-field button-field >r 2skip rot 3 habox new r> ;
: do_find ( -- ) ?replace off
S" Search and Replace" MODAL:
screen-field switch-field text-button 3 swap find-field self ;
: edifind ( -- ) (findbox on do_find ;
\ Put a stamp to the end of the line 14may91py
: stamp ( -- ) modify \ hide_c GEMcuroff
cur LineLen id 1+ c@ - dup InsSpaces pos!
liner@ nip DelString id 1+ count InsString
pos! linemodified ( GEMcuron 1 show_c ) ;
\ undo 01aug92py
: ret@ retbuf @ count ;
: undo retscr @ $31415926 = ?EXIT retscr @
0< IF ret@ @line buf>line EXIT THEN
retscr @ line#@ = 0= ?EXIT
cur >r 0 pos! ret@ pad place
line@ tuck >ret DelString
pad count InsString linemodified r> pos! ;
\ setmaxlen 17may91py
: !len textfield get cancel
drop 1+ stredit cols !
stredit resized ;
: setmaxlen S" Set Line Length" MODAL:
^ edit-o @ >o LineLen o> 0 SN[ ]SN
s" Line Length:" infotextfield new
2fill over S[ !len ]S s" OK " button new dup >r
2skip 3 pick S[ cancel ]S s" Cancel" button new
2fill 5 habox new 2 r> 0 ;
\ format 06oct93py
: concline ( addr1 n1 addr2 n2 -- addr1 n1+n2 )
dup >r 2over + swap move r> + ;
: inpar? ( addr count -- flag )
dup 0<= IF nip EXIT THEN 1- + c@ bl = ;
\ format 06oct93py
: extractlines ( addr n -- addr' n' ) LineLen >r
BEGIN dup r@ > WHILE
over r@ bl -scan dup 0= IF drop LineLen THEN
tuck (Line! thisline @ AddLine
1 line#+! safe/string
tuck pad 1+ swap move pad 1+ swap
REPEAT rdrop ;
: reformat ( -- -deleted ) pad 1+ 0 0 >r
BEGIN line@ concline line@ inpar? WHILE
thisline @ dup @ @ dup WHILE thisline!
dup (DelLine DisposHandle r> 1- >r extractlines
REPEAT 2drop THEN extractlines
0 pos! Line@ nip DelString InsString r> ;
: FormatPar ( -- ) cur >r line#@ >r reformat
line#@ r> - dup 0 ?DO PrevLine LOOP + ins+
r> dup pos! Line@ nip - dup
0>= IF NextLine pos! ELSE drop THEN
stredit draw ?reformat off ;
\ Table of actions 22apr91py
[defined] ?head [IF] ?head @ ?head off [THEN]
Create (straction
\ File
' UseFile A, ' MakeFile A, ' KillFile A, ' MakeDir A,
' saveText A, ' edibye A,
\ Exits
' cdone A, ' sdone A, ' xdone A, ' ldone A,
' undo A, ' undo A,
\ Screens
' n A, ' b A, ' n A, ' b A,
' w A, ' a A, ' jumpscreen A, ' do_view A,
' noop A, ' noop A, ' noop A, ' mark A,
\ Lines
' line>buf A, ' buf>line A, ' copyline A, ' clrright A,
' backline A, ' delline A, ' instline A, ' clrline A,
' split A, ' split A, ' lfsplit A, ' lfsplit A,
' FormatPar A,
\ Table of actions continue 18mar89py
\ Chars
' char>buf A, ' buf>char A, ' copychar A,
' backspace A, ' delchar A, ' instchar A,
' cr A, ' cr A,
\ Cursor
' Prevline A, ' NextLine A, ' curleft A, ' currite A,
' +tab A, ' -tab A, ' top A, ' bottom A,
\ Specials
' edifind A, ' repfind A, ' setimode A, ' clrimode A,
' do_getid A, \ DoKontrol ( ) do_copyr
( do_menuhelp mousehelp f1-10help ) ' setmaxlen A,
\ Windows
' noop A, ' stamp A, ' stamp A,
\ 8x8font 8x16font
' (putchar A,
\ open window 02jul94py
: opentwind ( -- )
screen self menu-window new menu-window with
stredi-menu
1 1 viewport new viewport with
(straction stredit new dup >r
0 1 *fil 2dup glue new
2 vbox new
assign ^ r> endwith
^ swap stredit with
bind win-title
isfile@ assign title$ endwith assign
edit-o @ stredit with 0 ins+ show-you endwith
c/l 1+ l/s 2* geometry show
endwith ;
: setup-edit ( addr n -- ) swap
stredit with s" " add 1+ cols ! ^ endwith ;
[defined] ?head [IF] ?head ! [THEN]