diff options
author | Vincent Driessen <vincent@datafox.nl> | 2010-08-19 10:49:51 +0200 |
---|---|---|
committer | Vincent Driessen <vincent@datafox.nl> | 2010-08-19 10:49:51 +0200 |
commit | bc3620adf956828562071f9feafc5923de567ea9 (patch) | |
tree | 317d3d80697a3982915e652e66522adde00e06e0 /ftplugin | |
parent | 3a4e12229e09e72619dc1bcc5403db1e452d9ecb (diff) | |
download | vim-rst-tables-bc3620adf956828562071f9feafc5923de567ea9.tar.gz vim-rst-tables-bc3620adf956828562071f9feafc5923de567ea9.tar.bz2 vim-rst-tables-bc3620adf956828562071f9feafc5923de567ea9.zip |
Add ability to remove all empty columns automatically.
Diffstat (limited to 'ftplugin')
-rw-r--r-- | ftplugin/rst_tables.vim | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/ftplugin/rst_tables.vim b/ftplugin/rst_tables.vim index 4892945..38f830e 100644 --- a/ftplugin/rst_tables.vim +++ b/ftplugin/rst_tables.vim @@ -42,12 +42,30 @@ def get_table_bounds(): def unify_table(table): max_fields = max(map(lambda row: len(row), table)) + empty_cols = [True] * max_fields output = [] for row in table: curr_len = len(row) if curr_len < max_fields: row += [''] * (max_fields - curr_len) output.append(row) + + # register empty columns (to be removed at the end) + for i in range(len(row)): + if row[i].strip(): + empty_cols[i] = False + + # remove empty columns from all rows + table = output + output = [] + for row in table: + cols = [] + for i in range(len(row)): + should_remove = empty_cols[i] + if not should_remove: + cols.append(row[i]) + output.append(cols) + return output |