jarod2d / sublime_valign

Vertical alignment plugin for Sublime Text 2 and 3
91 stars 7 forks source link

Doesn't align JS comma-style variable definitions correctly #7

Closed cbrst closed 11 years ago

cbrst commented 11 years ago

When I align a block like this:

var two = 2,
    three = 3,
    four = 4;

I would expect to see:

var two   = 2,
    three = 3,
    four  = 4;

Instead, when I call "valign" on the first line ('var two = 2,'), nothing happens, and when I'm on one of the other lines, it aligns those, but ignores the first line, so I end up with:

var two = 2,
    three = 3,
    four  = 4;
jarod2d commented 11 years ago

This happens because VAlign considers the first line to be outdented one level from the second and third lines based on the leading spaces of those lines. This is definitely a common use case though, so the next time I have a chance to work on this I'll see if I can work in an exception for this situation.

On Dec 2, 2012, at 5:38 PM, Christian Brassat notifications@github.com wrote:

When I align a block like this:

var two = 2, three = 3, four = 4; I would expect to see:

var two = 2, three = 3, four = 4; Instead, when I call "valign" on the first line ('var two = 2,'), nothing happens, and when I'm on one of the other lines, it aligns those, but ignores the first line, so I end up with:

var two = 2, three = 3, four = 4; — Reply to this email directly or view it on GitHub.

cbrst commented 11 years ago

That was quick :smiley:

I don't really know Python too well, but I gave it a shot in e728c96e05fad99271566699e84817f7fc8ebe73 Seems to work, but it's not very clean.

jarod2d commented 11 years ago

I think that'll work for now. I'd like to create a more general solution to accomodate other situations like this, but that probably won't happen for a while. If you'd like to open a pull request with this commit I'll merge it in, although I'd appreciate it if you could not remove all of that whitespace.

cbrst commented 11 years ago

I agree, it is a very crude solution, but it somewhat gets the job done. I've already found an issue with this - it doesn't work if the active line is the first one. Makes sense actually.

I am also interested in better, general solution. I might take a look at it when I get around to it.

P.S.: Sorry about the whitespace, I usually have my editors set up to automatically remove it for me. I'll just turn that off.

jarod2d commented 11 years ago

Ahh, yeah that makes sense. I've actually just updated it so that it works in that situation. I've changed it so that whenever it encounters "var " at the beginning of a line, it adds another level of indentation. It's not perfect yet (you have to use either four-space tabs or actual tab characters), but it should work for most people. I'll push up a commit shortly.