diff --git a/UltiSnips/rst.snippets b/UltiSnips/rst.snippets index e3808b8..ec11b7f 100644 --- a/UltiSnips/rst.snippets +++ b/UltiSnips/rst.snippets @@ -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}