This document is an attempt to supplement, not replace, the help files and other extensive literature available on emacs. It is intended as a beginning, nothing more.
For most simple text editing tasks on World, we recommend using pico, rather than emacs, especially for new users. However, if you feel ready for an editor with more power and utility, emacs, when used knowledgeably, is a very useful tool.
Emacs is a text editor, but it's also a lifestyle. Aside from its simple (or sophisticated!) text editor capabilities, it can also be used to read and send mail, access USENET news, enter regular shell commands, write and debug programs, and a lot more. Emacs has extensive on-line help which can be accessed through a menu system within emacs, while editing.
The emacs we use on World is called GNU emacs and is from the Free Software Foundation in Cambridge. This group of experienced programmers, led by Richard Stallman, is designing, implementing, and distributing free software. Their goal is to distribute an entirely free unix system.
If you are new to Emacs and want to access the built-in tutorial, you may do so from within an emacs session:
world% emacs filename
where filename is a filename of your creation, then once inside Emacs, type
C-h t
to access the online tutorial.
Alternatively, you may review the tutorial from this document.
I strongly suggest you download and print the tutorial in addition to running it inside Emacs. To do this, simply open the tutorial and save it to a file with the command C-x C-w, then download.
You may also access a helpful list of frequently asked questions about Emacs, which may be particularly useful if you are new to Emacs.
***WARNING ABOUT CONTROL-S AND SOFTWARE FLOW
During the search command in Emacs, the easiest command to use is "Control-s". In order NOT to have this command freeze up Emacs, you must have software flow control turned off. Somewhere within your telecom software, it will give you an option of X-ON, X-OFF. Be sure this function is turned OFF. If it is left on and EMACS freezes with the "Control-s" command, escape from this with CONTROL-q.
If you cannot for some reason function without software flow control turned off, then don't at any time use "Control-s" as a command.
Begin an emacs session with the command
emacs myfile
If the filename specified already exists, emacs will allow you to modify that file. If the file does not exist, Emacs will create it.
Emacs commands use either the "META" Key (designated by "M"), or the CONTROL key, "C". The CONTROL key is fairly easily located on most computers. The META key translates into the ESCAPE key on most keyboards.
If you don't have an ESCAPE key, your computer manual should tell you where it is (sometimes they put it on a function key.) If all else fails "CONTROL-[" is the same as ESCAPE, but I hope you don't have to use that. (Hold down CONTROL and hit open-square-bracket left.)
---> To use an CONTROL key command, just press the control key and while holding it, press the second key.
Example: C-x 1 (Control-x followed by the number ONE) This command will close extra windows. If you suddenly get extra windows in Emacs, this is a good one to remember!
If you suddenly get help menus instead of what you wanted, try hitting RETURN.
---> To use a META key command, press the ESCAPE key, **then release it**, then type the second key.
Example: ESC-< (Escape, then "<" Emacs goes to the beginning of the document.
Example: ESC-> (Escape, then ">" Emacs goes to the end of the document.
All command sequences in emacs will be visible on the bottom line of your screen. If you type a META key, you will be able to see it in the buffer at the bottom. Same for other emacs commands.
The following keys are defined in the minibuffer.
complete as much as possible TAB complete and execute RETURN show possible completions (handy!) ? abort command (very handy!) C-g
To Undo:
If you did something and wish you haven't, don't panic. Make the next command you give the following to UNDO:
C-x u
You will need this command!!
Emacs has many levels of undo, which can be handy.
TO ABORT A COMMAND
Sometimes you have partially typed a command sequence, or even accidentally typed one, and decide to abort. Use the following:
C-g (it will say "Quit")
Beginners often seem to open the help window by mistake. If this happens, don't panic. Just type
C-x 1
Sometimes just hitting RETURN key does it.
exit Emacs temporarily C-z exit Emacs permanently C-x C-c
Periodically, you may find it helpful to redraw the screen. Sometimes things are displayed on your screen that are different than what actually is in the text you are working on. The following command will redraw the screen as needed:
C-l (that's an el not the number one)
read a file into Emacs (thus opening a new window) C-x C-f insert contents of another file into this buffer C-x i write (save) buffer to a specified filename C-x C-w
These commands will all prompt for the filename.
If you are typing C-x C-f to open a file, and you don't know the filename, typing a question mark will supply a list. Type the name you want, or just enough to identify it and press the space or tab key, which will fill in the rest of the name. Press RETURN to enter the selection.
Emacs can open several files at once inside the current emacs session, using several buffers to hold them. If the buffers were started by opening a file, the name of the buffer is the same as the name of the file. If there is no file by that name, emacs will create one.
The commands below allow you to choose the buffer you will work in.
select another buffer C-x b kill a buffer C-x k
If you have several buffers open (in which you are editing files) and you want to shift your working buffer to another one, type C-x b. If the name of the buffer you wanted isn't the default, type a question mark "?" to display a list of possible completions. Type in the name you want (or just enough of it and hit the space or tab key), then press RETURN.
The Help system is simple. Type C-h and follow the directions. If you are a first-time user, type
C-h t for an online tutorial.
I strongly suggest you download and print the tutorial, as well as run it inside Emacs. To do this, simply open the tutorial and save it to a file with the command C-x C-w, then download.
close the Help window C-x 1 (that's a ONE)
You can use the ARROW KEYS a lot to move around. There are numerous shortcuts. I list only a few.
To move backward forward
go to line beginning (or end) C-a C-e go to paragraph beginning (or end) ESC-[ ESC-] go to buffer beginning (or end) ESC-< ESC->
Screen Motion:
scroll to next screen C-v scroll to previous screen ESC-v
If you add or subtract text from a paragraph, the result will not rewrap. This is not perversity on the part of Emacs. It needs to have carriage returns on the ends of each line, so it requires you to reformat the paragraph. Do this with the command
ESC-q
You will use this a lot if you edit your documents heavily.
This expression may seem violent, but it just means you will cut text to a temporary buffer and paste it again. To cut forward to the end of a line, use the command
C-k (kill)
To paste it back, use
C-y (yank)
As an exercise, go to the beginning of a line with C-a, then cut forward to the end of the line with C-k. Continue typing C-k without stopping, thus killing several lines.
Yank back the entire series of kills all at once with C-y
*** NOTE
If non-sequential Control-k commands are issued, the previously killed data will be lost. Experienced users can retrieve it, but newusers will have a simpler time assuming it is lost.
MARKING
In order to copy or kill a region of text with any precision, you need to mark the region.
To mark the entire paragraph you are in, use the command
ESC-h
In order to copy or cut over a more precise block of text, you need to mark the first part of the region using the command
C-spacebar
This "sets the mark."
* NOTE: Not all terminal emulators send the needed code when C-spacebar is hit. If not try the much more annoying c-@ (yeah, control-shift-2). The only way I have found to send this from Telix is ALT-` (that's backwards quote, the one typically above the TAB key and on the same key as ~).
Navigate to the other place in the text where you want the region to end. The region is then defined by your original mark, and the new cursor position.
To COPY the region marked in this way, use the command
ESC-w
To CUT ("kill") the region, use the command
C-w
You can then use "yank" to paste the result of either a copy or a cut ("kill"), using C-y as before.
search forward *** C-s (SEE THE WARNING at the beginning of this help file about software flow control. Have your X-ON, X-OFF turned OFF before using C-s) search backward C-r
Use C-s or C-r again to repeat the search in either direction.
abort current search C-g
If Emacs is still searching, C-g will cancel the part of the search not done, otherwise it aborts the entire search.
You can compose a mail message within Emacs. To open the mail program, use the command
ESC-x mail
You can fill in the address and subject. The text will automatically wrap with emacs in this mode. You can easily insert any files into the program and edit them in Emacs, using the commands as before. To insert a file into the mail buffer, use the command
C-x i
To send the mail, use the command
C-c C-c (send)
To read mail from within Emacs is a more complicated process, and we don't advise embarking on this without more instruction--especially with mh. This should be the subject of another help file and is beyond the scope of this discussion.
One of the more mysterious things about Emacs is setting it up. In order to cause emacs to behave as you wish, one has to add desired customizations within the .emacs file. This is an invisible file in your home directory (sometimes called a dot file), which you can see, together with other files, by typing "ls -a". These dot files govern various functions within Unix, and the .emacs file governs the options for emacs.
If you include these two commands in your .emacs file, emacs will open with a default of text editing mode, which is a common mode most new users would use. It specifies text wrapping.
You will need to insert these two commands in your .emacs file, using emacs itself.
Type the command
emacs .emacs
This will allow you to modify or create the file .emacs which allows you to set characteristics of how emacs behaves. Enter the following two lines:
(setq default-major-mode 'text-mode) (setq text-mode-hook 'turn-on-auto-fill)
Exit the editing session with C-x C-c and these new changes will take effect the next time (and every time) you invoke emacs.
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
If you made the right choice during the creation of your account as "new," the following should normally not be a problem.
Emacs expects the character CONTROL-h to invoke its internal help. Sadly, the backspace key on some software (usually DOS) emits "CONTROL-h". If you use BACKSPACE rather than DELETE (RUBOUT) for character erase, you will experience problems, such as having the Help Window appear when you meant to erase. In such a case, you have to choose between getting a delete key and getting help. If you want a delete key and only have the option of using the "backspace" key then the emacs help command has to be re-defined.
Fortunately, redefining the keys to correct this problem is simple. Copy the following files from the freduser directory like this:
% cp ~freduser/login.back .login % cp ~freduser/emacs.back .emacs
This will set up Unix so erase is backspace and set up Emacs so erase is backspace and anywhere backspace is normally used (e.g. Emacs HELP) will be on the DELETE key (got that? It swaps the backspace and delete key meaning.)
To make the .login file take effect (change to using backspace) type:
% source .login
Every time you login this will happen automatically, you only have to run the "source" command this time (or, logout and login again.)
=+=+=+=+=+=+=+=+=+=
A review of the Emacs command syntax
Control-a means hold down the control key and type "a"
Example: Control-p (move up one line)
Escape-a means type Escape then a (two keystrokes)
Example: Escape-q (fix up a paragraph)
Control-x always followed by another keystroke which could be a letter or number or another control sequence.
Example: Control-x s (save work) Control-x Control-c (exit emacs)
Escape-x always followed by a complete word-like emacs command and will prompt for the command at the bottom of the screen.
Example: Escape-x rnews (read USENET news)
A basic emacs command summary
Online Help
Control-h (the BACKSPACE key) get help Control-h i (two keystrokes) Online Menu-driven Manual Escape-x manual (prompts for the word "manual") Access to the entire on-line System Manuals from within Emacs.
Moving the cursor and text changes
Control-p P-revious Line (up) Control-n N-ext Line (down) Control-f F-orward Character (right) Control-b B-ackward Character (left) Control-a Beginning of line Control-e E-nd of line Escape-< Go to top of file Escape-> Go to bottom of file
Delete Delete character just before cursor Control-k Erase rest of typed in line Control-d Delete character the cursor is on
File access
Control-x s (two keystrokes) Save All Edited Files Control-x f Visit (or Create) a file Control-x w Save Current File Asking for a New Name
Fun and Games
Escape-x hanoi Solve the Tower of Hanoi Puzzle (for more discs type "CONTROL-U number":
CONTROL-U 6 ESCAPE-X hanoi
takes a while to solve!
Escape-x yow Print a Zippy the Pinhead message (Are We Having Fun Yet?)
Escape-x doctor The on-line psychiatrist
=+=+=+=+=+=+=+=+=+=
This concludes "A Gentle Introduction to Emacs," a beginning help file brought to you by Vedder Wright (vwright@world.std.com) on behalf of Software Tool and Die.
My special thanks to Elizabeth of World staff, who was so patient in teaching emacs to a "newbie."
This document was last modified on June 30, 1993
Software Tool & Die 1330 Beacon Street, Suite 215, Brookline, MA 02146 617-739-0202 office@world.std.com
HOME Top of Help Desk Eye On The World The World Kiosk