Emacs: align text, but not the entire line?

The only editor I have ever used that supports this (I'm sure many do, however) is Sublime Text 2, but hopefully emacs is also fooling its sleeve. Some of the classes I'm working on have a rather declarative syntax and look cleaner if the source is stored in a column. The problem arises when a new row increases the length of the column by a space or two ... Then you have to work through each row, overriding it.

The screenshot probably clarifies what I'm referring to:

Columnized text out of alignment

Here I added a row in which one, if its columns expand beyond the other columns, so I would like to rebuild it again. Usually I just repeat - I circle my fingers around the arrows and the space bar until I align everything in a row, but it would be nice if there was a way to just select a rectangular area and force the text that does not contain spaces in this area to be aligned.

Is it possible?

+8
indentation emacs
source share
3 answers

Instead of using rectangles, you can use align-regexp . Then select an area:

Cu Mx align-regexp RET ,\(\s-*\) RET 1 RET 1 RET y

If you do this a lot, make a function:

 (defun my-align-after-commas (beg end) (interactive "r") (align-regexp beg end ",\\(\\s-*\\)" 1 1 t)) 

Then select the region and Mx my-align-after-commas

+21
source share

There is also a columnize library that can convert this:

 (defvar enform-keywords-statements '( "AT END" "AT START" "CLOSE" "DECLARE" "DELINK" "DICTIONARY" "EXIT" "FIND" "FOOTING" "LINK" "LIST" "OPEN" "PARAM" "SET" "SUBFOOTING" "SUBTITLE" "TITLE" ) "List of ENFORM statement keywords. Used to create the `font-lock-keywords' table.") 

in it:

 (defvar enform-keywords-statements '( "AT END" "AT START" "CLOSE" "DECLARE" "DELINK" "DICTIONARY" "EXIT" "FIND" "FOOTING" "LINK" "LIST" "OPEN" "PARAM" "SET" "SUBFOOTING" "SUBTITLE" "TITLE" ) "List of ENFORM statement keywords. Used to create the `font-lock-keywords' table.") 

You select the region you want to align, and then Mx columnize-text .

The EmacsWiki page about this and others:
http://www.emacswiki.org/emacs/CategoryAlignment

+5
source share

Emacs allows you to select rectangular areas, and it allows you to edit entire columns. To remove a rectangular area, set the character in one corner, point to the other, and then Mx kill-rectangle . You can add a space rectangle by marking it in the same way, and then an Mx open-rectangle .

This is exactly how I know how to do this; there are undoubtedly other, perhaps better ways.

+4
source share

All Articles