One thing I use snippets for is as a simple, convenient memory aid; for example, I currently have (most) of the Ruby standard exception types as snippets with the tab trigger "exception". So I type in "exception", tab, and get to choose which of the exceptions I really want to use.
However, defining and maintaining (in case changes are wanted) such a large number of small snippets is sorta annoying when going through the Bundle Editor. Is there a way to have multiple snippets in one file, including the various settings such as tab trigger, keyboard shortcut, etc.?
Thanks, Ken
One thing I use snippets for is as a simple, convenient memory aid; for example, I currently have (most) of the Ruby standard exception types as snippets with the tab trigger "exception". So I type in "exception", tab, and get to choose which of the exceptions I really want to use.
However, defining and maintaining (in case changes are wanted) such a large number of small snippets is sorta annoying when going through the Bundle Editor. Is there a way to have multiple snippets in one file, including the various settings such as tab trigger, keyboard shortcut, etc.?
A better way to do this sort of thing is to write a command. Something like this:
#!/usr/bin/env ruby -wKU require "#{ENV['TM_SUPPORT_PATH']}/lib/ui" exceptions = [ 'Exception', 'AnotherException' ] index = TextMate::UI.menu(exceptions) STDOUT.write("${0:#{exceptions[index]}}")
Try creating a textmate command with these contents, set 'Input: None', 'Output: Insert as Snippet' and of course set Activation to 'Tab Trigger: exception'.
The command is attached as well.
Ah, my heart is pounding...I hadn't stumbled across TextMate::UI yet (actually, haven't really looked at programming textmate yet), so it's time to start!
Many thanks, Ken
Alex Ross wrote:
One thing I use snippets for is as a simple, convenient memory aid; for example, I currently have (most) of the Ruby standard exception types as snippets with the tab trigger "exception". So I type in "exception", tab, and get to choose which of the exceptions I really want to use.
However, defining and maintaining (in case changes are wanted) such a large number of small snippets is sorta annoying when going through the Bundle Editor. Is there a way to have multiple snippets in one file, including the various settings such as tab trigger, keyboard shortcut, etc.?
A better way to do this sort of thing is to write a command. Something like this:
#!/usr/bin/env ruby -wKU require "#{ENV['TM_SUPPORT_PATH']}/lib/ui" exceptions = [ 'Exception', 'AnotherException' ] index = TextMate::UI.menu(exceptions) STDOUT.write("${0:#{exceptions[index]}}")
Try creating a textmate command with these contents, set 'Input: None', 'Output: Insert as Snippet' and of course set Activation to 'Tab Trigger: exception'.
The command is attached as well.
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
You might also be interested in the CodeCompletion stuff. It does something similar to what Alex suggests but has some nice features specific to completing code. It'll find where your caret is and use the characters to the left of your caret to filter the list of completions. It'll also snippetize the completion to let you tab into quotes and stuff. It's what is used in the HTML & CSS bundles for completions. And a few other places.
#!/usr/bin/env ruby require "#{ENV['TM_SUPPORT_PATH']}/lib/codecompletion" print TextmateCodeCompletion.new(["something","something else","etc..."],STDIN.read).to_snippet
input: current line or selection output: snippet
Or you could even make some preference items in your personal bundle like this:
{ shellVariables = ( { name = 'TM_COMPLETIONS'; value = 'something,something else,etc...'; }, ); }
And then set the scope to only give you that list in certain places.
And write a command like this that works with multiple lists with the same shortcut:
#!/usr/bin/env ruby require "#{ENV['TM_SUPPORT_PATH']}/lib/codecompletion" print TextmateCodeCompletion .new(ENV['TM_COMPLETIONS'].split(','),STDIN.read).to_snippet
thomas Aylott — subtleGradient — CrazyEgg — bundleForge
On Aug 13, 2007, at 10:27 PM, Kenneth McDonald wrote:
Ah, my heart is pounding...I hadn't stumbled across TextMate::UI yet (actually, haven't really looked at programming textmate yet), so it's time to start!
Many thanks, Ken
Alex Ross wrote: