Improved Formula Engine

* Does not try to forcefully cast column content to float
* Silences any errors during formula evaluation, you can look at
  `v:errmsg` to see if there was any error during the evaluation for
  debugging
This commit is contained in:
Dhruva Sagar
2022-04-05 22:15:17 +05:30
parent 698ff3074c
commit 816072c0f5
4 changed files with 15 additions and 9 deletions

View File

@@ -1,5 +1,11 @@
# Change Log
## Version 4.8.0
* Improved formula engine
- Does not cast column values to float
- Silences errors during evaluation, see `v:errmsg` for error information
from last evaluation for debugging issues with formulas
## Version 4.7.6.1
* Improved handling of `g:table_mode_ignore_align` configuration, now allows
per buffer overrides

View File

@@ -1,4 +1,4 @@
# VIM Table Mode v4.7.6.1 [![Build Status](https://travis-ci.org/dhruvasagar/vim-table-mode.png?branch=master)](https://travis-ci.org/dhruvasagar/vim-table-mode)
# VIM Table Mode v4.8.0 [![Build Status](https://travis-ci.org/dhruvasagar/vim-table-mode.png?branch=master)](https://travis-ci.org/dhruvasagar/vim-table-mode)
An awesome automatic table creator & formatter allowing one to create neat
tables as you type.

View File

@@ -50,7 +50,7 @@ function! tablemode#spreadsheet#formula#Add(...) "{{{2
endif
endfunction
function! tablemode#spreadsheet#formula#EvaluateExpr(expr, line) abort "{{{2
function! tablemode#spreadsheet#formula#EvaluateExpr(expr, line) "{{{2
let line = tablemode#utils#line(a:line)
let [target, expr] = map(split(a:expr, '='), 'tablemode#utils#strip(v:val)')
let cell = substitute(target, '\$', '', '')
@@ -98,15 +98,15 @@ function! tablemode#spreadsheet#formula#EvaluateExpr(expr, line) abort "{{{2
if expr =~# '\$\-\?\d\+,\-\?\d\+'
let expr = substitute(expr, '\$\(\-\?\d\+\),\(\-\?\d\+\)',
\ '\=str2float(tablemode#spreadsheet#cell#GetCells(line, submatch(1), submatch(2)))', 'g')
\ '\=tablemode#spreadsheet#cell#GetCells(line, submatch(1), submatch(2))', 'g')
endif
if cell =~# ','
if expr =~# '\$'
let expr = substitute(expr, '\$\(\d\+\)',
\ '\=str2float(tablemode#spreadsheet#cell#GetCells(line, row, submatch(1)))', 'g')
\ '\=tablemode#spreadsheet#cell#GetCells(line, row, submatch(1))', 'g')
endif
call tablemode#spreadsheet#cell#SetCell(eval(expr), line, row, colm)
silent! call tablemode#spreadsheet#cell#SetCell(eval(expr), line, row, colm)
else
let [row, line] = [1, tablemode#spreadsheet#GetFirstRow(line)]
while !s:IsFormulaLine(line)
@@ -114,10 +114,10 @@ function! tablemode#spreadsheet#formula#EvaluateExpr(expr, line) abort "{{{2
let texpr = expr
if expr =~# '\$'
let texpr = substitute(texpr, '\$\(\d\+\)',
\ '\=str2float(tablemode#spreadsheet#cell#GetCells(line, row, submatch(1)))', 'g')
\ '\=tablemode#spreadsheet#cell#GetCells(line, row, submatch(1))', 'g')
endif
call tablemode#spreadsheet#cell#SetCell(eval(texpr), line, row, colm)
silent! call tablemode#spreadsheet#cell#SetCell(eval(texpr), line, row, colm)
let row += 1
endif
let line += 1
@@ -125,7 +125,7 @@ function! tablemode#spreadsheet#formula#EvaluateExpr(expr, line) abort "{{{2
endif
endfunction
function! tablemode#spreadsheet#formula#EvaluateFormulaLine() abort "{{{2
function! tablemode#spreadsheet#formula#EvaluateFormulaLine() "{{{2
let exprs = []
let cstring = &commentstring
let matchexpr = ''

View File

@@ -1,7 +1,7 @@
*table-mode.txt* Table Mode for easy table formatting
===============================================================================
Table Mode, THE AWESOME AUTOMATIC TABLE CREATOR & FORMATTER
VERSION 4.7.6.1
VERSION 4.8.0
Author: Dhruva Sagar <http://dhruvasagar.com/>
License: MIT <http://opensource.org/licenses/MIT/>