From fb63484e476d8bbaa804970c7eb5bf4e391e8602 Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Fri, 17 May 2013 10:00:00 +0530 Subject: [PATCH] Updated CHANGELOG & doc/table-mode.txt --- CHANGELOG.md | 5 ++ doc/table-mode.txt | 121 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 110 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a203902..81a4461 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ # Change Log +## Version 3.0 +* Removed dependence on Tabular and added code borrowed from Tabular for + aligning the table rows. +* Added feature to be able to define & evaluate formulas. + ## Version 2.4.0 * Added Table Cell text object. * Added api to delete entire table row. diff --git a/doc/table-mode.txt b/doc/table-mode.txt index d17dbad..bfc6a7b 100644 --- a/doc/table-mode.txt +++ b/doc/table-mode.txt @@ -1,7 +1,7 @@ -*table-mode.txt* Table Mode for easy table formatting. v2.4.0 +*table-mode.txt* Table Mode for easy table formatting. v3.0 =============================================================================== Table Mode, THE AWESOME AUTOMATIC TABLE CREATOR & FORMATTER - VERSION 2.4.0 + VERSION 3.0 Author: Dhruva Sagar License: MIT @@ -9,13 +9,12 @@ CONTENTS *table-mode-contents* 1. Introduction .................... |table-mode-introduction| - 2. Requirements .................... |table-mode-requirements| - 3. Getting Started ................. |table-mode-getting-started| - 4. Options ......................... |table-mode-options| - 5. Mappings ........................ |table-mode-mappings| - 6. Commands ........................ |table-mode-commands| - 7. Contributing .................... |table-mode-contributing| - 8. Report Issues ................... |table-mode-report-issues| + 2. Getting Started ................. |table-mode-getting-started| + 3. Options ......................... |table-mode-options| + 4. Mappings ........................ |table-mode-mappings| + 5. Commands ........................ |table-mode-commands| + 6. Contributing .................... |table-mode-contributing| + 7. Report Issues ................... |table-mode-report-issues| =============================================================================== INTRODUCTION *table-mode-introduction* @@ -25,12 +24,6 @@ inspired from tpope's auto aligning script for creating tables in vim - https://gist.github.com/tpope/287147, which in turn utilizes the Tabular Plugin. -=============================================================================== -REQUIREMENTS *table-mode-requirements* - -This depends on the Tabular plugin - https://github.com/godlygeek/tabular, -make sure it is installed and loaded. - =============================================================================== GETTING STARTED *table-mode-getting-started* @@ -69,6 +62,61 @@ Manipulation of tables: 3. Delete Row : Delete an entire table row using |table-mode-delete-row-map| +Table Formulas: + Table Mode now has support for formulas like a spreadsheet. There + are 2 ways of defining formulas : + + You can add formulas using |:TableAddFormula| or the mapping + |tfa| defined by the option + |table-mode-add-formula-map| from within a table cell, which + will ask for input on the cmd-line with a 'f=' prompt. The + input formula will be appended to the formula line if one + exists or a new one will be created with the input formula + taking the current cell as the target cell. The formula line + is evaluated immidiately to reflect the results. + + You can directly also add / manipulate formula expressions in + the formula line. The formula line is a commented line right + after the table, beginning with 'tmf:' (table mode formula). + eg) '# tmf: $3=$2*$1'. You can add multiple formulas on the + line separated with a ';' eg) '# tmf: $3=$2*$1;$4=$3/3.14' + + You can evaluate the formula line using |:TableEvalFormulaLine| or the + mapping |tfe| defined by the option |table-mode-expr-calc-map| + +Formula Expressions : + Expressions are of the format '$target = formula'. + + The target can be of 2 forms : + + '$n': This matches the table column number 'n'. So the formula + would be evaluated for each cell in that column and the result + would be placed in it. + + '$n,m': This matches the table cell n,m (row, column). So in + this case the formula would be evaluated and the result will + be placed in this cell. + + The formula can be a simple mathematical expression involving cells + which are also defined by the same format as that of the target cell. + Apart from basic mathematical expressions, table mode also provides + special functions 'Sum' and 'Average'. Both these functions take a + range as input. A range can be of two forms : + + 'n,m': This represents cells in the current column from row + 'n' through 'm'. If 'm' is negative it represents 'm' row + above the current row (of the target cell). + + 'r1,c1:r2,c2': This represents cells in the table from cell + r1,c1 through cell r2,c2 (row, column). + + Examples : + $2 = $1 * $1 + $2 = $1 / $1,3 + $1,2 = $1,1 * $1,1 + $5,1 = Sum(1:-1) + $5,3 = Sum(1,2:5,2) + =============================================================================== OPTIONS *table-mode-options* @@ -92,6 +140,10 @@ Overview: |table-mode-delete-row-map| ..... Set mapping for deleting table row. |table-mode-delete-column-map| .. Set mapping for deleting table column. + |table-mode-add-formula-map| .... Define a new table formula for the + current cell. + |table-mode-expr-calc-map| ...... Evaluate formula line and update + table. g:table_mode_loaded *table-mode-loaded* Use this option to disable the plugin: > @@ -210,12 +262,24 @@ g:table_mode_delete_row_map *table-mode-delete-row-map* let g:table_mode_delete_column_map = 'tdd' g:table_mode_delete_column_map *table-mode-delete-column-map* - USe this option to define the mapping for deletion of the entire table + Use this option to define the mapping for deletion of the entire table column. You can delete multiple columns to the right by preceeding this with a [count] > let g:table_mode_delete_column_map = 'tdc' < +g:table_mode_add_formula_map *table-mode-add-formula-map* + Use this option to define the mapping for invoking |TableAddFormula| + command. > + let g:table_mode_add_formula_map = 'tfa' +< + +g:table_mode_expr_calc_map *table-mode-expr-calc-map* + Use this option to define the mapping for invoking + |TableEvalFormulaLine| command. > + let g:table_mode_expr_calc_map = 'tfe' +< + =============================================================================== MAPPINGS *table-mode-mappings* @@ -253,6 +317,16 @@ MAPPINGS *table-mode-mappings* with a [count] to delete multiple columns to the right. You can change this using |table-mode-delete-column-map| option. + *table-mode-mappings-add-formula* +tfa Add a fomula for the current table cell. This invokes + |TableAddFormula| command. + + *table-mode-mappings-evaluate-formula-line* +tfe Evaluate the formula line which is a commented line right + after the table beginning with 'tmf:'. If one exists this + would evaluate the formula line and update the table + accordingly. + =============================================================================== COMMANDS *table-mode-commands* @@ -295,6 +369,21 @@ COMMANDS *table-mode-commands* NOTE this is optional, by default without the expression it will tableize the content using |g:table-mode-delimiter| as the delimiter. + + *:TableAddFormula* + *table-mode-:TableAddFormula* +:TableAddFormula + This command is for defining a formula for the current table cell. It + takes input on the cmd-line with a 'f=' prompt and appends it to the + formula line if it exists or adds a new formula line with the + expression using the current cell as the target and the input formula. + + *:TableEvalFormulaLine* + *table-mode-:TableEvalFormulaLine* +:TableEvalFormulaLine + This command when invoked from anywhere within the table or directly + on the formula line evaluates it and updates the table accordingly. + =============================================================================== CONTRIBUTING *table-mode-contributing*