[SVN] Re: Align Source

Timothy Bates timothy.c.bates at gmail.com
Fri May 20 15:09:18 UTC 2011


I think 90% of needs would be met by an algorithm that used each languages equate symbols

SO for R, align shoudl align on = and on <-, preferring the latter.

each language could say what its list of equate symbols are, and in order of preference.

All the macro has to do then is see which of the symbols is present first on each line, and align those to match

so this:
a<-rnorm(10)
cold<-factor(c(1,2,1,2,1,2,1,2,1,2))
becomes this:
a     <- rnorm(10)
cold<- factor(c(1,2,1,2,1,2,1,2,1,2))

and this is also caught
a    = rnorm(10)
cold = factor(c(1,2,1,2,1,2,1,2,1,2))

but this:
a    = rnorm(pi=10)
cold <- factor(cat=dog)
becomes this
a      = rnorm(pi=10)
cold <- factor(catastrophe=dog)

not this:
a      = rnorm(pi             =10)
cold <- factor(catastrophe=dog)

or worse this:
a                                   = rnorm(pi =10)
cold <- factor(catastrophe=dog)

On 20 May 2011, at 1:55 PM, Mads Hartmann Jensen wrote:

> 
> Ah, interesting. 
> 
> Once I have handed in my BSc project I will take a swing at this if you
> haven't gotten to it by then :)
> 
> Cheers,
> Mads Hartmann Jensen 
> 
> 
> Allan Odgaard-4 wrote:
>> 
>> Thanks for sharing.
>> 
>> I’ve been meaning to rework this command for quite some time, the basic
>> algorithm I want to do is here: http://pastie.textmate.org/747958
>> 
>> The align function takes a regexp which must have two captures. It match
>> each line against the regexp and then ensures that spacing is inserted
>> after capture one so that capture two falls on the same column for each
>> line.
>> 
>> In the example we first match up to comma followed by a space, aligns on
>> that, and then matches up to the closing brace, and align on that.
>> 
>> The thing I haven’t written yet is a way to automatically figure out the
>> regexp from the user’s code. I think this would be possible with some
>> heuristic which finds the first candidate character which exist for each
>> non-empty line, and which isn’t already aligned. One could perhaps cycle
>> through candidate matches on successive runs.
>> 
>> I’ve never gotten around to trying implementing such heuristic though.
>> 
> 
> -- 
> View this message in context: http://old.nabble.com/Align-Source-tp31636561p31663873.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