From d41ca9e656dfed11aff4c51ac6de66033830e1b8 Mon Sep 17 00:00:00 2001 From: Meng Zhuo Date: Wed, 19 Jun 2013 18:08:51 +0800 Subject: [PATCH] add rst auto complie most common code type --- UltiSnips/rst.snippets | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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}