[SVN] Re: Align Source
Allan Odgaard
mailinglist at textmate.org
Mon May 23 16:07:25 UTC 2011
Nice work!
I played a bit with improving it but didn’t get to where I wanted, so let me instead explain what I wanted to change.
The candidate_chars can be an array of regexps, for example:
regexps = [ /,/, /\}/, /<-/, /\s[-+\/*|]?(=)\s/, /\s(=>)\s/ ]
We then use the offset of capture 1 or offset of the entire match, if no such capture exists:
text.split("\n").map do |line|
if m = ptrn.match(line)
m.offset(m.size > 1 ? 1 : 0)[0]
end
end
In the above, we should use something like ’line[0..i].jlength’ (with i being the offset) for non-ASCII.
We should also collect all matches for each line, and then analyze this result, as we may need to skip the n first matches.
The alignment could be done similarly to above, i.e. apply the regexp against the line, then string post/pre match from leading/trailing whitespace, likewise trim the full match, and now align that.
Whether or not we should insert spaces before/after the match: The best I can come up with is to look at how much space is already to the left/right of the match. We may need to make this an explicit setting, or perhaps we can always insert space before the match *unless* no space was already there (ATM comma is the only case I can think of, where we insert the space after the character).
On 23 May 2011, at 16:58, Mads Hartmann Jensen wrote:
>
> Okay, so I finally handed in my BSc project and had some time to look at
> this. It's not complete but it has come a bit farther :)
>
> The pastie is here: http://pastie.textmate.org/1961439
>
> Here's what the new code does that the old didn't.
>
> - Declares a map from string -> regexp with candidate chars to match (comma,
> }, =, <- ) for now.
> - for each char, run through the text and if it is present in all non-empty
> lines and not already aligned -> do alignment.
>
> Here what it doesn't do yet:
>
> - Doesn't align chunks of text, so in the following nothing gets aligned
> { a, b }
> { aa, bb }
>
> a = b
> aa = bb
>
> - Only aligns the first occurrence of the chars (doesn't cycle through the
> chars until no candidate chars that are in all lines are all matched)
>
> I will definitely play around with this some more, but if you have any
> feedback don't hesitate to write :)
> --
> View this message in context: http://old.nabble.com/Align-Source-tp31636561p31682491.html
> Sent from the textmate-dev mailing list archive at Nabble.com.
>
> _______________________________________________
> textmate-dev mailing list
> textmate-dev at lists.macromates.com
> http://lists.macromates.com/listinfo/textmate-dev
More information about the textmate-dev
mailing list