diff options
author | Vincent Driessen <vincent@datafox.nl> | 2011-10-01 05:05:01 -0700 |
---|---|---|
committer | Vincent Driessen <vincent@datafox.nl> | 2011-10-01 05:05:01 -0700 |
commit | 8472e84fe463ee98ff02f6ae0b37e08239ad9907 (patch) | |
tree | f68fffe7675be70e190c916191ed6cf3676d4f74 /ftplugin | |
parent | 8db3e1740fce3232616509002b43b91e29b7769f (diff) | |
parent | 4189dce16ecfb7a680b45333995eec9a0fdb844d (diff) | |
download | vim-rst-tables-8472e84fe463ee98ff02f6ae0b37e08239ad9907.tar.gz vim-rst-tables-8472e84fe463ee98ff02f6ae0b37e08239ad9907.tar.bz2 vim-rst-tables-8472e84fe463ee98ff02f6ae0b37e08239ad9907.zip |
Merge pull request #7 from choplin/master
Support tables containing East Asian languages, too.
Diffstat (limited to 'ftplugin')
-rw-r--r-- | ftplugin/rst_tables.vim | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/ftplugin/rst_tables.vim b/ftplugin/rst_tables.vim index e042157..a77bafe 100644 --- a/ftplugin/rst_tables.vim +++ b/ftplugin/rst_tables.vim @@ -20,6 +20,7 @@ python << endpython import vim import re import textwrap +import unicodedata from vim_bridge import bridged @@ -160,8 +161,17 @@ def table_line(widths, header=False): def get_field_width(field_text): - return max(map(lambda s: len(s), field_text.split('\n'))) - + return max(map(get_string_width, field_text.split('\n'))) + +def get_string_width(string): + width = 0 + for char in list(string.decode('utf-8')): + eaw = unicodedata.east_asian_width(char) + if eaw == 'Na' or eaw == 'H': + width += 1 + else: + width += 2 + return width def split_row_into_lines(row): row = map(lambda field: field.split('\n'), row) |