From cc2207d08a255a627eb5290b54a7f1f143645bbb Mon Sep 17 00:00:00 2001 From: Klaatu Date: Thu, 21 Jun 2012 22:29:00 -0400 Subject: Added docbook markup where missing. Put keybinding table into a table. Fixed some spelling errors. Added a "save as" paragraph or too introducing C-x C-w and finishing off chapter. Added chapter and section ids so we can xref as needed. --- chapter_13.xml | 376 ++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 262 insertions(+), 114 deletions(-) diff --git a/chapter_13.xml b/chapter_13.xml index 2a0af86..771cb85 100644 --- a/chapter_13.xml +++ b/chapter_13.xml @@ -2,7 +2,7 @@ - + Emacs @@ -51,7 +51,7 @@ you use emacs or XEmacs, the differences between them to the normal user. -
+
Starting Emacs @@ -65,46 +65,61 @@ buffer. (See Section 17.2.) You can also start emacs on an existing file by typing + -% emacs /etc/resolv.conf + + % emacs + /etc/resolv.conf + + + This will cause emacs to load the specified file when it starts up, skipping the welcome message. -
+
Command Keys - + As mentioned above, emacs uses CTRL and ALT combinations for commands. The usual convention is to write these with C-letter and M-letter, respectively. So C-x means CTRL+x, and M-x means ALT+x. -(The letter M is used instead of A because originally the key was not + + + + + The letter M is used instead of A because originally the key was not the ALT key but the Meta key. The Meta key has all but disappeared from computer keyboards, and in emacs the ALT key has taken over its -function.) +function. + + + Many emacs commands consist of sequences of keys and key combinations. -For example, C-x C-c (that is CTRL-x followed by CTRL-c ) quits +For example, C-x C-c (that is CTRL-x followed by CTRL-c) quits Emacs, C-x C-s saves the current file. Keep in mind that C-x C-b is not the same as C-x b. The former means CTRL-x followed by CTRL-b, -while the latter means CTRL-x followed by just 'b'. +while the latter means CTRL-x followed by just 'b'. +
-
+
Buffers - -In emacs, the concept of "buffers" is essential. Every file that you + +In emacs, the concept of 'buffers' is essential. Every file that you open is loaded into its own buffer. Furthermore, emacs has several special buffers, which do not contain a file but are used for other things. Such special buffers usually have a name that starts and ends with an asterisk. For example, the buffer that emacs shows when it is -first started, is the so-called *scratch* buffer. In the *scratch* +first started, is the so-called *scratch* buffer. In the *scratch* buffer, you can type text in the normal way, but text that is typed there is not saved when emacs is closed. - + + There is one other special buffer you need to know about, and that is the minibuffer. This buffer consists of only one line, and is always on the screen: it is the very last line of the emacs window, below the @@ -112,202 +127,335 @@ status bar for the current buffer. The minibuffer is where emacsemacs will ask for its name in the minibuffer. - + + Switching from one buffer to another can be done with the command C-x b. This will prompt you for the name of a buffer (a buffer's name is usually the name of the file you are editing in it), and it gives a default choice, which is normally the buffer that you were in before you switched to or created the current buffer. Just hitting Enter will switch to that default buffer. - + + If you want to switch to another buffer than the default offered by Emacs, just type its name. Note that you can use so-called Tab-completion here: type the first few letters of the buffer's name and hit Tab; emacs will then complete the name of the buffer. Tab completion works everywhere in emacs where it makes sense. - + + You can get a list of open buffers by hitting C-x C-b. This command will usually split the screen in two, displaying the buffer you were -working in in the top half, and a new buffer called *Buffer List* in +working in in the top half, and a new buffer called *Buffer List* in the bottom half. This buffer contains a list of all the buffers, their sizes and modes, and the files, if any, that those buffers are visiting (as it is called in emacs). You can get rid of this split screen by typing C-x 1. - +
-
+
Modes - + Every buffer in emacs has an associated mode. This mode is very -different from the idea of modes in vi: a mode tells you what kind of +different from the idea of modes in vi: a mode tells you what kind of buffer you are in. For example, there is text-mode for normal text files, but there are also modes such as c-mode for editing C programs, sh-mode for editing shell scripts, latex-mode for editing LaTeX files, mail-mode for editing email and news messages, etc. A mode provides special customizations and functionality that is useful for the kind of file you are editing. It is even possible for a mode to redefine keys -and key commands. For example, in Text mode, the Tab key simply jumps -to the next tab stop, but in many programming language modes, the Tab +and key commands. For example, in Text mode, the Tab key simply jumps +to the next tab stop, but in many programming language modes, the Tab key indents the current line according to the depth of the block that line is in. + -The modes mentioned above are called major modes. Each buffer has + +The modes mentioned above are called major modes. Each buffer has exactly one major mode. Additionally, a buffer can have one or more -minor modes. A minor mode provides additional features that may be -useful for certain editing tasks. For example, if you hit the INSERT -key, you invoke overwrite-mode, which does what you'd expect. There is +minor modes. A minor mode provides additional features that may be +useful for certain editing tasks. For example, if you hit the INSERT +key, you invoke overwrite-mode, which does what you'd expect. There is also an auto-fill-mode, which is handy in combination with text-mode or latex-mode: it causes each line that you type to be automatically wrapped once the line reaches a certain number of characters. Without -auto-fill-mode, you have to type M-q to fill out a paragraph. (Which -you can also use to reformat a paragraph after you've edited some text -in it and it is no longer nicely filled out.) +auto-fill-mode, you have to type M-q to fill out a paragraph. (Which +you can also use to reformat a paragraph after you've edited some text +in it and it is no longer nicely filled out.) + -
+
Opening Files -To open a file in emacs, type - -C-x C-f + +To open a file in emacs, type C-x C-f + -Emacs will ask you for the name of the file, filling in some default -path for you (which is usually ~/ ). After you type the filename (you -can use Tab completion) and hit ENTER , emacs will open the file in a + +Emacs will ask you for the name of the file, filling in some default +path for you (which is usually ~/ ). After you type the filename (you +can use Tab completion) and hit ENTER, emacs will open the file in a new buffer and display that buffer on the screen. -Note - -Emacs will automatically create a new buffer, it will not load the file -into the current buffer. - -In order to create a new file in emacs, you cannot just go typing right -away. You first have to create a buffer for it, and come up with a -filename. You do this by typing C-x C-f and typing a filename, just as -if you were opening an existing file. emacs will notice that the file -you typed doesn't exist, and will create a new buffer and report "(New -file)" in the minibuffer. + + + + Emacs will automatically create a new + buffer, it will not load the file into the current buffer. + + + + + In order to create a new file in emacs, + you cannot just go typing right away. You first have to create a + buffer for it, and come up with a filename. You do this by typing + C-x C-f and typing a filename, + just as if you were opening an existing + file. Emacs will notice that the file + you typed doesn't exist, and will create a new buffer and report + "(New file)" in the minibuffer. + + + When you type C-x C-f and then enter a directory name instead of a filename, emacs will create a new buffer in which you will find a list of all the files in that directory. You can move the cursor to the file -that you are looking for and type , and emacs will open it. (There are -in fact a lot more actions you can perform here, such as deleting, -renaming and moving files, etc. emacs is now in dired-mode, which is -basically a simple file manager.) +that you are looking for and type , and +emacs will open it. + + + + + There are in fact a lot more actions you can perform here, such as + deleting, renaming and moving files, + and so on. This is the dired-mode of emacs, which + is basically a simple file manager. + + + When you have typed C-x C-f and suddenly change your mind, you can type C-g to cancel the action. C-g works almost everywhere where you want to -cancel an action or command that you've started but don't want to +cancel an action or command that you've started but don't want to finish. + +
-
+
-
- -
+
Basic Editing + When you have opened a file, you can of course move around in it with -the cursor. The cursor keys and PgUp, PgDn do what you'd expect. Home -and End jump to the beginning and end of the line. (In older versions, -they would actually jump to the beginning and end of the buffer.) -However, there are also CTRL and Meta (ALT) key combos that move the +the cursor. The cursor keys and PgUp, PgDn do what you'd expect. Home +and End jump to the beginning and end of the line. (In older versions, +they would actually jump to the beginning and end of the buffer.) +However, there are also CTRL and Meta (ALT) key combos that move the cursor around. Because you do not need to move your hands to another part of the keyboard for these, they are much quicker once you get used -to them. The most important such commands are listed in Table 17-1. - -Table 17-1. Basic emacs Editing Commands -Command Result -C-b go one character back -C-f go one character forward -C-n go one line down -C-p go one line up -C-a go to the beginning of the line -C-e go to the end of the line -M-b go one word back -M-f go one word forward -M-} go one paragraph forward -M-{ go one paragraph backward -M-a go one sentence backward -M-e go one sentence forward -C-d delete the character under the cursor -M-d delete until the end of the current word -C-v go down one screen (i.e., PgDn) -M-v go up one screen (i.e., PgUp) -M-< go to the beginning of the buffer -M-> go to the end of the buffer -C-_ undo the last change (can be repeated); note that you actually -have to type SHIFT+CTRL+hyphen for this. -C-k delete to end of line -C-s forward search -C-r backward search +to them. + + + +Basic <application>emacs</application> Editing Commands + + + + Command + Result + + + + + C-b + go one character back + + + C-f + go one character forward + + + C-n + go one line down + + + C-p + go one line up + + + C-a + go to the beginning of the line + + + C-e + go to the end of the line + + + M-b + go one word back + + + M-f + go one word forward + + + M-} + go one paragraph forward + + + M-{ + go one paragraph backward + + + M-a + go one sentence backward + + + M-e + go one sentence forward + + + C-d + delete the character under the cursor + + + M-d + delete until the end of the current word + + + C-v + go down one screen (i.e., + PgDn) + + + M-v + go up one screen (i.e., + PgUp) + + + M-< + go to the beginning of the buffer + + + M-> + go to the end of the buffer + + + C-_ + undo the last change (can be repeated); note + that you actually have to type + SHIFT+CTRL+hyphen for this. + + + + C-k + delete to end of line + + + C-s + forward search + + + C-r + reverse search + + + +
+ Note that many Meta commands are parallel to the CTRL commands except that they operate on larger units: while C-f goes forward one character, M-f goes forward an entire word, etc. + + Also note that M-< and M-> require you to type SHIFT+ALT+comma and SHIFT+ALT+dot respectively, since < and > are on SHIFT+comma and -SHIFT+dot. (Unless of course you have a different keyboard layout from -the standard US layout.) +SHIFT+dot. (Unless of course you have a different keyboard layout from +the standard US layout.) + -Note that C-k deletes (kills, as it is commonly called) all the text + +Note that C-k deletes (kills, as it is commonly called) all the text after the cursor to the end of the line, but doesn't delete the line -itself (i.e., it doesn't delete the final newline). It only deletes the +itself (i.e., it doesn't delete the final newline). It only deletes the line if there was no text after the cursor. In other words, in order to delete a complete line, you have to put the cursor at the beginning of the line, and then hit C-k twice: once to delete the text on the line, -once to delete the line itself. +and once to delete the line itself. + -
+
-
+
Saving Files -In order to save a file, you type - -C-x C-s + +In order to save a file, you type C-x C-s + -Emacs will not ask you for a filename, the buffer will just be saved to + +Emacs will not ask you for a filename, the buffer will just be saved to the file it was loaded from. If you want to save your text to another file, type C-x C-w + + When you save the file for the first time in this session, emacs will normally save the old version of your file to a backup file, which has -the same name appended with a tilde: so if you're editing a file -"cars.txt", emacs will create a backup "cars.txt~". +the same name appended with a tilde: so if you're editing a file +cars.txt, emacs will create a backup cars.txt~. + + This backup file is a copy of the file that you opened. While you are working, emacs will also regularly create an auto-save copy of the work -you are doing, to a file named with hash signs: #cars.txt#. This backup +you are doing, to a file named with hash signs: #cars.txt#. This backup is deleted when you save the file with C-x C-s. + + When you are done editing a file, you can kill the buffer that holds it -by typing - -C-x k +by typing C-x k + -Emacs will then ask you which buffer you want to kill, with the current -buffer as default, which you can select by hitting ENTER. If you -haven't saved your file yet, emacs will ask you if you really want to + +Emacs will then ask you which buffer you want to kill, with the current +buffer as default, which you can select by hitting ENTER. If you +haven't saved your file yet, emacs will ask you if you really want to kill the buffer. + + + + If you'd prefer to save the file with a new name so that you + don't overwrite the original version, use C-x + C-w instead. You may then give a new name for the + file, and the buffer will be updated to reflect the contents of this + new file, leaving the old file unchanged. +
-
+
Quitting Emacs -When you are done with emacs altogether, you can type - -C-x C-c + +When you are done with emacs altogether, +you can type C-x C-c + + This quits emacs. If you have any unsaved files, emacs will tell you so, and ask if you want to save them each in turn. If you answer no to any of these, emacs will ask for one final confirmation and then quit. + -
+
-- cgit v1.2.3