[TxMt] Combining snippets and commands?

Charilaos Skiadas cskiadas at uchicago.edu
Tue Feb 21 21:38:41 UTC 2006

On Feb 21, 2006, at 1:45 PM, Dr. Drang wrote:
> I've written a snippet that does some of what I want:
>     [${1:description}][${2:id}]$0
>     [${2:id}]: ${3:href}
> but it puts the reference on the line below the link rather than at  
> the bottom of the file. Although I haven't done it, I suspect that  
> writing a command that takes the link label line and puts it at the  
> bottom of the file wouldn't be too difficult. But before I give it  
> a try, I'd like to know if it's possible to combine the snippet and  
> the command into a single instruction that allows me to enter the 3  
> pieces of information, puts the link label at the bottom of the  
> file, and leaves the caret back at the [id].
You could do the following. Write a macro that does the following:

1) selects everything from where you are to the end of file
2) Calls a command that does the following:
2a) Input is current selection
2b) Output is as snippet
2c) The command prepends to the selected text the top line, and  
appends to it the bottom line, and then just spits it out.

You could do this with ruby for instance:
#!/usr/bin/env ruby
print "[${1:description}][${2:id}]$0" + STDIN.read + "\n[${2:id}]:  

I'm sure there is an easier way through the "filter through  
command..." menu item, and a bit of shell magic.

> --
> Dr. Drang


More information about the textmate mailing list