On Wed, Jul 8, 2009 at 9:24 AM, Dru Kepple <span dir="ltr"><<a href="mailto:dru@summitprojects.com">dru@summitprojects.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
> From: Neil <<a href="mailto:kngspook@gmail.com">kngspook@gmail.com</a>><br>
<div class="im">><br>
> 3. As I make these Templates, I'm finding a lot of common text between them,<br>
> and when I want to tweak it across the board...well, it's like programming<br>
> without functions. What, if anything, can I do to reduce redundancy in my<br>
> templates?<br>
<br>
</div>I'm sure this is possible, and I've fiddled about with doing something<br>
similar, but haven't put too much effort into this. You can execute Ruby<br>
from within snippets, and in theory you could put your repository of<br>
reusable snippet text within a file or a preference or something, and just<br>
put the text in through Ruby.<br>
<br>
So, I just threw something together, and got this working.<br>
<br>
1. In your bundle on the hard drive, create a folder called "Support"<br>
(right-click the bundle in ~/Library/Application Support/TextMate/Bundles/,<br>
choose show package contents)<br>
<br>
2. In this folder, create a few ruby files that will contain your reusable<br>
snippet text.<br>
<br>
3. Each file might look like this:<br>
<br>
print 'Here is some reusable text.'<br>
<br>
4. In your snippet, add this "tab stop" to load the file and insert the<br>
text:<br>
<br>
This is my snippet... ${1:`#!/usr/bin/env ruby<br>
require ENV['TM_BUNDLE_SUPPORT'] + '/SnippetRepo'<br>
`}$0<br>
<br>
Starting with the ${1: is the embedded ruby that executes; I don't know if<br>
you know ruby or not, but all it does is load and execute that file you<br>
created in the Support folder. Again, not sure how much you know, but<br>
TM_BUNDLE_SUPPORT provide the path to the bundle's Support folder. You have<br>
to manually create the Support folder (as far as I know), and it has to be<br>
at the root level of the bundle, spelled right, etc. But then<br>
TM_BUNDLE_SUPPORT provides easy access to files that your bundle will use,<br>
but isn't directly a Snippet, or Command, or whatever.<br>
<br>
The disadvantage with this technique is that, as far as I know, ruby can<br>
only be executed from the tab stops, so when the snippet expands and you tab<br>
through the other stops, this boiler plate text will get highlighted, as<br>
well, and potentially altered.<br>
<br>
Also, I'm not sure how to be more intelligent about the text inserted this<br>
way; I'm sure it's possible, but I don't know if the snippet can communicate<br>
with the script you run or vice versa. You can, however, run ruby as if it<br>
were a command, so you should have access to all of those shell variables<br>
that you can use in commands, like TM_FILENAME and the like.<br>
<br>
I hope that helps; please post any further advancements you make in this<br>
area. I'm interested, as well!<br>
<br>
+dru<br>
<br></blockquote><div><br>Thanks for the response.<br><br>That will help quite a bit, for things like making #include guards in my C bundle. But for some other things, I'd like to be able to share across bundles (eg. copyright notices). I suppose I could do something like that by just putting it in the TM_SUPPORT folder instead of the TM_BUNDLE_SUPPORT?<br>
<br>I do know a little Ruby... Is it just Ruby that's supported, or any scripting language?<br><br>Thanks again,<br>Neil.<br></div></div>