Êíèãà: Learning GNU Emacs, 3rd Edition
7.2.5 Using Fill Prefixes
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.
Table 7-2 lists the indentation commands we've discussed.
Table 7-2. Indentation commands
Keystrokes | Command name | Action |
---|---|---|
C-j | newline-and-indent | Move to the next line and indent to the current level. |
(none) | paragraph-indent-text-mode | A major mode for writing paragraphs with indented first lines and no blank lines between paragraphs. |
(none) | paragraph-indent-minor-mode | The minor mode equivalent of paragraph-indent-text mode. |
(none) | fill-individual-paragraphs | Reformat indented paragraphs, preserving indentation. |
C-x Tab | indent-rigidly | Indent one column; preface with C-u or M-n to specify multiple columns. |
C-M- | indent-region | Indent a region to match the first line in the region. |
M-m | back-to-indentation | Move the cursor to the first non-whitespace character on a line. |
C-M-o | split-line | Split the line at the cursor position and indent it to the column of the cursor position. |
(none)Edit ? Text Properties ? Indentation ? Indent More | increase-left-margin | Increase the left indentation level for the buffer by four characters by default. |
(none)Edit ? Text Properties ? Indentation ? Indent Less | decrease-left-margin | Decrease the left indentation level for the buffer by four characters by default. |
(none)Edit ? Text Properties ? Indentation ? Indent Right More | decrease-right-margin | Decrease the right indentation level for the buffer by four characters by default. |
(none)Edit ? Text Properties ? Indentation ? Indent Left More | increase-right-margin | Increase the right indentation level for the buffer by four characters by default. |
C-x . | set-fill-prefix | Use the information up to the cursor column as a prefix to each line of the paragraph; typing this command in column 1 cancels the fill prefix. |
- Caveats using NAT
- Using Double Quotes to Resolve Variables in Strings with Embedded Spaces
- Data Binding Using the GridView Control
- Using the kill Command to Control Processes
- Installing Using a Network
- Using X
- Using a Display Manager
- Starting X from the Console by Using startx
- Using Fedora's switchdesk Client
- Using Environment Variables
- Using the Text Editors
- Using Man Pages