aboutsummaryrefslogtreecommitdiffstats
path: root/ftplugin
diff options
context:
space:
mode:
authorJorge Scandaliaris <jorgesca@users.noreply.github.com>2015-04-24 18:56:03 -0300
committerJorge Scandaliaris <jorgesca@users.noreply.github.com>2015-04-24 18:56:03 -0300
commit7d8699bfb0c4e1a7df0f7c5e4e9d3f62b9721f91 (patch)
treeb12b66b0173a3167cbc82bb46be19b822ee406bb /ftplugin
parent8ce5be8cb1b99bb02fa80f56843f73c72435a7d1 (diff)
downloadvim-rst-tables-7d8699bfb0c4e1a7df0f7c5e4e9d3f62b9721f91.tar.gz
vim-rst-tables-7d8699bfb0c4e1a7df0f7c5e4e9d3f62b9721f91.tar.bz2
vim-rst-tables-7d8699bfb0c4e1a7df0f7c5e4e9d3f62b9721f91.zip
Fix wrong table width when non-ascii characters are present
Diffstat (limited to 'ftplugin')
-rw-r--r--ftplugin/rst_tables.vim18
1 files changed, 13 insertions, 5 deletions
diff --git a/ftplugin/rst_tables.vim b/ftplugin/rst_tables.vim
index 4b4ebb7..88ef42c 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,27 @@ 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])
+ print 'encoding: ', encoding
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