2013-03-17 15:13:47 -04:00
|
|
|
# This file contains snippets that are always defined. I personally
|
|
|
|
# have snippets for signatures and often needed texts
|
|
|
|
|
2014-03-04 11:46:35 -05:00
|
|
|
# sligthly lower priority than everything else. After all these should
|
|
|
|
# overwrite.
|
|
|
|
priority -51
|
2014-02-26 03:31:33 -05:00
|
|
|
|
2013-03-17 15:13:47 -04:00
|
|
|
##############
|
|
|
|
# NICE BOXES #
|
|
|
|
##############
|
|
|
|
global !p
|
|
|
|
import string, vim
|
|
|
|
|
|
|
|
""" Maps a filetype to comment format used for boxes.
|
|
|
|
Automatically filled during usage"""
|
|
|
|
_commentDict = { }
|
|
|
|
|
|
|
|
def _parse_comments(s):
|
2014-02-26 03:31:33 -05:00
|
|
|
""" Parses vim's comments option to extract comment format """
|
|
|
|
i = iter(s.split(","))
|
|
|
|
|
|
|
|
rv = []
|
|
|
|
try:
|
|
|
|
while True:
|
|
|
|
# get the flags and text of a comment part
|
|
|
|
flags, text = next(i).split(':', 1)
|
|
|
|
|
|
|
|
if len(flags) == 0:
|
|
|
|
rv.append((text, text, text, ""))
|
|
|
|
# parse 3-part comment, but ignore those with O flag
|
|
|
|
elif flags[0] == 's' and 'O' not in flags:
|
|
|
|
ctriple = []
|
|
|
|
indent = ""
|
|
|
|
|
|
|
|
if flags[-1] in string.digits:
|
|
|
|
indent = " " * int(flags[-1])
|
|
|
|
ctriple.append(text)
|
|
|
|
|
|
|
|
flags,text = next(i).split(':', 1)
|
|
|
|
assert(flags[0] == 'm')
|
|
|
|
ctriple.append(text)
|
|
|
|
|
|
|
|
flags,text = next(i).split(':', 1)
|
|
|
|
assert(flags[0] == 'e')
|
|
|
|
ctriple.append(text)
|
|
|
|
ctriple.append(indent)
|
|
|
|
|
|
|
|
rv.append(ctriple)
|
|
|
|
elif flags[0] == 'b':
|
|
|
|
if len(text) == 1:
|
|
|
|
rv.insert(0, (text,text,text, ""))
|
|
|
|
except StopIteration:
|
|
|
|
return rv
|
2013-03-17 15:13:47 -04:00
|
|
|
|
2014-02-26 03:31:33 -05:00
|
|
|
def _get_comment_format():
|
|
|
|
""" Returns a 4-element tuple representing the comment format for
|
|
|
|
the current file. """
|
|
|
|
return _parse_comments(vim.eval("&comments"))[0]
|
2013-03-17 15:13:47 -04:00
|
|
|
|
|
|
|
|
2014-02-26 03:31:33 -05:00
|
|
|
def make_box(twidth, bwidth=None):
|
|
|
|
b, m, e, i = _get_comment_format()
|
|
|
|
bwidth_inner = bwidth - 3 - max(len(b), len(i + e)) if bwidth else twidth + 2
|
|
|
|
sline = b + m + bwidth_inner * m[0] + 2 * m[0]
|
|
|
|
nspaces = (bwidth_inner - twidth) // 2
|
|
|
|
mlines = i + m + " " + " " * nspaces
|
|
|
|
mlinee = " " + " "*(bwidth_inner - twidth - nspaces) + m
|
|
|
|
eline = i + m + bwidth_inner * m[0] + 2 * m[0] + e
|
|
|
|
return sline, mlines, mlinee, eline
|
2013-03-17 15:13:47 -04:00
|
|
|
|
2014-02-26 03:31:33 -05:00
|
|
|
def foldmarker():
|
|
|
|
"Return a tuple of (open fold marker, close fold marker)"
|
|
|
|
return vim.eval("&foldmarker").split(",")
|
2013-03-17 15:13:47 -04:00
|
|
|
|
|
|
|
endglobal
|
|
|
|
|
|
|
|
snippet box "A nice box with the current comment symbol" b
|
|
|
|
`!p
|
|
|
|
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
|
2014-02-26 03:31:33 -05:00
|
|
|
width = int(vim.eval("&textwidth")) or 71
|
|
|
|
box = make_box(len(t[1]), width)
|
2013-03-17 15:13:47 -04:00
|
|
|
snip.rv = box[0] + '\n' + box[1]
|
|
|
|
`${1:content}`!p
|
2014-02-26 03:31:33 -05:00
|
|
|
box = make_box(len(t[1]), width)
|
2013-03-17 15:13:47 -04:00
|
|
|
snip.rv = box[2] + '\n' + box[3]`
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
2014-02-26 03:31:33 -05:00
|
|
|
snippet fold "Insert a vim fold marker" b
|
|
|
|
`!p snip.rv = _get_comment_format()[0]` ${1:Fold description} `!p snip.rv = foldmarker()[0]`${2:1} `!p snip.rv = _get_comment_format()[2]`
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet foldc "Insert a vim fold close marker" b
|
|
|
|
`!p snip.rv = _get_comment_format()[0]` ${2:1}`!p snip.rv = foldmarker()[1]` `!p snip.rv = _get_comment_format()[2]`
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet foldp "Insert a vim fold marker pair" b
|
|
|
|
`!p snip.rv = _get_comment_format()[0]` ${1:Fold description} `!p snip.rv = foldmarker()[0]` `!p snip.rv = _get_comment_format()[2]`
|
|
|
|
${2:${VISUAL:Content}}
|
|
|
|
`!p snip.rv = _get_comment_format()[0]` `!p snip.rv = foldmarker()[1]` $1 `!p snip.rv = _get_comment_format()[2]`
|
|
|
|
endsnippet
|
|
|
|
|
2013-03-17 15:13:47 -04:00
|
|
|
##########################
|
|
|
|
# LOREM IPSUM GENERATORS #
|
|
|
|
##########################
|
|
|
|
snippet lorem "Lorem Ipsum - 50 Words" b
|
|
|
|
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
|
|
|
|
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
|
|
|
|
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
|
|
|
|
no sea takimata sanctus est Lorem ipsum dolor sit amet.
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
# vim:ft=snippets:
|