2013-03-17 15:13:47 -04:00
|
|
|
|
|
|
|
|
|
|
|
###########################################################################
|
|
|
|
# General Stuff #
|
|
|
|
###########################################################################
|
2013-06-19 23:29:44 -04:00
|
|
|
global !p
|
|
|
|
import re
|
|
|
|
def rst_char_len(char):
|
|
|
|
return len(re.findall(r'[^\u4e00-\u9fff\s]', char))+len(char)
|
|
|
|
|
|
|
|
endglobal
|
2013-03-17 15:13:47 -04:00
|
|
|
snippet part "Part" b
|
2013-06-19 23:29:44 -04:00
|
|
|
`!p snip.rv = rst_char_len(t[1])*'#'`
|
2013-03-17 15:13:47 -04:00
|
|
|
${1:Part name}
|
2013-06-19 23:29:44 -04:00
|
|
|
`!p snip.rv = rst_char_len(t[1])*'#'`
|
2013-03-17 15:13:47 -04:00
|
|
|
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet sec "Section" b
|
|
|
|
${1:Section name}
|
2013-06-19 23:29:44 -04:00
|
|
|
`!p snip.rv = rst_char_len(t[1])*'='`
|
2013-03-17 15:13:47 -04:00
|
|
|
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet ssec "Subsection" b
|
|
|
|
${1:Section name}
|
2013-06-19 23:29:44 -04:00
|
|
|
`!p snip.rv = rst_char_len(t[1])*'-'`
|
2013-03-17 15:13:47 -04:00
|
|
|
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet sssec "Subsubsection" b
|
|
|
|
${1:Section name}
|
2013-06-19 23:29:44 -04:00
|
|
|
`!p snip.rv = rst_char_len(t[1])*'^'`
|
2013-03-17 15:13:47 -04:00
|
|
|
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet chap "Chapter" b
|
2013-06-19 23:29:44 -04:00
|
|
|
`!p snip.rv = rst_char_len(t[1])*'*'`
|
2013-03-17 15:13:47 -04:00
|
|
|
${1:Chapter name}
|
2013-06-19 23:29:44 -04:00
|
|
|
`!p snip.rv = rst_char_len(t[1])*'*'`
|
2013-03-17 15:13:47 -04:00
|
|
|
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet para "Paragraph" b
|
|
|
|
${1:Paragraph name}
|
2013-06-19 23:29:44 -04:00
|
|
|
`!p snip.rv = rst_char_len(t[1])*'"'`
|
2013-03-17 15:13:47 -04:00
|
|
|
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
2013-06-19 05:37:01 -04:00
|
|
|
snippet em "Emphasize string" i
|
|
|
|
*${1:Em}* $0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet ec "Emphasize string (CJK)" w
|
|
|
|
\ *${1:Em}*\ $0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet st "Strong string" i
|
|
|
|
**${1:Strong}** $0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet sc "Strong string (CJK)" w
|
|
|
|
\ **${1:Strong}**\ $0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
global !p
|
|
|
|
def make_items(times, leading='+'):
|
|
|
|
times = int(times)
|
|
|
|
if leading == 1:
|
|
|
|
msg = ""
|
|
|
|
for x in xrange(1, times+1):
|
|
|
|
msg += "%s. Item\n" % x
|
|
|
|
return msg
|
|
|
|
else:
|
|
|
|
return ("%s Item\n" % leading) * times
|
|
|
|
endglobal
|
|
|
|
|
2013-06-19 22:27:05 -04:00
|
|
|
# usage: li 3<tab>
|
2013-06-19 05:37:01 -04:00
|
|
|
snippet "li(st)? (?P<num>\d+)" "List" br
|
|
|
|
$0
|
|
|
|
`!p
|
|
|
|
snip.rv = make_items(match.groupdict()['num'])
|
|
|
|
`
|
|
|
|
endsnippet
|
|
|
|
|
2013-06-19 22:27:05 -04:00
|
|
|
# usage: ol 3<tab>
|
2013-06-19 05:37:01 -04:00
|
|
|
snippet "ol(st)? (?P<num>\d+)" "Order List" br
|
|
|
|
$0
|
|
|
|
`!p
|
|
|
|
snip.rv = make_items(match.groupdict()['num'], 1)
|
|
|
|
`
|
|
|
|
endsnippet
|
2013-03-17 15:13:47 -04:00
|
|
|
###########################################################################
|
|
|
|
# More Specialized Stuff. #
|
|
|
|
###########################################################################
|
2013-06-19 06:08:51 -04:00
|
|
|
global !p
|
|
|
|
from collections import Counter
|
2013-06-19 22:15:00 -04:00
|
|
|
def get_popular_code_type(path):
|
2013-06-19 06:08:51 -04:00
|
|
|
with open(path) as source:
|
|
|
|
types = re.findall(r'[:|\.\.\s]code::?\s(\w+)', source.read())
|
|
|
|
try:
|
|
|
|
popular_type = Counter(types).most_common()[0][0]
|
2013-06-19 06:12:12 -04:00
|
|
|
except IndexError:
|
2013-06-19 06:08:51 -04:00
|
|
|
popular_type = "lua" # Don't break default
|
|
|
|
|
|
|
|
return popular_type
|
|
|
|
endglobal
|
2013-03-17 15:13:47 -04:00
|
|
|
snippet cb "Code Block" b
|
2013-06-19 22:15:00 -04:00
|
|
|
.. code-block:: ${1:`!p snip.rv = get_popular_code_type(path)`}
|
2013-03-17 15:13:47 -04:00
|
|
|
|
|
|
|
${2:code}
|
|
|
|
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
2013-06-19 03:35:26 -04:00
|
|
|
snippet img "Image Block" b
|
|
|
|
.. |${2:alias}| image:: ${1:img}
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet fig "Figure Block" b
|
|
|
|
.. figure:: ${1:img}
|
|
|
|
:alt: ${2:alter text}
|
|
|
|
|
|
|
|
${3}
|
|
|
|
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet cont "Content Block" b
|
2013-06-19 05:37:01 -04:00
|
|
|
.. contents:: ${1:Contents Title}
|
2013-06-19 03:35:26 -04:00
|
|
|
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet tip "Tip Block" b
|
|
|
|
.. tip::
|
|
|
|
|
|
|
|
${1:some tips}
|
|
|
|
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet not "Note Block" b
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
${1:some notes}
|
|
|
|
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet war "Warning Block" b
|
|
|
|
.. warning::
|
|
|
|
|
|
|
|
${1:Warning!}
|
|
|
|
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet imp "Important Block" b
|
|
|
|
.. important::
|
|
|
|
|
|
|
|
${1:This is important}
|
|
|
|
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet att "Attention " b
|
|
|
|
.. attention::
|
|
|
|
|
|
|
|
${1:Attention!}
|
|
|
|
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet dan "Danger" b
|
|
|
|
.. danger::
|
|
|
|
|
|
|
|
${1:Danger}
|
|
|
|
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet err "Error Block" b
|
|
|
|
.. error::
|
|
|
|
|
|
|
|
${1:Errors!}
|
|
|
|
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet cau "Cautions Block" b
|
|
|
|
.. caution::
|
|
|
|
|
|
|
|
${1:Cautions!}
|
|
|
|
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
|
|
|
snippet top "Topic" b
|
|
|
|
.. topic:: ${1:title}
|
|
|
|
|
|
|
|
${2:contents}
|
|
|
|
|
|
|
|
$0
|
|
|
|
endsnippet
|
|
|
|
|
2013-06-19 05:37:01 -04:00
|
|
|
############
|
|
|
|
# Sphinx #
|
|
|
|
############
|
|
|
|
|
2013-06-19 03:35:26 -04:00
|
|
|
snippet sid "SideBar" b
|
|
|
|
.. sidebar:: ${1:SideBar Title}
|
|
|
|
|
|
|
|
${2:SideBar Content}
|
|
|
|
endsnippet
|
2013-03-17 15:13:47 -04:00
|
|
|
# vim:ft=snippets:
|