1
1
# This file contains snippets that are always defined. I personally
2
2
# have snippets for signatures and often needed texts
3
3
4
+ priority -50
5
+
4
6
# #############
5
7
# NICE BOXES #
6
8
# #############
@@ -12,71 +14,62 @@ Automatically filled during usage"""
12
14
_commentDict = { }
13
15
14
16
def _parse_comments (s ):
15
- """ Parses vim's comments option to extract comment format """
16
- i = iter (s.split(" ," ))
17
-
18
- rv = []
19
- try :
20
- while True :
21
- # get the flags and text of a comment part
22
- flags,text = i.next().split(' :' , 1 )
23
-
24
- if len (flags) == 0 :
25
- if len (text) == 1 :
26
- rv.append((text,text,text, " " ))
27
- # parse 3-part comment, but ignore those with O flag
28
- elif flags[0 ] == ' s' and ' O' not in flags:
29
- ctriple = []
30
- indent = " "
31
-
32
- if flags[- 1 ] in string.digits:
33
- indent = " " * int (flags[- 1 ])
34
- ctriple.append(text)
17
+ """ Parses vim's comments option to extract comment format """
18
+ i = iter (s.split(" ," ))
19
+
20
+ rv = []
21
+ try :
22
+ while True :
23
+ # get the flags and text of a comment part
24
+ flags, text = next (i).split(' :' , 1 )
25
+
26
+ if len (flags) == 0 :
27
+ rv.append((text, text, text, " " ))
28
+ # parse 3-part comment, but ignore those with O flag
29
+ elif flags[0 ] == ' s' and ' O' not in flags:
30
+ ctriple = []
31
+ indent = " "
32
+
33
+ if flags[- 1 ] in string.digits:
34
+ indent = " " * int (flags[- 1 ])
35
+ ctriple.append(text)
36
+
37
+ flags,text = next (i).split(' :' , 1 )
38
+ assert (flags[0 ] == ' m' )
39
+ ctriple.append(text)
40
+
41
+ flags,text = next (i).split(' :' , 1 )
42
+ assert (flags[0 ] == ' e' )
43
+ ctriple.append(text)
44
+ ctriple.append(indent)
45
+
46
+ rv.append(ctriple)
47
+ elif flags[0 ] == ' b' :
48
+ if len (text) == 1 :
49
+ rv.insert(0 , (text,text,text, " " ))
50
+ except StopIteration :
51
+ return rv
35
52
36
- flags,text = i.next().split(' :' , 1 )
37
- assert (flags[0 ] == ' m' )
38
- ctriple.append(text)
39
-
40
- flags,text = i.next().split(' :' , 1 )
41
- assert (flags[0 ] == ' e' )
42
- ctriple.append(text)
43
- ctriple.append(indent)
53
+ def _get_comment_format ():
54
+ """ Returns a 4-element tuple representing the comment format for
55
+ the current file. """
56
+ return _parse_comments(vim.eval(" &comments" ))[0 ]
44
57
45
- rv.append(ctriple)
46
58
47
- elif flags[0 ] == ' b' :
48
- if len (text) == 1 :
49
- rv.insert(0 , (text,text,text, " " ))
59
+ def make_box (twidth , bwidth = None ):
60
+ b, m, e, i = _get_comment_format()
61
+ bwidth_inner = bwidth - 3 - max (len (b), len (i + e)) if bwidth else twidth + 2
62
+ sline = b + m + bwidth_inner * m[0 ] + 2 * m[0 ]
63
+ nspaces = (bwidth_inner - twidth) // 2
64
+ mlines = i + m + " " + " " * nspaces
65
+ mlinee = " " + " " * (bwidth_inner - twidth - nspaces) + m
66
+ eline = i + m + bwidth_inner * m[0 ] + 2 * m[0 ] + e
67
+ return sline, mlines, mlinee, eline
50
68
51
- except StopIteration :
52
- return rv
69
+ def foldmarker ():
70
+ " Return a tuple of (open fold marker, close fold marker)"
71
+ return vim.eval(" &foldmarker" ).split(" ," )
53
72
54
- def _get_comment_format ():
55
- """ Returns a 4-element tuple representing the comment format for
56
- the current file. """
57
-
58
- ft = vim.eval(" &filetype" )
59
- # check if the comment dict has the format for the current file
60
- if _commentDict.has_key(ft):
61
- return _commentDict[ft]
62
-
63
- # otherwise parse vim's comments and add it for later use
64
- commentformat = _parse_comments(vim.eval(" &comments" ))[0 ]
65
- _commentDict[ft] = commentformat
66
-
67
- return commentformat
68
-
69
-
70
- def make_box (twidth , bwidth = None ):
71
- if bwidth is None :
72
- bwidth = twidth + 2
73
- b,m,e,i = _get_comment_format()
74
- sline = b + m + bwidth* m + 2 * m
75
- nspaces = (bwidth - twidth)// 2
76
- mlines = i + m + " " + " " * nspaces
77
- mlinee = " " + " " * (bwidth- twidth- nspaces) + m
78
- eline = i + 2 * m + bwidth* m + m + e
79
- return sline, mlines, mlinee, eline
80
73
endglobal
81
74
82
75
snippet box " A nice box with the current comment symbol" b
@@ -91,14 +84,29 @@ endsnippet
91
84
92
85
snippet bbox " A nice box over the full width" b
93
86
`!p
94
- box = make_box(len (t[1 ]), 71 )
87
+ width = int (vim.eval(" &textwidth" )) or 71
88
+ box = make_box(len (t[1 ]), width)
95
89
snip.rv = box[0 ] + ' \n ' + box[1 ]
96
90
` ${1: content } `!p
97
- box = make_box(len (t[1 ]), 71 )
91
+ box = make_box(len (t[1 ]), width )
98
92
snip.rv = box[2 ] + ' \n ' + box[3 ] `
99
93
$0
100
94
endsnippet
101
95
96
+ snippet fold " Insert a vim fold marker" b
97
+ `!p snip.rv = _get_comment_format()[0 ] ` ${1: Fold description } `!p snip.rv = foldmarker()[0 ] ` ${2: 1 } `!p snip.rv = _get_comment_format()[2 ] `
98
+ endsnippet
99
+
100
+ snippet foldc " Insert a vim fold close marker" b
101
+ `!p snip.rv = _get_comment_format()[0 ] ` ${2: 1 } `!p snip.rv = foldmarker()[1 ] ` `!p snip.rv = _get_comment_format()[2 ] `
102
+ endsnippet
103
+
104
+ snippet foldp " Insert a vim fold marker pair" b
105
+ `!p snip.rv = _get_comment_format()[0 ] ` ${1: Fold description } `!p snip.rv = foldmarker()[0 ] ` `!p snip.rv = _get_comment_format()[2 ] `
106
+ ${2: ${VISUAL:Content } }
107
+ `!p snip.rv = _get_comment_format()[0 ] ` `!p snip.rv = foldmarker()[1 ] ` $1 `!p snip.rv = _get_comment_format()[2 ] `
108
+ endsnippet
109
+
102
110
# #########################
103
111
# LOREM IPSUM GENERATORS #
104
112
# #########################
0 commit comments