aboutsummaryrefslogtreecommitdiffstats
path: root/ftplugin
diff options
context:
space:
mode:
authorVincent Driessen <vincent@3rdcloud.com>2013-03-30 01:42:47 -0700
committerVincent Driessen <vincent@3rdcloud.com>2013-03-30 01:42:47 -0700
commit72bb0d5b872b8963860a47dd06c4e654270e9589 (patch)
treeb9fa5a611da6167a131cfb6e8f7765b35802dc17 /ftplugin
parent381f5dd69905ad1497bb1943070fcc089b89f93b (diff)
parent18a7de511c6b53538e56a49c44e1812f6a9bdc17 (diff)
downloadvim-rst-tables-72bb0d5b872b8963860a47dd06c4e654270e9589.tar.gz
vim-rst-tables-72bb0d5b872b8963860a47dd06c4e654270e9589.tar.bz2
vim-rst-tables-72bb0d5b872b8963860a47dd06c4e654270e9589.zip
Merge pull request #14 from insanum/master
when modifying a table maintain its current indentation
Diffstat (limited to 'ftplugin')
-rw-r--r--ftplugin/rst_tables.vim22
1 files changed, 12 insertions, 10 deletions
diff --git a/ftplugin/rst_tables.vim b/ftplugin/rst_tables.vim
index a77bafe..f17eba2 100644
--- a/ftplugin/rst_tables.vim
+++ b/ftplugin/rst_tables.vim
@@ -43,7 +43,9 @@ def get_table_bounds():
else:
lower -= 1
- return (upper, lower)
+ match = re.match('^(\s*).*$', vim.current.buffer[upper-1])
+
+ return (upper, lower, match.group(1))
def join_rows(rows, sep='\n'):
"""Given a list of rows (a list of lists) this function returns a
@@ -244,7 +246,7 @@ def reflow_row_contents(row, widths):
return new_row
-def draw_table(table, manual_widths=None):
+def draw_table(indent, table, manual_widths=None):
if table == []:
return []
@@ -258,7 +260,7 @@ def draw_table(table, manual_widths=None):
header_line = table_line(sep_col_widths, header=True)
normal_line = table_line(sep_col_widths, header=False)
- output = [normal_line]
+ output = [indent+normal_line]
first = True
for row in table:
@@ -270,34 +272,34 @@ def draw_table(table, manual_widths=None):
# draw the lines (num_lines) for this row
for row_line in row_lines:
row_line = pad_fields(row_line, col_widths)
- output.append("|".join([''] + row_line + ['']))
+ output.append(indent+"|".join([''] + row_line + ['']))
# then, draw the separator
if first:
- output.append(header_line)
+ output.append(indent+header_line)
first = False
else:
- output.append(normal_line)
+ output.append(indent+normal_line)
return output
@bridged
def reformat_table():
- upper, lower = get_table_bounds()
+ upper, lower, indent = get_table_bounds()
slice = vim.current.buffer[upper - 1:lower]
table = parse_table(slice)
- slice = draw_table(table)
+ slice = draw_table(indent, table)
vim.current.buffer[upper - 1:lower] = slice
@bridged
def reflow_table():
- upper, lower = get_table_bounds()
+ upper, lower, indent = get_table_bounds()
slice = vim.current.buffer[upper - 1:lower]
widths = get_column_widths_from_border_spec(slice)
table = parse_table(slice)
- slice = draw_table(table, widths)
+ slice = draw_table(indent, table, widths)
vim.current.buffer[upper - 1:lower] = slice
endpython