aboutsummaryrefslogtreecommitdiffstats
path: root/ftplugin
diff options
context:
space:
mode:
authorVincent Driessen <me@nvie.com>2015-04-29 20:36:14 +0200
committerVincent Driessen <me@nvie.com>2015-04-29 20:36:14 +0200
commit7797a9fe721cf7116e28a49fff3595071c48ce63 (patch)
tree41153ff1f43ca2d0ddddc6dace5b5105c715935e /ftplugin
parent8ce5be8cb1b99bb02fa80f56843f73c72435a7d1 (diff)
parentb0defcc4ea77717ec255003621bae55769e4c75c (diff)
downloadvim-rst-tables-7797a9fe721cf7116e28a49fff3595071c48ce63.tar.gz
vim-rst-tables-7797a9fe721cf7116e28a49fff3595071c48ce63.tar.bz2
vim-rst-tables-7797a9fe721cf7116e28a49fff3595071c48ce63.zip
Merge pull request #22 from jorgesca/fix_utf8
Fix wrong table width when non-ascii characters are present
Diffstat (limited to 'ftplugin')
-rw-r--r--ftplugin/rst_tables.vim17
1 files changed, 12 insertions, 5 deletions
diff --git a/ftplugin/rst_tables.vim b/ftplugin/rst_tables.vim
index 4b4ebb7..6c994ce 100644
--- a/ftplugin/rst_tables.vim
+++ b/ftplugin/rst_tables.vim
@@ -21,6 +21,7 @@ import vim
import re
import textwrap
import unicodedata
+import codecs
from vim_bridge import bridged
@@ -167,7 +168,7 @@ def get_field_width(field_text):
def get_string_width(string):
width = 0
- for char in list(string.decode('utf-8')):
+ for char in list(string):
eaw = unicodedata.east_asian_width(char)
if eaw == 'Na' or eaw == 'H':
width += 1
@@ -287,20 +288,26 @@ def draw_table(indent, table, manual_widths=None):
@bridged
def reformat_table():
upper, lower, indent = get_table_bounds()
- slice = vim.current.buffer[upper - 1:lower]
+ encoding = vim.eval("&encoding")
+ slice = map(lambda x: codecs.decode(x, encoding), \
+ vim.current.buffer[upper - 1:lower])
table = parse_table(slice)
slice = draw_table(indent, table)
- vim.current.buffer[upper - 1:lower] = slice
+ vim.current.buffer[upper - 1:lower] = map(lambda x: \
+ codecs.encode(x, encoding), slice)
@bridged
def reflow_table():
upper, lower, indent = get_table_bounds()
- slice = vim.current.buffer[upper - 1:lower]
+ encoding = vim.eval("&encoding")
+ slice = map(lambda x: codecs.decode(x, encoding), \
+ vim.current.buffer[upper - 1:lower])
widths = get_column_widths_from_border_spec(slice)
table = parse_table(slice)
slice = draw_table(indent, table, widths)
- vim.current.buffer[upper - 1:lower] = slice
+ vim.current.buffer[upper - 1:lower] = map(lambda x: \
+ codecs.encode(x, encoding), slice)
endpython