tags:

views:

964

answers:

3

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?

+3  A: 

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.

SCdF
Thanks, will look at that and see if it is inherited by the editor I'm using (the Perl editor in EPIC).
rjray
OH, you're not coding in Java. That may be a problem then sorry. I think you will need to check if your plugin has a similar feature.
SCdF
OK, a quick look on the side confirms that they have *some* kind of source formatting :-)
SCdF
A slightly longer look suggests it can do anything PerlTidy can do
SCdF
+1  A: 

If you wish to do something more complex than just aligning fields (or anything else the Eclipse code formatter offers you) you are pretty much left with having to write your own plugin.

SCdF
A: 

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

mfeber