[TxMt] Converting a single-line block into a multi-line block
David Lee
david at davelee.com.au
Mon Nov 28 14:07:47 UTC 2005
just to complicate matters, I much prefer the curlybrace style
expansion. It's also more robust:
items.collect { |i| i.children }.reject{|c| c.children.empty? }
with your regex macro becomes
items.collect do |i|
i.children
end.reject{|c| c.children.empty? }
which is illegal Ruby; with a curly-style expansion your macro holds
up admirably.
I know it's easy enough to change manually, but if your'e considering
putting it in the distribution I'd advise to err on the side of curlies
( hope I'm not starting a ruby style religious war ... )
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