About

Introduction

Most computer programs are written in plain text format, but rich text, i.e. text that supports colours, fonts, graphics, multimedia etc. can be more conducive to reading and comprehension due to the availability of additional visual and sensory cues. That is probably why software writers often resort to producing additional rich text documents for presenting the code. In such documents, parts of the code gets excerpted and annotated with highlights, emphasis, and pictures. For example, figure 1 is a still photo taken from a Google TechTalk by a famous developer, who, in this photo, is using colorful highlights to help with describing the code. This suggests that it might be useful to the developers if programming in itself could be done in a rich text environment.

Figure 1. Guy L Steele showing highlighted code in a Google Tech Talk

This idea gave rise to a new text editor that can make programming more fun and programs easier to read. It is a tool that allows you to write rich text in a novel format that automatically maintains the underlying plain-text file. This editor is named the spectral editor - an allusion to the fact that it allows you to break down black and white plain text into colorful rich text. A key innovation behind this editor is its file format designed as a marriage between rich text and plain text formats which brings about the best of both worlds. It gets you the maintainability merits of plain text - i.e. simplicity of automatic merging, concatenation, and version management, alongside the visual appeal of rich text i.e. fonts, color, graphics, multimedia etc. The file format represents rich text in a way that preserves line-to-line correspondence with the plain text content. The rich text layer enhances the presentation and comprehension while the plain text source code is maintained behind the scenes, thanks to a clever mapping between the plain and the rich text, as described in the next section.

The Spectral File Format

The file format is a textual sequence of records, each record identified by its type followed by its details. The record type descriptor tells as to what kind of record is represented by the details that follow - i.e. it tells whether it is a text record, whether it is an image record, an audio/visual record, a span record, and so on. A text record’s type descriptor is the letter T, which is followed by the text itself. The type descriptors and the detail blocks are mutually separated by white-space, as are the records. The blocks are enclosed by braces where such delimiting is required due to internal white-space within the block. Alternately spaces in a block can be escaped using a backslash. Nothing out of the ordinary so far, but here is the crux - the only blocks that can have a new-line in them are text details, and every new-line in a text detail block corresponds to a new-line in the underlying plain text. This requirement, in itself, ensures that there is a line-to-line correspondence between the rich-text and its plain text equivalent. The font and colors are described by spans. Spans are regions of text enclosed by records of type span-start (given by the type descriptor S) and span-end (given by the type descriptor /S). The detail block for a span record is a name, whose properties may be described in a property (P) record. There are record types for images, multimedia files, and so on. New record types can be introduced without getting in the way of existing record types, because all we need to take off on the new type’s meaning is a unique type identifier symbol. Figure 2 presents the content of a sample rich text file, which when rendered by spectral would look like what is shown in Figure 3.

Figure 2. Sample of Spectral rich text file

Figure 3. Visual rendering of the rich text given in Figure 2

Figure 4 shows the text content of figure 2 with some color annotations. The yellow highlighted boldfaced characters in figure 4 represent record type descriptors. The first one among them is a P or property type descriptor, followed by its details - the red-highlighted part - that describes the properties of a span called “h1” (this span is subsequently used for the title text). The details say that the font for the “h1” spans would be boldfaced “Cambria”, of size 14, and teal in color. The first text block (i.e. one preceded by the type descriptor T) contains the text “This is the Title”. It is surrounded by the span blocks “S h1” and “/S h1” meaning that the font and colour properties of the “h1” span applies to that text. There are some predefined span tags (e.g. bg_yellow and bg_turquoise in this example) named after the background color that applies to their spanned text.

Figure 4. Annotated version of the text in Figure 2

