mirror of
https://github.com/dhruvasagar/vim-table-mode.git
synced 2025-11-09 03:23:47 -05:00
Updated Table Mode Public API
- Added tablemode#RowCount(line). Returns the total number of rows in a table given a line (row). - Added tablemode#ColumnCount(line). Returns the total number of columns in a line (row). - Added tablemode#RowNr(line). Returns the row number on given line. - Added tablemode#ColumnNr(line). Returns the column on given line.
This commit is contained in:
@@ -175,18 +175,13 @@ function! s:Tableizeline(line, ...) "{{{2
|
|||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
function! s:ColumnCount(line) "{{{2
|
|
||||||
return s:Strlen(substitute(getline(a:line), '[^' . g:table_mode_separator . ']', '', 'g'))-1
|
|
||||||
endfunction
|
|
||||||
" }}}2
|
|
||||||
|
|
||||||
function! s:IsFirstCell() "{{{2
|
function! s:IsFirstCell() "{{{2
|
||||||
return tablemode#TableColumnNr('.') ==# 1
|
return tablemode#TableColumnNr('.') ==# 1
|
||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
function! s:IsLastCell() "{{{2
|
function! s:IsLastCell() "{{{2
|
||||||
return tablemode#TableColumnNr('.') ==# s:ColumnCount('.')
|
return tablemode#TableColumnNr('.') ==# tablemode#ColumnCount('.')
|
||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
@@ -265,14 +260,52 @@ function! tablemode#IsATableRow(line) "{{{2
|
|||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
function! tablemode#TableRowNr(pos) "{{{2
|
function! tablemode#RowCount(line) "{{{2
|
||||||
let line = 0
|
let line = 0
|
||||||
if type(a:pos) == type('')
|
if type(line) == type('')
|
||||||
let line = line(a:pos)
|
let line = line(a:line)
|
||||||
elseif type(a:pos) == type(1)
|
else
|
||||||
let line = a:pos
|
let line = a:line
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let rowCount = 1
|
||||||
|
if g:table_mode_border | let rowCount = 2 | endif
|
||||||
|
|
||||||
|
let [tline, totalRowCount] = [line, 0]
|
||||||
|
while tline > 0
|
||||||
|
if tablemode#IsATableRow(tline)
|
||||||
|
let totalRowCount = totalRowCount + 1
|
||||||
|
else
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
let tline = tline - rowCount
|
||||||
|
endwhile
|
||||||
|
|
||||||
|
let tline = line + rowCount
|
||||||
|
while tline <= line('$')
|
||||||
|
if tablemode#IsATableRow(tline)
|
||||||
|
let totalRowCount = totalRowCount + 1
|
||||||
|
else
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
let tline = tline + rowCount
|
||||||
|
endwhile
|
||||||
|
|
||||||
|
return totalRowCount
|
||||||
|
endfunction
|
||||||
|
" }}}2
|
||||||
|
|
||||||
|
function! tablemode#RowNr(line) "{{{2
|
||||||
|
let line = 0
|
||||||
|
if type(a:line) == type('')
|
||||||
|
let line = line(a:line)
|
||||||
|
else
|
||||||
|
let line = a:line
|
||||||
|
endif
|
||||||
|
|
||||||
|
let rowCount = 1
|
||||||
|
if g:table_mode_border | let rowCount = 2 | endif
|
||||||
|
|
||||||
let rowNr = 0
|
let rowNr = 0
|
||||||
while line > 0
|
while line > 0
|
||||||
if tablemode#IsATableRow(line)
|
if tablemode#IsATableRow(line)
|
||||||
@@ -280,13 +313,26 @@ function! tablemode#TableRowNr(pos) "{{{2
|
|||||||
else
|
else
|
||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
let line = line - 2
|
let line = line - rowCount
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
return rowNr
|
return rowNr
|
||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
function! tablemode#TableColumnNr(pos) "{{{2
|
function! tablemode#ColumnCount(line) "{{{2
|
||||||
|
let line = 0
|
||||||
|
if type(line) == type('')
|
||||||
|
let line = line(a:line)
|
||||||
|
else
|
||||||
|
let line = a:line
|
||||||
|
endif
|
||||||
|
|
||||||
|
return s:Strlen(substitute(getline(line), '[^' . g:table_mode_separator . ']', '', 'g'))-1
|
||||||
|
endfunction
|
||||||
|
" }}}2
|
||||||
|
|
||||||
|
function! tablemode#ColumnNr(pos) "{{{2
|
||||||
let pos = []
|
let pos = []
|
||||||
if type(a:pos) == type('')
|
if type(a:pos) == type('')
|
||||||
let pos = [line(a:pos), col(a:pos)]
|
let pos = [line(a:pos), col(a:pos)]
|
||||||
@@ -295,6 +341,7 @@ function! tablemode#TableColumnNr(pos) "{{{2
|
|||||||
else
|
else
|
||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return s:Strlen(substitute(getline(pos[0])[0:pos[1]-2], '[^' . g:table_mode_separator . ']', '', 'g'))
|
return s:Strlen(substitute(getline(pos[0])[0:pos[1]-2], '[^' . g:table_mode_separator . ']', '', 'g'))
|
||||||
endfunction
|
endfunction
|
||||||
" }}}2
|
" }}}2
|
||||||
@@ -313,7 +360,7 @@ function! tablemode#TableMotion(direction) "{{{2
|
|||||||
|
|
||||||
" If line starts with g:table_mode_separator
|
" If line starts with g:table_mode_separator
|
||||||
if getline('.')[col('.')-1] ==# g:table_mode_separator
|
if getline('.')[col('.')-1] ==# g:table_mode_separator
|
||||||
execute 'normal! 2l'
|
normal! 2l
|
||||||
else
|
else
|
||||||
execute 'normal! f' . g:table_mode_separator . '2l'
|
execute 'normal! f' . g:table_mode_separator . '2l'
|
||||||
endif
|
endif
|
||||||
|
|||||||
Reference in New Issue
Block a user