From 6ac725a309217a3a0417783043f40ab1a371bc49 Mon Sep 17 00:00:00 2001 From: Meng Zhuo Date: Thu, 20 Jun 2013 11:29:44 +0800 Subject: [PATCH] fix CJK lens --- UltiSnips/rst.snippets | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/UltiSnips/rst.snippets b/UltiSnips/rst.snippets index c8b62e5..0fed43f 100644 --- a/UltiSnips/rst.snippets +++ b/UltiSnips/rst.snippets @@ -3,46 +3,52 @@ ########################################################################### # General Stuff # ########################################################################### +global !p +import re +def rst_char_len(char): + return len(re.findall(r'[^\u4e00-\u9fff\s]', char))+len(char) + +endglobal snippet part "Part" b -`!p snip.rv = len(t[1])*'#'` +`!p snip.rv = rst_char_len(t[1])*'#'` ${1:Part name} -`!p snip.rv = len(t[1])*'#'` +`!p snip.rv = rst_char_len(t[1])*'#'` $0 endsnippet snippet sec "Section" b ${1:Section name} -`!p snip.rv = len(t[1])*'='` +`!p snip.rv = rst_char_len(t[1])*'='` $0 endsnippet snippet ssec "Subsection" b ${1:Section name} -`!p snip.rv = len(t[1])*'-'` +`!p snip.rv = rst_char_len(t[1])*'-'` $0 endsnippet snippet sssec "Subsubsection" b ${1:Section name} -`!p snip.rv = len(t[1])*'^'` +`!p snip.rv = rst_char_len(t[1])*'^'` $0 endsnippet snippet chap "Chapter" b -`!p snip.rv = len(t[1])*'*'` +`!p snip.rv = rst_char_len(t[1])*'*'` ${1:Chapter name} -`!p snip.rv = len(t[1])*'*'` +`!p snip.rv = rst_char_len(t[1])*'*'` $0 endsnippet snippet para "Paragraph" b ${1:Paragraph name} -`!p snip.rv = len(t[1])*'"'` +`!p snip.rv = rst_char_len(t[1])*'"'` $0 endsnippet @@ -94,7 +100,6 @@ endsnippet # More Specialized Stuff. # ########################################################################### global !p -import re from collections import Counter def get_popular_code_type(path): with open(path) as source: