mirror of
https://github.com/dhruvasagar/vim-table-mode.git
synced 2025-11-09 03:23:47 -05:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a0618db019 | ||
|
|
176999f347 | ||
|
|
5a6a9b3473 | ||
|
|
aa8817621c |
@@ -186,8 +186,14 @@ endfunction
|
|||||||
|
|
||||||
function! s:GenerateHeaderBorder(line) "{{{2
|
function! s:GenerateHeaderBorder(line) "{{{2
|
||||||
let line = s:Line(a:line)
|
let line = s:Line(a:line)
|
||||||
if tablemode#IsATableRow(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())
|
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(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_fillchar, 'g')
|
||||||
let border = substitute(border, '^' . g:table_mode_corner . '\(.*\)' . g:table_mode_corner . '$', g:table_mode_separator . '\1' . g:table_mode_separator , '')
|
let border = substitute(border, '^' . g:table_mode_corner . '\(.*\)' . g:table_mode_corner . '$', g:table_mode_separator . '\1' . g:table_mode_separator , '')
|
||||||
@@ -649,31 +655,26 @@ function! tablemode#TableRealign(line) "{{{2
|
|||||||
let line = s:Line(a:line)
|
let line = s:Line(a:line)
|
||||||
|
|
||||||
let [lnums, lines] = [[], []]
|
let [lnums, lines] = [[], []]
|
||||||
let [bline, tline] = [0, line]
|
let [tline, blines] = [line, []]
|
||||||
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 insert(lnums, tline)
|
call insert(lnums, tline)
|
||||||
call insert(lines, getline(tline))
|
call insert(lines, getline(tline))
|
||||||
let tline = tline - s:RowGap()
|
let tline = tline - s:RowGap()
|
||||||
endwhile
|
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()
|
let tline = line + s:RowGap()
|
||||||
|
|
||||||
" If we start at header
|
while tablemode#IsATableRow(tline) || getline(tline) =~# s:HeaderBorderExpr()
|
||||||
if !bline && getline(tline) =~# s:HeaderBorderExpr()
|
if getline(tline) =~# s:HeaderBorderExpr()
|
||||||
let bline = tline
|
call insert(blines, tline)
|
||||||
let tline = tline + s:RowGap()
|
let tline = tline + s:RowGap()
|
||||||
|
continue
|
||||||
endif
|
endif
|
||||||
|
|
||||||
while tablemode#IsATableRow(tline)
|
|
||||||
call add(lnums, tline)
|
call add(lnums, tline)
|
||||||
call add(lines, getline(tline))
|
call add(lines, getline(tline))
|
||||||
let tline = tline + s:RowGap()
|
let tline = tline + s:RowGap()
|
||||||
@@ -686,9 +687,9 @@ function! tablemode#TableRealign(line) "{{{2
|
|||||||
call setline(lnum, lines[index])
|
call setline(lnum, lines[index])
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
if bline
|
for bline in blines
|
||||||
call tablemode#AddHeaderBorder(bline)
|
call tablemode#AddHeaderBorder(bline)
|
||||||
endif
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#IsATableRow(line) "{{{2
|
function! tablemode#IsATableRow(line) "{{{2
|
||||||
@@ -696,6 +697,10 @@ function! tablemode#IsATableRow(line) "{{{2
|
|||||||
\ g:table_mode_fillchar . ']*[^' . g:table_mode_corner . ']*$')
|
\ g:table_mode_fillchar . ']*[^' . g:table_mode_corner . ']*$')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! tablemode#IsATableHeader(line) "{{{2
|
||||||
|
return getline(a:line) =~# s:HeaderBorderExpr()
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! tablemode#LineNr(row) "{{{2
|
function! tablemode#LineNr(row) "{{{2
|
||||||
if tablemode#IsATableRow('.')
|
if tablemode#IsATableRow('.')
|
||||||
let line = s:Line('.')
|
let line = s:Line('.')
|
||||||
@@ -760,7 +765,9 @@ function! tablemode#TableMotion(direction) "{{{2
|
|||||||
if tablemode#IsATableRow('.')
|
if tablemode#IsATableRow('.')
|
||||||
if a:direction ==# 'l'
|
if a:direction ==# 'l'
|
||||||
if s:IsLastCell()
|
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')
|
call tablemode#TableMotion('j')
|
||||||
normal! 0
|
normal! 0
|
||||||
endif
|
endif
|
||||||
@@ -773,7 +780,9 @@ function! tablemode#TableMotion(direction) "{{{2
|
|||||||
endif
|
endif
|
||||||
elseif a:direction ==# 'h'
|
elseif a:direction ==# 'h'
|
||||||
if s:IsFirstCell()
|
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')
|
call tablemode#TableMotion('k')
|
||||||
normal! $
|
normal! $
|
||||||
endif
|
endif
|
||||||
@@ -785,9 +794,17 @@ function! tablemode#TableMotion(direction) "{{{2
|
|||||||
execute 'normal! 2F' . g:table_mode_separator . '2l'
|
execute 'normal! 2F' . g:table_mode_separator . '2l'
|
||||||
endif
|
endif
|
||||||
elseif a:direction ==# 'j'
|
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'
|
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
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
@@ -889,6 +906,7 @@ function! tablemode#AddFormula() "{{{2
|
|||||||
if fr !=# ''
|
if fr !=# ''
|
||||||
let fr = '$' . row . ',' . colm . '=' . fr
|
let fr = '$' . row . ',' . colm . '=' . fr
|
||||||
let fline = tablemode#GetLastRow('.') + s:RowGap()
|
let fline = tablemode#GetLastRow('.') + s:RowGap()
|
||||||
|
if getline(fline) =~# s:HeaderBorderExpr() | let fline += s:RowGap() | endif
|
||||||
let cursor_pos = [line('.'), col('.')]
|
let cursor_pos = [line('.'), col('.')]
|
||||||
if getline(fline) =~# 'tmf: '
|
if getline(fline) =~# 'tmf: '
|
||||||
" Comment line correctly
|
" Comment line correctly
|
||||||
@@ -977,11 +995,14 @@ function! tablemode#EvaluateFormulaLine() abort "{{{2
|
|||||||
endif
|
endif
|
||||||
if tablemode#IsATableRow('.') " We're inside the table
|
if tablemode#IsATableRow('.') " We're inside the table
|
||||||
let line = s:GetLastRow('.')
|
let line = s:GetLastRow('.')
|
||||||
if getline(line + s:RowGap()) =~# 'tmf: '
|
let fline = line + s:RowGap()
|
||||||
let exprs = split(matchstr(getline(line + s:RowGap()), matchexpr), ';')
|
if getline(fline) =~# s:HeaderBorderExpr() | let fline += s:RowGap() | endif
|
||||||
|
if getline(fline) =~# 'tmf: '
|
||||||
|
let exprs = split(matchstr(getline(fline), matchexpr), ';')
|
||||||
endif
|
endif
|
||||||
elseif getline('.') =~# 'tmf: ' " We're on the formula line
|
elseif getline('.') =~# 'tmf: ' " We're on the formula line
|
||||||
let line = line('.') - s:RowGap()
|
let line = line('.') - s:RowGap()
|
||||||
|
if getline(line) =~# s:HeaderBorderExpr() | let line -= s:RowGap() | endif
|
||||||
if tablemode#IsATableRow(line)
|
if tablemode#IsATableRow(line)
|
||||||
let exprs = split(matchstr(getline('.'), matchexpr), ';')
|
let exprs = split(matchstr(getline('.'), matchexpr), ';')
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ GETTING STARTED *table-mode-getting-started*
|
|||||||
|
|
||||||
Create Table on the fly:
|
Create Table on the fly:
|
||||||
Using Table Mode is dead simple. You simply start typing on a new line
|
Using Table Mode is dead simple. You simply start typing on a new line
|
||||||
with the table separator - |g:table-mode-separator|, and you just type
|
with the table separator - |table-mode-separator|, and you just type
|
||||||
away! The plugin does the rest automatically for you as you type. With
|
away! The plugin does the rest automatically for you as you type. With
|
||||||
each additional separator you add, it aligns the table properly,
|
each additional separator you add, it aligns the table properly,
|
||||||
without having to do anything else.
|
without having to do anything else.
|
||||||
|
|||||||
Reference in New Issue
Block a user