The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

how do text editors work?

Does any one know of any literature on how to design and develop text editors that allow basic formatting of text: color characters, words, indent lines, layout paragraphs, etc.?

I'm sure there are little widgets in Java/C# that allow rich text editing, I'm interested in the actual data structures, algorithms and design patterns used.

I'd like to write a source code editor.  Not to sell, just to understand how it is done.  I expected it to be trivial, but more I think about it, it is not so trivial :)  That could be, partially, due to my lack of GUI development experience.
texteditor Send private email
Sunday, November 26, 2006
 
 
In the GoF book http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612 the Chapter 2 case study (43 pages) is "Designing a Document Editor"; if I recall correctly it also has bibliographic references.
Christopher Wells Send private email
Sunday, November 26, 2006
 
 
*FAR* from trivial to do properly.

There must be any number of open source editors that you can look at the source code of. For example:

http://www.scintilla.org/
Andy Brice Send private email
Sunday, November 26, 2006
 
 
AbiWord is another open-source one: http://www.abisource.com/
John Topley Send private email
Sunday, November 26, 2006
 
 
I'm curius, too. I guess code editors that identify symbols with colors have to half to implement a compiler. At very least the scanner phase. The parser phase and to know about the gramatic of the laguange may be useful, too. And may be they have to work with symbol tables, so, the semantic phase could be involved too.

In short words, a compiler without generating object code.
Are they so complex or they are just scanners?

If someone who knows about it want to tell, I would be pleased to read, thanks.
Ross Sampere Send private email
Sunday, November 26, 2006
 
 
The various language-specific emacs modes might be worth a look.

In fact, if you are interested in editor design then a look at emacs, and that other two letter one, would be strongly recommended.
Arethuza Send private email
Sunday, November 26, 2006
 
 
Writing a text editor is reasonably complicated, writing a programmers editor with syntax highlighting and source code browsing etc. is a major undertaking. I should know as I've been developing "ED for Windows" http://www.getsoft.com for many, many years now.

As others have said there are plenty of free and open source editors around these days. Scitie, scintila, Eclipse to name a few. Also have a look at www.codeproject.com and www.codeguru.com You'll find basic editors there.
Neville Franks Send private email
Sunday, November 26, 2006
 
 
The guy behind this is my compatriot, so I have to tout this. Feel free to ask him any questions, I'm sure he'll gladly help.
Berislav Lopac Send private email
Sunday, November 26, 2006
 
 
Errr... This = http://context.cx/
Berislav Lopac Send private email
Sunday, November 26, 2006
 
 
You might want to pick up a copy of either "Software Tools" or "Software Tools in Pascal" by Kernighan & Plauger.

The basic premise of the books is building samll utilities (tools) that are combined into a larger system. The tools are very heavily text processing oriented, and they are used to build a basic text editior.

I found a copy of the Pascal version in a used book store for < $5, so that's where you might start looking.
*myName
Sunday, November 26, 2006
 
 
Check out the SharpDeveop IDE - it is an "Open Source Development Environment for .NET". One aspect is the "ICSharpCode.TextEditor", it is an excellent text editor that supports configurable highlighting etc:

 http://www.icsharpcode.net/OpenSource/SD/

I have used it in previous projects and currently for an in house tool. The design is quite good following known patterns etc so it would make an excellent learning tool... The syntax highlighting is done in such a way as to make extensions easy, for example I knocked up an article recently when we had to make some enhancements: http://www.pksoftware.net/Articles.aspx?id=803100dd-80fc-4604-b44f-bf243710cfac&name=Extending_ICSharpCode.TextEditor_to_support_additional_Syntax_Highlighting

And you are right, it gets quite complicated!
Paul Kohler Send private email
Sunday, November 26, 2006
 
 
Thanks folks!
I had heard that the design pattern book had such an example.  I should read that anyway, perhaps I'll get it.  I like the SharpeDevelop idea too.  Actually I purchased the book explaining its internals a year or two ago...never got around to reading it and can't seem to find it now :)

I'll be taking a look at the open source projects as well.

After building a prototype, the two main things I wanted to experiment with are:
1. Instead of using regular expressions to do syntax highlighting, just use a CFG to gain a deeper understanding of the code!
2. Make a 'text editor' act like a table top with many pages on it...so if one makes the font very small, they can see several different files on the same screen (conversly, let the editor adjust the fond size so the whole document fits in the editor window)


...if i ever get to it :)
texteditor Send private email
Sunday, November 26, 2006
 
 
If you search for "Codemax 2" you should be able to find the source code for Codemax which is a source code editor COM control. It would be some pretty good code to look at to compare and contrast with the code for something like scintilla. Probably simpler code than scintilla since it's only for Windows...

