You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

940 lines
32 KiB

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Emacs Tutorial</title>
<meta name="generator" content="muse.el">
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<style type="text/css">
body {
background: white; color: black;
margin-left: 3%; margin-right: 7%;
}
p { margin-top: 1% }
p.verse { margin-left: 3% }
.example { margin-left: 3% }
h2 {
margin-top: 25px;
margin-bottom: 0px;
}
h3 { margin-bottom: 0px; }
</style>
</head>
<body>
<h1>Emacs Tutorial</h1>
<!-- Page published by Emacs Muse begins here -->
<div class="contents">
<dl>
<dt>
<a href="#sec1">Getting Started</a>
</dt>
<dt>
<a href="#sec2">Basic Commands</a>
</dt>
<dt>
<a href="#sec3">Getting Help</a>
</dt>
<dt>
<a href="#sec4">Extended Commands and Command Completion</a>
</dt>
<dt>
<a href="#sec5">Kill &amp; Yank (Cut/Copy and Paste)</a>
</dt>
<dt>
<a href="#sec6">Search &amp; Replace</a>
</dt>
<dt>
<a href="#sec7">Emacs Modes</a>
</dt>
<dt>
<a href="#sec8">Buffers</a>
</dt>
<dt>
<a href="#sec9">Windows</a>
</dt>
<dt>
<a href="#sec10">Dired Mode</a>
</dt>
<dt>
<a href="#sec11">Shell Modes</a>
</dt>
<dt>
<a href="#sec12">Emacs Startup and Configuration</a>
</dt>
<dt>
<a href="#sec13">Browsing the Web in Emacs with w3m</a>
</dt>
<dt>
<a href="#sec14">Where to Go From Here</a>
</dt>
</dl>
</div>
<h2><a name="sec1" id="sec1"></a>
Getting Started</h2>
<p class="first">Emacs is an extensible, customizable, full-screen text editor. You can
learn enough to be productive in Emacs in 30 minutes, but there is
enough to learn about Emacs to keep you busy for years. The goal of
this tutorial is to show you enough so that you are comfortable using
Emacs as a work environment, not just as a text editor. This document
refers to GNU Emacs version 24 (the version installed on SDF).</p>
<p>Start by typing <code>emacs</code> at the shell prompt, read the splash screen and
hit any key to clear it. You'll be in a so-called <em>scratch buffer</em>. A
<em>buffer</em> is a place in Emacs that usually contains the text of a file
for editing (but can contain other text, like error messages, command
output or directory contents). Anyway, the scratch buffer is just that
- a place to scratch notes or otherwise put temporary snippets of text
you don't care to save. When you exit Emacs, the contents of the
scratch buffer are discarded.</p>
<p>You will see a white or grey line at the bottom of the Emacs window,
with some information displayed like the name of the buffer or file
you are viewing, the line number your cursor is on, and whether or not
the current buffer has been modified (indicated by two asterisks to
the left of the buffer name). This is called the <em>modeline</em>. Like
everything else in Emacs, what is displayed in the modeline is
configurable, but the defaults should work fine for most people.</p>
<p>Just below the modeline is a blank line called the <em>echo area</em> or
<em>minibuffer</em>. The minibuffer is used when Emacs has to gather data from
the user, like which filename to edit, or when Emacs has to display
information to the user, like error messages. You will also see Emacs
command sequences echoed here as you type them.</p>
<h2><a name="sec2" id="sec2"></a>
Basic Commands</h2>
<p class="first">Emacs is a non-modal editor, meaning when you have a file loaded into
a buffer, you can type text and it will appear directly in the
buffer. You don't need to be in a special insert mode as in vi. That
also means cursor movement and other text manipulation commands are
not mapped to single alphabetic characters as in vi. Commands in Emacs
are typically entered with a two- or three-key sequence, either
Control- or Alt- followed by a one- or two-key sequence. The Control
key in the Emacs documentation is denoted by &quot;C&quot; and Alt by &quot;M&quot; (Emacs
documentation refers to the Alt key as Meta, hence the &quot;M&quot;. The Esc
key on most keyboards acts as an Alt or Meta key as well). For
example, to quit Emacs, you type <code>C-x C-c</code>, meaning you hold down the
Control key, hit the &quot;x&quot; key and release it, then hit the &quot;c&quot; key and
release it. To move up a screenfull of text, you type <code>M-v</code>, meaning
hold down the Alt key and type &quot;v&quot;. With that in mind, here are a few
useful key sequences:</p>
<table class="muse-table" border="2" cellpadding="5">
<tbody>
<tr>
<td>C-x C-f</td>
<td>Find file and load into buffer (Emacs prompts for filename)</td>
</tr>
<tr>
<td>C-x C-s</td>
<td>Save the current buffer</td>
</tr>
<tr>
<td>C-x C-w</td>
<td>Save the current buffer under a different name (Emacs prompts for the new name)</td>
</tr>
<tr>
<td>C-x C-c</td>
<td>Quit Emacs, prompting if you have not saved any buffers</td>
</tr>
<tr>
<td>Arrow keys or C-f, C-b, C-n, C-p</td>
<td>Right (forward), left (back), down (next), up (previous), respectively</td>
</tr>
<tr>
<td>C-k</td>
<td>Delete from cursor to end of line</td>
</tr>
<tr>
<td>C-a</td>
<td>Go to start of line</td>
</tr>
<tr>
<td>C-e</td>
<td>Go to end of line</td>
</tr>
<tr>
<td>C-v</td>
<td>Go down a page</td>
</tr>
<tr>
<td>M-v</td>
<td>Go up a page</td>
</tr>
<tr>
<td>C-/</td>
<td>Undo</td>
</tr>
<tr>
<td>C-_</td>
<td>Undo (alias for C-/)</td>
</tr>
<tr>
<td>C-x u</td>
<td>Undo (alias for C-/)</td>
</tr>
<tr>
<td>C-g</td>
<td>Abort the current command</td>
</tr>
<tr>
<td>C-l</td>
<td>Redraw and center screen at cursor</td>
</tr>
<tr>
<td>M-&lt;</td>
<td>Go to start of buffer</td>
</tr>
<tr>
<td>M-&gt;</td>
<td>Go to end of buffer</td>
</tr>
<tr>
<td>Backspace</td>
<td>Delete previous character</td>
</tr>
</tbody>
</table>
<h2><a name="sec3" id="sec3"></a>
Getting Help</h2>
<p class="first">GNU Emacs has excellent help facilities. Most of them are accessed
with the prefix <code>C-h</code>. The Emacs tutorial is an interactive introduction
you can work through fairly quickly to learn the most common key
bindings. <code>C-h i</code> accesses the GNU hypertext info browser from within
Emacs, displaying system info pages (including the Emacs manual
itself). Here are some of the help-related key bindings:</p>
<table class="muse-table" border="2" cellpadding="5">
<tbody>
<tr>
<td>C-h t</td>
<td>Emacs tutorial</td>
</tr>
<tr>
<td>C-h i</td>
<td>Load info browser</td>
</tr>
<tr>
<td>C-h m</td>
<td>Display help on current mode</td>
</tr>
<tr>
<td>C-h f</td>
<td>Display help on function (Emacs prompts for function)</td>
</tr>
<tr>
<td>C-h k</td>
<td>Display help on key (Emacs prompts for key)</td>
</tr>
<tr>
<td>M-x man</td>
<td>Display a man page in a new buffer (Emacs prompts for man page)</td>
</tr>
</tbody>
</table>
<h2><a name="sec4" id="sec4"></a>
Extended Commands and Command Completion</h2>
<p class="first">Emacs has the concept of <em>extended commands</em>, which consist of <code>M-x</code>
followed by the name of the command. As an example of a useful
extended command, sometimes the backspace key gets mapped to C-h (I
find this happens sometimes under remote screen sessions, you'll know
this is the case if you hit the backspace key twice and the emacs help
buffer pops up, just hit <code>C-g</code> to clear the help window). To get the
backspace key to act as it should (i.e., it deletes the previous
character), you enter <code>M-x normal-erase-is-backspace-mode</code>. That's a lot
to type, so you can take advantage of Emacs' <em>command-completion</em> by
typing a partial command and hitting the <code>Tab</code> key one or more times. In
this case, you type <code>M-x normal-e</code> and hit <code>Tab</code>, and Emacs will complete
the command for you. You can then just hit <code>Enter</code> to execute the
command. If you don't type enough of the command to make it unique,
Emacs will display a list of alternatives for you to choose from. For
example, if you type <code>M-x normal-</code> and hit the <code>Tab</code> key, Emacs will pop
up a buffer named *Completion* with with two
alternatives for you to choose from: normal-mode and
mormal-erase-is-backspace-mode. Just type a bit more of the command
you want and hit tab again to narrow the completion list or to
complete the command if it is the only one left.</p>
<h2><a name="sec5" id="sec5"></a>
Kill &amp; Yank (Cut/Copy and Paste)</h2>
<p class="first">Most Emacs commands operate on the region defined by the <em>point</em>, which
is the location of the cursor at any given time, and the <em>mark</em>, which
is set with the command <code>C-space</code>. To copy or cut a region of text, move
the cursor to the start of the text area you are interested in and
type <code>C-space</code>. You will see &quot;Mark set&quot; in the echo area. Now move the
cursor to the end of the text region (which moves the point) and type
<code>M-w</code> for copy or <code>C-w</code> for cut (both called killing text). The text you
copy or cut is stored by Emacs in the <em>kill-ring</em>, which is a circular
buffer that stores the text snippets you kill in a last-in-first-out
order. To paste the most recently stored text, move the cursor to
where the text should be inserted, and type <code>C-y</code>. The &quot;y&quot; stands for
yank, what you'll see paste referred to in the Emacs help
documentation (remember Emacs pre-dated modern windowing systems and
other full-screen editors, so the terms cut and paste were not in use
yet). After a yank (<code>C-y</code>) command, you can replace the inserted text
with earlier kills in turn by typing <code>M-y</code> one or more times. Each time
you press <code>M-y</code> the next block of killed text is popped off of the kill
ring and inserted into your buffer, replacing the last insert at the
same time.</p>
<p>Here are the commands we discussed above, and a few other useful ones:</p>
<table class="muse-table" border="2" cellpadding="5">
<tbody>
<tr>
<td>C-space</td>
<td>Set the mark</td>
</tr>
<tr>
<td>C-w</td>
<td>Cut (kill)</td>
</tr>
<tr>
<td>M-w</td>
<td>Copy (kill)</td>
</tr>
<tr>
<td>C-y</td>
<td>Paste (yank)</td>
</tr>
<tr>
<td>M-y</td>
<td>Paste (yank) next saved selection</td>
</tr>
<tr>
<td>C-x h</td>
<td>Set point to start of buffer and mark to end of buffer (select the entire buffer)</td>
</tr>
<tr>
<td>C-x C-x</td>
<td>Go back to the last mark that was set</td>
</tr>
</tbody>
</table>
<h2><a name="sec6" id="sec6"></a>
Search &amp; Replace</h2>
<p class="first">Emacs has a nice search mode called <em>incremental search</em>. To use it,
type <code>C-s</code>. The text &quot;I-search:&quot; will appear in the echo area. Now
start typing a search string. As you type, Emacs will search for your
string in real-time (starting at point), highlighting any matches it
finds. You can backspace and re-type text, and the search will
continue to change with the text you type. When you find a match, you
can hit <code>C-s</code> to search again and jump to the next match, or you can
just hit <code>Enter</code> to exit the search mode and leave the cursor at the
last match. <code>C-g</code> will abort the search and put your cursor back where
you started. Searches will re-start at the top of a buffer if they hit
the bottom. You can search backwards in a similar fashion with <code>C-r</code>.</p>
<p>To replace text that matches a search pattern, type <code>M-%</code>. You'll see
&quot;Query replace:&quot; in the echo area. Type a search string, and hit
<code>Enter</code>. The echo area will now display &quot;Query replace &lt;search string&gt;
with:&quot;. Type the replacement string, and hit <code>Enter</code> again. Emacs will
search through your buffer, looking for the search string. When it
finds it, it will display &quot;Query replacing &lt;search string&gt; with
&lt;replacement string&gt;: (? for help)&quot;. Type &quot;y&quot; to replace this match
and move onto the next, or &quot;n&quot; to skip this match. Type &quot;!&quot; to replace
this occurrence of the search string and all other occurrences in your
buffer without prompting. As usual, you can type <code>C-g</code> to abort a
search/replace operation.</p>
<p>All searches in Emacs are case-insensitive by default, unless you type
at least one capital letter in your search string - in that case, the
search becomes case-sensitive.</p>
<p>One nice feature you'll notice is that Emacs remembers the search and
replacement strings you've used, so if you type <code>M-%</code> again, the last
search/replace operation can be repeated by just hitting the <code>Enter</code>
key. Prior search and replacement strings can be accessed with up- or
down-arrow keys or <code>M-p</code> and <code>M-n</code> (for previous- and next-,
respectively) - this is like the history mechanism in the Bash shell.</p>
<p>Another nice tip during searches is that <code>C-w</code> will highlight the word
around the cursor, then successive words each time it's pressed during
a search (so the highlighted area will grow with each press of
<code>C-w</code>). You can search again by typing <code>C-s</code>, this time the search
string is whatever was highlighted.</p>
<p>Here are the search and replace commands we discussed:</p>
<table class="muse-table" border="2" cellpadding="5">
<tbody>
<tr>
<td>C-s</td>
<td>Search forward</td>
</tr>
<tr>
<td>C-r</td>
<td>Search backward</td>
</tr>
<tr>
<td>M-%</td>
<td>Search and replace</td>
</tr>
<tr>
<td>C-g</td>
<td>Abort a search</td>
</tr>
<tr>
<td>C-w</td>
<td>During a search, highlight the word around the cursor</td>
</tr>
<tr>
<td>Up, down arrow keys or M-p, M-n</td>
<td>Access search string history</td>
</tr>
</tbody>
</table>
<h2><a name="sec7" id="sec7"></a>
Emacs Modes</h2>
<p class="first">Emacs buffers are associated with one so-called <em>major mode</em> and one or
more <em>minor modes</em>. Major modes typically denote a type of file, and are
associated with special command sequences and syntax highlighting just
for that file type. Minor modes change the behavior of an associated
major mode in small ways. For example, the major mode for editing text
is called text-mode, while the one for editing HTML is called
html-mode. Both text and html modes have a minor mode called
refill-mode that automatically formats paragraphs of text as you type
(similar to the behavior you expect from a word processor). You can
switch modes by just typing <code>M-x modename</code>, so <code>M-x html-mode</code> would
switch you into html-mode. Emacs can usually figure out the mode to
use by the file extension, so if you visit (load with <code>C-x C-f</code>) a file
ending in .html or .htm, html-mode will be selected for you, and if
you visit a file ending in .txt, text mode will be selected.</p>
<p>As an example, say you want to create a new text document. You type
<code>C-x C-f foo.txt</code> and Emacs creates an empty buffer for you named
&quot;foo.txt&quot;. Notice the modeline displays &quot;(Text)&quot; to indicate the major
mode. Now type <code>M-x refi</code> and hit the Tab key. Emacs will complete
&quot;refill-mode&quot;. Hit enter, now the modeline displays &quot;(Text Refill)&quot; to
indicate the major and minor modes in effect. Experiment with refill
mode by typing some text and watch as Emacs wraps the lines for
you. Now go back and add or delete some text and notice how the
paragraph re-formats itself. Modes toggle on and off, so a second <code>M-x
refill-mode</code> will turn refilling off. Type some text and notice Emacs
no longer wraps lines or formats paragraphs for you. The mode for
buffers not associated with any special file type is called
fundamental-mode. This is the mode your scratch buffer is put in at
startup.</p>
<p>There are lots of Emacs major modes, many of which are useful for
programmers. There is c-mode, perl-mode, and c++-mode, for
example. Each mode has its own key bindings and syntax highlighting
rules. You can see the details of the currently selected major mode by
typing <code>C-h m</code>. To enable syntax highlighting on a source-code file,
you can type <code>M-x global-font-lock-mode</code> (on some operating systems,
packaged versions of Emacs will enable font lock [syntax highlighting]
for you automatically).</p>
<p>As an example of special key bindings, in html-mode, the key sequence
<code>C-c C-c h</code> will insert a properly formatted hyperlink into the text,
prompting you for the URL first. In other modes this key sequence will
have no effect.</p>
<p>Here are some of the most useful mode commands:</p>
<table class="muse-table" border="2" cellpadding="5">
<tbody>
<tr>
<td>M-x modename</td>
<td>Toggle the given major or minor mode</td>
</tr>
<tr>
<td>C-h m</td>
<td>Display help on the current major mode, including any special key bindings in effect</td>
</tr>
<tr>
<td>M-q</td>
<td>Used in text-mode to reformat a paragraph of text manually</td>
</tr>
<tr>
<td>M-x global-font-lock-mode</td>
<td>Toggle syntax highlighting</td>
</tr>
</tbody>
</table>
<h2><a name="sec8" id="sec8"></a>
Buffers</h2>
<p class="first">When you visit a file with <code>C-x C-f</code>, Emacs loads the file into a new
buffer created just for that file. Existing buffers are not destroyed,
but persist and can be switched to with <code>C-x b</code>. Emacs will prompt you
for a buffer name to switch to; tab-completion works here as it does
in other places. One tip that I wish I had known when I first started
using Emacs is to use a special mode called <em>iswitch mode</em> to help
manage buffers. Since it's not uncommon to have dozens of buffers in
an Emacs editing session, you can easily forget buffer names. With
iswitch mode enabled, a <code>C-x b</code> displays a list of buffers in the echo
area that changes in real-time as you type characters. You don't even
have to type the first few letters of a buffer name, any substring of
a buffer name will do. To enable iswitch mode, type the extended
command <code>M-x iswitchb-mode</code> (we'll see later how to permanently enable
modes like this in a startup file). To see a list of all buffers, type
<code>C-x C-b</code>. The buffer list will appear in a new window. Here is a list
of some useful buffer commands:</p>
<table class="muse-table" border="2" cellpadding="5">
<tbody>
<tr>
<td>C-x b</td>
<td>Switch to another buffer</td>
</tr>
<tr>
<td>C-x C-b</td>
<td>Display buffer list</td>
</tr>
<tr>
<td>C-x k</td>
<td>Kill current buffer (Emacs prompts for confirmation)</td>
</tr>
<tr>
<td>M-x iswitchb-mode</td>
<td>Enable iswitch mode, for smart buffer name completion with C-x b</td>
</tr>
</tbody>
</table>
<h2><a name="sec9" id="sec9"></a>
Windows</h2>
<p class="first">The Emacs screen area can be divided into multiple <em>windows</em>. Each
window contains one buffer, so the contents of a window can change
depending on the buffer it contains. The most common way to create new
windows is to split the screen into two regions with <code>C-x 2</code> or <code>C-x
3</code>. The first splits the screen in half horizontally, the second splits
it vertically. Any Emacs window can be split multiple times, so if you
have a large display, you could have lots of windows open. You can
cycle through visible windows with <code>C-x o</code> (think of the &quot;o&quot; as meaning
&quot;other window&quot;). When you do have another window open, it's sometimes
useful to scroll the other window without leaving your current
one. You can do this with <code>C-M-v</code>. This is particularly useful for when
Emacs pops up a completion or help buffer in a new window that you
would like to scroll through.</p>
<p>You can close a window with <code>C-x 0</code> or <code>C-x 1</code>. The first closes the
window you are currently in, the second closes all the other windows,
but leaves the window you are currently in open for you. Closing a
window does not destroy the buffer it contains, so you can think of a
window as a view into a buffer (in fact you can have multiple windows
visiting different parts of the same buffer). Here is a list of the
most useful window commands:</p>
<table class="muse-table" border="2" cellpadding="5">
<tbody>
<tr>
<td>C-x 0</td>
<td>Close this window</td>
</tr>
<tr>
<td>C-x 1</td>
<td>Close all other visible windows</td>
</tr>
<tr>
<td>C-x 2</td>
<td>Split horizontally</td>
</tr>
<tr>
<td>C-x 3</td>
<td>Split vertically</td>
</tr>
<tr>
<td>C-x o</td>
<td>Switch to other window</td>
</tr>
<tr>
<td>C-M-v</td>
<td>Scroll other window</td>
</tr>
</tbody>
</table>
<h2><a name="sec10" id="sec10"></a>
Dired Mode</h2>
<p class="first">If you type the name of a directory after a <code>C-x C-f</code> command, Emacs
will display the directory contents in a new buffer. By default, Emacs
displays the file name, permissions, owner/group, size and timestamp
of each file on a line by itself. You can visit a file by just moving
the cursor to it and hitting <code>Enter</code>. Dired mode is unlike other modes
in that single keys are used to effect commands. Here is a list of the
most useful dired commands:</p>
<table class="muse-table" border="2" cellpadding="5">
<tbody>
<tr>
<td>Left, right arrow keys or p, n</td>
<td>Previous and next file, respectively</td>
</tr>
<tr>
<td>Enter</td>
<td>Visit this file in this window</td>
</tr>
<tr>
<td>o</td>
<td>Visit this file in a new window</td>
</tr>
<tr>
<td>g</td>
<td>Refresh directory view</td>
</tr>
<tr>
<td>m</td>
<td>Mark file</td>
</tr>
<tr>
<td>u</td>
<td>Un-mark file</td>
</tr>
<tr>
<td>d</td>
<td>Mark a file for later deletion</td>
</tr>
<tr>
<td>x</td>
<td>Delete all files marked for deletion (Emacs prompts for confirmation)</td>
</tr>
<tr>
<td>D</td>
<td>Delete this file right now (Emacs prompts for confirmation)</td>
</tr>
<tr>
<td>C</td>
<td>Copy this file, or copy currently marked files (Emacs prompts for destination)</td>
</tr>
<tr>
<td>R</td>
<td>Rename/move this file, or rename/move currently marked files (Emacs prompts for destination)</td>
</tr>
<tr>
<td>M</td>
<td>Chmod this file, or chmod currently marked files (Emacs prompts for new permissions)</td>
</tr>
<tr>
<td>O</td>
<td>Chown this file, or chown currently marked files (Emacs prompts for new owner)</td>
</tr>
<tr>
<td>G</td>
<td>Chgrp this file, or chgrp currently marked files (Emacs prompts for new group)</td>
</tr>
<tr>
<td>+</td>
<td>Create directory (Emacs prompts for directory name)</td>
</tr>
<tr>
<td>!</td>
<td>Execute shell command on this file, or currently marked files (Emacs prompts for command)</td>
</tr>
</tbody>
</table>
<h2><a name="sec11" id="sec11"></a>
Shell Modes</h2>
<p class="first">It is possible to run a shell from within Emacs; there are a few
different ways to do so. The easiest way is to type <code>M-x shell</code>. This
creates a a buffer called *shell* with a shell
prompt. Shell commands you type are sent to a system shell and the
output displayed in the shell buffer. One thing you'll notice in shell
mode is that the arrow keys move you around the buffer - they don't
access command history as they do in most shells. To access command
history, use <code>M-p</code> and <code>M-n</code> for previous and next, respectively.</p>
<p>One of the drawbacks of shell-mode is that it is not suitable for
full-screen applications (like less, lynx, mutt or pine), to run these
inside of Emacs, you need to use a terminal mode. Type <code>M-x ansi-term</code>,
and specify which shell you would like to run (your default will be
the shell you are using, e.g. <code>/usr/pkg/bin/bash</code>).</p>
<p>On platforms without an underlying shell (e.g., Windows), Emacs has a
terminal emulator written entirely in Emacs Lisp. To enter it, type
<code>M-x eshell</code>. While not suitable for full-screen applications, it does
emulate a limited subset of shell features rather nicely. In this
shell mode, the arrow keys work as you would expect, and most shell
builtins and shell aliases work as well. Some external commands such
as grep work, although input/output redirection is not yet
implemented.</p>
<p>Here are the commands we discussed above:</p>
<table class="muse-table" border="2" cellpadding="5">
<tbody>
<tr>
<td>M-x shell</td>
<td>Shell mode, use M-p and M-n for command history</td>
</tr>
<tr>
<td>M-x eshell</td>
<td>Emacs Lisp shell emulator, use arrow keys for command history</td>
</tr>
<tr>
<td>M-x ansi-term</td>
<td>Full terminal emulator, suitable for full-screen applications.</td>
</tr>
</tbody>
</table>
<h2><a name="sec12" id="sec12"></a>
Emacs Startup and Configuration</h2>
<p class="first">When Emacs starts it will load a file named <code>.emacs</code> in your home
directory and execute the commands found in it. This file is written
in Emacs Lisp, but you can use it without knowing any Lisp, by copying
other people's sample files. It is mainly useful for making certain
extended commands a permanent part of your Emacs experience, so you
don't have to type them every time you start Emacs. In the example
below, comment lines start with one or more semi-colons, so you would
delete the semi-colons to enable the given feature.</p>
<pre class="example">
;; Sample ~/.emacs file
;;
;; Un-comment what you want to enable and re-start Emacs
;;
;;Load iswitch mode
;;(require 'iswitchb)
;;Make text mode the default for new buffers
;;(setq default-major-mode 'text-mode)
;;Turn on refill-mode whenever text mode is entered
;;(add-hook 'text-mode-hook
;; '(lambda () (refill-mode 1)))
;;Enable syntax highlighting when it's allowed
;;(when (fboundp 'global-font-lock-mode)
;; (global-font-lock-mode t))
;;Fix the backspace key
;;(normal-erase-is-backspace-mode 1)
;;Use cperl-mode for editing Perl code, it is better than perl-mode
;;(defalias 'perl-mode 'cperl-mode)
;;Don't blink my cursor, please
;;(blink-cursor-mode nil)
;;Display the current time in the modeline
;;(display-time-mode t)
;;Start the emacs server
;;
;;When this is running, programs calling emacsclient open a buffer
;;in the already running emacs. Useful in mutt or pine for composing
;;mail in Emacs. Type C-x # to exit client buffer and send the text
;;back to the application that called it.
;;(server-start)
</pre>
<p>The above example gives you a good idea of what can be done in a
<code>.emacs</code> file, for more in-depth configuration Emacs has a customization
mode that can be accessed with the extended command <code>M-x
customize</code>. Running it will put you in a curses-style application where
you can choose from customization menus and have your changes written
to your <code>.emacs</code> file automatically.</p>
<h2><a name="sec13" id="sec13"></a>
Browsing the Web in Emacs with w3m</h2>
<p><a href="http://sourceforge.net/projects/w3m/files/">Emacs w3m mode</a> will use the excellent <a href="http://w3m.sourceforge.net">w3m</a> text-mode browser and allow you to
surf the web in an Emacs buffer. To get started, add the following to your
<code>.emacs</code> file:</p>
<pre class="example">
(require 'w3m-load)
</pre>
<p>Then restart emacs, or place the cursor at the end of each line in turn and
press <code>C-x e</code>. Then you can open a new w3m buffer with <code>M-x w3m</code>. The basic key
bindings are as follows (note that these are taken from the w3m-mode help
page, which can be accessed at any time in a new window with <code>C-h m</code>):</p>
<table class="muse-table" border="2" cellpadding="5">
<tbody>
<tr>
<td>M-x w3m</td>
<td>Start browsing web with emacs-w3m.</td>
</tr>
<tr>
<td>q</td>
<td>Close all emacs-w3m windows, without deleting buffers.</td>
</tr>
<tr>
<td>Q</td>
<td>Exit browsing web. All emacs-w3m buffers will be deleted.</td>
</tr>
<tr>
<td>RET</td>
<td>Display the page pointed to by the link under point.</td>
</tr>
<tr>
<td>C-c C-c</td>
<td>Submit the form at point.</td>
</tr>
<tr>
<td>R</td>
<td>Reload the current page.</td>
</tr>
<tr>
<td>r</td>
<td>Redisplay the current page.</td>
</tr>
<tr>
<td>TAB</td>
<td>Move the point to the next anchor.</td>
</tr>
<tr>
<td>M-TAB</td>
<td>Move the point to the previous anchor.</td>
</tr>
<tr>
<td>B</td>
<td>Move back to the previous page in the history.</td>
</tr>
<tr>
<td>N</td>
<td>Move forward to the next page in the history.</td>
</tr>
<tr>
<td>U</td>
<td>Visit the web page.</td>
</tr>
<tr>
<td>H</td>
<td>Go to the Home page.</td>
</tr>
<tr>
<td>M-d</td>
<td>Download the URL.</td>
</tr>
<tr>
<td>d</td>
<td>Download the URL under point.</td>
</tr>
<tr>
<td>\</td>
<td>Display the html source of the current page.</td>
</tr>
<tr>
<td>SPC</td>
<td>Scroll up the current window, or go to the next page.</td>
</tr>
<tr>
<td>b</td>
<td>Scroll down the current window, or go to the previous page.</td>
</tr>
<tr>
<td>&gt;</td>
<td>Scroll to the left.</td>
</tr>
<tr>
<td>&lt;</td>
<td>Scroll to the right.</td>
</tr>
<tr>
<td>.</td>
<td>Shift to the left.</td>
</tr>
<tr>
<td>,</td>
<td>Shift to the right.</td>
</tr>
<tr>
<td>M-l</td>
<td>Recenter horizontally.</td>
</tr>
<tr>
<td>j</td>
<td>Next line.</td>
</tr>
<tr>
<td>k</td>
<td>Previous line.</td>
</tr>
<tr>
<td>l</td>
<td>Forward char.</td>
</tr>
<tr>
<td>h</td>
<td>Backward char.</td>
</tr>
<tr>
<td>s</td>
<td>Display the history of pages you have visited in the session.</td>
</tr>
<tr>
<td>S</td>
<td>Prompt for a search query and submit it to google.</td>
</tr>
<tr>
<td>v</td>
<td>Display the bookmarks list.</td>
</tr>
<tr>
<td>a</td>
<td>Add a url of the current page to a new bookmark.</td>
</tr>
<tr>
<td>M-a</td>
<td>Add the url under point to a new bookmark.</td>
</tr>
</tbody>
</table>
<p>There are many more features in w3m-mode, the mode help text details them
all with keybindings. To end your session and close all w3m buffers, just
press <code>Q</code> and answer <code>y</code> when prompted.</p>
<h2><a name="sec14" id="sec14"></a>
Where to Go From Here</h2>
<p class="first">Below are some links to resources and useful Emacs Lisp packages. Many Linux
and BSD-based operating systems have packages for most of these, so check
there before you attempt to install by hand:</p>
<ul>
<li><a href="http://www.gnu.org/software/emacs/tour/">Emacs Tour</a>: Guided tour of GNU Emacs with lots of screenshots.</li>
<li><a href="http://mwolson.org/projects/EmacsMuse.html">Muse</a>: A publishing and authoring environment that converts simple text markup into HTML, PDF, Texinfo, Docbook, LaTeX, Blosxom blog entries and more. This tutorial was written using muse-mode.</li>
<li><a href="http://www.emacswiki.org/cgi-bin/wiki">Emacs Wiki</a>: Loads of tips and howtos.
<center>
<p>$Id: emacs-tutorial.html,v 1.17 2015/04/30 11:30:50 slugmax Exp $</p>
</center></li>
</ul>
<!-- Page published by Emacs Muse ends here -->
</body>
</html>