-->
Previous Table of Contents Next


Using emacs

You edit text by creating new text or by modifying existing text. When creating new text, you place the text in a file with an ordinary Linux filename. When you modify existing text, you use the existing filename to call a copy of the file into the editing session. In either case, as you use the editor, the text is held in the system’s memory in a storage area called a buffer.

Using a buffer prevents you from directly changing the contents of a file until you decide to save the buffer. This is to your benefit if you decide you want to forget the changes you’ve made and start over.

emacs allows you to edit multiple buffers at once. This way, you can cut and paste text from one buffer to another, compare text from different files, or merge one file into another file. emacs even uses a special buffer to accept commands and report information to the user. This buffer, the mini-buffer, appears at the bottom of the screen.

emacs also lets you display the contents of various buffers in their own windows; thus, you can see several files at once, even if you aren’t using a graphical user interface.

Looking Over the emacs Screen

Figure 28.1 shows a typical emacs screen. The top portion displays the contents of various buffers, sometimes in multiple windows. Then a mode line is displayed at the bottom of the screen. This line, usually displayed in reverse video, provides users with information about the buffer, such as the buffer’s name, the major and minor mode, and the amount of text displayed in the buffer. Under the mode line is the one-line mini-buffer, where you enter emacs commands and where emacs reports the outcome of various commands.


FIG. 28.1  A typical emacs screen shows the buffer and mini-buffer areas.

The current position in the buffer is shown by a cursor. emacs refers to the cursor as the point, especially in the online help system, so it’s important to remember this term for the cursor.

Creating Your First emacs File

The following instructions show how to edit your first emacs file. If you run into difficulties, you can quit and start over by pressing <Ctrl-x><Ctrl-c>. Follow these steps:

1.  Start emacs (type emacs and press <Return>). You see the screen shown in Figure 28.1.
2.  Add the following lines of text to the buffer:

Things to do today.

a. Practice emacs.

b. Sort sales data and print the results.


You can use the <Backspace> key to correct mistakes on the line you’re typing. Don’t worry about being precise here: This example is for practice. You learn other ways to make changes in some of the later sections of this chapter.


NOTE:  Notice the mini-buffer at the bottom of the screen. Your keystrokes appear there because you’re typing commands to the emacs editor.
3.  Save your buffer in a file called emacs-pract.1. First press <Ctrl-x><Ctrl-s> and type emacs-pract.1. Notice that emacs-pract.1 appears at the bottom of the screen. Press <Return>. This command saves or writes the buffer to the file emacs-pract.1 (the specified file).
You should see the following confirmation on the status line:

Wrote /root/emacs-pract.1


This statement confirms that the file emacs-pract.1 has been created and saved to disk. Your display may be different if you didn’t type the information exactly as specified.


NOTE:  Notice the number of characters in the filename. Unlike MS-DOS and Windows, Linux allows you to enter more than eight characters and a three-character extension for a filename.
4.  Exit emacs by pressing <Ctrl-x><Ctrl-c> and then <Return>. If you have unsaved material, emacs might prompt you to save an unsaved buffer/file. If emacs does prompt you, simply press <y> to save the information, or <n> if you don’t want to save the information. emacs then terminates, and you return to the login shell prompt.


TROUBLESHOOTING:  
emacs is placing the characters I type into the mini-buffer and attempting to perform strange actions with the characters. If you press the <Esc> key twice, emacs enters a LISP programming environment. LISP is the original language that Stallman used to program emacs, and it’s through LISP that programmers can extend and customize emacs. If you press <Esc><Esc>, emacs enters the eval-expression mode and expects the user to enter a LISP command; simply press <Return> to exit this mode.


Previous Table of Contents Next