Книга: Learning GNU Emacs, 3rd Edition

7.2.3.1 Indenting regions

7.2.3.1 Indenting regions

What if you have already typed your text without indentation and want to indent it later? Two commands can handle this, depending on how far you want to indent the region.

The indent-region command, bound to C-M-, can indent a region one level easily. If you want to indent two levels, it is unpredictable. (This command is designed for indenting code.)

Here's an example. The second paragraph is marked as a region.

Type: C-M-


Emacs indents the paragraph one level.

You decide that's not far enough.

Type: C-M-


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-region pulls 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-rigidly uniformly 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.

Оглавление книги

Оглавление статьи/книги

Генерация: 1.680. Запросов К БД/Cache: 3 / 1
поделиться
Вверх Вниз