diff --git a/UltiSnips/all.snippets b/UltiSnips/all.snippets index cf64396..362c0d8 100644 --- a/UltiSnips/all.snippets +++ b/UltiSnips/all.snippets @@ -5,39 +5,64 @@ # NICE BOXES # ############## global !p -def cs(snip): - c = '#' - cs = snip.opt("&commentstring") - if len(cs) == 3: - c = cs[0] - return c +import string, vim +def _parse_comments(s): + i = iter(s.split(",")) + + rv = [] + try: + while True: + n = i.next() + if n[0] == 's': + ctriple = [] + indent = "" + if n[1] in string.digits: + indent = " " * int(n[1]) + ctriple.append(n.split(":",1)[1]) + n = i.next() + assert(n[0] == 'm') + ctriple.append(n.split(":",1)[1]) + n = i.next() + assert(n[0] == 'e') + ctriple.append(n.split(":",1)[1]) + ctriple.append(indent) + rv.append(ctriple) + elif n[0] == 'b': + cm = n.split(":", 1)[1] + if len(cm) == 1: + rv.insert(0, (cm,cm,cm, "")) + except StopIteration: + return rv + +def make_box(twidth, bwidth = None): + if bwidth is None: + bwidth = twidth + 2 + b,m,e,i = _parse_comments(vim.eval("&comments"))[0] + sline = b + m + bwidth*m + 2*m + nspaces = (bwidth - twidth)//2 + mlines = i + m + " " + " "*nspaces + mlinee = " " + " "*(bwidth-twidth-nspaces) + m + eline = i + 2*m + bwidth*m + m + e + return sline, mlines, mlinee, eline endglobal snippet box "A nice box with the current comment symbol" b `!p -c = cs(snip) - -snip.rv = (len(t[1])+4)*c -bar = snip.rv -snip += c + ' '`${1:content}`!p - -snip.rv = ' ' + c -snip += bar` +box = make_box(len(t[1])) +snip.rv = box[0] + '\n' + box[1] +`${1:content}`!p +box = make_box(len(t[1])) +snip.rv = box[2] + '\n' + box[3]` $0 endsnippet snippet bbox "A nice box over the full width" b `!p -c = cs(snip) -bar = 75*c - -snip.rv = bar -snip += c + " " + (71-len(t[1]))/2*' ' +box = make_box(len(t[1]), 71) +snip.rv = box[0] + '\n' + box[1] `${1:content}`!p - -a = 71-len(t[1]) -snip.rv = (a/2 + a%2) * " " + " " + c -snip += bar` +box = make_box(len(t[1]), 71) +snip.rv = box[2] + '\n' + box[3]` $0 endsnippet