old-www/LDP/LG/issue87/bint.html

356 lines
17 KiB
HTML

<!--startcut ==============================================-->
<!-- *** BEGIN HTML header *** -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML><HEAD>
<title>The Ultimate Editor LG #87</title>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#0000AF"
ALINK="#FF0000">
<!-- *** END HTML header *** -->
<!-- *** BEGIN navbar *** -->
<IMG ALT="" SRC="../gx/navbar/left.jpg" WIDTH="14" HEIGHT="45" BORDER="0" ALIGN="bottom"><A HREF="lg_bytes.html"><IMG ALT="[ Prev ]" SRC="../gx/navbar/prev.jpg" WIDTH="16" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="index.html"><IMG ALT="[ Table of Contents ]" SRC="../gx/navbar/toc.jpg" WIDTH="220" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../index.html"><IMG ALT="[ Front Page ]" SRC="../gx/navbar/frontpage.jpg" WIDTH="137" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="http://www.linuxgazette.com/cgi-bin/talkback/all.py?site=LG&article=http://www.linuxgazette.com/issue87/bint.html"><IMG ALT="[ Talkback ]" SRC="../gx/navbar/talkback.jpg" WIDTH="121" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../lg_faq.html"><IMG ALT="[ FAQ ]" SRC="./../gx/navbar/faq.jpg"WIDTH="62" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="collinge.html"><IMG ALT="[ Next ]" SRC="../gx/navbar/next.jpg" WIDTH="15" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><IMG ALT="" SRC="../gx/navbar/right.jpg" WIDTH="15" HEIGHT="45" ALIGN="bottom">
<!-- *** END navbar *** -->
<!--endcut ============================================================-->
<TABLE BORDER><TR><TD WIDTH="200">
<A HREF="http://www.linuxgazette.com/">
<IMG ALT="LINUX GAZETTE" SRC="../gx/2002/lglogo_200x41.png"
WIDTH="200" HEIGHT="41" border="0"></A>
<BR CLEAR="all">
<SMALL>...<I>making Linux just a little more fun!</I></SMALL>
</TD><TD WIDTH="380">
<CENTER>
<BIG><BIG><STRONG><FONT COLOR="maroon">The Ultimate Editor</FONT></STRONG></BIG></BIG>
<BR>
<STRONG>By <A HREF="../authors/bint.html">Stephen Bint</A></STRONG>
</CENTER>
</TD></TR>
</TABLE>
<P>
<!-- END header -->
<P><CENTER><B><I>Somewhere, out there, is a C++ programmer whom destiny has
chosen to be our liberator.</I></B></CENTER>
<H3>The Ultimate Editor's Time Has Come</H3>
<P>How can it be that Windows users are spoiled for choice of excellent
text editors, while not one decent one exists for the Linux console?
Linux is a better OS, supported by better programmers who are dedicated
to producing better tools for eachother's benefit. The text editor is
the programmer's most important and frequently used tool. Yet Linux
console editors are rubbish. How can this be?
<P>Those of us who migrate from windows to Linux expect a text editor,
at the very least, to allow selection of text with the mouse and to have
mouse-sensitive menus and dialogs. Of all the editors only mcedit, the
editor built in to the Midnight Commander disk navigator, has these
features. The rest have no dialogs and either no mouse interface or a
very limited, stupid one.
<P>Yet even mcedit has a fatal flaw. If there is anything about its
behaviour you don't like, or a function it lacks which you would like to
add, you will find that reverse-engineering the source to solve that
problem is more difficult than writing your own text editor from
scratch. Unfortunately mcedit is quite basic, so it really needs added
functionality and there is no easy way to add it.
<P><I>What is the point of Open Source being open, if it is so complicated
and poorly documented as to be impenetrable to anyone but the author?</I>
<P>Let's face it, we are all the same. We love writing code and hate
writing docs. Writing slick algorithms is fun but explaining how they
work to newbies is a bore. Yet if someone were to take the trouble to
write an editor with maintenace in mind and build in a simple way to add
C++ functions to menus, it might be the last editor ever written. No one
would bother to write a text editor if one existed, whose behaviour was
easy to change and to which any function could be added.
<H3>Blasphemy</H3>
<P>Stallmanist Fundamentalists may say at this point, emacs is
extensible. So it is, but you need to learn a second language to extend
it. Besides that, the basic editor has a crude and confusing user
interface which cannot be improved by adding lisp modules.
<P>Some of us who aspire to use Linux are ordinary people, not software
supermen. It is cruel and unnecessary to tell someone struggling to
learn their first language, that they must simultaneously learn a second
language in order to make their editor work they way they want it to.
<P>It will never do. Emacs isn't a tool. It's an intelligence test. It
is time stupid people fought back against the elitists who are so
clever, they find learning emacs a breeze. Notice that you do not have
to learn how to use mcedit. It does what you expect so there is nothing
to learn.
<P>The Ultimate Editor would be what emacs should have been: an
extensible editor with an intuitive mouse-and-menu interface.
<EM>[Editor's note: emacs was born before mice and pulldown
menus were invented.]</EM> Instead of
complicating the picture with a second language, the extensions would be
written in C++. It would come with a programmer's guide, explaining how
to install your own menu commands and also describing the anatomy of the
source so that you can easily locate the module you are after if you
want to change something about its basic behaviour. It would be a
do-it-yourself editor kit.
<H3>O, Beautiful Tool</H3>
<P>If the Ultimate Editor existed, this is what it would be like. You
would download it and build it and find it has the basic functionality
of mcedit. It would have mouse selection, mouse-sensitive menus and a
file open dialog box that allows you to navigate the disk by
double-clicking on directories.
<P>It would have few functions: File Open, File Save, File Save As,
Exit, Cut, Copy, Paste, Delete and Help. At first there would be no
search function, but the README would explain that the source file for
the search function is included and would give simple instructions for
how to add it. The lines to be added to the source would already be
there, but commented out, to make it easy to add the search function.
<P>To add the search function you would have to:
<P>1. Move its source file to the editor's src directory
<P>2. Declare the function at the top of main.cc like this:
<PRE> int show_search_dlg();</PRE>
<P>3. Add a line to main() (actually uncomment a line) like this:
<PRE> ed.add_menu_cmd( show_search_dlg, "Search", "Edit", F2_key, SHIFT_PRESSED );</PRE>
<P>...which installs a command labelled "Search" on the "Edit" menu,
which can be activated directly by pressing Shift-F2.
<P>4. In the Makefile, add (uncomment) a compile rule for the source
file and add its name to the list of objects to be linked.
<P>5. Run Make and find that the search function is now on the menu.
<P>Having followed this procedure, even a complete newbie will know how
to write their own menu functions. The editor will be a global variable,
(C++ object) accessible in any source file the user writes, through its
header file. Its member functions will report the states of all its
internal variables, such as cursor position and area selected. The text
array containing the file being edited will be accessible as a member
variable, so that the file can be scanned and modified within the user
function.
<H3>Living Colour</H3>
<P>Usually, the logic of colourization is imposed on users. Some editors
offer a dialog to change the colours and to add keywords, but the logic
is dictated by the author.
<P>The Ultimate Editor will offer an easy way for users to write their
own colourization routines. Apart from enabling people to colourize rare
and eccentric languages, this feature will unlock the hidden potential
of colourization.
<P>Think how many ways you could choose to colour source and what an aid
to reverse engineering it could be. Depending on your purpose, you might
want to colour identifiers according to which header file they are
declared in, or whether they are automatic or allocated, or use colours
to indicate their scope. You might choose to have several colouring
schemes installed and switch between them with hot keys.
<P>To make colourizing simple, the Ultimate Editor will store its files
in file arrays which contain two arrays of strings - one for the text
and another for the colours. The file array will keep the sizes of the
strings in these arrays synchronized so that, for every character stored
in the text array, there is always a byte representing its colour at the
same co-ordinates in the colour array.
<P>The editor will always draw on the colour array when it refreshes, so
all the programmer has to do in order to colour a character at certain
co-ordinates, is change the value in the colour array at those same
co-ordinates and refresh the display.
<H3>Ninety Percent Widgets</H3>
<P>From the user's point of view, dialog boxes appear to be a small part
of a text editor. From the programmer's perspective, it is the other way
round. The editable fields which appear in dialogs are fully functional
editing windows with a couple of features disabled. So to write the
Ultimate Editor is really to write the Ultimate Widget Library.
<P>A well-written widget library with good docs is more than an
accessory to an extensible editor. If users become familiar with the
library in order to improve the editor, they can use it to produce
configuration dialogs which assist non-experts in configuring other
software, by asking simple questions and writing out their wishes in a
config file.
<P>Linuxconf is a very important configuration tool, but it is fading
like a dead language because it is hard to use. Because it is hard to
use, it is hard to get enthusiastic about improving it. Users and
programmers both drift instead towards other, distribution-specific
configuration programs. If linuxconf was rewritten to show
mouse-sensitive dialogs that behave like proper dialogs (like X-windows
dialogs), it might grow to include modules to enable clueless newbies to
configure any popular package.
<P>Do you not agree, that the main obstacle to the popularity of Linux,
is esotericism? I mean, no-one bothers to write software for newbies
because only software experts ever use Linux. The growth of Linux is
being prevented by an elitist Catch-22. If idiot-friendly configuration
programs were not important to the popularity of an OS, would Microsoft
have lavished so much time and money on them?
<P>Rewriting linuxconf with a simple but modern widget library would be
the first step to making what it should be - a project that never ends.
It should be continually growing as more modules are added, until it
becomes the one-stop-shop through which all Linux software can be
configured by children.
<H3>A Little Help</H3>
<P>I want this challenge to be open to anyone who knows C++. Because
interfacing with the mouse, keyboard and colour-text screen under Linux
is a low-level nightmare, I have produced an interface library which
makes it as simple under Linux as it is under DOS. I recommend it over
Slang for the purpose of writing an editor for several reasons.
<P>First, the Slang source (including docs and demo programs) zipped is
740k, whereas my library's source zips to 42k. Second, Slang does not
report mouse movement, so a Slang program cannot drag-select with the
mouse. Third, the colouring system in Slang is complicated, but mine
represents the screen as an EGA-style buffer of character/colour byte
pairs.
<P>I wrote my library after an attempt to use Slang myself drove me to
the conclusion that its all-platform capability generated an
unacceptable overhead and took less than full advantage of the potential
of the Linux console. I don't doubt that the author of Slang is a better
programmer than me, but I have produced a library specifically to serve
programmers who want to produce the first adequate editor for the Linux
console.
<P>You can download it here: <A href="http://members.lycos.co.uk/ctio/">http://members.lycos.co.uk/ctio/</A>
<P>And now that interfacing with the console is as simple under Linux as
it ever was under DOS, the obstacle to Linux editors having the same
basic features as DOS editors has been removed. Now anyone who knows C++
can do something great. To produce the editor and widget library I have
described might change the course of the history of free software, by
rolling out a red carpet to entry-level programmers.
<H3>Invent the Wheel</H3>
<P>I am constantly being told that there is no need to reinvent the
wheel. A ship could sail the Atlantic, powered only by my sighs. Let me
assure you, I will march up and down the High Street blowing a trumpet
and proclaiming at the top of my voice, "NO NEED TO REINVENT THE WHEEL!"
on the day that someone actually produces a ROUND WHEEL.
<P>In theory, any Open Source editor can be hacked and made perfect, but
we are still waiting for a mouse-aware console editor which can be
hacked and improved by programmers with I.Q.s under 170. Without
adequate documentation, Open Source is a Closed Book to ordinary
mortals.
<H3>Destiny</H3>
<P>What are you, C++ programmer? Someone with the power to build
abstract machines, an inventor that has transcended the limitations of
the material world that crushed the dreams of human inventors of every
generation before this? The citizens of the beautiful city of Free
Software scrape along on square wheels and you could solve their
problem.
<P>If you are sitting on your flabby backside thinking, "Nyaahh. It's
not for me", then who is it for? Not me, I'm homeless. I have had access
to a computer long enough to write the interface library, but now I am
living in a tent and the closest I get to a computer is occasional
internet access at a day centre for the unemployed. That is why it can't
be me. Why can't it be you?
<P>It might be your destiny to be the author of that Ultimate Editor,
the last editor ever written. Perhaps no more than a month after the
importance of free software has been recognised and Stallman's face is
carved on Mount Rushmore, they may have to blow it off with dynamite and
carve yours on there instead.
<H2>Reference</H2>
<P><STRONG><A href="http://www.s-lang.org/">Slang</A></STRONG>, by John
E. Davis. Slang appears to have eclipsed curses, as the
keyboard/mouse/colour text interface library most programmers would
recommend. If you are dead clever, you might find a way to use the
subset of Slang purely concerned with the console interface, which is
part of the <A href="http://www.ibiblio.org/mc/">Midnight Commander</A>
source. It is smaller and allows text selection at the Linux console, while
still offering limited functionality on less capable terminals, even
telnet windows!
<P><STRONG><A href="http://members.lycos.co.uk/ctio/">CTIO</A></STRONG>,
by Stephen Bint. By far the simplest and best console interface library
I have ever written. Only works at the Linux console and DOS, not in
rxvt/xterm nor telnet windows (but it's only 42k). Read about my struggle
to write it <A href="http://www.linuxgazette.com/issue86/bint.html">
here.</A>
<P><STRONG><A href="http://www.gnu.org/software/emacs/emacs.html">emacs</A></STRONG>,
by Richard Stallman. A millstone in the history of free software.
<!-- *** BEGIN author bio *** -->
<P>&nbsp;
<P>
<!-- *** BEGIN bio *** -->
<P>
<img ALIGN="LEFT" ALT="[BIO]" SRC="../gx/2002/note.png">
<em>
Stephen is a homeless Englishman who lives in a tent in the woods. He eats out
of bins and smokes cigarette butts he finds on the road. Though he once worked
for a short time as a C programmer, he prefers to describe himself as a "keen
amateur".
</em>
<br CLEAR="all">
<!-- *** END bio *** -->
<!-- *** END author bio *** -->
<!-- *** BEGIN copyright *** -->
<hr>
<CENTER><SMALL><STRONG>
Copyright &copy; 2003, Stephen Bint.
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 87 of <i>Linux Gazette</i>, February 2003
</STRONG></SMALL></CENTER>
<!-- *** END copyright *** -->
<HR>
<!--startcut ==========================================================-->
<CENTER>
<!-- *** BEGIN navbar *** -->
<IMG ALT="" SRC="../gx/navbar/left.jpg" WIDTH="14" HEIGHT="45" BORDER="0" ALIGN="bottom"><A HREF="lg_bytes.html"><IMG ALT="[ Prev ]" SRC="../gx/navbar/prev.jpg" WIDTH="16" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="index.html"><IMG ALT="[ Table of Contents ]" SRC="../gx/navbar/toc.jpg" WIDTH="220" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../index.html"><IMG ALT="[ Front Page ]" SRC="../gx/navbar/frontpage.jpg" WIDTH="137" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="http://www.linuxgazette.com/cgi-bin/talkback/all.py?site=LG&article=http://www.linuxgazette.com/issue87/bint.html"><IMG ALT="[ Talkback ]" SRC="../gx/navbar/talkback.jpg" WIDTH="121" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><A HREF="../lg_faq.html"><IMG ALT="[ FAQ ]" SRC="./../gx/navbar/faq.jpg"WIDTH="62" HEIGHT="45" BORDER="0" ALIGN="bottom"></A><A HREF="collinge.html"><IMG ALT="[ Next ]" SRC="../gx/navbar/next.jpg" WIDTH="15" HEIGHT="45" BORDER="0" ALIGN="bottom" ></A><IMG ALT="" SRC="../gx/navbar/right.jpg" WIDTH="15" HEIGHT="45" ALIGN="bottom">
<!-- *** END navbar *** -->
</CENTER>
</BODY></HTML>
<!--endcut ============================================================-->