Make box and bigbox snippet aware of &comments setting
This commit is contained in:
parent
ea14690099
commit
11c69a853f
@ -5,39 +5,64 @@
|
|||||||
# NICE BOXES #
|
# NICE BOXES #
|
||||||
##############
|
##############
|
||||||
global !p
|
global !p
|
||||||
def cs(snip):
|
import string, vim
|
||||||
c = '#'
|
def _parse_comments(s):
|
||||||
cs = snip.opt("&commentstring")
|
i = iter(s.split(","))
|
||||||
if len(cs) == 3:
|
|
||||||
c = cs[0]
|
rv = []
|
||||||
return c
|
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
|
endglobal
|
||||||
|
|
||||||
snippet box "A nice box with the current comment symbol" b
|
snippet box "A nice box with the current comment symbol" b
|
||||||
`!p
|
`!p
|
||||||
c = cs(snip)
|
box = make_box(len(t[1]))
|
||||||
|
snip.rv = box[0] + '\n' + box[1]
|
||||||
snip.rv = (len(t[1])+4)*c
|
`${1:content}`!p
|
||||||
bar = snip.rv
|
box = make_box(len(t[1]))
|
||||||
snip += c + ' '`${1:content}`!p
|
snip.rv = box[2] + '\n' + box[3]`
|
||||||
|
|
||||||
snip.rv = ' ' + c
|
|
||||||
snip += bar`
|
|
||||||
$0
|
$0
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
snippet bbox "A nice box over the full width" b
|
snippet bbox "A nice box over the full width" b
|
||||||
`!p
|
`!p
|
||||||
c = cs(snip)
|
box = make_box(len(t[1]), 71)
|
||||||
bar = 75*c
|
snip.rv = box[0] + '\n' + box[1]
|
||||||
|
|
||||||
snip.rv = bar
|
|
||||||
snip += c + " " + (71-len(t[1]))/2*' '
|
|
||||||
`${1:content}`!p
|
`${1:content}`!p
|
||||||
|
box = make_box(len(t[1]), 71)
|
||||||
a = 71-len(t[1])
|
snip.rv = box[2] + '\n' + box[3]`
|
||||||
snip.rv = (a/2 + a%2) * " " + " " + c
|
|
||||||
snip += bar`
|
|
||||||
$0
|
$0
|
||||||
endsnippet
|
endsnippet
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user