Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align selected region in emacs

Tags:

emacs

For example I write code

if Foo do
  # do something
end

And then, I paste in my code many lines.

if Foo do
  # do something
# do something
# do something
# do something
# do something
end

How I can fast align added lines?

like image 535
Rusty Robot Avatar asked Aug 05 '11 09:08

Rusty Robot


People also ask

How do I align in Emacs?

align-regexp First, we align the text. Select the text first, then press Ctrl + u then call align-regexp , with the regexp . * \([0-9,]+\). * then choose -1 for group, 1 for spacing, and n for repeat.

How do I align text in Emacs?

In Emacs, to justify text, first you'll need to define the region of text that you want justified. Place the cursor at the beginning of the text that you want justified and press C-@ to set the mark. Then move your cursor to the end of the text to be justified. This should justify your text across 70 columns.


1 Answers

Do you want to align automatically on insert, or you want to align it later? For later you can use indent-region function (bound to C-M-\). For automatic align on insert you can use following recipe (I don't remember where I took it, so I'll refer to my config) - see lines 45-66. You will need to add more modes to yank-indent-modes, but concrete mode should provide working indent function.

like image 51
Alex Ott Avatar answered Sep 24 '22 14:09

Alex Ott