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

Allan Odgaard throw-away-1 at macromates.com
Sun Nov 27 00:10:35 UTC 2005


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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Toggle Single : Multi Line Block.plist
Type: application/octet-stream
Size: 2089 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20051127/3dcaa4cc/attachment.plist>


More information about the textmate mailing list