Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the Eclipse editor have an equivalent of Emacs's "align-regex"?

Tags:

emacs

eclipse

I've been using Eclipse pretty regularly for several years now, but I admit to not having explored all the esoterica it has to offer, particularly in the areas of what formatting features the editors offer.

The main thing I miss from (X)emacs is the "align-regex" command, which let me take several lines into a region and then format them so that some common pattern in all lines was aligned. The simplest example of this is a series of variable assignments:

var str = new String('aString');
var index = 0;
var longCamelCaseObjectName = new LongNameObject();

After doing align-regex on "=", that would become:

var str                     = new String('aString');
var index                   = 0;
var longCamelCaseObjectName = new LongNameObject();

Now, you may have your own thoughts on stylistic (ab)use of white space and alignment, etc., but that's just an example (I'm actually trying to align a different kind of mess entirely).

Can anyone tell me off-hand if there's an easy key-combo-shortcut for this in Eclipse? Or even a moderately-tricky one?

like image 391
rjray Avatar asked Sep 29 '08 22:09

rjray


2 Answers

You can set the formatter to do this:

Preferences -> Java -> Code Style -> Formatter. Click 'Edit' on the profile (you may need to make a new one since you can't edit the default).

In the indentation section select 'Align fields with columns'.

Then, in your code CTRL+SHIFT+F will run that formatter.

That will of course run all the other rules, so you may want to peruse the various options here.

like image 118
SCdF Avatar answered Sep 22 '22 12:09

SCdF


Version 2.8.7 of the Emacs+ plugin now supplies a fairly complete align-regexp implementation in Eclipse

like image 32
mfeber Avatar answered Sep 25 '22 12:09

mfeber