|
|
|
|
@@ -113,9 +113,6 @@ function! s:StartExpr() "{{{2
|
|
|
|
|
endif
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! s:HeaderBorderExpr() "{{{2
|
|
|
|
|
return '^\s*' . g:table_mode_corner . '[' . g:table_mode_fillchar . g:table_mode_corner . ']*' . g:table_mode_corner . '$'
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! s:EndExpr() "{{{2
|
|
|
|
|
let cend = s:GetCommentEnd()
|
|
|
|
|
@@ -126,6 +123,14 @@ function! s:EndExpr() "{{{2
|
|
|
|
|
endif
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! s:HeaderBorderExpr() "{{{2
|
|
|
|
|
return s:StartExpr() .
|
|
|
|
|
\ '[' . g:table_mode_corner . g:table_mode_separator . ']' .
|
|
|
|
|
\ '[' . g:table_mode_fillchar . g:table_mode_corner . ']*' .
|
|
|
|
|
\ '[' . g:table_mode_corner . g:table_mode_separator . ']' .
|
|
|
|
|
\ s:EndExpr()
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! s:StartCommentExpr() "{{{2
|
|
|
|
|
let cstartexpr = s:GetCommentStart()
|
|
|
|
|
if s:Strlen(cstartexpr) > 0
|
|
|
|
|
@@ -165,12 +170,12 @@ function! s:ToggleMapping() "{{{2
|
|
|
|
|
execute "inoremap <silent> <buffer> " . b:table_mode_separator_map . ' ' .
|
|
|
|
|
\ b:table_mode_separator_map . "<Esc>:call tablemode#TableizeInsertMode()<CR>a"
|
|
|
|
|
|
|
|
|
|
execute "inoreabbrev <silent> <buffer> " . g:table_mode_corner .
|
|
|
|
|
execute "inoremap <silent> <buffer> " . g:table_mode_corner .
|
|
|
|
|
\ g:table_mode_fillchar . " <Esc>:call tablemode#AddHeaderBorder('.')<CR>A"
|
|
|
|
|
else
|
|
|
|
|
execute "iunmap <silent> <buffer> " . b:table_mode_separator_map
|
|
|
|
|
|
|
|
|
|
execute "iunabbrev <silent> <buffer> " . g:table_mode_corner . g:table_mode_fillchar
|
|
|
|
|
execute "iunmap <silent> <buffer> " . g:table_mode_corner . g:table_mode_fillchar
|
|
|
|
|
endif
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
@@ -181,10 +186,17 @@ endfunction
|
|
|
|
|
|
|
|
|
|
function! s:GenerateHeaderBorder(line) "{{{2
|
|
|
|
|
let line = s:Line(a:line)
|
|
|
|
|
if tablemode#IsATableRow(line - s:RowGap())
|
|
|
|
|
let line_val = getline(line - s:RowGap())
|
|
|
|
|
if tablemode#IsATableRow(line - s:RowGap()) || tablemode#IsATableRow(line + s:RowGap())
|
|
|
|
|
let line_val = ''
|
|
|
|
|
if tablemode#IsATableRow(line + s:RowGap())
|
|
|
|
|
let line_val = getline(line + s:RowGap())
|
|
|
|
|
endif
|
|
|
|
|
if tablemode#IsATableRow(line - s:RowGap()) && s:Strlen(line_val) < s:Strlen(getline(line - s:RowGap()))
|
|
|
|
|
let line_val = getline(line - s:RowGap())
|
|
|
|
|
endif
|
|
|
|
|
let border = substitute(line_val[stridx(line_val, g:table_mode_separator):strridx(line_val, g:table_mode_separator)], g:table_mode_separator, g:table_mode_corner, 'g')
|
|
|
|
|
let border = substitute(border, '[^' . g:table_mode_corner . ']', g:table_mode_fillchar, 'g')
|
|
|
|
|
let border = substitute(border, '^' . g:table_mode_corner . '\(.*\)' . g:table_mode_corner . '$', g:table_mode_separator . '\1' . g:table_mode_separator , '')
|
|
|
|
|
|
|
|
|
|
let cstartexpr = s:StartCommentExpr()
|
|
|
|
|
if s:Strlen(cstartexpr) > 0 && getline(line) =~# cstartexpr
|
|
|
|
|
@@ -408,7 +420,7 @@ function! s:ParseRange(range, ...) "{{{2
|
|
|
|
|
else
|
|
|
|
|
let [row2, col2] = [rcs2[0], default_col]
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return [row1, col1, row2, col2]
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
@@ -643,31 +655,26 @@ function! tablemode#TableRealign(line) "{{{2
|
|
|
|
|
let line = s:Line(a:line)
|
|
|
|
|
|
|
|
|
|
let [lnums, lines] = [[], []]
|
|
|
|
|
let [bline, tline] = [0, line]
|
|
|
|
|
while tablemode#IsATableRow(tline)
|
|
|
|
|
let [tline, blines] = [line, []]
|
|
|
|
|
while tablemode#IsATableRow(tline) || getline(tline) =~# s:HeaderBorderExpr()
|
|
|
|
|
if getline(tline) =~# s:HeaderBorderExpr()
|
|
|
|
|
call insert(blines, tline)
|
|
|
|
|
let tline = tline - s:RowGap()
|
|
|
|
|
continue
|
|
|
|
|
endif
|
|
|
|
|
call insert(lnums, tline)
|
|
|
|
|
call insert(lines, getline(tline))
|
|
|
|
|
let tline = tline - s:RowGap()
|
|
|
|
|
endwhile
|
|
|
|
|
|
|
|
|
|
" If we reached header walking upwards
|
|
|
|
|
if getline(tline) =~# s:HeaderBorderExpr() && tablemode#IsATableRow(tline - s:RowGap())
|
|
|
|
|
let bline = tline
|
|
|
|
|
let tline = tline - s:RowGap()
|
|
|
|
|
" Insert the header line
|
|
|
|
|
call insert(lnums, tline)
|
|
|
|
|
call insert(lines, getline(tline))
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
let tline = line + s:RowGap()
|
|
|
|
|
|
|
|
|
|
" If we start at header
|
|
|
|
|
if !bline && getline(tline) =~# s:HeaderBorderExpr()
|
|
|
|
|
let bline = tline
|
|
|
|
|
let tline = tline + s:RowGap()
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
while tablemode#IsATableRow(tline)
|
|
|
|
|
while tablemode#IsATableRow(tline) || getline(tline) =~# s:HeaderBorderExpr()
|
|
|
|
|
if getline(tline) =~# s:HeaderBorderExpr()
|
|
|
|
|
call insert(blines, tline)
|
|
|
|
|
let tline = tline + s:RowGap()
|
|
|
|
|
continue
|
|
|
|
|
endif
|
|
|
|
|
call add(lnums, tline)
|
|
|
|
|
call add(lines, getline(tline))
|
|
|
|
|
let tline = tline + s:RowGap()
|
|
|
|
|
@@ -680,15 +687,19 @@ function! tablemode#TableRealign(line) "{{{2
|
|
|
|
|
call setline(lnum, lines[index])
|
|
|
|
|
endfor
|
|
|
|
|
|
|
|
|
|
if bline
|
|
|
|
|
for bline in blines
|
|
|
|
|
call tablemode#AddHeaderBorder(bline)
|
|
|
|
|
endif
|
|
|
|
|
endfor
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! tablemode#IsATableRow(line) "{{{2
|
|
|
|
|
return getline(a:line) =~# (s:StartExpr() . g:table_mode_separator)
|
|
|
|
|
return getline(a:line) =~# (s:StartExpr() . g:table_mode_separator . '[^' .
|
|
|
|
|
\ g:table_mode_fillchar . ']*[^' . g:table_mode_corner . ']*$')
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! tablemode#IsATableHeader(line) "{{{2
|
|
|
|
|
return getline(a:line) =~# s:HeaderBorderExpr()
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! tablemode#LineNr(row) "{{{2
|
|
|
|
|
if tablemode#IsATableRow('.')
|
|
|
|
|
@@ -754,7 +765,9 @@ function! tablemode#TableMotion(direction) "{{{2
|
|
|
|
|
if tablemode#IsATableRow('.')
|
|
|
|
|
if a:direction ==# 'l'
|
|
|
|
|
if s:IsLastCell()
|
|
|
|
|
if !tablemode#IsATableRow(line('.') + s:RowGap()) | return | endif
|
|
|
|
|
if !tablemode#IsATableHeader(line('.') + s:RowGap()) && !tablemode#IsATableRow(line('.') + s:RowGap())
|
|
|
|
|
return
|
|
|
|
|
endif
|
|
|
|
|
call tablemode#TableMotion('j')
|
|
|
|
|
normal! 0
|
|
|
|
|
endif
|
|
|
|
|
@@ -767,7 +780,9 @@ function! tablemode#TableMotion(direction) "{{{2
|
|
|
|
|
endif
|
|
|
|
|
elseif a:direction ==# 'h'
|
|
|
|
|
if s:IsFirstCell()
|
|
|
|
|
if !tablemode#IsATableRow(line('.') - s:RowGap()) | return | endif
|
|
|
|
|
if !tablemode#IsATableHeader(line('.') - s:RowGap()) && !tablemode#IsATableRow(line('.') - s:RowGap())
|
|
|
|
|
return
|
|
|
|
|
endif
|
|
|
|
|
call tablemode#TableMotion('k')
|
|
|
|
|
normal! $
|
|
|
|
|
endif
|
|
|
|
|
@@ -779,9 +794,17 @@ function! tablemode#TableMotion(direction) "{{{2
|
|
|
|
|
execute 'normal! 2F' . g:table_mode_separator . '2l'
|
|
|
|
|
endif
|
|
|
|
|
elseif a:direction ==# 'j'
|
|
|
|
|
if tablemode#IsATableRow(line('.') + s:RowGap()) | execute 'normal ' . s:RowGap() . 'j' | endif
|
|
|
|
|
if tablemode#IsATableRow(line('.') + s:RowGap())
|
|
|
|
|
execute 'normal ' . s:RowGap() . 'j'
|
|
|
|
|
elseif tablemode#IsATableHeader(line('.') + s:RowGap())
|
|
|
|
|
execute 'normal ' . (s:RowGap() + 1) . 'j'
|
|
|
|
|
endif
|
|
|
|
|
elseif a:direction ==# 'k'
|
|
|
|
|
if tablemode#IsATableRow(line('.') - s:RowGap()) | execute 'normal ' . s:RowGap() . 'k' | endif
|
|
|
|
|
if tablemode#IsATableRow(line('.') - s:RowGap())
|
|
|
|
|
execute 'normal ' . s:RowGap() . 'k'
|
|
|
|
|
elseif tablemode#IsATableHeader(line('.') - s:RowGap())
|
|
|
|
|
execute 'normal ' . (s:RowGap() + 1) . 'k'
|
|
|
|
|
endif
|
|
|
|
|
endif
|
|
|
|
|
endif
|
|
|
|
|
endfunction
|
|
|
|
|
@@ -802,7 +825,21 @@ endfunction
|
|
|
|
|
function! tablemode#DeleteColumn() "{{{2
|
|
|
|
|
if tablemode#IsATableRow('.')
|
|
|
|
|
for i in range(v:count1)
|
|
|
|
|
call s:MoveToFirstRow()
|
|
|
|
|
call s:MoveToStartOfCell()
|
|
|
|
|
|
|
|
|
|
if tablemode#IsATableRow(line('.') + 1)
|
|
|
|
|
call s:MoveToFirstRow()
|
|
|
|
|
" If we have a header delete it first
|
|
|
|
|
if tablemode#IsATableRow(line('.')-2)
|
|
|
|
|
call cursor(line('.')-2, col('.'))
|
|
|
|
|
silent! execute "normal! h\<C-V>f" . g:table_mode_separator
|
|
|
|
|
normal! jdjj
|
|
|
|
|
endif
|
|
|
|
|
else " We're already on the header
|
|
|
|
|
silent! execute "normal! h\<C-V>f" . g:table_mode_separator
|
|
|
|
|
normal! jdjj
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
call s:MoveToStartOfCell()
|
|
|
|
|
silent! execute "normal! h\<C-V>f" . g:table_mode_separator
|
|
|
|
|
call s:MoveToLastRow()
|
|
|
|
|
@@ -816,15 +853,11 @@ endfunction
|
|
|
|
|
function! tablemode#DeleteRow() "{{{2
|
|
|
|
|
if tablemode#IsATableRow('.')
|
|
|
|
|
for i in range(v:count1)
|
|
|
|
|
if tablemode#RowCount('.') ==# 1
|
|
|
|
|
normal! kVjjd
|
|
|
|
|
else
|
|
|
|
|
normal! kVjd
|
|
|
|
|
if tablemode#IsATableRow('.')
|
|
|
|
|
normal! dd
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
if tablemode#IsATableRow(line('.')+1)
|
|
|
|
|
normal! j
|
|
|
|
|
else
|
|
|
|
|
if !tablemode#IsATableRow('.')
|
|
|
|
|
normal! k
|
|
|
|
|
endif
|
|
|
|
|
endfor
|
|
|
|
|
@@ -873,6 +906,7 @@ function! tablemode#AddFormula() "{{{2
|
|
|
|
|
if fr !=# ''
|
|
|
|
|
let fr = '$' . row . ',' . colm . '=' . fr
|
|
|
|
|
let fline = tablemode#GetLastRow('.') + s:RowGap()
|
|
|
|
|
if getline(fline) =~# s:HeaderBorderExpr() | let fline += s:RowGap() | endif
|
|
|
|
|
let cursor_pos = [line('.'), col('.')]
|
|
|
|
|
if getline(fline) =~# 'tmf: '
|
|
|
|
|
" Comment line correctly
|
|
|
|
|
@@ -961,11 +995,14 @@ function! tablemode#EvaluateFormulaLine() abort "{{{2
|
|
|
|
|
endif
|
|
|
|
|
if tablemode#IsATableRow('.') " We're inside the table
|
|
|
|
|
let line = s:GetLastRow('.')
|
|
|
|
|
if getline(line + s:RowGap()) =~# 'tmf: '
|
|
|
|
|
let exprs = split(matchstr(getline(line + s:RowGap()), matchexpr), ';')
|
|
|
|
|
let fline = line + s:RowGap()
|
|
|
|
|
if getline(fline) =~# s:HeaderBorderExpr() | let fline += s:RowGap() | endif
|
|
|
|
|
if getline(fline) =~# 'tmf: '
|
|
|
|
|
let exprs = split(matchstr(getline(fline), matchexpr), ';')
|
|
|
|
|
endif
|
|
|
|
|
elseif getline('.') =~# 'tmf: ' " We're on the formula line
|
|
|
|
|
let line = line('.') - s:RowGap()
|
|
|
|
|
if getline(line) =~# s:HeaderBorderExpr() | let line -= s:RowGap() | endif
|
|
|
|
|
if tablemode#IsATableRow(line)
|
|
|
|
|
let exprs = split(matchstr(getline('.'), matchexpr), ';')
|
|
|
|
|
endif
|
|
|
|
|
|