aboutsummaryrefslogtreecommitdiffstats
path: root/ftplugin
diff options
context:
space:
mode:
authorVincent Driessen <vincent@datafox.nl>2010-08-19 11:36:53 +0200
committerVincent Driessen <vincent@datafox.nl>2010-08-19 11:38:50 +0200
commit4c81fb1df579143bdd1ec7f5b2a1779d3c3c58fd (patch)
tree17d7130e5bcd0b045fd536da56711faf8bf65862 /ftplugin
parentc72ce15d5941aaa3384a1a160996b0c92ec0efef (diff)
downloadvim-rst-tables-4c81fb1df579143bdd1ec7f5b2a1779d3c3c58fd.tar.gz
vim-rst-tables-4c81fb1df579143bdd1ec7f5b2a1779d3c3c58fd.tar.bz2
vim-rst-tables-4c81fb1df579143bdd1ec7f5b2a1779d3c3c58fd.zip
Add join_rows helper function (necessary for joining long lines later on).
Diffstat (limited to 'ftplugin')
-rw-r--r--ftplugin/rst_tables.vim24
1 files changed, 24 insertions, 0 deletions
diff --git a/ftplugin/rst_tables.vim b/ftplugin/rst_tables.vim
index 38f830e..43b674f 100644
--- a/ftplugin/rst_tables.vim
+++ b/ftplugin/rst_tables.vim
@@ -39,8 +39,32 @@ def get_table_bounds():
return (upper, lower)
+def join_rows(rows, sep='\n'):
+ """Given a list of rows (a list of lists) this function returns a
+ flattened list where each the individual columns of all rows are joined
+ together using the line separator.
+
+ """
+ output = []
+ for row in rows:
+ # grow output array, if necessary
+ if len(output) <= len(row):
+ for i in range(len(row) - len(output)):
+ output.extend([[]])
+
+ for i, field in enumerate(row):
+ field_text = field.strip()
+ if field_text:
+ output[i].append(field_text)
+ return map(lambda lines: sep.join(lines), output)
+
def unify_table(table):
+ """Given a list of rows (i.e. a table), this function returns a new table
+ in which all rows have an equal amount of columns. If all full column is
+ empty (i.e. all rows have that field empty), the column is removed.
+
+ """
max_fields = max(map(lambda row: len(row), table))
empty_cols = [True] * max_fields
output = []