Online Book Reader

Home Category

Running Linux, 5th Edition - Matthias Kalle Dalheimer [357]

By Root 1423 0
the X Window System (even though you can also use it from the command line, despite its name). If you are not tight on memory and have a reasonably fast computer, we suggest using XEmacs. Another advantage of XEmacs is that many useful packages that you would need to download and install separately with GNU Emacs are already shipped with XEmacs. We will not cover the differences here, though; the discussion in this section applies to both. Whenever we talk about Emacs in this section, we mean either version.

Firing It Up

GNU Emacs is simply invoked as follows:

$ emacsoptions

Likewise, XEmacs is invoked as follows:

$ xemacsoptions

Most of the time, you don't need options. You can specify filenames on the command line, but it's more straightforward to read them in after starting the program.

In Emacs lingo, C-x means Ctrl-X, and M-p is equivalent to Alt-P. As you might guess, C-M-p means Ctrl-Alt-P.

Using these conventions, press C-x followed by C-f to read in a file or create a new one. The keystrokes display a prompt at the bottom of your screen that shows your current working directory. You can create a buffer now to hold what will end up being the content of a new file; let's call the file wibble.txt, shown in Figure 19-16.

Figure 19-16. Emacs when opening a new file

The mode line at the bottom indicates the name of the file as well as the type of buffer you're in (which here is Fundamental). Emacs supports many kinds of editing modes; Fundamental is the default for plain-text files, but other modes exist for editing C and TEX source, modifying directories, and so on. Each mode has certain key bindings and commands associated with it, as we'll see soon. Emacs typically determines the mode of the buffer based on the filename extension.

To the right of the buffer type is the word All, which means that you are currently looking at the entire file (which is empty). Typically, you will see a percentage, which represents how far into the file you are.

If you're running Emacs under the X Window System, a new window will be created for the editor with a menubar at the top, scrollbars, and other goodies. In "Emacs and the X Window System" later in this chapter we discuss Emacs's special features when used within X.

Simple Editing Commands

Emacs is more straightforward than vi when it comes to basic text editing. The arrow keys should move the cursor around the buffer; if they don't (in case Emacs is not configured for your terminal), use the keys C-p (previous line), C-n (next line), C-f (forward character), and C-b (backward character).

If you find using the Alt key uncomfortable, press Esc and then p. Pressing and releasing Esc is equivalent to holding down Alt.

Already we must make the first digression in our discussion of Emacs. Literally every command and key within Emacs is customizable. That is, with a "default" Emacs configuration, C-p maps to the internal function previous-line, which moves the cursor (also called "point") to the previous line. However, you can easily rebind different keys to these functions, or write new functions and bind keys to them, and so forth. Unless otherwise stated, the keys we introduce here work for the default Emacs configuration. Later we'll show you how to customize the keys for your own use.

Back to editing: using the arrow keys or one of the equivalents moves the cursor around the current buffer. Just start typing text, and it is inserted at the current cursor location. Pressing the Backspace or Delete key should delete text at the cursor. If it doesn't, we show how to fix it in "Tailoring Emacs" later in this chapter. See Figure 19-17.

The keys C-a and C-e move the cursor to the beginning and end of the current line, respectively. C-v moves forward a page; M-v moves back a page. There are many more basic editing commands, but we'll allow the Emacs online documentation (discussed shortly) to fill those in.

In order to get out of Emacs, use the command C-x C-c. This is the first of the extended commands we've seen; many Emacs commands require

Return Main Page Previous Page Next Page

®Online Book Reader