add rst auto complie most common code type

This commit is contained in:
Meng Zhuo 2013-06-19 18:08:51 +08:00
parent f2e535fd94
commit d41ca9e656

View File

@ -91,8 +91,21 @@ endsnippet
###########################################################################
# More Specialized Stuff. #
###########################################################################
global !p
import re
from collections import Counter
def find_all_code_type(path):
with open(path) as source:
types = re.findall(r'[:|\.\.\s]code::?\s(\w+)', source.read())
try:
popular_type = Counter(types).most_common()[0][0]
except KeyError:
popular_type = "lua" # Don't break default
return popular_type
endglobal
snippet cb "Code Block" b
.. code-block:: ${1:lua}
.. code-block:: ${1:`!p snip.rv = find_all_code_type(path)`}
${2:code}