Editor Extender
Volume Number: 5
Issue Number: 7
Column Tag: C Workshop
Related Info: Scrap Manager Desk Manager
Extend Your Favorite Editor
By Joel McNamara, Bellevue, WA
Note: Source code files accompanying article are located on MacTech CD-ROM or
source code disks.
Extending Your Editor: Edit Extender DA
If you’ve programmed for awhile, you’re bound to to encounter one or two text
editors you really feel comfortable with. Be it EMACS on a mainframe or QUED on a
Mac, a good editor has a way of growing on you. You savor the power, the flexibility,
and all of those little features that really make it stand out. Then comes the day, for
some reason or another, when you’re forced to use another editor. You click on the
menu bar and your favorite feature isn’t there. A keyboard command just puts a
non-ASCII character on the screen. You grit your teeth and code away, wishing your
preferred editor was around.
I was rudely awakened to this predicament when I started to use MPW and
Lightspeed C. QUED had long been my editor of choice on the Mac, and I suddenly found a
few of my favorite features weren’t around anymore. Granted, I could continue to use
QUED or even be more ambitious and write my own editor with a little help from
Symantec’s CAPPS, but I really like the notion of an integrated programming
environment. To me, it’s a hassle to transfer from your editor into your main
development environment all of the time.
Ah, but that’s the joy of being a programmer. You’re not forever an end user,
hoping and praying the software gods will deliver you from want. You can rise above
the masses with an idea and a compiler. The problem of creating an extendible editor
can easily be solved by simply writing a desk accessory.
The theory goes like this. You have a chunk of text you want to manipulate within
your editor. You just select the text, copy it into the clipboard, capitalize/count/do
whatever to it, and then paste the altered text back in, replacing the previous
selection. You let the text editor do all of the work, while you sit on top, adding your
own features through the DA. No sweat, DA spell checkers like Thunder! do it all the
time. Just combine the concepts of the sample “Windows” desk accessory included
with Lightspeed C with some clipboard related code, and viola, a few quick hours of
programming gives you the features of your favorite editor in a least favored one.
Specifically, in the following example, capitalization, changing case, word counting,
time and date insertion, and saving a selected region to a text file.
The Clipboard, Fake Keydowns, and Timing
The obvious storage location for storing text to be manipulated is the clipboard,
alias the desk scrap. Once the text is there, it can be twiddled with to your heart’s
content. So, the first thing to do is get the selected text into it. Now being somewhat
lazy in not wanting to menu select Copy or Paste or type their keyboard equivalents all
of the time, I decided there must be a better way, more in tune with the Mac interface.
Something along the lines of having the text selected, pulling down the DA’s menu, and
having the command executed.
The solution is to post a Command “C” (the non-case sensitive, universal Mac
key command for “Copy”), and fake the editor into thinking the user had just done a