BBEdit 5.0
Volume Number: 15
Issue Number: 2
Column Tag: Tools Of The Trade
Review of BBEdit 5.0
by Vicki Brown
Edited by Rich Morin
Editing Text in a GUI World
BBEdit, the text editor from Bare Bones Software is quite a product. If you haven't
tried it yet, now would be a great time. Bare Bones has recently released version 5.0
of BBEdit, with more advanced HTML editing, improved language-sensitive syntax
coloration, and several new features that are sure to make even experienced BBEdit
users take note. BBEdit has been a terrific product for several years now. With the 5.0
release, it's gotten even better.
BBEdit is available in two forms. BBEdit 5.0 is a commercial product, available as a
boxed distribution (HFS CD-ROM and a 290-page manual); a downloadable demo is
also available. BBEdit Lite, also downloadable, is binary-only freeware. The Lite
version has fewer features; for instance, it can't do text coloring. BBEdit Lite is a good
editor; however, if you really want to give BBEdit's most interesting features a test
drive, download a copy of the BBEdit version 5.0 demo.
This article covers BBEdit 5.0; many of the features described here are unavailable in
BBEdit Lite. You'll find a table comparing BBEdit 5.0 to BBEdit Lite on Bare Bones
Software's web site. Bare Bones offers a cross-upgrade discount price on BBEdit 5.0 to
users of Lite (and several other products). Check the Bare Bones web site for more
information.
Figure 1. BBEdit Session.
What is a Text Editor, Anyway?
For those who aren't quite sure, some terminology might be in order. What is a text
editor, anyway, and how does it compare to all the other text editing, word-processing,
and source code development tools on the market?
Quite simply, a text editor deals with text. No styles, no special formatting, no fancy
fonts, no page layout capabilities, just text. If you want to write a fancy README file
with bold, italic, and embedded pictures, use a Styled Text Editor (such as
SimpleText). If you want to write a paper, a book, or a magazine article such as this
one, with special formatting, paragraph styles and the like, use a word processor.
(Although, to be honest, I wrote the first draft of this article in BBEdit, then "poured
the result into a word processor to finish it!).
Rich Siegel, of Bare Bones Software, puts it this way: "a word processor is used for
producing documents in which the presentation of the content is the primary
consideraton, and a text editor is primarily for producing documents which are
subsequently used as input to other programs (e.g. compilers, MacPerl, Web
browsers).
Finally, don't think that using a text editor means you can only work with files of type
TEXT. BBEdit is happy to open just about any file if you ask it. Just be careful what you
edit!
Why would I want a Text Editor?
You might wonder why anyone would want to use a text editor on the Macintosh, that
bastion of GUI, WYSIWYG, and other fine graphical acronyms! The text editor might
seem a throwback to command-line systems such as vi and Emacs under Unix, or EDT
under VMS. Besides, you've probably already got at least one word processor, as well
as a code development environment (e.g., Metrowerks CodeWarrior).
Actually, a text editor can be very useful and very powerful. When writing in a text
editor, the writer doesn't worry about styles or formatting (except for indentation),
only text. This makes a text editor an excellent tool for composing code, in languages
ranging from Fortran to C to Perl.
If you're willing to give up the convenience of a graphical page-layout application for
the power of twiddling actual code, a text editor can be a very handy way to work with
markup languages such as TeX and HTML. BBEdit has a number of features (described
below) that make HTML editing easy, quick, and safe.
Although all text editors specialize in entering and editing text, the best also provide
extended features to make this process simpler and more flexible. The best text editors
share such features as automatic line numbering, find and replace, keyboard
navigation, auto-indentation, line wrapping, and various simple text transformations
such as changing case. They may also provide integrated capabilities for sorting lines,
checking spelling, and comparing files.
BBEdit has oodles of preferences (27 categories in version 5.0!) which are fairly well
organized under one, very large, easily navigable preferences dialog. Many
preferences can also be changed temporarily for the current session (using the popup
menus in the status bar) or changed permanently for a file (using the Window Options
or Printing Options items in the Edit menu).
(Aside for those who like trivia - the Philip Bar in a BBEdit window marks the
maximum width a window can be and still display completely on a classic Macintosh
screen (512 pixels wide) without horizontal scrolling. In a standard font such as
ProFont 9, the Philip Bar comes at 80 characters. The Philip Bar was named after
Philip Borenstein, the technical documentation writer who requested the feature.
Wouldn't you like to have a feature named after you? :-)
Figure 2. Preferences: Editor.
Source Code Development
BBEdit provides a wide range of features to support source code development. These
include syntax-sensitive text coloration, function popups, line shifting, split window
operation, and delimiter matching (when I type a closing parenthesis, brace, or
bracket, BBEdit can automatically highlight the matching delimiter).
BBEdit currently supports more than a dozen languages: 68K Assembler, C, C++,
Fortran, GuideScript, HTML, Java, Javascript, ObjectPascal, Perl, Rez, ScriptX,
Setext, Tcl, and TeX. Language types are determined from filename extensions (e.g., .pl
or .html); BBEdit does not (presently :-) "taste" the file's contents to determine its
type.
You can designate your preferred default language, as well as setting a language for
untitled windows and filenames without extensions, using the Languages preference
dialog. You can also add extensions to the list. For example, when MacPerl sends a file
to your preferred editor it appends " [Perl]" to the filename. I've set both ".pl [Perl]
and ".pm [Perl]" as Perl language file extensions.
Figure 3. Preferences: Languages.
Navigating your code
BBEdit takes note of all functions in the current file, listing them in a popup menu in
the status bar at the top of the window. You can choose to list functions alphabetically,
or in order within the file, using the Function Popup preference. Functions can also be
marked (using the Mark popup), as can just about anything else in the file.
If you combine the marking and function-handling capabilities with BBEdit's
split-screen feature, you have a very powerful editing and code-browsing tool. Just
grab the black mark at the top of the scroll bar (using the mouse) and drag it down to
turn one window into two. This creates a second, linked view into the file being edited.
Now, scroll (or jump) to a function calling point in the top pane; jump to the function
definition in the lower pane. You can keep the function definition in view as you scroll
through the code in the other pane. Edits made in either pane will be reflected in the
other.
Syntax coloring
Syntax colors are editable in the preferences. For most languages, BBEdit
differentiates between (and colors) keywords, strings, and comments. For HTML,
BBEdit differentiates between Images (IMG tags), Anchors, and General keywords, as
well using the Comment color defined for other languages. As of version 4.5.3, BBEdit
has been able to print in color (if you have a color printer) or in grayscale (if you
have a good grayscale printer).
Extending BBEdit's Capabilities
One of BBEdit's most useful features is the ability to install plug-ins which extend the
text editor's capabilities. Plug-ins can add powerful text-transformation
functionality. There's a plug-in that helps with indenting C code, several that work
with HTML and web sites, and quite a few that perform text insertion (e.g., Insert
Date, Insert Time) or modification (e.g., Sort..., Un/Comment, Copy Lines
Containing..., Prefix/Suffix Lines).
One favorite of mine is the LineSort Plugin http://home.rmi.net/~chm/linesort.html,
an enhancement over the standard Sort... plug-in. This plug-in features a floating
window, Undo capability, and the ability to choose to merge, remove, or retain
duplicate lines. If you pay the shareware fee, you also get to sort based on grep-style
pattern matching criteria.
I use a set of plug-ins, written by Brad Hansen
http://www.pobox.com/~bradh/bbedit, which turns BBEdit into my editor and code
development environment for MacPerl. The MacPerl plug-ins allow me to write my
code in BBEdit, check syntax, run the program, and browse any (gasp!) errors, all
from within BBEdit. Other plug-ins interface to formatters such as OzTeX and
Textures (Macintosh implementations of the TeX formatting language), PostScript
(for printing), the VOODOO version control software from Uni Software Plus
http://www.unisoft.co.at/products/voodoo.html, and more.
A large set of third-party plug-ins is included on the BBEdit CD (although check the
authors' web sites for recent updates!) Note, however, that not all plug-ins will work
with BBEdit Lite!
If you're interested in writing your own plug-ins, a plug-in SDK is available. See the
BBEdit online plug-in library pages http://web.barebones.com/support/plugins.html
for more information on extending BBEdit's features through plug-ins.
MacPerl - a Practical Example
Thanks to the MacPerl BBEdit plug-ins, BBEdit is my tool of choice for working with
MacPerl http://www.ptf.com/macperl, the freely available port of Perl 5 for the
Macintosh. MacPerl is an elegant and powerful standalone application. Its internal text
editor, however, is based on TextEdit (as used by SimpleText). As an code editing
environment, this leaves, ahem, some things to be desired, such as good indentation,
true monospace fonts, and the ability to edit large files (the 32 KB limit allows
approximately 1000 lines of Perl code).
In contrast, BBEdit handles large files, line numbering, function lookup, syntax
coloring, and more. The MacPerl plug-ins make calls (via Apple Events) to MacPerl,
providing me with syntax checking as well as the ability to run my script and view the
results without leaving BBEdit. Then, using BBEdit's FTP and line-termination
capabilities (described below), I can push the resulting files to a remote (e.g., Unix)
host for immediate use!
One of the MacPerl plug-ins provides the ability to create filters written in MacPerl.
These filters can then be run on the text in any BBEdit window.
When you run a filter, any text selected in the active BBEdit window is written to a
temporary file; the full path name of this file is then passed to the filter script as the
first element in the @ARGV array. If no text is selected, then all the text in the window
will be used.
A set of example filters is provided with the MacPerl plugin set. For example, there is
a filter to convert runs of spaces to tabs:
#!perl -p
# Remove spaces at beginning and end of each line
# change any other sequence of spaces to a tab
s/^ +//;
s/ +$//;
s/ +/\t/g;
The -p option in the first line imposes an implicit loop, causing MacPerl to read
through its arguments (in this case, the temporary file containing your selected text),
processing one line at a time.
Here is another filter, which inserts an (editable) C header template; the <> structure
is an input operator which retrieves the file name. $ucname is an upper-case version
of the name, for use in cpp macros. Note that the print command sees a multi-line text
string, enclosed by double quotes.
#!perl
# Insert heading for .h file
# use selected text as file name.
$filename = <>;
$ucname = uc $filename;
print "#ifndef ${ucname}_H
#define ${ucname}_H
/**********************************************************
*
* File: $filename.h
*
* Function: Declarations for $filename.cpp
*
*
* Copyright: Copyright (c) 1995
* All Rights Reserved.
*