From 94ee96cb310daaddc636c0b4d420d4043ec9003e Mon Sep 17 00:00:00 2001 From: Holger Rapp Date: Thu, 16 Jul 2009 15:51:15 +0200 Subject: [PATCH] Added vim module into imported python modules for python interpolation. box and bbox are now in the all.snippets and use the comment leader extracted from the commentstring option --- UltiSnips/all.snippets | 40 +++++++++++++++++++++++++++++++++ UltiSnips/python.snippets | 17 -------------- plugin/UltiSnips/TextObjects.py | 2 +- 3 files changed, 41 insertions(+), 18 deletions(-) diff --git a/UltiSnips/all.snippets b/UltiSnips/all.snippets index 24598da..6bc572a 100644 --- a/UltiSnips/all.snippets +++ b/UltiSnips/all.snippets @@ -1,3 +1,43 @@ # This file contains snippets that are always defined. I personally # have snippets for signatures and often needed texts +############## +# NICE BOXES # +############## +snippet box +`!p +c = '#' +cs = vim.eval("&commentstring") +if len(cs) == 3: + c = cs[0] + +res = (len(t[1])+4)*c + '\n' + c + ' '`${1:content}`!p +c = '#' +cs = vim.eval("&commentstring") +if len(cs) == 3: + c = cs[0] + +res = ' ' + c + '\n' + (len(t[1])+4)*c` +$0 +endsnippet + +snippet bbox +`!p +c = '#' +cs = vim.eval("&commentstring") +if len(cs) == 3: + c = cs[0] + +res = 75*c + '\n' + c + " "+ (71-len(t[1]))/2*' ' +`${1:content}`!p +c = '#' +cs = vim.eval("&commentstring") +if len(cs) == 3: + c = cs[0] + +a = 71-len(t[1]); res = (a/2 + a%2) * " " + " " + c + '\n' + 75*c` +$0 +endsnippet + + + diff --git a/UltiSnips/python.snippets b/UltiSnips/python.snippets index 43f7ea0..68236e3 100644 --- a/UltiSnips/python.snippets +++ b/UltiSnips/python.snippets @@ -14,23 +14,6 @@ if __name__ == '__main__': ${1:main()}$0 endsnippet -############## -# NICE BOXES # -############## -snippet box -`!p res = (len(t[1])+4)*"#"` -# ${1:content} # -`!p res = (len(t[1])+4)*"#"` -$0 -endsnippet - -snippet bbox -`!p res = 75*"#"` -# `!p res = (71-len(t[1]))/2*' '`${1:content}`!p a = 71-len(t[1]); res = (a/2 + a%2) * " " ` # -`!p res = 75*"#"` -$0 -endsnippet - ########## # COMMON # diff --git a/plugin/UltiSnips/TextObjects.py b/plugin/UltiSnips/TextObjects.py index 6dc7e2b..834ccac 100644 --- a/plugin/UltiSnips/TextObjects.py +++ b/plugin/UltiSnips/TextObjects.py @@ -626,7 +626,7 @@ class PythonCode(TextObject): code = code.replace("\\`", "`") # Add Some convenience to the code - self._code = "import re, os\n" + code.strip() + self._code = "import re, os, vim\n" + code.strip() TextObject.__init__(self, parent, start, end, "")