6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Mon May 20, 2024 7:53 pm

All times are UTC




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Mon Jul 20, 2015 11:34 am 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
Since the thread about screen editors in Forth resurfaced (viewtopic.php?f=9&t=2941), this might be a good time to ask if there is a general ASCII non--screen based editor in the language. Because I can't seem to find one (see viewtopic.php?f=9&t=2576 for more screen stuff, for example), and at some point I'm going to need one for the Übersquirrel.

My research and ideas so far, in case other people have the same problem at some point:

The standard text on the structure of editors seems to be "Data Structures for Text Sequences" by Charles Crowley (https://www.cs.unm.edu/~crowley/papers/sds.pdf). There is also "The Craft of Text Editing" by Craig A. Finseth (http://www.finseth.com/craft/) which uses (sigh) EMACS as an example. James Brown has a fantastic introduction to piece chains (http://www.catch22.net/tuts/piece-chains), one of the most highly recommended storage formats. There is a nice list of literature at http://texteditors.org/cgi-bin/wiki.pl? ... vision=197 I'm (very) slowly working my way through, as I am through http://www.guckes.net/vi/mirror/ediger_ ... ditor.html .

What I would like to have is something that is not screen based (this is the 21. century, and if I can't drive a flying car, at least I don't want to have to work in small units of text any more), will let me write texts in any reasonable length (say, up to the low mega-byte range, since I hope to have enough storage via SPI), and has auto-indent and undo as features (sad but true: Undo is really important in my life).

Based on what I have read so far, I'm currently thinking it might make more sense to create two editors: One "far future" editor that does all that and includes the kitchen sink, with the data saved in a more efficient but complex struture (piece chains or buffer gap) structures. The other one, the first one, is really small, so small that it fits into the Forth implementation, and really simple, and always there. The "Far Future Forth Editor" (FFFE -- 6502 pun intended) is something I'll be kicking around for a few years before anything happens; I don't have the background yet. The small editor should be a lot easier; I'm thinking of basing it on ed.

Wait! Come back! I can explain!

If you are a Windows person and are wondering about the howls of laughter: ed (https://en.wikipedia.org/wiki/Ed_(text_editor) ) is a line-based editor that has been included with Unix since 1971. It is really, really primitive, to the point where you have to retype the whole line you are editing, and is terse even for Unix (the error message for everything is "?"). It's main usefulness today is for shell scripting and being a smart-ass: Firing up ed is showing off.

But something ed-like fits the bill here wonderfully. Since it is line-orientated, we don't have to deal with text rendering and the complications of a full screen. We don't care at all about the screen, because ed was designed for paper teletypes. Also, we now have something we can put on the Forth stack: The line number. So we go from
Code:
2d
to delete line number 2 in ed to
Code:
2 d
in Forth. Spans don't work that way, of course, because we don't know how many elements on the stack are for the editor. So instead of
Code:
1,10d
we could use
Code:
1 10 dd
(note double d). This way, "1,2p" becomes "1 2 pp". Some things need to be changed, of course: ";" for the whole text will have to use the synonym "%", search is going to be difficult, and there is no way in hell I am implementing regular expressions, because this seems to be akin to summoning Cthulhu.

Internally, we structure the text as a doubly linked list of lines (horribly inefficient for longer texts, but it will work and is trivial to implement) and convert those to the actual address in memory with a word such as, well, LINE.
Code:
: line ( u -- addr )  ( ... does stuff ... ) ;
This gives us, say, a cell worth of line numbers. If our cell is 16 bits, we have 64k of lines max, and if each line is 256 byte max, this gives us -- surprise! -- 16 Mb as the theoretical maximal size of the text space, perfect for the 65816 (actual max size will be smaller of course because we have to fit the program etc in somewhere). Once we have the address where the line starts, we can do all sorts of things and can have the file located anywhere in memory, not only at the page or block boundries.

Oh, and since we're using Forth, we can easily beat ed in one feature: Instead of having to retype the whole line for changes (which my experiments with ed now allow me to confidently say sucks beyond belief), we should be able to just load it into the normal input line buffer and manipulate with backspace and delete and whatnot. Luxury!

So, that's the idea unless somebody pulls an editor out of their hats. Feedback and comments most welcome, of course.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 20, 2015 11:46 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10802
Location: England
Line editing is just a mindset. You can certainly write significant code that way. And, if you want to print 10 or even 20 lines of context, you won't have to wait for a dot-matrix to print it out for you. Or a teletype.

So: go for it!


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 20, 2015 2:01 pm 
Offline

Joined: Sat Aug 21, 2010 7:52 am
Posts: 231
Location: Arlington VA
When it comes to line-based editors, I've always been a fan of TECO (Digital Equipment) but ed or edlin would do the trick. Have you considered adapting the "Starting Forth" line-based screen editor to files? Everybody knows it, and it's very "forthy"

The "Screen editor design" thread has morphed into a catch-all thread about several design aspects of PETTIL, because I didn't want thread proliferation and I didn't know how to change the subject line.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 20, 2015 2:21 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10802
Location: England
(A thread's subject, or title, is just the same as the first post's - so edit your head post to retitle your thread.)


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 20, 2015 3:14 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8440
Location: Southern California
What sort of keyboard and display do you want to orient this to? I wrote a rather full-featured text editor for my HP-71 hand-held computer 25+ years ago which has a 1-line, 22-character display and a QWERTY keyboard whose key spacing is only 60% of that of a full size keyboard (which I could type about 30wpm on, which coincidentally is also about 60% of the speed I could do on a full-sized keyboard).

Image

I have an 80-column video monitor for it, but I wanted something that's really flexible for when I wanted to use it portably (which means usually), not wanting to lug the big CRT monitor around. Doing a text editor on a 1x22 LCD makes it like looking at your work through a keyhole (for those who are old enough to remember the kind of keyholes you could see through); but if you can move the keyhole around your work nimbly, scrolling up and down and left and right, it's not really a problem-- usually. Sometimes it really was necessary to see a lot of lines at once, so I'd connect the monitor if I was near it.

It was about 7K of code in a BASIC that was super rich, having for example search functions with wildcards already in the BASIC (thanks to the huge contributions of the user groups). I didn't give it auto-indent, but I optionally had a record at the beginning of each text file that was for keeping things like the default tab positions and margin setting, so I could do for example a TAB4 (which is assigned to a particular blue-shifted key) and it would go to the column that the 4th tab was supposed to go to. That's useful for even when you're already past that column.

I used this editor for writing Forth source code, and plenty of unrelated writing too. I could have lots of files open at once. Commands were through a shift key that was not the same one used for upper/lower case; so <blue_shift>M for example let you enter the extended DOS/ANSI-character value [Edit: that should say IBM437] of a character that wasn't on the keyboard, or see what the value was of a special character that's not on the keyboard. Deleting, like you mentioned, was a matter of marking the desired block, and doing a block delete.

Since there's only a 1x22 LCD and you can't always be showing file name, the line & column number the cursor is on, etc., another shifted key showed those at any time, for as long as you hold the key, then when you release it, it went back to the normal display. As you're typing, since the column number is not showing all the time, there's a short chirp sound when you reach the column you told it to chirp at, like the "ding" on the old typewriters that would tell you when to start thinking about doing a carriage-return when you're typing without constantly looking.

A key overlay labels all the hot keys without restricting access in any way to keys. Nearly every key had a hot-key function as well.

I guess my emphasis here is two-fold:
  1. There's a lot you can do with even a tiny display; and
  2. without having to put commands in the display like your "2 d" above, you can put commands on hot keys and access them more quickly without leaving your place in the text or changing the display in most cases.
(I'll probably think of more, soon after I post this.)

BigEd wrote:
And, if you want to print 10 or even 20 lines of context, you won't have to wait for a dot-matrix to print it out for you.

Dot-matrix printers are slow for a page or more, but 10 or 20 lines in draft mode is done almost as quick as you can walk over to the printer to pick it up, and I sure like the fact that you can print a line at a time on dot-matrix and do it again and again on the same page, and that page boundaries don't need to exist at all on a programming printout.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 22, 2015 10:14 am 
Offline

Joined: Mon Jan 26, 2015 6:19 am
Posts: 85
You might find some useful ideas from GPascal for Commodore 64 which included a line based editor.
http://www.lyonlabs.org/commodore/onreq ... Manual.pdf


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 22, 2015 2:34 pm 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
GARTHWILSON wrote:
I wrote a rather full-featured text editor for my HP-71 hand-held computer 25+ years ago which has a 1-line, 22-character display and a QWERTY keyboard whose key spacing is only 60% of that of a full size keyboard.
Wow, that is impressive. The HP-71 was the successor to the HP-41, right? By the time I could afford any of those, the were history ... but boy did I drool over them. Still have my HP-15C, but it can't do anything like that.

About the hot keys -- that's a definite yes for the FFFE (life-long vim user here), but I was thinking of something more primitive for the ed-like editor so it can more easily scripted like ed inside other programs. That doesn't mean you can't have hot keys as well, but I'm going to start simple and then see.

@theGSman, thanks for the link!


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 22, 2015 2:56 pm 
Offline
User avatar

Joined: Sat Dec 07, 2013 4:32 pm
Posts: 246
Location: The Kettle Moraine
The HP-42 was the successor to the HP-41. The HP-71 was an unrelated product, a handheld computer running BASIC.


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 22, 2015 6:57 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8440
Location: Southern California
O.T.: Unfortunately the HP-42, the 41's successor, had no real I/O, and had other disadvantages too. I think there was something rotten going on in management at HP at the time. They also discontinued HPIL (Hewlett-Packard Interface Loop) which was a serial, ring-type version of IEEE-488 with some advantages over IEEE-488 (just not speed), and they discontinued the 71 also for idiotic reasons. Management never seemed to understand the power and potential of either of those. The 71 was aimed at technical professionals; but of those, not one in ten knew it existed, and of those, not one in ten had any idea how much capability it had. The HPIL idea could have been brought forward to much higher speeds as technology allowed, and even at its old max of 250kbps best case, it still should have been used for a lot more lab instrumentation.

Both the 41 and the 71 have had a lot of software and hardware modules contributed by the users' groups, and in fact serious users are still producing new ones. The big thing for the 41 now is the 41CL transplant board which emulates the 41's Nut processor in programmable logic and goes up to 50 times as fast and yet is able to accept the old plug-in modules (yes, it's a true emulator), but also comes with about 240 modules' ROM images built in, including ones that have just come out in the last few years, for example the 41z module that gives it a true, 4-level complex-number stack and over a hundred complex-number functions written in assembly for maximum performance, and the Sandmath one with oodles of high-level-math functions. Hardware ones you would still have to plug in would be like the HPIL (for interface to other equipment), Time (because the 41CL cannot keep alarm and time-of-day functions going when the rest of the unit it supposedly turned off, as it just takes way too much battery power for that), the IR interface, and bar-code reader.

There's a 71FRAM module for the 71 that's had a pre-production run and they're getting the last bugs worked out now. It lets you fill out the 512KB (or even 1MB, with paging is my guess) of the memory map, and load in other module images. I might get one or two. One of my 71's only has 160KB of RAM (which was huge at the time), plus HPIL, MATH, and Forth/Assembler hardware modules, while the other one is just the mainframe. The BASIC in the 71 is by far the best I've ever seen, at least with the user contributions. At my last place of work, in the late 1980's, I used HP's Rocky Mountain BASIC 5.1 on a 68000-based HP computer and was very disappointed that there were many things it couldn't do that the 71 did very gracefully. The 71 is also the computer I learned Forth on, although it was a bit strange with its 4-bit data bus and 20-bit address bus. Forth cells were 20 bits wide but C@ and others worked on 8-bit quantities.

If you're interested in this stuff, you should get on the HP Museum forum which is very active, with a lot of professionals, at http://hpmuseum.org/forum/ . The HP Museum web site is at http://hpmuseum.org/ . There's an HP-41-only site at http://www.hp41.org/Intro.cfm and its forum (with very little activity) at http://forum.hp41.org/ . I'm a moderator on that forum too. The HP-41 section of my links page is at http://wilsonminesco.com/links.html#hp41 .

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Thu Apr 07, 2016 7:46 am 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
So it took a bit longer than expected, but today I am happy to present "Fed", an ed-inspired line editor in Forth (https://github.com/scotws/Fed). It only has a few commands so far - basically, what is a, c, d, i, n, p, r, w in ed - but on the positive side, it's stripped version without comments is 3.2 Kb in size. I don't want to go over 4 Kb, so there is a bit more room for something like j.

Obviously this is still somewhat untested, so be careful and don't use it for your tax returns.


Top
 Profile  
Reply with quote  
PostPosted: Thu Apr 07, 2016 10:35 am 
Offline

Joined: Mon Jan 26, 2015 6:19 am
Posts: 85
Nice coding there. The comments and stack diagrams are first class.

One question: Were you planning to have all the editor commands be part of a EDIT or EDITOR dictionary or do you have to avoid creating words that conflict with the editor words?


Top
 Profile  
Reply with quote  
PostPosted: Thu Apr 07, 2016 11:26 am 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
Why thank you! My idea was to leave all that up to whoever uses this in their Forth instead of forcing it on the user one way or another -- Tali Forth for instance is so primitive that it doesn't even have vocabularies. For a larger Forth, personally I'd make EDITOR point to Fed somehow.

EDIT: "vocabularies", not "dictionaries". Thanks to Garth, see below.


Last edited by scotws on Fri Apr 08, 2016 7:44 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Thu Apr 07, 2016 7:03 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8440
Location: Southern California
scotws wrote:
Tali Forth for instance is so primitive that it doesn't even have dictionaries.

From earlier posts, I take it you mean it does not have separate vocabularies, but it does have a dictionary. I have a paper in my files somewhere explaining the internal operation of vocabularies which I'll scan and post if I ever find it. [Edit: It's at viewtopic.php?p=50247#p50247 .] It's by Walter Rottenkolber (sp?) who wrote a lot of good, short articles for Forth Dimensions magazine years ago.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 08, 2016 7:43 am 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
Argh, yes, of course, vocabularies. Need more sleep. I'd be very interested in that article, BTW, since this is one of the things that I'm going to try to include in Liara Forth this time.


Top
 Profile  
Reply with quote  
PostPosted: Tue Apr 26, 2016 8:33 pm 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
The problem with screen editors in Forth is not the screen per se, it's the environment.

Text editors rely on a stream of text (nominally), but the original screens is based on the underlying block model of disk I/O. Simply, the early Forth model doesn't have a filesystem to rely upon, with which it can use to easily managed arbitrary, named, Blobs-o-bytes (that just so happen to be text files).

The original Fig implementations had a "line oriented" Forth screen editor. Back in the day, with Val-Forth on the Atari, that was a Full Screen editor (but Val-Forth screens were 512 byte screens, rather than 1K screens, since that worked better with a 40x25 display). It was able to leverage the E: device (which is the screen editor that can be manipulated with the arrow keys that comes in the Atari ROM), so they pretty much get an editor almost for free.

So, the problem with a non-screen Forth editor isn't the editor, it's the underlying storage. The Fig line editor plus the few disk blocks being buffered gives you a mostly functional editor in < 1K of code, with an overhead of only a 1-2K for buffers that the system uses already. So that editor is almost free.

The other fundamental issue with editors, outside of how to represent the files in memory, is paging large files from memory to disk. Nowadays, this is rarely an issue. But it most certainly was back in the day. I remember fighting TECO and having to manually page our code in and out as we swapped from one part of the file to another. Buffer management was a science unto itself that distinguished good editors from bad ones.

Of course, the Fig screen editor doesn't suffer this problem, rather it embraces it. It certainly can be clunky to use, especially today where we don't think twice about cutting and pasting megabytes of text from document to document. But old school Forth guys will call out how the screen model enforces the "keep them small" and "endless refactoring" idioms of Forth coding.

With a little more memory, a cross reference to word definitions is not difficult. Then you add shadow screens for documentation. It's pretty powerful in a very small editor.

The fiddly-ness kicks in when you want to insert screens, but the --> word does a lot to fix that. You can also make a crude "table of contents" with a couple of screens to show how sequences of blocks are allocated. Just manage those by hand.

Pygmy Forth does the cross referencing and shadow screens -- it's a pretty nice screen based Forth, but it works in the expanded memory of a PC vs the small world of something like a 6502. But on a 65816, it could be really nice.

But going back, the original, minimal screen model with the Fig line editor -- it's a decent amount of capability in almost no code.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: