old-www/LDP/LG/issue35/anderson.html

178 lines
6.0 KiB
HTML

<!--startcut ==========================================================-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<title>Basic Emacs LG #35</title>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#A000A0"
ALINK="#FF0000">
<!--endcut ============================================================-->
<H4>
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">Basic Emacs</font></H1>
<H4>By <a href="mailto:paul@geeky1.ebtech.net">Paul Anderson</a></H4>
</center>
<P> <HR> <P>
Emacs is, by nature, a very difficult program to use. Few people can even
figure out how to exit it, let alone use it. I won't cover configuring
emacs, as that is a whole art unto itself, one which I have yet to master.
<p>
You probably already have emacs installed, I'll assume you do. At the
command prompt, type:
<p>
<pre>emacs</pre>
<p>
Emacs will start up with a scratch buffer, which isn't really meant for anything
other than scratch notes. So, we must bring emacs up with a filename on the
command-line. Before we do that, we must exit emacs. Hit C-x C-c(hold down
control, then press x, then press c), and it'll exit. Now, let's bring it
up with a filename:
<p>
<pre>emacs bork.txt</pre>
<p>
The screen will look something like this:
<p>
<pre>
Buffers Files Tools Edit Search Mule Help
----:---F1 bork.txt (Text)--L1--All-----------------------------------
(New file)
</pre>
<p>
Now, let's look at the bottom status line. It displays the filename we're working
on, informs that it's using the Text mode(more on emacs modes later in this doc)
, that we're on line 1, and it's display all of the file. As an example of what it will display while editing a file with information in it, here's what's on
the status bar on my screen:
<pre>
----:**-F1 emacs.html (HTML)--L59--70%----------------------------------
</pre>
<p>
The two asterisks show that file has been changed since I last saved, I'm
editing emacs.html, emacs is using it's HTML mode, I'm on line 59 and 70% of
file is displayed on the screen. Now, type some text in. You'll notice the
asterisks and line number. Now, let's save your masterpeice! Hit C-x C-s(that's
hold down control, press x then s), and at the bottom it will say:
<p>
<pre>
Wrote /home/paul/bork.txt
</pre>
<p>
You've just saved your work! Let's exit emacs and bring it back up with our
text file, and you can see for certain that the file has been saved. That covers
the basics you need to get around with emacs, now on to....
<p>
<hr>
<h1>Special Modes</h1>
<p>
Emacs has a built-in LISP interpreter, making it so that emacs can be programmed
to do various tasks. This allows it to handle HTML, SGML, shell scripts, C code,
texinfo source, TeX source, etc. more appropriately. The classic thing to do
with programmable calculators has always been to write games for them - guess
what one of the classic things to do with a programmable text editor like emacs
is. Emacs has a LISP-based version of the classic pseudo-AI program, Eliza.
In this case, it's designed to act as a psychoanalyst. Now this part can
get a bit tricky, as the official key used to run these modes is named 'meta'.
PCs don't have a true-blue meta key, so it's often mapped to one of the alt keys,
or a control key. Hit M-x, trying first the left alt, then right alt and same
for controls, you'll know when you've hit the right one when the bottom line
displays M-x with the cursor beside it. Now, type doctor and hit enter.
The following text will appear on your screen:
<p>
<pre>
I am the psychotherapist. Please, describe your problems. Each time
you are finished talking, type RET twice.
</pre>
<p>
Go ahead, chatter with doc for a bit. It can be entertaining...
<p>
Back so soon? Well, it does get a wee bit boring after a while... Now that
you're back, we're gonna write some C code to show the benefit of using emacs.
I want you bring up emacs, and edit ~/.emacs<p>
Put the following in it:
<p>
<pre>
(add-hook 'c-mode-common-hook
'(lambda () (c-toggle-auto-state 1)))
</pre>
<p>
This may, at first glance, look like gibberish. It's actually LISP code,
at seeing this you now understand why some derisevly state that LISP
really stands for <u>Lots of Irritating Superfluous Parentheses</u>.
Fortunately, you don't need to know LISP right now - though you will
have to learn it to do much configuring with emacs. Save the file, and
start emacs editing a file named foo.c<p>
Type the following:
<p>
<pre>
#include &lt;stdio.h&gt;
main(){printf("\nHello.\n");}
</pre>
<p>
Doesn't look like what's here, does it? Notice how emacs automagically
indents the code properly and indicates to you that the braces are matched?
If you don't program in C, you won't realize just how neat this is.
Beleive me, if you do much coding, it's a godsend!
<p>
Emacs has similar modes for HTML, SGML, even plaintext. It can read e-mail,
usenet news and browse the web. Emacs includes everything, including the
kitchen sink. Browse the docs, and use it, and with time you will
begin to use emacs to it's full capacity.
<p>
<p>
May the source be with you,<br>
<i>--Paul Anderson, paul@geeky1.ebtech.net</i>
<!--===================================================================-->
<P> <hr> <P>
<center><H5>Copyright &copy; 1998, Paul Anderson <BR>
Published in Issue 35 of <i>Linux Gazette</i>, December 1998</H5></center>
<!--===================================================================-->
<P> <hr> <P>
<A HREF="./index.html"><IMG ALIGN=BOTTOM SRC="../gx/indexnew.gif"
ALT="[ TABLE OF CONTENTS ]"></A>
<A HREF="../index.html"><IMG ALIGN=BOTTOM SRC="../gx/homenew.gif"
ALT="[ FRONT PAGE ]"></A>
<A HREF="./lg_answer35.html"><IMG SRC="../gx/back2.gif"
ALT=" Back "></A>
<A HREF="./york.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
<P> <hr> <P>
<!--startcut ==========================================================-->
</BODY>
</HTML>
<!--endcut ============================================================-->