Re: coding text editor
- From: Steve Kirkendall <skirkendall@xxxxxxxxxxxx>
- Date: Thu, 20 Mar 2008 10:06:57 -0800
sid wrote:
Hi!
I am writiing a VI like text editor in C++ for the console. I
would like to know some opensource tools that would help me build it
faster. Also, What would be the best approach to build it?
Thank You.
Hi, I'm the primary author of elvis.
I suggest you get a book entitled "The Craft of Editing Text" by Craig
Finseth. It uses EMACS for many of the examples, but really it tries
to be a generic reference for how to write text editors. It is online
at http://www.finseth.com/craft
You should also read http://www.cs.unm.edu/~crowley/papers/sds/sds.html
which discusses various data structures for storing edit buffers.
The POSIX documentation for ex and vi are very vague, and not worth
tracking down. Clearly, the authors had never implemented vi before.
I can tell you that in elvis, there are a lot of data structures with
associated sets of functions for manipulating them. It should be easy
to derive classes and methods from that. For example, there's a LOWBUF
data structure, and the lowbuf.c file containing functions which replace
text and maintain versions. There's also a BUFFER data structure which
uses LOWBUF to store the text, remembers which versions to use for
"undo", and adds buffer options like "filename" and "readonly".
I'm *NOT* saying you should base your editor on elvis -- I'm just
saying that any C editor is likely to be organized in a way that
translates well to C++. So look at as many C editors as you can
find.
The ex command processor and vi command processors are both driven off
dispatch tables -- basically an array of structs containing a command
name, a function pointer, and a bitmap of each command's quirks.
There are a lot of quirks, and I suggest you look at an existing vi
clone REAL SOON to get an idea of the kind of quirks you'll need to
support. In elvis, the dispatch tables are in ex.c and vi.c.
Screen updates are tricky in elvis. Elvis supports multiple display
modes (including HTML, nroff -man, and hex dump) and multiple user
interfaces (including X11 and ASCII terminals), so the screen update
logic had to be very versatile. Unless you can dedicate big steaming
piles of time to your project, I suggest you stick with plain text
displays in a terminal emulator using the curses library.
Some other potential problem areas: Key maps. External programs (the !
command and its variations). Security. Regular expressions. Options
(the :set command). Tags (the :tag command).
Elvis is available at ftp://ftp.cs.pdx.edu/pub/elvis/elvis-2.2_0.tar.gz
.
- Follow-Ups:
- Re: coding text editor
- From: llothar
- Re: coding text editor
- References:
- coding text editor
- From: sid
- coding text editor
- Prev by Date: Re: coding text editor
- Next by Date: Re: coding text editor
- Previous by thread: Re: coding text editor
- Next by thread: Re: coding text editor
- Index(es):
Relevant Pages
|