From 9adaccabf1eabe3f6b70c45ba425a80e489125e2 Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Tue, 7 Jul 2009 09:41:09 +0200 Subject: [PATCH] Added a very basic fetching utility that fetches TextMate Bundle Snippets from the TextMate site and writes out a file that is compatible with us. Also added a new critical feature/bug that needs fixing: Tabstops in Default Text of Tabstops --- test.py | 1 + utils/get_tm_snippets.py | 58 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100755 utils/get_tm_snippets.py diff --git a/test.py b/test.py index a0176e3..c006ed5 100755 --- a/test.py +++ b/test.py @@ -227,6 +227,7 @@ class TabStopTestMultilineExpand_ExceptCorrectResult(_VimTest): print "expand, jump forward, jump backwards should all be individual" print "Shell eval snippets" +print "Tabstop in default text of tabstop. Like in Ruby Dir snippet in TextMate" # functions # Multiline text pasting diff --git a/utils/get_tm_snippets.py b/utils/get_tm_snippets.py new file mode 100755 index 0000000..369dfd9 --- /dev/null +++ b/utils/get_tm_snippets.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# encoding: utf-8 + +import urllib +import re +from xml.etree import ElementTree + +def parse_content(c): + data = ElementTree.fromstring(c)[0] + + rv = {} + for k,v in zip(data[::2], data[1::2]): + rv[k.text] = v.text + + return rv + +def fetch_snippets(name): + base_url = "http://svn.textmate.org/trunk/Bundles/" + name + ".tmbundle/" + snippet_idx = base_url + "Snippets/" + + idx_list = urllib.urlopen(snippet_idx).read() + + + rv = [] + for link in re.findall("
  • (.*?)
  • ", idx_list): + m = re.match(r'(.*)', link) + link, name = m.groups() + if name == "..": + continue + + name = name.rsplit('.', 1)[0] # remove Extension + print "Fetching data for Snippet '%s'" % name + content = urllib.urlopen(snippet_idx + link).read() + + rv.append((name, parse_content(content))) + + return rv + + +def write_snippets(snip_descr, f): + + for name, d in snip_descr: + if "tabTrigger" not in d: + continue + + f.write('snippet %s "%s"\n' % (d["tabTrigger"], name)) + f.write(d["content"] + "\n") + f.write("endsnippet\n\n") + + + +if __name__ == '__main__': + import sys + + bundle = sys.argv[1] + rv = fetch_snippets(bundle) + write_snippets(rv, open("tm_" + bundle.lower() + ".snippets","w")) +