From 8309a33aa7d6a35bfe39afd75c3de5039f1218eb Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Tue, 23 Aug 2016 09:26:24 +0530 Subject: [PATCH] Fix #90 Allow for multiple formula lines --- autoload/tablemode/spreadsheet/formula.vim | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/autoload/tablemode/spreadsheet/formula.vim b/autoload/tablemode/spreadsheet/formula.vim index 8271b5d..65478c4 100644 --- a/autoload/tablemode/spreadsheet/formula.vim +++ b/autoload/tablemode/spreadsheet/formula.vim @@ -1,4 +1,7 @@ " Private Functions {{{1 +function! s:IsFormulaLine(line) "{{{2 + return getline(a:line) =~# 'tmf: ' +endfunction " Public Functions {{{1 function! tablemode#spreadsheet#formula#Add(...) "{{{2 @@ -105,14 +108,21 @@ function! tablemode#spreadsheet#formula#EvaluateFormulaLine() abort "{{{2 let line = tablemode#spreadsheet#GetLastRow('.') let fline = line + 1 if tablemode#table#IsBorder(fline) | let fline += 1 | endif - if getline(fline) =~# 'tmf: ' - let exprs = split(matchstr(getline(fline), matchexpr), ';') - endif - elseif getline('.') =~# 'tmf: ' " We're on the formula line + while s:IsFormulaLine(fline) + let exprs += split(matchstr(getline(fline), matchexpr), ';') + let fline += 1 + endwhile + elseif s:IsFormulaLine('.') + let fline = line('.') let line = line('.') - 1 + while s:IsFormulaLine(line) | let fline = line | let line -= 1 | endwhile if tablemode#table#IsBorder(line) | let line -= 1 | endif if tablemode#table#IsRow(line) - let exprs = split(matchstr(getline('.'), matchexpr), ';') + " let exprs = split(matchstr(getline('.'), matchexpr), ';') + while s:IsFormulaLine(fline) + let exprs += split(matchstr(getline(fline), matchexpr), ';') + let fline += 1 + endwhile endif endif