aboutsummaryrefslogtreecommitdiffstats
path: root/ftplugin
diff options
context:
space:
mode:
Diffstat (limited to 'ftplugin')
-rw-r--r--ftplugin/rst_tables.vim42
1 files changed, 11 insertions, 31 deletions
diff --git a/ftplugin/rst_tables.vim b/ftplugin/rst_tables.vim
index 6c994ce..ed2bd9f 100644
--- a/ftplugin/rst_tables.vim
+++ b/ftplugin/rst_tables.vim
@@ -20,16 +20,13 @@ python << endpython
import vim
import re
import textwrap
-import unicodedata
-import codecs
-from vim_bridge import bridged
def get_table_bounds():
row, col = vim.current.window.cursor
upper = lower = row
try:
- while vim.current.buffer[upper - 1].strip() and upper > 0:
+ while vim.current.buffer[upper - 1].strip():
upper -= 1
except IndexError:
pass
@@ -164,17 +161,8 @@ def table_line(widths, header=False):
def get_field_width(field_text):
- return max(map(get_string_width, field_text.split('\n')))
-
-def get_string_width(string):
- width = 0
- for char in list(string):
- eaw = unicodedata.east_asian_width(char)
- if eaw == 'Na' or eaw == 'H':
- width += 1
- else:
- width += 2
- return width
+ return max(map(lambda s: len(s), field_text.split('\n')))
+
def split_row_into_lines(row):
row = map(lambda field: field.split('\n'), row)
@@ -285,39 +273,31 @@ def draw_table(indent, table, manual_widths=None):
return output
-@bridged
def reformat_table():
upper, lower, indent = get_table_bounds()
- encoding = vim.eval("&encoding")
- slice = map(lambda x: codecs.decode(x, encoding), \
- vim.current.buffer[upper - 1:lower])
+ slice = vim.current.buffer[upper - 1:lower]
table = parse_table(slice)
slice = draw_table(indent, table)
- vim.current.buffer[upper - 1:lower] = map(lambda x: \
- codecs.encode(x, encoding), slice)
+ vim.current.buffer[upper - 1:lower] = slice
-@bridged
def reflow_table():
upper, lower, indent = get_table_bounds()
- encoding = vim.eval("&encoding")
- slice = map(lambda x: codecs.decode(x, encoding), \
- vim.current.buffer[upper - 1:lower])
+ slice = 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] = map(lambda x: \
- codecs.encode(x, encoding), slice)
+ vim.current.buffer[upper - 1:lower] = slice
endpython
" Add mappings, unless the user didn't want this.
" The default mapping is registered, unless the user remapped it already.
if !exists("no_plugin_maps") && !exists("no_rst_table_maps")
- if !hasmapto('ReformatTable(')
- noremap <silent> <leader><leader>c :call ReformatTable()<CR>
+ if !hasmapto(' reformat_table(')
+ noremap <silent> <leader><leader>c :python reformat_table()<CR>
endif
- if !hasmapto('ReflowTable(')
- noremap <silent> <leader><leader>f :call ReflowTable()<CR>
+ if !hasmapto(' reflow_table(')
+ noremap <silent> <leader><leader>f :python reflow_table()<CR>
endif
endif