That was just a description of the file format for the tech-savvy. To use spectral you don’t really need to deal with those details since the editor presents a what-you-see-is-what-you-get (WYSWYG) interface. You can open a text file (let’s say a source code file named “main.cpp”) on this editor, and add value to it using color, fonts, graphics, audio etc. Each time you save the file, the editor will save the plain-text changes to the original file (“main.cpp”) and the rich text to a file named by appending “.hlt” to the original file’s name, which in this case will be “main.cpp.hlt”. If you change the original file using some other editor, the “.hlt” file will go out of sync with the original text but the next time you open it on spectral, the change will be merged into the rich text. The merged regions of the text will be highlighted with a special colour. If you store “.hlt” files in a source control system (e.g. svn, git, etc.), and if merge conflict markers are introduced by a merge from concurrent changes to the same file, the markers will not corrupt the file. Instead the conflict markers will get superposed into the rich-text, within a text block. This is a slight deviation from the file format described above. The handling of conflict markers may be seen as an additional pre-processing that scans the files for conflict markers and convert them into text records that comply with the format described earlier. If the conflict block happens to have some graphics in it, the graphics will also be displayed as shown below (Figure 5).

Figure 5. Merge conflict markers displayed on Spectral

Concatenation of two such rich text files (e.g. as ‘cat’ would do) will also not corrupt the file, and result in the concatenation you would expect, one that preserves the rich text markup and graphics while concatenating the textual content. It is also possible to make the “hlt” format the primary code format in a project where Makefile rules are used to extract the source code files from hlt files before further compilation. For example, a five line script can serve as a text extraction tool, thanks to the simplicity of the hlt format.

Spectral Features Overview

The spectral format supports images, audio, video, notes, and other file references. It can help you write value-added code that is cross referenced with other bits of code, data, and multimedia. There are many possible creative uses of these features. For example, you can attach audio clips recorded during a code walkthrough or review meeting. The audio you record will be attached with the current cursor/caret position when the record button is clicked, thereby keeping it in the context of the code that was being described/discussed. Notes i.e. textual annotations that don’t result in change to the underlying source code or plain text file may be similarly attached with code locations. One can define commenting standards with colour codes. For example, green highlighted comments might be targeted at new recruits who don’t know much about the code-base yet, yellow comments might be for assumptions and requirements, red comments might be for caveats, purple might be for purpose, and so on. The regular expressions support on Spectral is more powerful than in most other editors, in that : You can find/replace by left and right context, limit to selection (including 2d rectangular selections). Left and right context expressions can be negated (i.e. one can ask for it not to match a given expression). The replacement text in a find-replace operation can be computed (i.e. can be a function of the match, maybe a number incremented at each match, maybe a random string, a GUID etc.). Spectral supports a “log/trace to source” lookup feature in which one can open a log or trace file using spectral and jump to source code locations that generated a given bit of log. This comes handy as a debugging tool, since it enables a trace to be rapidly comprehended and annotated. This feature is programming language independent. Spectral comes with a command interpreter with handy text processing commands. Many common unix commands like grep, sed, awk, zip, gzip, find, flex, bison, mv, rm, wc etc. are included in the command interpreter alongside the tcl/tk libraries. The editor can be automated and scripted using tcl. Plugins and extensions to spectral can be written in the scripting language called Tcl (in the same way that Emacs is extended using Emacs Lisp). New and custom commands, menus, widgets, and event bindings can be created by the user. It seems fair to claim that spectral is maximally re-programmable. Every bit of behavior in spectral could potentially be overridden by a user-written extension. The user can add and override functions and event-bindings in the same Tcl interpreter that runs Spectral.

What does the Kickstarter project aim ?

The spectral editor originated as a hobby project and we find it useful in everyday tasks but it lacks a few elements before it can be commercialized. The aim of the Kickstarter project would be to productize the editor, which involves the following :

1. Writing a user guide for Spectral.

2. Buy code-signing certificate from a certification authority, so that the installer doesn't show warning because of the code being unsigned.

3. Porting the code to linux and mac OSX. It is written in ANSI C and Tcl/Tk,so porting shouldn't involve a huge effort, but we need mac and linux machines to get started with the porting.