Alpha
Volume Number: | | 10
|
Issue Number: | | 7
|
Column Tag: | | Tools of the Trade
|
Alpha - An Adaptable Programmers Editor
Dont let that shareware label fool you - this editors feature-rich and powerful
By David Rogers, Aldus Corporation
About the author
A programmer for fifteen years, David is a software engineer at Aldus, and lives with his wife, two small children, and a cocker spaniel in Issaquah, Washington.
[About the article:When we made mention in comp.sys.mac.programmer of the review of programmer editors in our June issue, David was quick to let us know that we had missed one. Sure enough, Alpha is a contender, and David was good enough to write up an introduction to Alpha for us - Ed stb]
Overview
Alpha is a shareware programmers editor for the Macintosh with a wide range of capabilities. Alpha is a product of Pete Keleher, a graduate student at Rice University.
Like most programmers editors, Alpha is designed to work with ASCII text, normally source code. Alpha also edits TEX files, but that capability is not reviewed here. When needed, Alpha can store text with DOS or UNIX line-ends. Alpha can also save MPW state information when you close the file. When you reopen the file, the window will be restored to its former position and the cursor positioned at its previous point in the file. This is a real advantage if you open and close files frequently.
A quick look at the look of Alpha
Alpha has a layered architecture. At the core of Alpha is an editing engine which provides the editing primitives. Layered on top of this is the command language, TCL. Thats an acronym for Tool Command Language and is pronounced tickle. TCL is a full-fledged C-like language. Most of the Alpha user interface is written in TCL. This exposes the internals of Alpha to the user. This access to the internals gives Alpha a great deal of flexibility.
In particular, all the keyboard mappings and menu definitions are user definable. Alpha even allows you to use multiple keystrokes as a single command in the manner of Emacs or Wordstar (Word who?). You can, of course, write your own procedures in TCL and attach menu items or keystrokes to your commands.
In addition to a rare measure of customizability, Alpha has extensive support for programmers: ToolServer support, Apple Event (including Symantec Project Manager) support, and Electric Aliases (Ill describe this below).
Unfortunately, all this power comes at a price. Like any full-featured application, it takes time to learn to use Alpha to the fullest. This problem is exacerbated in Alpha because it lacks extensive documentation. Nevertheless, Alpha offers so much that it deserves a closer look.
More Power!- Tim Allen
Details Details
The power, or usefulness if you prefer, of a programmers editor is often a matter of attention to detail. Many of the features of Alpha are just little things. But, those little conveniences add up. Moreover, Alpha chooses to emphasize features you use often. A feature that saves you two or three minutes once a month is not nearly a helpful as the feature that saves you a second or two again and again.
Cursor Control
Alpha includes all the standard cursor control operations, moving by page, jumping to the top or bottom of the file and so forth. Alpha also includes some less common capabilities. Alpha attempts to maintain the column position when you move the cursor up or down a line. In most Macintosh editors, the cursor jumps to the left margin when the cursor hits a blank line.
Youll notice another nice feature when you page up or down. The cursor moves with you. This allows you to quickly move great distances in your code without having to take your hands off of the keyboard. This feature could be improved, however. Currently the cursor is arbitrarily moved to the upper left corner of the window after a paging movement. It would be better if the cursor stayed in the same relative spot in the window. That would allow you to page down and page back to the exact spot you started.
Somewhat related to cursor control is the fact that Alpha includes a true undo and redo capability. Unlike many other editors, Alpha can undo and redo most actions, not just text entry.
Block Moves
Again the power is in the details. Alpha does the standard cut, copy and paste, but also includes drag-and-drop editing and rectangular selection. Drag-and-drop allows you to move blocks of code using only the mouse. Very nice - especially when modifying existing code. Youre normally mousing around a bit then anyway. Unfortunately, you cannot drag-and-drop between windows. Also, Alpha does not use Apples Drag Manager, so you cant drop Finder items onto Alpha windows or text clippings into other applications.
Rectangular editing is one of those features that you dont use often. But when you need it, you really need it. It is very useful when modifying tables of static data, for instance. Unfortunately, sometimes the rectangular selection feature isnt quite right. Selections which include tabs arent calculated properly. It is obvious that the tabs are being treated a single character. Pete suggests that you convert tabs to spaces before using rectangular selection until this feature is fixed.
Example of rectangular selection
Keyboard selection (holding down Shift and typing arrow keys to make a selection) is also unusual. Once you have started selecting in a particular direction, you cant back up. Reversing direction doesnt shrink the selected area. It grows the opposite end of the selection. In order to shrink the selection, you have to start the selection over. This is time consuming and inconsistent with the way mouse selection works.
Searching
Alpha includes a number of ways to search your text - incremental search, multi-file search, batch multi-file search, and a grep command in the shell. More on the shell later. Incremental search allows you to start searching immediately, no muss, no fuss, no dialog. Press the key for incremental search and start typing. With each character you type, incremental search finds the next occurrence of what you have typed so far. Thats the incremental part of incremental search. Incremental search is a boon when you dont need all the fancy options. You just want to start searching.
When you do need the options, Alpha also includes a find dialog. Alphas find allows full regular expression searching. For those not familiar, regular expression searching allows you to search for patterns of text. This allows you to search for something that looks like this. The find dialog also allows you to specify a multi-file search. You can select from predefined sets of files, or you can specify a directory to be searched. In multi-file searches, you have the choice of finding matches one at a time, the same way that Symantec does it. However, you can also elect to do a batch search. In this case, a new untitled window is opened and the output of the search is placed there.
The output is typical of grep-style output. You can also perform a grep search from the command line in the Alpha shell. No command-line parameters though. In this case, the output is displayed right in the shell window.
Two changes would greatly enhance the usefulness of Alphas search facilities. The multi-file searching would profit from the ability to search sub-folders recursively. The options dialog off the find dialog contains a check-box for it, but it would never activate for me - no matter how sternly I told it to. Another improvement would be to provide the option of having the grep command output TCL commands. Then you could execute a line of the output to open the file and see the surrounding text. This is the way MPW does it and it can be enormously helpful when you are searching large amounts of code.
Window Control
Window manipulation is not a sexy topic, but can be enormously helpful when you have a gaggle of windows open. Of course, Alpha has commands to switch to the next and previous windows. Alpha also allows you to choose a window from a list and to organize your windows. The choose window dialog allows you to switch to an arbitrary window without taking your hands off the keyboard.
The arrange window menu allows you to arrange your Alpha windows vertically or horizontally or to tile or overlay them. Arranging affects only the top two windows. Tiling and overlaying affects all Alpha windows.
Some sample TCL code
One thing Alpha really needs in the window management sector is split windows. It is very convenient to look at two portions of the same file at the same time. Named marks (described below) partially alleviate the need for this feature, but the split windows feature would be a better solution. [Note: Alpha allows you to open more than one copy of a file, so you can achieve a similar effect without window panes - Ed stb]
TCL command language
TCL was developed by John Ousterhout, a professor at U.C. Berkeley, for a microkernel operating system he was developing called Sprite. John developed TCL as a common command language for various Sprite tools. Well, Sprite never took off, but TCL did. In due course, an Alpha user suggested that TCL would be a nice addition to Alpha.
When Alpha was originally developed, it had a very simple and non-standard macro language. Pete saw the power of TCL and redesigned Alpha with a C core and a TCL interface. Pete continues to add features to the Alpha engine, but many of the enhancements to Alpha are done completely in TCL.
TCL is a string based language. Its only data type is string. Also, every operation is an operation on strings. TCL can manipulate numeric values, but the values are stored as strings. TCLs syntax will often look like C on first glance, but do not be confused. TCL is entirely command based. For instance, the if statement in the following procedure is actually an if command, and the statement collections and the else are parameters.
/* 1 */
proc testThis {a b} {
if { $a < $b} {
set a 10
} else {
set b 10
}
}
The TCL Shell window
As if that werent strange enough, proc in the command above is also a command. The name of the proc, the parameter list and the statement body are all parameters to the proc command. While this is an unusual approach, the language is so consistent that you should have no trouble learning to use TCL in short order. As stated above, most of Alphas interface is in TCL, so there are lots of examples if you do get stuck.
TCL is quite good at what it is intended for. It has arrays (lists) but nothing more complicated in the way of data structures. However, it has the usual complement of flow control statements, and a full procedural language. In addition, it has string and list processing commands you wont find in most other languages. As a tool command language, thats just the way youd want it.
If you do need to perform some action that is beyond the capabilities of TCL, you can write an XTCL in your favorite compiled language. XTCLs are similar in form and function to HyperCards XCMDs. Unlike most of Alpha, XTCLs are adequately documented and several examples are included.
Alpha allows you interactive access to TCL through the Shell menu item. You can execute any currently defined procedure through the shell. Since Alpha comes with commands to copy, move, and delete files, the shell makes a usable, if limited, command-line interface. I realize that command-line interfaces are anathema to most Mac users. However, they are handy when file manipulation is repetitious or when large numbers of files are involved. You can also use the shell to quickly test commands your are developing. [MPW afficionados know theres little reason to apologize for an interactive shell - Ed stb]
Alphas TCL documentation is limited. It includes a very brief definition of the language and a description of each keyword and built-in command. This is fine if you already understand the quirks of TCL, but is not sufficient for a newcomer to the language. Fortunately, the language is better documented elsewhere. If you can find documentation for version 6 of TCL, it provides a much better overview.
Interpreted languages have a bad reputation. Slow is the word that usually comes to mind. This is not the case with TCL. Even though Alpha executes quite a bit of TCL code at startup, Alpha loads in 4 seconds on a IIfx - less than that on an 840AV.
Programmer Specific Support
Electric Aliases / Template editing
When youre editing code, you spend a large portion of your time typing for statements, while statements, if statements, and so forth. Wouldnt it be nice if the editor did a lot of that work for you? Thats the principle behind Alphas Electric Alias feature (also known as template editing). The way it works is this: You enter if and press tab. The editor types the parens and the curly braces and positions the cursor in the parens. Youre ready to type the condition. Another key jumps the cursor between the condition and body of the if statement. Like everything else in Alpha, Electric Aliases are easily modified. It is convenient to set them to trigger on single characters. So, in the case of a while statement, you only have to enter a w, press tab, and youre ready to enter the condition. Template editing saves a lot of time and a lot of wear and tear on the fingers.
ToolServer Support
Alpha provides support for Apples ToolServer by providing an editing window set to a special ToolServer mode. Anything entered in that window is sent via Apple Events to the ToolServer application. ToolServer, for the uninitiated, is MPW with no user interface. Most commands you can give in MPW will also work as commands sent to ToolServer.
Unfortunately, Alphas implementation is flawed. Alpha does not allow you to switch to dialogs put up by ToolServer. This precludes you from using any MPW tools which contain a dialog, or even the lowly alert command. Unless you are sure that you will never invoke a ToolServer dialog, I recommend that you do not use the ToolServer shell until this feature is fixed.
Apple Events/AppleScript Support
Alpha provides Apple Event/AppleScript support both into and out of the editor. Going into the editor, Alpha provides open, print, quit, and run events from the required suite. From the misc suite, Alpha provides the DoScript event. This is a powerful facility since you can send TCL strings to Alpha from AppleScript scripts and have them executed. Alpha does not support the full editing suite, but, given the power of TCL and the inclusion of the DoScript command, it is not a great loss. One limitation, though, is that DoScript doesnt return the value of the executed TCL command.
Alpha provides two methods for sending apple events to other applications. The dosc command provides a number of parameters for designating the target and nature of the event. The limitation is that the data of the event must be a string or a file. Alpha also provides an AEBuild command. There is no documentation at all for this command, except that the documentation warns that this command is under development and subject to change.
Alpha uses the above commands to provide support for communicating with the Symantec Project Manager and Symantec Reference. When editing a C or C++ file, Alpha attaches an extra menu with commands for driving the Symantec Project Manager and for looking up Symantec Reference templates.
The Think Menu
Other Programming Goodies
Alpha displays the current line and column on the title bar. Alpha also searches source code at load time for function names. Alpha uses these names in a pop-up menu on the title bar. You can click on the pop-up and jump directly to a specific function.
Automatic function popup
The named-marks feature is not specifically for programmers, but it is especially useful in that context. Often when modifying existing code, you need to examine more than one function at different spots in a source file. Named marks allow you to quickly note the location of each spot and jump between them easily.
Alpha as word processor - not!
While you do not want to use Alpha as a word processor, it is useful for the occasional note and for typing long comments in source code. Alpha behaves differently (and may present different menus) depending on the mode of the active window. Each window opened in Alpha is considered to belong to a particular mode - normally based on the file extension or file type. In text mode, text wrap is active. Text entered in text mode is automatically wrapped at a user defined column. You can also wrap arbitrary areas of text on command.
Alpha will also check the spelling of selections or entire files using the freeware spelling checker Excalibur. Imagine having no spelling errors in your comments!
Omega
The topic of programmers editors is prone to heated debate, if not outright warfare. Everyone has a favorite feature that they swear by (and other features that they swear at). I feel compelled, therefore, to state that this article does not contain a comprehensive list of Alphas features. Fortunately, since Alpha is shareware, you can take a look for yourself to see if Alpha contains that gotta-have-it-or-Ill-die feature.
Alpha Shrugged
Alphas greatest lack is not in the range of features or in the implementation of those features. With few exceptions, Alpha does many things and does them well. Where Alpha falls down is in making Alpha accessible to the new user. Alpha needs a great deal more documentation, including a Getting Started document. It also needs a way to easily set the new users preferences.
Alphas Future
Alpha is currently written in Symantec C. Pete is currently evaluating Metrowerks CodeWarrior. If all goes well, Pete hopes to port the Alpha source to CodeWarrior sometime this summer. At that point he will consider porting Alpha to PowerPC.
Conclusions
Whether Alpha will interest you depends on whether you are willing to pay the price for the power contained there. Alpha requires little learning to use as delivered. However, if you want to take full advantage of Alphas power, you must take some time to customize it to your needs.
Another price might be paid in the fact that Alpha is shareware. Because its shareware, it is inexpensive and you can try before you buy. However, support for Alpha is not as readily available as support for commercial products. You can reach Pete by e-mail if you have access to the Internet, but there is no phone support. Furthermore, Alpha is a sideline for Pete. He is currently a busy graduate student, but is due to finish this summer and hopes to find a research lab or faculty position soon. Obviously, support for Alpha will vary with the other demands on Petes time.
Availability and Pricing
Alpha has a shareware fee of $25. That fee includes all future releases of Alpha. Alpha is updated regularly. The latest update of Alpha is always available via the Internet by anonymous ftp at cs.rice.edu in the /public/Alpha directory. Alpha is also distributed to other major sites and to the major BBSs. I reviewed version 5.76.