It's a pretty decent editor with support for syntax highlighting in many languages, line numbering, split views and many other advanced features. There is even a version out there called "Codesense 2.0" which is Codemax 2 with intellisense support added.

If you can't find the source code, i'll be glad to locate it for you, just shoot me an email.
Wayne B Send private email
Monday, November 27, 2006
 
 
You can still get the pdf of the SharpDevelop book. Click on the book cover on the SharpDevelop site and follow the link. They reference this free book (1st edition) on parsers:

http://www.cs.vu.nl/~dick/PTAPG.html
el
Monday, November 27, 2006
 
 
As someone who has only toyed with writing an editor on several occasions, I can tell you that there a couple of central topics in writing an editor (and a huge number of peripheral topics). The central topics are buffer management and display management.

Buffer management is, to my mind, where the real meat of writing an editor is. You have several different strategies to choose from: 1) keep all characters in a simple linea buffer and move them around as characters are inserted or deleted, 2) keep all characters in a simple buffer with a gap in the middle so that insertion and deletion is easy, but the gap needs to be moved just before an edit takes place, and 3) keep the edits as a list of inserts and deletes based on an initial buffer. (there may be some other, less obvious, strategies, but these are the big ones) Each strategy has advantages and disadvantages. Each strategy is also used by at least existing popular editor.

Display management is a similarly rich and historied topic, specifically as regards the unix editor vi and the curses/termcap/termios libraries. The problems encountered (and solved) in managing text displays have analogs in the GUI world, so you might want to be at least familiar with curses/termcap while you think about managing a graphical display.

Once you have a working buffer management strategy and display management strategy, you can start tackling other details. Along with buffer management you will want to worry about line management (keeping track of where lines start in the buffer, wrapping of lines to a set width, calculating character widths for line wrapping, etc.), character attributes (font, color, etc.), syntax highlighting/language sensitivity, etc.

As for resources, I don't know of very many. Once, long ago, I saw a book by Don Knuth about text editing, I think it is part of his TeX series: "Computers and Typesetting" but I can't be sure. Under any circumtance, I can't find it (the book on writing an editor) in an Amazon search or at Don Knuth's homepage. The suggestion of the Kernighan and Plaugher book is a good one, but you may find the implementation simplistic and dated (it's a line editor). As for looking at Open Source text editors, it may be a bit daunting, although some of the small console based editors (nano or pico, for example) may be managible.

Interestingly enough, the tutorial application in the original phone-book sized version of Inside Macintosh was a simple text editor. Unfortunately,  almost all the heavy lifting was done by the built-in EditText control, so all you had to do was build the GUI surrounding it. This is, however, how I got interested in text editors and a programming topic, in the first place.
Jeff Dutky Send private email
Monday, November 27, 2006
 
 
One of the best places to go:
http://www.catch22.net/
There you find excellent writing about development of a win32 texteditor for unicode.

cs
Christof Send private email
Monday, November 27, 2006
 
 
The concept of a "piece table" is well worth understanding:

http://e98cuenc.free.fr/wordprocessor/piecetable.html
Eric Sink Send private email
Tuesday, November 28, 2006
 
 
The catch22 site is incredible!

Thanks
falcon Send private email
Tuesday, November 28, 2006
 
 
Neville:

"I should know as I've been developing "ED for Windows" http://www.getsoft.com for many, many years now."

And you still haven't found the time to make some decent screenshots of it and put them on your webpage?
Roman Werpachowski Send private email
Thursday, November 30, 2006
 
 
> I guess code editors that identify symbols
> with colors have to half to implement a
> compiler. At very least the scanner phase.

As far as the Zeus for Windows IDE is concerned:

http://www.zeusedit.com

there is very little in the way of a compiler to be found in the Zeus code.

For example to implement syntax highlighting all you really need do is maintain a list of words and assoicate a color to that list.

To draw a line all you do is tokenize the line into its individual words, then search for each word in turn deciding on its color.

> The parser phase and to know about the gramatic of
> the laguange may be useful, too.

Maybe for something like intellisensing or some form of real time syntax checking engine, but for general editing, navigation and display this is not really required.

Zeus gets away with using nothing more than ctags for its class browsing and intellisensing features.
Jussi Jumppanen
Monday, December 04, 2006
 
 
>Neville:

"I should know as I've been developing "ED for Windows" http://www.getsoft.com for many, many years now."

And you still haven't found the time to make some decent screenshots of it and put them on your webpage?

If you look on the home page under "Top 11 features" you will see "screen shot" images you can click on. Is there a problem with these?
Neville Franks Send private email
Sunday, December 10, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz