Emacs creates a stairstep hanging indent.
So you can see that this works fine if you're indenting one level. If you try this with multiple paragraphs of different indentation levels, indent-regionpulls them all to the right, aligning them with the least indented paragraph, probably not what you intended. If you write code, however, this command is great for cleaning up messy indentation.
The other option is to mark the region and type C-x Tab(for indent-rigidly). By default, this command indents only one space, so if you want to indent further, you need to give it an argument. For example, to indent the previous paragraph 15 spaces:
Mark the region then type: M-15 C-x Tab

Emacs indents the paragraph 15 spaces.
Although arguably it can be a pain to supply an argument, indent-rigidlyuniformly indents text, leaving indented paragraphs indented. If you find yourself wanting to indent whole files, you may actually want to change the margin settings, as described in the next section.
7.2.3.2 Other indentation tricks
Whenever you are using indentation, you can use M-m(for back-to-indentation) to move to the first nonblank character on a line. On a line that's not indented, this command simply moves you to the beginning of the line. In other words, M-mbrings you to the "logical" beginning of the line, which is what you usually mean when you type C-a.
Another indentation command is C-M-o(for split-line). You can use this command to create a stairstep effect. Move the cursor to the text that you want to put on the next line and press C-M-o. Note that there must be some text following the cursor in order for this command to work properly; if you try it at the end of a line, it does nothing.
Initial state:

We want to split this line.
Type: C-M-o

C-M-osplits the line at the cursor position.
Emacs is not a word processor, but it does have a few commands that change left and right indentation for a buffer for the current session. First, mark the whole buffer using C-x h. You can then gchange the indention using M-xfollowed by one of the following commands:
increase-left-margin
decrease-left-margin
increase-right-margin
decrease-right-margin
These commands are also available through the Edit menu. Choose Edit → Text Properties → Indentation to see the options.
Unless you supply a numeric argument using C-uor M- n preceding these commands, Emacs increases or decreases the margins by the number of characters in the variable standard-indent, which defaults to 4. If auto-fill mode is on, Emacs also reformats the paragraphs automatically.
Margin settings remain in effect for the current session and the current buffer only. Although the values don't persist to another session, any text that is indented using this method remains indented when you reopen the file. If you open the file again and add some text, however, it is not indented; you have to set the margins again.
These commands work best in cases where you want to change the margin for the whole buffer. If you define a smaller region, the commands work but if you type more paragraphs, the margin settings persist whether you want them to or not. These commands work fine if you've completed the file and then decide to change the indentation.
Alternatively, you can set and save margins using enriched mode, a minor mode that allows Emacs to save text properties, including margin settings and font changes. See Chapter 10for more details on enriched mode.
7.2.5 Using Fill Prefixes
Fill prefixes are a way of putting a certain string of characters at the beginning of each line in a paragraph or a file. Developers will immediately think of comments as a potential fill prefix. When writing email or newsposts, email programs often insert a string to help readers distinguish the threads of a discussion. For those of us writing text files, fill prefixes can be used to insert whitespace in paragraphs or any relevant string of characters.
The term fill prefix comes from the fact that Emacs calls word wrap auto-fill mode ; in other words, a fill prefix is a string that Emacs should insert at the beginning of each line (or "prefix" each line with) when doing word wrap.
To use fill prefixes, it's best to be in auto-fill mode. If your mode line says Fill
on it, you're already in auto-fill mode. If it doesn't, type M-x auto-fill-mode Enter.
Now let's assume that you want to indent a letter. For the first line of the letter, type your indentation by hand—say, eight spaces. Then type C-x. (for set-fill-prefix). Emacs displays the message: fill prefix " "
in the minibuffer. Then start typing normally. Whenever you type past the right margin and Emacs breaks a line for you, it automatically inserts your eight-space indentation at the beginning of the line.
Here's a slightly more exciting example. There's no reason that fill prefixes must to be spaces; they can be anything you choose. Assume that you're sending an email message to your friends to announce a unique event and you want an eye-catching fill prefix.
Type: Elephant Riding Party!!! C-x.

Type the prefix, then C-x. to set it.
Once you've set the prefix, you can type your message normally.
Type: The time . . . the zoo.

Emacs inserts the fill prefix at the beginning of each line of the message.
You had to type "Elephant Riding Party!!!" only once; Emacs inserted the rest automatically. Here are some things you might want to know about fill prefixes:
• Emacs never applies the fill prefix to the first line of a paragraph. You obviously can't apply it to the first line of the first paragraph (you have to type it somewhere). But Emacs can't apply it to the first line of any paragraph. In other words, if the "elephant riding" message had two paragraphs, you'd have to type (or yank) the phrase "Elephant Riding Party!!!" at the beginning of the second paragraph.
• However, you don't need to set the fill prefix again. Emacs supplies your prefix for all lines but the first in subsequent paragraphs. It just gets confused about the initial line of any paragraph.
• Once you've started using a fill prefix, how do you turn it off? There's no special command. All you do is put the cursor at the left margin and type C-x. to define a new, empty fill prefix.
• You can edit paragraphs with fill prefixes, then reformat them with M-q, as long as the fill prefix is still defined. If you have cleared the fill prefix, Emacs reformats the paragraph without regard to the fill prefix. If you need to reformat your paragraphs later, after you've canceled the fill prefix, define it again and then type M-q.
Читать дальше