Posted on 13-11-2012
Filed Under (Technology) by bigbang

We always need to indent spaces for code block or text block in Emacs, especially in Org files.

For example, when you inserts a code block in Emacs Org file, you always need to insert blocks similar to following:

#+begin_src cpp
#include <iostream>

int main()
    return 0;

But when you copy the code from your source code file, the code is always aligned to the left of the page. When you export your org file to html file, the # mark will damage all the code block content.

We need to indent the code block for 2 spaces or 4 spaces, then the block mark will work.

It’s easy! There are two ways to do the indention.

The first way, Use the indent-rigidly command with a numeric prefix.

For example, after selecting the block, C-u 4 M-x indent-rigidly to indent the region by four spaces, C-u -4 M-x indent-rigidly to remove four spaces.

You can also use C-x <TAB> key bindings to replace M-x indent-rigidly command.

The second way, we could also use column mode.

We can select the lines in column mode, then add four spaces to all of them at once by following steps:

  1. Jump to column 1 of the first line you want to indent.
  2. C-<space> to set mark.
  3. move the point down to the last lines (stay in column one).
  4. C-x r t to enter column mode (or C-<RET> if you’ve got CUA mode), the input <space><space><space><space><RET> to indent four spaces.

© 2012, The Big Bang on Reading Busy. All rights reserved.
On republishing this post you must provide link to the original post.

(0) Comments    (952) Views   
Post a Comment