[TxMt] Converting a single-line block into a multi-line block

David Lee david at davelee.com.au
Mon Nov 28 14:15:11 UTC 2005


actually, a separate command to switch blocks between do .. end and  
{ .. } syntax would be pretty sweet if you feel inclined. ...

at the rate textmate's coming a long I gotta work out how to get work  
to spring for an imac ..

cheers,
David


On 27/11/2005, at 11:10 AM, Allan Odgaard wrote:

> On 25/11/2005, at 21:08, Matt Mower wrote:
>
>> I was looking earlier on at a video some guy did of a VIM macro he'd
>> written that could turn: [...] into [...]
>>
>> I thought for a few minutes about how you might achieve this in TxMt
>> and then realised I didn't have the first clue.  I tried recording a
>> macro but of course it would only work for the simple case, as  
>> soon as
>> I did: [...] it broke.
>>
>> Can this (and/or the inverse) be done with a simple recordable macro?
>
> Yes -- the trick is to use a regexp replacement.
>
> It's a complex expression though, if you search for: ^([\s&&[^\n]]*) 
> (.*?)\s*(?:\{\s*(\|[^|]+\|)\s*(.*?)\s*\}|do\s*(\|[^|]+\|)\s*(\S.*$) 
> \s*end)
>
> It'll find both types of blocks, and put the stuff in captures.  
> Then do replace all in selection with this format string: $1$2(?3:  
> do $3\n$1  $4\n$1end: { $5 $6 })
>
> The (?3:…) part does a conditional replacement, based on whether  
> capture 3 matches or not (which depends on the type of block-style  
> we matched.
>
> I recorded the macro myself and attached below. Save the file to  
> e.g. Ruby.tmbundle/Macros -- it's bound to ctrl-shift-B by default  
> (with scope source.ruby). I can add it to the default bundle, if  
> this is of general use.
>
> <Toggle Single : Multi Line Block.plist>
>
> ______________________________________________________________________
> For new threads USE THIS: textmate at lists.macromates.com
> (threading gets destroyed and the universe will collapse if you don't)
> http://lists.macromates.com/mailman/listinfo/textmate




More information about the textmate mailing list