mirror of
https://github.com/dhruvasagar/vim-table-mode.git
synced 2025-11-08 19:13:46 -05:00
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
766066394c | ||
|
|
f2f62d78e5 | ||
|
|
7810ce0ca0 | ||
|
|
b22d793135 | ||
|
|
de2ad0b71d | ||
|
|
29c7ec1a23 | ||
|
|
9ce981cc77 | ||
|
|
0c9cd8fb50 | ||
|
|
da39088fd8 | ||
|
|
a0fcb89f43 | ||
|
|
5007e5f728 | ||
|
|
71051e2c22 | ||
|
|
43d0c0ff6f | ||
|
|
00c54e8e02 | ||
|
|
cfbac6979d | ||
|
|
7e00cea7f5 | ||
|
|
79166b3d4e | ||
|
|
6862a8b7e4 | ||
|
|
d889c342d3 | ||
|
|
8a54ef28ab | ||
|
|
a2492fbf08 |
12
CHANGELOG.md
12
CHANGELOG.md
@@ -1,4 +1,14 @@
|
|||||||
# Change Log
|
# Change Log
|
||||||
|
## Version 4.4.0
|
||||||
|
* Minor bug fixes
|
||||||
|
* Added feature to allow using negative indices within formulas to access rows,
|
||||||
|
columns relative to the last, -1 being the last.
|
||||||
|
|
||||||
|
## Version 4.3.0
|
||||||
|
* Refactored some more
|
||||||
|
* Fixed issue #19, hiphens in the table broke alignment
|
||||||
|
* Added feature #26, you can now define column alignments in the table header
|
||||||
|
|
||||||
## Version 4.2.0
|
## Version 4.2.0
|
||||||
* Refactored cells logic out to autoload/tablemode/spreadsheet/cell.vim
|
* Refactored cells logic out to autoload/tablemode/spreadsheet/cell.vim
|
||||||
* Refactored formula logic out to autoload/tablemode/spreadsheet/formula.vim
|
* Refactored formula logic out to autoload/tablemode/spreadsheet/formula.vim
|
||||||
@@ -11,7 +21,7 @@
|
|||||||
* Major refactoring of the codebase.
|
* Major refactoring of the codebase.
|
||||||
* Improved modular tests.
|
* Improved modular tests.
|
||||||
* Fixed long standing unicode character alignment issue.
|
* Fixed long standing unicode character alignment issue.
|
||||||
* Moved to providing <Plug> mappings rather than configuration based mappings
|
* Moved to providing \<Plug\> mappings rather than configuration based mappings
|
||||||
which can be more easily overriden by end user.
|
which can be more easily overriden by end user.
|
||||||
|
|
||||||
## Version 3.3.2
|
## Version 3.3.2
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -1,4 +1,4 @@
|
|||||||
# VIM Table Mode v4.2.0 [](https://travis-ci.org/dhruvasagar/vim-table-mode)
|
# VIM Table Mode v4.4.0 [](https://travis-ci.org/dhruvasagar/vim-table-mode)
|
||||||
|
|
||||||
An awesome automatic table creator & formatter allowing one to create neat
|
An awesome automatic table creator & formatter allowing one to create neat
|
||||||
tables as you type.
|
tables as you type.
|
||||||
@@ -48,6 +48,10 @@ $ git submodule add git@github.com:dhruvasagar/vim-table-mode.git bundle/table-m
|
|||||||
per buffer basis and so it does not cause any unusual behavior unless it is
|
per buffer basis and so it does not cause any unusual behavior unless it is
|
||||||
enabled explicitly. Please read `:h table-mode` for further information.
|
enabled explicitly. Please read `:h table-mode` for further information.
|
||||||
|
|
||||||
|
You can also define in a table header border how it's content should be
|
||||||
|
aligned, whether right or left by using a `:` character defined by
|
||||||
|
`g:table_mode_align_char` option.
|
||||||
|
|
||||||
- **Format existing content into a table** :
|
- **Format existing content into a table** :
|
||||||
|
|
||||||
Table Mode wouldn't justify it's name if it didn't allow formatting
|
Table Mode wouldn't justify it's name if it didn't allow formatting
|
||||||
@@ -133,11 +137,13 @@ $ git submodule add git@github.com:dhruvasagar/vim-table-mode.git bundle/table-m
|
|||||||
|
|
||||||
- `$n`: This matches the table column number `n`. So the `formula` would
|
- `$n`: This matches the table column number `n`. So the `formula` would
|
||||||
be evaluated for each cell in that column and the result would be placed
|
be evaluated for each cell in that column and the result would be placed
|
||||||
in it.
|
in it. You can use negative indice to represent column relative to the
|
||||||
|
last, -1 being the last.
|
||||||
|
|
||||||
- `$n,m`: This matches the table cell n,m (row, column). So in this case
|
- `$n,m`: This matches the table cell n,m (row, column). So in this case
|
||||||
the formula would be evaluated and the result will be placed in this
|
the formula would be evaluated and the result will be placed in this
|
||||||
cell.
|
cell. You can also use negative values to refer to cells relative to
|
||||||
|
the size, -1 being the last (row or column).
|
||||||
|
|
||||||
- The `formula` can be a simple mathematical expression involving cells
|
- The `formula` can be a simple mathematical expression involving cells
|
||||||
which are also defined by the same format as that of the target cell. You
|
which are also defined by the same format as that of the target cell. You
|
||||||
|
|||||||
@@ -32,13 +32,6 @@ function! s:SetBufferOptDefault(opt, val) "{{{2
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:IsTableModeActive() "{{{2
|
|
||||||
if g:table_mode_always_active | return 1 | endif
|
|
||||||
|
|
||||||
call s:SetBufferOptDefault('table_mode_active', 0)
|
|
||||||
return b:table_mode_active
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:ToggleMapping() "{{{2
|
function! s:ToggleMapping() "{{{2
|
||||||
if exists('b:table_mode_active') && b:table_mode_active
|
if exists('b:table_mode_active') && b:table_mode_active
|
||||||
call s:SetBufferOptDefault('table_mode_separator_map', g:table_mode_separator)
|
call s:SetBufferOptDefault('table_mode_separator_map', g:table_mode_separator)
|
||||||
@@ -58,13 +51,13 @@ function! s:SetActive(bool) "{{{2
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:ConvertDelimiterToSeparator(line, ...) "{{{2
|
function! s:ConvertDelimiterToSeparator(line, ...) "{{{2
|
||||||
let gflag = 'g'
|
let old_gdefault = &gdefault
|
||||||
if &gdefault | let gflag = 'gg' | endif
|
set nogdefault
|
||||||
|
|
||||||
let delim = g:table_mode_delimiter
|
let delim = g:table_mode_delimiter
|
||||||
if a:0 | let delim = a:1 | endif
|
if a:0 | let delim = a:1 | endif
|
||||||
if delim ==# ','
|
if delim ==# ','
|
||||||
silent! execute a:line . 's/' . "[\'\"][^\'\"]*\\zs,\\ze[^\'\"]*[\'\"]/__COMMA__/" . gflag
|
silent! execute a:line . 's/' . "[\'\"][^\'\"]*\\zs,\\ze[^\'\"]*[\'\"]/__COMMA__/g"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let [cstart, cend] = [tablemode#table#GetCommentStart(), tablemode#table#GetCommentEnd()]
|
let [cstart, cend] = [tablemode#table#GetCommentStart(), tablemode#table#GetCommentEnd()]
|
||||||
@@ -74,11 +67,13 @@ function! s:ConvertDelimiterToSeparator(line, ...) "{{{2
|
|||||||
|
|
||||||
silent! execute a:line . 's/' . tablemode#table#StartExpr() . '\zs\ze' . match_char_start .
|
silent! execute a:line . 's/' . tablemode#table#StartExpr() . '\zs\ze' . match_char_start .
|
||||||
\ '\|' . delim . '\|' . match_char_end . '\zs\ze' . tablemode#table#EndExpr() . '/' .
|
\ '\|' . delim . '\|' . match_char_end . '\zs\ze' . tablemode#table#EndExpr() . '/' .
|
||||||
\ g:table_mode_separator . '/' . gflag
|
\ g:table_mode_separator . '/g'
|
||||||
|
|
||||||
if delim ==# ','
|
if delim ==# ','
|
||||||
silent! execute a:line . 's/' . "[\'\"][^\'\"]*\\zs__COMMA__\\ze[^\'\"]*[\'\"]/,/" . gflag
|
silent! execute a:line . 's/' . "[\'\"][^\'\"]*\\zs__COMMA__\\ze[^\'\"]*[\'\"]/,/g"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let &gdefault=old_gdefault
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:Tableizeline(line, ...) "{{{2
|
function! s:Tableizeline(line, ...) "{{{2
|
||||||
@@ -97,28 +92,35 @@ function! tablemode#scope() "{{{2
|
|||||||
return s:
|
return s:
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! tablemode#IsActive() "{{{2
|
||||||
|
if g:table_mode_always_active | return 1 | endif
|
||||||
|
|
||||||
|
call s:SetBufferOptDefault('table_mode_active', 0)
|
||||||
|
return b:table_mode_active
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! tablemode#TableizeInsertMode() "{{{2
|
function! tablemode#TableizeInsertMode() "{{{2
|
||||||
if s:IsTableModeActive() && getline('.') =~# (tablemode#table#StartExpr() . g:table_mode_separator . g:table_mode_separator)
|
if tablemode#IsActive() && getline('.') =~# (tablemode#table#StartExpr() . g:table_mode_separator . g:table_mode_separator)
|
||||||
call tablemode#table#AddHeaderBorder('.')
|
call tablemode#table#AddHeaderBorder('.')
|
||||||
normal! A
|
normal! A
|
||||||
elseif s:IsTableModeActive() && getline('.') =~# (tablemode#table#StartExpr() . g:table_mode_separator)
|
elseif tablemode#IsActive() && getline('.') =~# (tablemode#table#StartExpr() . g:table_mode_separator)
|
||||||
let column = tablemode#utils#strlen(substitute(getline('.')[0:col('.')], '[^' . g:table_mode_separator . ']', '', 'g'))
|
let column = tablemode#utils#strlen(substitute(getline('.')[0:col('.')], '[^' . g:table_mode_separator . ']', '', 'g'))
|
||||||
let position = tablemode#utils#strlen(matchstr(getline('.')[0:col('.')], '.*' . g:table_mode_separator . '\s*\zs.*'))
|
let position = tablemode#utils#strlen(matchstr(getline('.')[0:col('.')], '.*' . g:table_mode_separator . '\s*\zs.*'))
|
||||||
call tablemode#table#TableRealign('.')
|
call tablemode#table#Realign('.')
|
||||||
normal! 0
|
normal! 0
|
||||||
call search(repeat('[^' . g:table_mode_separator . ']*' . g:table_mode_separator, column) . '\s\{-\}' . repeat('.', position), 'ce', line('.'))
|
call search(repeat('[^' . g:table_mode_separator . ']*' . g:table_mode_separator, column) . '\s\{-\}' . repeat('.', position), 'ce', line('.'))
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#TableModeEnable() "{{{2
|
function! tablemode#Enable() "{{{2
|
||||||
call s:SetActive(1)
|
call s:SetActive(1)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#TableModeDisable() "{{{2
|
function! tablemode#Disable() "{{{2
|
||||||
call s:SetActive(0)
|
call s:SetActive(0)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#TableModeToggle() "{{{2
|
function! tablemode#Toggle() "{{{2
|
||||||
if g:table_mode_always_active
|
if g:table_mode_always_active
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
@@ -135,7 +137,7 @@ function! tablemode#TableizeRange(...) range "{{{2
|
|||||||
let lnum += 1
|
let lnum += 1
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
call tablemode#table#TableRealign(lnum - 1)
|
call tablemode#table#Realign(lnum - 1)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#TableizeByDelimiter() "{{{2
|
function! tablemode#TableizeByDelimiter() "{{{2
|
||||||
|
|||||||
@@ -64,11 +64,21 @@ function! s:Padding(string, length, where) "{{{3
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" function! s:Split() - Split a string into fields and delimiters {{{2
|
" Public Functions {{{1
|
||||||
|
function! tablemode#align#sid() "{{{2
|
||||||
|
return maparg('<sid>', 'n')
|
||||||
|
endfunction
|
||||||
|
nnoremap <sid> <sid>
|
||||||
|
|
||||||
|
function! tablemode#align#scope() "{{{2
|
||||||
|
return s:
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" function! tablemode#align#Split() - Split a string into fields and delimiters {{{2
|
||||||
" Like split(), but include the delimiters as elements
|
" Like split(), but include the delimiters as elements
|
||||||
" All odd numbered elements are delimiters
|
" All odd numbered elements are delimiters
|
||||||
" All even numbered elements are non-delimiters (including zero)
|
" All even numbered elements are non-delimiters (including zero)
|
||||||
function! s:Split(string, delim)
|
function! tablemode#align#Split(string, delim)
|
||||||
let rv = []
|
let rv = []
|
||||||
let beg = 0
|
let beg = 0
|
||||||
|
|
||||||
@@ -107,59 +117,65 @@ function! s:Split(string, delim)
|
|||||||
return rv
|
return rv
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Public Functions {{{1
|
function! tablemode#align#alignments(lnum, ncols) "{{{2
|
||||||
function! tablemode#align#sid() "{{{2
|
let alignments = []
|
||||||
return maparg('<sid>', 'n')
|
if tablemode#table#IsHeader(a:lnum+1)
|
||||||
endfunction
|
let hcols = tablemode#align#Split(getline(a:lnum+1), '[' . g:table_mode_corner . g:table_mode_corner_corner . ']')
|
||||||
nnoremap <sid> <sid>
|
for idx in range(len(hcols))
|
||||||
|
" Right align if header
|
||||||
function! tablemode#align#scope() "{{{2
|
call add(alignments, 'l')
|
||||||
return s:
|
if hcols[idx] =~# g:table_mode_align_char . '$' | let alignments[idx] = 'r' | endif
|
||||||
|
if hcols[idx] !~# '[^0-9\.]' | let alignments[idx] = 'r' | endif
|
||||||
|
endfor
|
||||||
|
end
|
||||||
|
return alignments
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#align#Align(lines) "{{{2
|
function! tablemode#align#Align(lines) "{{{2
|
||||||
let lines = map(a:lines, 's:Split(v:val, g:table_mode_separator)')
|
let lines = map(a:lines, 'map(v:val, "v:key =~# \"text\" ? tablemode#align#Split(v:val, g:table_mode_separator) : v:val")')
|
||||||
|
|
||||||
for line in lines
|
for line in lines
|
||||||
if len(line) <= 1 | continue | endif
|
let stext = line.text
|
||||||
|
if len(stext) <= 1 | continue | endif
|
||||||
|
|
||||||
if line[0] !~ tablemode#table#StartExpr()
|
if stext[0] !~ tablemode#table#StartExpr()
|
||||||
let line[0] = s:StripTrailingSpaces(line[0])
|
let stext[0] = s:StripTrailingSpaces(stext[0])
|
||||||
endif
|
endif
|
||||||
if len(line) >= 2
|
if len(stext) >= 2
|
||||||
for i in range(1, len(line)-1)
|
for i in range(1, len(stext)-1)
|
||||||
let line[i] = tablemode#utils#strip(line[i])
|
let stext[i] = tablemode#utils#strip(stext[i])
|
||||||
endfor
|
endfor
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
let maxes = []
|
let maxes = []
|
||||||
for line in lines
|
for line in lines
|
||||||
if len(line) <= 1 | continue | endif
|
let stext = line.text
|
||||||
for i in range(len(line))
|
if len(stext) <= 1 | continue | endif
|
||||||
|
for i in range(len(stext))
|
||||||
if i == len(maxes)
|
if i == len(maxes)
|
||||||
let maxes += [ s:Strlen(line[i]) ]
|
let maxes += [ s:Strlen(stext[i]) ]
|
||||||
else
|
else
|
||||||
let maxes[i] = max([ maxes[i], s:Strlen(line[i]) ])
|
let maxes[i] = max([ maxes[i], s:Strlen(stext[i]) ])
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
|
let alignments = tablemode#align#alignments(lines[0].lnum, len(lines[0].text))
|
||||||
|
|
||||||
for idx in range(len(lines))
|
for idx in range(len(lines))
|
||||||
let line = lines[idx]
|
let tlnum = lines[idx].lnum
|
||||||
|
let tline = lines[idx].text
|
||||||
|
|
||||||
if len(line) <= 1 | continue | endif
|
if len(tline) <= 1 | continue | endif
|
||||||
for i in range(len(line))
|
for jdx in range(len(tline))
|
||||||
if line[i] !~# '[^0-9\.]'
|
" Dealing with the header being the first line
|
||||||
let field = s:Padding(line[i], maxes[i], 'r')
|
if jdx >= len(alignments) | call add(alignments, 'l') | endif
|
||||||
else
|
let field = s:Padding(tline[jdx], maxes[jdx], alignments[jdx])
|
||||||
let field = s:Padding(line[i], maxes[i], 'l')
|
let tline[jdx] = field . (jdx == 0 || jdx == len(tline) ? '' : ' ')
|
||||||
endif
|
|
||||||
|
|
||||||
let line[i] = field . (i == 0 || i == len(line) ? '' : ' ')
|
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
let lines[idx] = s:StripTrailingSpaces(join(line, ''))
|
let lines[idx].text = s:StripTrailingSpaces(join(tline, ''))
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
return lines
|
return lines
|
||||||
|
|||||||
@@ -47,50 +47,50 @@ function! tablemode#spreadsheet#scope() "{{{2
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#spreadsheet#GetFirstRow(line) "{{{2
|
function! tablemode#spreadsheet#GetFirstRow(line) "{{{2
|
||||||
if tablemode#table#IsATableRow(a:line)
|
if tablemode#table#IsRow(a:line)
|
||||||
let line = tablemode#utils#line(a:line)
|
let line = tablemode#utils#line(a:line)
|
||||||
|
|
||||||
while tablemode#table#IsATableRow(line - 1) || tablemode#table#IsATableHeader(line - 1)
|
while tablemode#table#IsRow(line - 1) || tablemode#table#IsHeader(line - 1)
|
||||||
let line -= 1
|
let line -= 1
|
||||||
endwhile
|
endwhile
|
||||||
if tablemode#table#IsATableHeader(line) | let line += 1 | endif
|
if tablemode#table#IsHeader(line) | let line += 1 | endif
|
||||||
|
|
||||||
return line
|
return line
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#spreadsheet#MoveToFirstRow() "{{{2
|
function! tablemode#spreadsheet#MoveToFirstRow() "{{{2
|
||||||
if tablemode#table#IsATableRow('.')
|
if tablemode#table#IsRow('.')
|
||||||
call cursor(tablemode#spreadsheet#GetFirstRow('.'), col('.'))
|
call cursor(tablemode#spreadsheet#GetFirstRow('.'), col('.'))
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#spreadsheet#GetLastRow(line) "{{{2
|
function! tablemode#spreadsheet#GetLastRow(line) "{{{2
|
||||||
if tablemode#table#IsATableRow(a:line)
|
if tablemode#table#IsRow(a:line)
|
||||||
let line = tablemode#utils#line(a:line)
|
let line = tablemode#utils#line(a:line)
|
||||||
|
|
||||||
while tablemode#table#IsATableRow(line + 1) || tablemode#table#IsATableHeader(line + 1)
|
while tablemode#table#IsRow(line + 1) || tablemode#table#IsHeader(line + 1)
|
||||||
let line += 1
|
let line += 1
|
||||||
endwhile
|
endwhile
|
||||||
if tablemode#table#IsATableHeader(line) | let line -= 1 | endif
|
if tablemode#table#IsHeader(line) | let line -= 1 | endif
|
||||||
|
|
||||||
return line
|
return line
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#spreadsheet#MoveToLastRow() "{{{2
|
function! tablemode#spreadsheet#MoveToLastRow() "{{{2
|
||||||
if tablemode#table#IsATableRow('.')
|
if tablemode#table#IsRow('.')
|
||||||
call cursor(tablemode#spreadsheet#GetLastRow('.'), col('.'))
|
call cursor(tablemode#spreadsheet#GetLastRow('.'), col('.'))
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#spreadsheet#LineNr(row) "{{{2
|
function! tablemode#spreadsheet#LineNr(row) "{{{2
|
||||||
if tablemode#table#IsATableRow('.')
|
if tablemode#table#IsRow('.')
|
||||||
let line = tablemode#spreadsheet#GetFirstRow('.')
|
let line = tablemode#spreadsheet#GetFirstRow('.')
|
||||||
let row_nr = 0
|
let row_nr = 0
|
||||||
|
|
||||||
while tablemode#table#IsATableRow(line + 1) || tablemode#table#IsATableHeader(line + 1)
|
while tablemode#table#IsRow(line + 1) || tablemode#table#IsHeader(line + 1)
|
||||||
if tablemode#table#IsATableRow(line)
|
if tablemode#table#IsRow(line)
|
||||||
let row_nr += 1
|
let row_nr += 1
|
||||||
if row ==# row_nr | break | endif
|
if row ==# row_nr | break | endif
|
||||||
endif
|
endif
|
||||||
@@ -105,8 +105,8 @@ function! tablemode#spreadsheet#RowNr(line) "{{{2
|
|||||||
let line = tablemode#utils#line(a:line)
|
let line = tablemode#utils#line(a:line)
|
||||||
|
|
||||||
let rowNr = 0
|
let rowNr = 0
|
||||||
while tablemode#table#IsATableRow(line) || tablemode#table#IsATableHeader(line)
|
while tablemode#table#IsRow(line) || tablemode#table#IsHeader(line)
|
||||||
if tablemode#table#IsATableRow(line) | let rowNr += 1 | endif
|
if tablemode#table#IsRow(line) | let rowNr += 1 | endif
|
||||||
let line -= 1
|
let line -= 1
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
@@ -117,14 +117,14 @@ function! tablemode#spreadsheet#RowCount(line) "{{{2
|
|||||||
let line = tablemode#utils#line(a:line)
|
let line = tablemode#utils#line(a:line)
|
||||||
|
|
||||||
let [tline, totalRowCount] = [line, 0]
|
let [tline, totalRowCount] = [line, 0]
|
||||||
while tablemode#table#IsATableRow(tline) || tablemode#table#IsATableHeader(tline)
|
while tablemode#table#IsRow(tline) || tablemode#table#IsHeader(tline)
|
||||||
if tablemode#table#IsATableRow(tline) | let totalRowCount += 1 | endif
|
if tablemode#table#IsRow(tline) | let totalRowCount += 1 | endif
|
||||||
let tline -= 1
|
let tline -= 1
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
let tline = line + 1
|
let tline = line + 1
|
||||||
while tablemode#table#IsATableRow(tline) || tablemode#table#IsATableHeader(tline)
|
while tablemode#table#IsRow(tline) || tablemode#table#IsHeader(tline)
|
||||||
if tablemode#table#IsATableRow(tline) | let totalRowCount += 1 | endif
|
if tablemode#table#IsRow(tline) | let totalRowCount += 1 | endif
|
||||||
let tline += 1
|
let tline += 1
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
@@ -167,33 +167,33 @@ function! tablemode#spreadsheet#MoveToStartOfCell() "{{{2
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#spreadsheet#GetLastRow(line) "{{{2
|
function! tablemode#spreadsheet#GetLastRow(line) "{{{2
|
||||||
if tablemode#table#IsATableRow(a:line)
|
if tablemode#table#IsRow(a:line)
|
||||||
let line = tablemode#utils#line(a:line)
|
let line = tablemode#utils#line(a:line)
|
||||||
|
|
||||||
while tablemode#table#IsATableRow(line + 1) || tablemode#table#IsATableHeader(line + 1)
|
while tablemode#table#IsRow(line + 1) || tablemode#table#IsHeader(line + 1)
|
||||||
let line += 1
|
let line += 1
|
||||||
endwhile
|
endwhile
|
||||||
if tablemode#table#IsATableHeader(line) | let line -= 1 | endif
|
if tablemode#table#IsHeader(line) | let line -= 1 | endif
|
||||||
|
|
||||||
return line
|
return line
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#spreadsheet#GetFirstRow(line) "{{{2
|
function! tablemode#spreadsheet#GetFirstRow(line) "{{{2
|
||||||
if tablemode#table#IsATableRow(a:line)
|
if tablemode#table#IsRow(a:line)
|
||||||
let line = tablemode#utils#line(a:line)
|
let line = tablemode#utils#line(a:line)
|
||||||
|
|
||||||
while tablemode#table#IsATableRow(line - 1) || tablemode#table#IsATableHeader(line - 1)
|
while tablemode#table#IsRow(line - 1) || tablemode#table#IsHeader(line - 1)
|
||||||
let line -= 1
|
let line -= 1
|
||||||
endwhile
|
endwhile
|
||||||
if tablemode#table#IsATableHeader(line) | let line += 1 | endif
|
if tablemode#table#IsHeader(line) | let line += 1 | endif
|
||||||
|
|
||||||
return line
|
return line
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#spreadsheet#DeleteColumn() "{{{2
|
function! tablemode#spreadsheet#DeleteColumn() "{{{2
|
||||||
if tablemode#table#IsATableRow('.')
|
if tablemode#table#IsRow('.')
|
||||||
for i in range(v:count1)
|
for i in range(v:count1)
|
||||||
call tablemode#spreadsheet#MoveToStartOfCell()
|
call tablemode#spreadsheet#MoveToStartOfCell()
|
||||||
call tablemode#spreadsheet#MoveToFirstRow()
|
call tablemode#spreadsheet#MoveToFirstRow()
|
||||||
@@ -202,23 +202,23 @@ function! tablemode#spreadsheet#DeleteColumn() "{{{2
|
|||||||
normal! d
|
normal! d
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
call tablemode#table#TableRealign('.')
|
call tablemode#table#Realign('.')
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#spreadsheet#DeleteRow() "{{{2
|
function! tablemode#spreadsheet#DeleteRow() "{{{2
|
||||||
if tablemode#table#IsATableRow('.')
|
if tablemode#table#IsRow('.')
|
||||||
for i in range(v:count1)
|
for i in range(v:count1)
|
||||||
if tablemode#table#IsATableRow('.')
|
if tablemode#table#IsRow('.')
|
||||||
normal! dd
|
normal! dd
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !tablemode#table#IsATableRow('.')
|
if !tablemode#table#IsRow('.')
|
||||||
normal! k
|
normal! k
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
call tablemode#table#TableRealign('.')
|
call tablemode#table#Realign('.')
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -234,14 +234,3 @@ function! tablemode#spreadsheet#Average(range, ...) abort "{{{2
|
|||||||
return s:Average(call('tablemode#spreadsheet#cell#GetCellRange', args))
|
return s:Average(call('tablemode#spreadsheet#cell#GetCellRange', args))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#spreadsheet#CellTextObject(inner) "{{{2
|
|
||||||
if tablemode#table#IsATableRow('.')
|
|
||||||
call tablemode#spreadsheet#MoveToStartOfCell()
|
|
||||||
if a:inner
|
|
||||||
normal! v
|
|
||||||
call search('[^' . g:table_mode_separator . ']\ze\s*' . g:table_mode_separator)
|
|
||||||
else
|
|
||||||
execute 'normal! vf' . g:table_mode_separator . 'l'
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ endfunction
|
|||||||
function! tablemode#spreadsheet#cell#GetCells(line, ...) abort
|
function! tablemode#spreadsheet#cell#GetCells(line, ...) abort
|
||||||
let line = tablemode#utils#line(a:line)
|
let line = tablemode#utils#line(a:line)
|
||||||
|
|
||||||
if tablemode#table#IsATableRow(line)
|
if tablemode#table#IsRow(line)
|
||||||
if a:0 < 1
|
if a:0 < 1
|
||||||
let [row, colm] = [line, 0]
|
let [row, colm] = [line, 0]
|
||||||
elseif a:0 < 2
|
elseif a:0 < 2
|
||||||
@@ -81,11 +81,12 @@ function! tablemode#spreadsheet#cell#GetCells(line, ...) abort
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
let first_row = tablemode#spreadsheet#GetFirstRow(line)
|
let first_row = tablemode#spreadsheet#GetFirstRow(line)
|
||||||
|
let last_row = tablemode#spreadsheet#GetLastRow(line)
|
||||||
if row == 0
|
if row == 0
|
||||||
let values = []
|
let values = []
|
||||||
let line = first_row
|
let line = first_row
|
||||||
while tablemode#table#IsATableRow(line) || tablemode#table#IsATableHeader(line)
|
while tablemode#table#IsRow(line) || tablemode#table#IsHeader(line)
|
||||||
if tablemode#table#IsATableRow(line)
|
if tablemode#table#IsRow(line)
|
||||||
let row_line = getline(line)[stridx(getline(line), g:table_mode_separator):strridx(getline(line), g:table_mode_separator)]
|
let row_line = getline(line)[stridx(getline(line), g:table_mode_separator):strridx(getline(line), g:table_mode_separator)]
|
||||||
call add(values, tablemode#utils#strip(get(split(row_line, g:table_mode_separator), colm>0?colm-1:colm, '')))
|
call add(values, tablemode#utils#strip(get(split(row_line, g:table_mode_separator), colm>0?colm-1:colm, '')))
|
||||||
endif
|
endif
|
||||||
@@ -94,13 +95,14 @@ function! tablemode#spreadsheet#cell#GetCells(line, ...) abort
|
|||||||
return values
|
return values
|
||||||
else
|
else
|
||||||
let row_nr = 0
|
let row_nr = 0
|
||||||
let line = first_row
|
let row_diff = row > 0 ? 1 : -1
|
||||||
while tablemode#table#IsATableRow(line) || tablemode#table#IsATableHeader(line)
|
let line = row > 0 ? first_row : last_row
|
||||||
if tablemode#table#IsATableRow(line)
|
while tablemode#table#IsRow(line) || tablemode#table#IsHeader(line)
|
||||||
let row_nr += 1
|
if tablemode#table#IsRow(line)
|
||||||
|
let row_nr += row_diff
|
||||||
if row ==# row_nr | break | endif
|
if row ==# row_nr | break | endif
|
||||||
endif
|
endif
|
||||||
let line += 1
|
let line += row_diff
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
let row_line = getline(line)[stridx(getline(line), g:table_mode_separator):strridx(getline(line), g:table_mode_separator)]
|
let row_line = getline(line)[stridx(getline(line), g:table_mode_separator):strridx(getline(line), g:table_mode_separator)]
|
||||||
@@ -142,7 +144,7 @@ function! tablemode#spreadsheet#cell#GetCellRange(range, ...) abort "{{{2
|
|||||||
|
|
||||||
let values = []
|
let values = []
|
||||||
|
|
||||||
if tablemode#table#IsATableRow(line)
|
if tablemode#table#IsRow(line)
|
||||||
let [row1, col1, row2, col2] = s:ParseRange(a:range, colm)
|
let [row1, col1, row2, col2] = s:ParseRange(a:range, colm)
|
||||||
|
|
||||||
if row1 == row2
|
if row1 == row2
|
||||||
@@ -193,7 +195,11 @@ function! tablemode#spreadsheet#cell#SetCell(val, ...) "{{{2
|
|||||||
let [line, row, colm] = a:000
|
let [line, row, colm] = a:000
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if tablemode#table#IsATableRow(line)
|
" Account for negative values to reference from relatively from the last
|
||||||
|
if row < 0 | let row = tablemode#spreadsheet#RowCount(line) + row + 1 | endif
|
||||||
|
if colm < 0 | let colm = tablemode#spreadsheet#ColumnCount(line) + colm + 1 | endif
|
||||||
|
|
||||||
|
if tablemode#table#IsRow(line)
|
||||||
let line = tablemode#utils#line(line) + (row - tablemode#spreadsheet#RowNr(line)) * 1
|
let line = tablemode#utils#line(line) + (row - tablemode#spreadsheet#RowNr(line)) * 1
|
||||||
let line_val = getline(line)
|
let line_val = getline(line)
|
||||||
let cstartexpr = tablemode#table#StartCommentExpr()
|
let cstartexpr = tablemode#table#StartCommentExpr()
|
||||||
@@ -207,11 +213,11 @@ function! tablemode#spreadsheet#cell#SetCell(val, ...) "{{{2
|
|||||||
let line_value = sce . line_value . ece
|
let line_value = sce . line_value . ece
|
||||||
endif
|
endif
|
||||||
call setline(line, line_value)
|
call setline(line, line_value)
|
||||||
call tablemode#table#TableRealign(line)
|
call tablemode#table#Realign(line)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
function! tablemode#spreadsheet#cell#TextObject(inner) "{{{2
|
function! tablemode#spreadsheet#cell#TextObject(inner) "{{{2
|
||||||
if tablemode#table#IsATableRow('.')
|
if tablemode#table#IsRow('.')
|
||||||
call tablemode#spreadsheet#MoveToStartOfCell()
|
call tablemode#spreadsheet#MoveToStartOfCell()
|
||||||
if a:inner
|
if a:inner
|
||||||
normal! v
|
normal! v
|
||||||
@@ -223,11 +229,11 @@ function! tablemode#spreadsheet#cell#TextObject(inner) "{{{2
|
|||||||
endfunction
|
endfunction
|
||||||
function! tablemode#spreadsheet#cell#Motion(direction, ...) "{{{2
|
function! tablemode#spreadsheet#cell#Motion(direction, ...) "{{{2
|
||||||
let l:count = a:0 ? a:1 : v:count1
|
let l:count = a:0 ? a:1 : v:count1
|
||||||
if tablemode#table#IsATableRow('.')
|
if tablemode#table#IsRow('.')
|
||||||
for ii in range(l:count)
|
for ii in range(l:count)
|
||||||
if a:direction ==# 'l'
|
if a:direction ==# 'l'
|
||||||
if tablemode#spreadsheet#IsLastCell()
|
if tablemode#spreadsheet#IsLastCell()
|
||||||
if !tablemode#table#IsATableRow(line('.') + 1) && (tablemode#table#IsATableHeader(line('.') + 1) && !tablemode#table#IsATableRow(line('.') + 2))
|
if !tablemode#table#IsRow(line('.') + 1) && (tablemode#table#IsHeader(line('.') + 1) && !tablemode#table#IsRow(line('.') + 2))
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
call tablemode#spreadsheet#cell#Motion('j', 1)
|
call tablemode#spreadsheet#cell#Motion('j', 1)
|
||||||
@@ -242,7 +248,7 @@ function! tablemode#spreadsheet#cell#Motion(direction, ...) "{{{2
|
|||||||
endif
|
endif
|
||||||
elseif a:direction ==# 'h'
|
elseif a:direction ==# 'h'
|
||||||
if tablemode#spreadsheet#IsFirstCell()
|
if tablemode#spreadsheet#IsFirstCell()
|
||||||
if !tablemode#table#IsATableRow(line('.') - 1) && (tablemode#table#IsATableHeader(line('.') - 1) && !tablemode#table#IsATableRow(line('.') - 2))
|
if !tablemode#table#IsRow(line('.') - 1) && (tablemode#table#IsHeader(line('.') - 1) && !tablemode#table#IsRow(line('.') - 2))
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
call tablemode#spreadsheet#cell#Motion('k', 1)
|
call tablemode#spreadsheet#cell#Motion('k', 1)
|
||||||
@@ -256,18 +262,18 @@ function! tablemode#spreadsheet#cell#Motion(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#table#IsATableRow(line('.') + 1)
|
if tablemode#table#IsRow(line('.') + 1)
|
||||||
" execute 'normal! ' . 1 . 'j'
|
" execute 'normal! ' . 1 . 'j'
|
||||||
normal! j
|
normal! j
|
||||||
elseif tablemode#table#IsATableHeader(line('.') + 1) && tablemode#table#IsATableRow(line('.') + 2)
|
elseif tablemode#table#IsHeader(line('.') + 1) && tablemode#table#IsRow(line('.') + 2)
|
||||||
" execute 'normal! ' . 2 . 'j'
|
" execute 'normal! ' . 2 . 'j'
|
||||||
normal! 2j
|
normal! 2j
|
||||||
endif
|
endif
|
||||||
elseif a:direction ==# 'k'
|
elseif a:direction ==# 'k'
|
||||||
if tablemode#table#IsATableRow(line('.') - 1)
|
if tablemode#table#IsRow(line('.') - 1)
|
||||||
" execute 'normal! ' . 1 . 'k'
|
" execute 'normal! ' . 1 . 'k'
|
||||||
normal! k
|
normal! k
|
||||||
elseif tablemode#table#IsATableHeader(line('.') - 1) && tablemode#table#IsATableRow(line('.') - 2)
|
elseif tablemode#table#IsHeader(line('.') - 1) && tablemode#table#IsRow(line('.') - 2)
|
||||||
" execute 'normal! ' . (1 + 1) . 'k'
|
" execute 'normal! ' . (1 + 1) . 'k'
|
||||||
normal! 2k
|
normal! 2k
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ function! tablemode#spreadsheet#formula#Add(...) "{{{2
|
|||||||
if fr !=# ''
|
if fr !=# ''
|
||||||
let fr = '$' . row . ',' . colm . '=' . fr
|
let fr = '$' . row . ',' . colm . '=' . fr
|
||||||
let fline = tablemode#spreadsheet#GetLastRow('.') + 1
|
let fline = tablemode#spreadsheet#GetLastRow('.') + 1
|
||||||
if tablemode#table#IsATableHeader(fline) | let fline += 1 | endif
|
if tablemode#table#IsHeader(fline) | let fline += 1 | 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
|
||||||
@@ -98,7 +98,7 @@ function! tablemode#spreadsheet#formula#EvaluateExpr(expr, line) abort "{{{2
|
|||||||
call tablemode#spreadsheet#cell#SetCell(eval(expr), line, row, colm)
|
call tablemode#spreadsheet#cell#SetCell(eval(expr), line, row, colm)
|
||||||
else
|
else
|
||||||
let [row, line] = [1, tablemode#spreadsheet#GetFirstRow(line)]
|
let [row, line] = [1, tablemode#spreadsheet#GetFirstRow(line)]
|
||||||
while tablemode#table#IsATableRow(line)
|
while tablemode#table#IsRow(line)
|
||||||
let texpr = expr
|
let texpr = expr
|
||||||
if expr =~# '\$'
|
if expr =~# '\$'
|
||||||
let texpr = substitute(texpr, '\$\(\d\+\)',
|
let texpr = substitute(texpr, '\$\(\d\+\)',
|
||||||
@@ -126,17 +126,17 @@ function! tablemode#spreadsheet#formula#EvaluateFormulaLine() abort "{{{2
|
|||||||
else
|
else
|
||||||
let matchexpr = '^\s* tmf: \zs.*$'
|
let matchexpr = '^\s* tmf: \zs.*$'
|
||||||
endif
|
endif
|
||||||
if tablemode#table#IsATableRow('.') " We're inside the table
|
if tablemode#table#IsRow('.') " We're inside the table
|
||||||
let line = tablemode#spreadsheet#GetLastRow('.')
|
let line = tablemode#spreadsheet#GetLastRow('.')
|
||||||
let fline = line + 1
|
let fline = line + 1
|
||||||
if tablemode#table#IsATableHeader(fline) | let fline += 1 | endif
|
if tablemode#table#IsHeader(fline) | let fline += 1 | endif
|
||||||
if getline(fline) =~# 'tmf: '
|
if getline(fline) =~# 'tmf: '
|
||||||
let exprs = split(matchstr(getline(fline), matchexpr), ';')
|
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('.') - 1
|
let line = line('.') - 1
|
||||||
if tablemode#table#IsATableHeader(line) | let line -= 1 | endif
|
if tablemode#table#IsHeader(line) | let line -= 1 | endif
|
||||||
if tablemode#table#IsATableRow(line)
|
if tablemode#table#IsRow(line)
|
||||||
let exprs = split(matchstr(getline('.'), matchexpr), ';')
|
let exprs = split(matchstr(getline('.'), matchexpr), ';')
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -21,13 +21,13 @@
|
|||||||
function! s:HeaderBorderExpr() "{{{2
|
function! s:HeaderBorderExpr() "{{{2
|
||||||
return tablemode#table#StartExpr() .
|
return tablemode#table#StartExpr() .
|
||||||
\ '[' . g:table_mode_corner . g:table_mode_corner_corner . ']' .
|
\ '[' . g:table_mode_corner . g:table_mode_corner_corner . ']' .
|
||||||
\ '[' . g:table_mode_fillchar . g:table_mode_corner . ']*' .
|
\ '[' . g:table_mode_fillchar . g:table_mode_corner . g:table_mode_align_char . ']*' .
|
||||||
\ '[' . g:table_mode_corner . g:table_mode_corner_corner . ']' .
|
\ '[' . g:table_mode_corner . g:table_mode_corner_corner . ']' .
|
||||||
\ tablemode#table#EndExpr()
|
\ tablemode#table#EndExpr()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:DefaultHeaderBorder() "{{{2
|
function! s:DefaultHeaderBorder() "{{{2
|
||||||
if s:IsTableModeActive()
|
if tablemode#IsActive()
|
||||||
return g:table_mode_corner_corner . g:table_mode_fillchar . g:table_mode_corner . g:table_mode_fillchar . g:table_mode_corner_corner
|
return g:table_mode_corner_corner . g:table_mode_fillchar . g:table_mode_corner . g:table_mode_fillchar . g:table_mode_corner_corner
|
||||||
else
|
else
|
||||||
return ''
|
return ''
|
||||||
@@ -36,19 +36,38 @@ endfunction
|
|||||||
|
|
||||||
function! s:GenerateHeaderBorder(line) "{{{2
|
function! s:GenerateHeaderBorder(line) "{{{2
|
||||||
let line = tablemode#utils#line(a:line)
|
let line = tablemode#utils#line(a:line)
|
||||||
if tablemode#table#IsATableRow(line - 1) || tablemode#table#IsATableRow(line + 1)
|
if tablemode#table#IsRow(line - 1) || tablemode#table#IsRow(line + 1)
|
||||||
let line_val = ''
|
let line_val = ''
|
||||||
if tablemode#table#IsATableRow(line + 1)
|
if tablemode#table#IsRow(line + 1)
|
||||||
let line_val = getline(line + 1)
|
let line_val = getline(line + 1)
|
||||||
endif
|
endif
|
||||||
if tablemode#table#IsATableRow(line - 1) && tablemode#utils#strlen(line_val) < tablemode#utils#strlen(getline(line - 1))
|
if tablemode#table#IsRow(line - 1) && tablemode#utils#strlen(line_val) < tablemode#utils#strlen(getline(line - 1))
|
||||||
let line_val = getline(line - 1)
|
let line_val = getline(line - 1)
|
||||||
endif
|
endif
|
||||||
if tablemode#utils#strlen(line_val) <= 1 | return s:DefaultHeaderBorder() | endif
|
if tablemode#utils#strlen(line_val) <= 1 | return s:DefaultHeaderBorder() | 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_corner_corner . '\1' . g:table_mode_corner_corner, '')
|
let border = substitute(border, '^' . g:table_mode_corner . '\(.*\)' . g:table_mode_corner . '$', g:table_mode_corner_corner . '\1' . g:table_mode_corner_corner, '')
|
||||||
|
|
||||||
|
" Incorporate header alignment chars
|
||||||
|
if getline(line) =~# g:table_mode_align_char
|
||||||
|
let pat = '[' . g:table_mode_corner_corner . g:table_mode_corner . ']'
|
||||||
|
let hcols = tablemode#align#Split(getline(line), pat)
|
||||||
|
let gcols = tablemode#align#Split(border, pat)
|
||||||
|
|
||||||
|
for idx in range(len(hcols))
|
||||||
|
if hcols[idx] =~# g:table_mode_align_char
|
||||||
|
if hcols[idx] =~# g:table_mode_align_char . '$'
|
||||||
|
let gcols[idx] = gcols[idx][:-2] . g:table_mode_align_char
|
||||||
|
else
|
||||||
|
let gcols[idx] = g:table_mode_align_char . gcols[idx][1:]
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
let border = join(gcols, '')
|
||||||
|
endif
|
||||||
|
|
||||||
let cstartexpr = tablemode#table#StartCommentExpr()
|
let cstartexpr = tablemode#table#StartCommentExpr()
|
||||||
if tablemode#utils#strlen(cstartexpr) > 0 && getline(line) =~# cstartexpr
|
if tablemode#utils#strlen(cstartexpr) > 0 && getline(line) =~# cstartexpr
|
||||||
let sce = matchstr(line_val, tablemode#table#StartCommentExpr())
|
let sce = matchstr(line_val, tablemode#table#StartCommentExpr())
|
||||||
@@ -134,109 +153,51 @@ function! tablemode#table#EndExpr() "{{{2
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#table#IsATableRow(line) "{{{2
|
function! tablemode#table#IsHeader(line) "{{{2
|
||||||
return getline(a:line) =~# (tablemode#table#StartExpr() . g:table_mode_separator . '[^' .
|
return getline(a:line) =~# s:HeaderBorderExpr()
|
||||||
\ g:table_mode_fillchar . ']*[^' . g:table_mode_corner . ']*$')
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#table#IsATableHeader(line) "{{{2
|
function! tablemode#table#IsRow(line) "{{{2
|
||||||
return getline(a:line) =~# s:HeaderBorderExpr()
|
return !tablemode#table#IsHeader(a:line) && getline(a:line) =~# (tablemode#table#StartExpr() . g:table_mode_separator)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#table#AddHeaderBorder(line) "{{{2
|
function! tablemode#table#AddHeaderBorder(line) "{{{2
|
||||||
call setline(a:line, s:GenerateHeaderBorder(a:line))
|
call setline(a:line, s:GenerateHeaderBorder(a:line))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#table#TableRealign(line) "{{{2
|
function! tablemode#table#Realign(line) "{{{2
|
||||||
let line = tablemode#utils#line(a:line)
|
let line = tablemode#utils#line(a:line)
|
||||||
|
|
||||||
let [lnums, lines] = [[], []]
|
let lines = []
|
||||||
let [tline, blines] = [line, []]
|
let [lnum, blines] = [line, []]
|
||||||
while tablemode#table#IsATableRow(tline) || tablemode#table#IsATableHeader(tline)
|
while tablemode#table#IsRow(lnum) || tablemode#table#IsHeader(lnum)
|
||||||
if tablemode#table#IsATableHeader(tline)
|
if tablemode#table#IsHeader(lnum)
|
||||||
call insert(blines, tline)
|
call insert(blines, lnum)
|
||||||
let tline -= 1
|
let lnum -= 1
|
||||||
continue
|
continue
|
||||||
endif
|
endif
|
||||||
call insert(lnums, tline)
|
call insert(lines, {'lnum': lnum, 'text': getline(lnum)})
|
||||||
call insert(lines, getline(tline))
|
let lnum -= 1
|
||||||
let tline -= 1
|
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
let tline = line + 1
|
let lnum = line + 1
|
||||||
|
while tablemode#table#IsRow(lnum) || tablemode#table#IsHeader(lnum)
|
||||||
while tablemode#table#IsATableRow(tline) || tablemode#table#IsATableHeader(tline)
|
if tablemode#table#IsHeader(lnum)
|
||||||
if tablemode#table#IsATableHeader(tline)
|
call add(blines, lnum)
|
||||||
call insert(blines, tline)
|
let lnum += 1
|
||||||
let tline += 1
|
|
||||||
continue
|
continue
|
||||||
endif
|
endif
|
||||||
call add(lnums, tline)
|
call add(lines, {'lnum': lnum, 'text': getline(lnum)})
|
||||||
call add(lines, getline(tline))
|
let lnum += 1
|
||||||
let tline += 1
|
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
let lines = tablemode#align#Align(lines)
|
let lines = tablemode#align#Align(lines)
|
||||||
|
|
||||||
for lnum in lnums
|
for aline in lines
|
||||||
let index = index(lnums, lnum)
|
call setline(aline.lnum, aline.text)
|
||||||
call setline(lnum, lines[index])
|
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
for bline in blines
|
for bline in blines
|
||||||
call tablemode#table#AddHeaderBorder(bline)
|
call tablemode#table#AddHeaderBorder(bline)
|
||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#table#TableMotion(direction, ...) "{{{2
|
|
||||||
let l:count = a:0 ? a:1 : v:count1
|
|
||||||
if tablemode#table#IsATableRow('.')
|
|
||||||
for ii in range(l:count)
|
|
||||||
if a:direction ==# 'l'
|
|
||||||
if tablemode#spreadsheet#IsLastCell()
|
|
||||||
if !tablemode#table#IsATableRow(line('.') + 1) && (tablemode#table#IsATableHeader(line('.') + 1) && !tablemode#table#IsATableRow(line('.') + 2 * 1))
|
|
||||||
return
|
|
||||||
endif
|
|
||||||
call tablemode#table#TableMotion('j', 1)
|
|
||||||
normal! 0
|
|
||||||
endif
|
|
||||||
|
|
||||||
" If line starts with g:table_mode_separator
|
|
||||||
if getline('.')[col('.')-1] ==# g:table_mode_separator
|
|
||||||
normal! 2l
|
|
||||||
else
|
|
||||||
execute 'normal! f' . g:table_mode_separator . '2l'
|
|
||||||
endif
|
|
||||||
elseif a:direction ==# 'h'
|
|
||||||
if tablemode#spreadsheet#IsFirstCell()
|
|
||||||
if !tablemode#table#IsATableRow(line('.') - 1) && (tablemode#table#IsATableHeader(line('.') - 1) && !tablemode#table#IsATableRow(line('.') - 2 * 1))
|
|
||||||
return
|
|
||||||
endif
|
|
||||||
call tablemode#table#TableMotion('k', 1)
|
|
||||||
normal! $
|
|
||||||
endif
|
|
||||||
|
|
||||||
" If line ends with g:table_mode_separator
|
|
||||||
if getline('.')[col('.')-1] ==# g:table_mode_separator
|
|
||||||
execute 'normal! F' . g:table_mode_separator . '2l'
|
|
||||||
else
|
|
||||||
execute 'normal! 2F' . g:table_mode_separator . '2l'
|
|
||||||
endif
|
|
||||||
elseif a:direction ==# 'j'
|
|
||||||
if tablemode#table#IsATableRow(line('.') + 1)
|
|
||||||
execute 'normal! ' . 1 . 'j'
|
|
||||||
elseif tablemode#table#IsATableHeader(line('.') + 1) && tablemode#table#IsATableRow(line('.') + 2)
|
|
||||||
execute 'normal! ' . (1 + 1) . 'j'
|
|
||||||
endif
|
|
||||||
elseif a:direction ==# 'k'
|
|
||||||
if tablemode#table#IsATableRow(line('.') - 1)
|
|
||||||
execute 'normal! ' . 1 . 'k'
|
|
||||||
elseif tablemode#table#IsATableHeader(line('.') - 1) && tablemode#table#IsATableRow(line('.') - 2)
|
|
||||||
execute 'normal! ' . (1 + 1) . 'k'
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" vim: sw=2 sts=2 fdl=0 fdm=marker
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
*table-mode.txt* Table Mode for easy table formatting. v4.2.0
|
*table-mode.txt* Table Mode for easy table formatting. v4.4.0
|
||||||
===============================================================================
|
===============================================================================
|
||||||
Table Mode, THE AWESOME AUTOMATIC TABLE CREATOR & FORMATTER
|
Table Mode, THE AWESOME AUTOMATIC TABLE CREATOR & FORMATTER
|
||||||
VERSION 4.2.0
|
VERSION 4.4.0
|
||||||
|
|
||||||
Author: Dhruva Sagar <http://dhruvasagar.com/>
|
Author: Dhruva Sagar <http://dhruvasagar.com/>
|
||||||
License: MIT <http://opensource.org/licenses/MIT/>
|
License: MIT <http://opensource.org/licenses/MIT/>
|
||||||
@@ -34,6 +34,11 @@ Create Table on the fly:
|
|||||||
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.
|
||||||
|
|
||||||
|
Table Mode now supports gfm style tables and allows to define column
|
||||||
|
alignments with the aid of placing ':' (configured using
|
||||||
|
|g:table_mode_align_char|) on the table header border appropriately to
|
||||||
|
align content left or right.
|
||||||
|
|
||||||
The table mode is disabled by default and you can enter table mode
|
The table mode is disabled by default and you can enter table mode
|
||||||
using |table-mode-toggle-map| or you can also enable it permanently
|
using |table-mode-toggle-map| or you can also enable it permanently
|
||||||
using |table-mode-always-active| if you wish though not recommended.
|
using |table-mode-always-active| if you wish though not recommended.
|
||||||
@@ -99,11 +104,14 @@ Formula Expressions :
|
|||||||
|
|
||||||
'$n': This matches the table column number 'n'. So the formula
|
'$n': This matches the table column number 'n'. So the formula
|
||||||
would be evaluated for each cell in that column and the result
|
would be evaluated for each cell in that column and the result
|
||||||
would be placed in it.
|
would be placed in it. You can use negative indice to
|
||||||
|
represent column relative to the last, -1 being the last.
|
||||||
|
|
||||||
'$n,m': This matches the table cell n,m (row, column). So in
|
'$n,m': This matches the table cell n,m (row, column). So in
|
||||||
this case the formula would be evaluated and the result will
|
this case the formula would be evaluated and the result will
|
||||||
be placed in this cell.
|
be placed in this cell. You can also use negative values to
|
||||||
|
refer to cells relative to the size, -1 being the last (row or
|
||||||
|
column).
|
||||||
|
|
||||||
The formula can be a simple mathematical expression involving cells
|
The formula can be a simple mathematical expression involving cells
|
||||||
which are also defined by the same format as that of the target cell.
|
which are also defined by the same format as that of the target cell.
|
||||||
@@ -139,6 +147,10 @@ Overview:
|
|||||||
|table-mode-delimiter| .......... Set the delimiter for Tableize.
|
|table-mode-delimiter| .......... Set the delimiter for Tableize.
|
||||||
|table-mode-corner-corner| ...... Set the character to be used for
|
|table-mode-corner-corner| ...... Set the character to be used for
|
||||||
extreme corners of the table border.
|
extreme corners of the table border.
|
||||||
|
|table-mode-align-char|.......... Set the alignment character which
|
||||||
|
can be added to the table header
|
||||||
|
border to control alignment of that
|
||||||
|
column.
|
||||||
|
|
||||||
g:loaded_table_mode *table-mode-loaded*
|
g:loaded_table_mode *table-mode-loaded*
|
||||||
Use this option to disable the plugin: >
|
Use this option to disable the plugin: >
|
||||||
@@ -196,6 +208,11 @@ g:table_mode_corner_corner *table-mode-corner-corner*
|
|||||||
corners of the table border. >
|
corners of the table border. >
|
||||||
let g:table_mode_corner_corner = '|'
|
let g:table_mode_corner_corner = '|'
|
||||||
<
|
<
|
||||||
|
g:table_mode_align_char *table-mode-align-char*
|
||||||
|
Use this option to define the character to be used for defining
|
||||||
|
alignments for columns in the table header border. >
|
||||||
|
let g:table_mode_align_char = ':'
|
||||||
|
<
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
MAPPINGS *table-mode-mappings*
|
MAPPINGS *table-mode-mappings*
|
||||||
|
|||||||
@@ -42,9 +42,10 @@ call s:SetGlobalOptDefault('table_mode_toggle_map', 'm')
|
|||||||
call s:SetGlobalOptDefault('table_mode_always_active', 0)
|
call s:SetGlobalOptDefault('table_mode_always_active', 0)
|
||||||
call s:SetGlobalOptDefault('table_mode_delimiter', ',')
|
call s:SetGlobalOptDefault('table_mode_delimiter', ',')
|
||||||
call s:SetGlobalOptDefault('table_mode_corner_corner', '|')
|
call s:SetGlobalOptDefault('table_mode_corner_corner', '|')
|
||||||
|
call s:SetGlobalOptDefault('table_mode_align_char', ':')
|
||||||
|
|
||||||
function! s:TableEchoCell() "{{{1
|
function! s:TableEchoCell() "{{{1
|
||||||
if tablemode#table#IsATableRow('.')
|
if tablemode#table#IsRow('.')
|
||||||
echomsg '$' . tablemode#spreadsheet#RowNr('.') . ',' . tablemode#spreadsheet#ColumnNr('.')
|
echomsg '$' . tablemode#spreadsheet#RowNr('.') . ',' . tablemode#spreadsheet#ColumnNr('.')
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
@@ -52,10 +53,10 @@ endfunction
|
|||||||
" Define Commands & Mappings {{{1
|
" Define Commands & Mappings {{{1
|
||||||
if !g:table_mode_always_active "{{{2
|
if !g:table_mode_always_active "{{{2
|
||||||
exec "nnoremap <silent> " . g:table_mode_map_prefix . g:table_mode_toggle_map .
|
exec "nnoremap <silent> " . g:table_mode_map_prefix . g:table_mode_toggle_map .
|
||||||
\ " <Esc>:call tablemode#TableModeToggle()<CR>"
|
\ " <Esc>:call tablemode#Toggle()<CR>"
|
||||||
command! -nargs=0 TableModeToggle call tablemode#TableModeToggle()
|
command! -nargs=0 TableModeToggle call tablemode#Toggle()
|
||||||
command! -nargs=0 TableModeEnable call tablemode#TableModeEnable()
|
command! -nargs=0 TableModeEnable call tablemode#Enable()
|
||||||
command! -nargs=0 TableModeDisable call tablemode#TableModeDisable()
|
command! -nargs=0 TableModeDisable call tablemode#Disable()
|
||||||
else
|
else
|
||||||
let table_mode_separator_map = g:table_mode_separator
|
let table_mode_separator_map = g:table_mode_separator
|
||||||
" '|' is a special character, we need to map <Bar> instead
|
" '|' is a special character, we need to map <Bar> instead
|
||||||
@@ -67,16 +68,16 @@ else
|
|||||||
endif
|
endif
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
command! -nargs=? -range Tableize <line1>,<line2>call tablemode#table#TableizeRange(<q-args>)
|
command! -nargs=? -range Tableize <line1>,<line2>call tablemode#TableizeRange(<q-args>)
|
||||||
command! TableAddFormula call tablemode#spreadsheet#formula#Add()
|
command! TableAddFormula call tablemode#spreadsheet#formula#Add()
|
||||||
command! TableModeRealign call tablemode#spreadsheet#TableRealign('.')
|
command! TableModeRealign call tablemode#table#Realign('.')
|
||||||
command! TableEvalFormulaLine call tablemode#spreadsheet#formula#EvaluateFormulaLine()
|
command! TableEvalFormulaLine call tablemode#spreadsheet#formula#EvaluateFormulaLine()
|
||||||
|
|
||||||
nnoremap <silent> <Plug>(table-mode-tableize) :Tableize<CR>
|
nnoremap <silent> <Plug>(table-mode-tableize) :Tableize<CR>
|
||||||
xnoremap <silent> <Plug>(table-mode-tableize) :Tableize<CR>
|
xnoremap <silent> <Plug>(table-mode-tableize) :Tableize<CR>
|
||||||
xnoremap <silent> <Plug>(table-mode-tableize-delimiter) :<C-U>call tablemode#TableizeByDelimiter()<CR>
|
xnoremap <silent> <Plug>(table-mode-tableize-delimiter) :<C-U>call tablemode#TableizeByDelimiter()<CR>
|
||||||
|
|
||||||
nnoremap <silent> <Plug>(table-mode-realign) :call tablemode#table#TableRealign('.')<CR>
|
nnoremap <silent> <Plug>(table-mode-realign) :call tablemode#table#Realign('.')<CR>
|
||||||
|
|
||||||
nnoremap <silent> <Plug>(table-mode-motion-up) :<C-U>call tablemode#spreadsheet#cell#Motion('k')<CR>
|
nnoremap <silent> <Plug>(table-mode-motion-up) :<C-U>call tablemode#spreadsheet#cell#Motion('k')<CR>
|
||||||
nnoremap <silent> <Plug>(table-mode-motion-down) :<C-U>call tablemode#spreadsheet#cell#Motion('j')<CR>
|
nnoremap <silent> <Plug>(table-mode-motion-down) :<C-U>call tablemode#spreadsheet#cell#Motion('j')<CR>
|
||||||
|
|||||||
12
t/align.vim
12
t/align.vim
@@ -3,12 +3,20 @@ source t/config/options.vim
|
|||||||
|
|
||||||
call vspec#hint({'scope': 'tablemode#align#scope()', 'sid': 'tablemode#align#sid()'})
|
call vspec#hint({'scope': 'tablemode#align#scope()', 'sid': 'tablemode#align#sid()'})
|
||||||
|
|
||||||
|
function! ConvertLines2Dict(lines)
|
||||||
|
let lines = []
|
||||||
|
for idx in range(len(a:lines))
|
||||||
|
call insert(lines, {"lnum": idx+1, "text": a:lines[idx]})
|
||||||
|
endfor
|
||||||
|
return lines
|
||||||
|
endfunction
|
||||||
|
|
||||||
describe 'Align'
|
describe 'Align'
|
||||||
it 'should align table content correctly'
|
it 'should align table content correctly'
|
||||||
Expect tablemode#align#Align(readfile('t/fixtures/align/simple_before.txt')) == readfile('t/fixtures/align/simple_after.txt')
|
Expect tablemode#align#Align(ConvertLines2Dict(readfile('t/fixtures/align/simple_before.txt'))) == ConvertLines2Dict(readfile('t/fixtures/align/simple_after.txt'))
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should align table content with unicode characters correctly'
|
it 'should align table content with unicode characters correctly'
|
||||||
Expect tablemode#align#Align(readfile('t/fixtures/align/unicode_before.txt')) == readfile('t/fixtures/align/unicode_after.txt')
|
Expect tablemode#align#Align(ConvertLines2Dict(readfile('t/fixtures/align/unicode_before.txt'))) == ConvertLines2Dict(readfile('t/fixtures/align/unicode_after.txt'))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
82
t/cell.vim
82
t/cell.vim
@@ -3,7 +3,8 @@ source t/config/options.vim
|
|||||||
|
|
||||||
call vspec#hint({'scope': 'tablemode#spreadsheet#cell#scope()', 'sid': 'tablemode#spreadsheet#cell#sid()'})
|
call vspec#hint({'scope': 'tablemode#spreadsheet#cell#scope()', 'sid': 'tablemode#spreadsheet#cell#sid()'})
|
||||||
|
|
||||||
describe 'cell API'
|
describe 'cell'
|
||||||
|
describe 'API'
|
||||||
before
|
before
|
||||||
new
|
new
|
||||||
read t/fixtures/sample.txt
|
read t/fixtures/sample.txt
|
||||||
@@ -46,4 +47,83 @@ describe 'cell API'
|
|||||||
Expect tablemode#spreadsheet#cell#GetCellRange('1:-1', 2, 2) == ['test12']
|
Expect tablemode#spreadsheet#cell#GetCellRange('1:-1', 2, 2) == ['test12']
|
||||||
Expect tablemode#spreadsheet#cell#GetCellRange('1:-1', 3, 2) == ['test12']
|
Expect tablemode#spreadsheet#cell#GetCellRange('1:-1', 3, 2) == ['test12']
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'Motions'
|
||||||
|
describe 'left or right'
|
||||||
|
before
|
||||||
|
new
|
||||||
|
normal! ggdG
|
||||||
|
call tablemode#Enable()
|
||||||
|
normal i|test11|test12|
|
||||||
|
|test21|test22|
|
||||||
|
call cursor(1, 3)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should move left when not on first column'
|
||||||
|
call cursor(1, 12)
|
||||||
|
Expect tablemode#spreadsheet#ColumnNr('.') == 2
|
||||||
|
call tablemode#spreadsheet#cell#Motion('h')
|
||||||
|
Expect tablemode#spreadsheet#ColumnNr('.') == 1
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should move to the previous row last column if it exists when on first column'
|
||||||
|
call cursor(2, 3)
|
||||||
|
Expect tablemode#spreadsheet#RowNr('.') == 2
|
||||||
|
Expect tablemode#spreadsheet#ColumnNr('.') == 1
|
||||||
|
call tablemode#spreadsheet#cell#Motion('h')
|
||||||
|
Expect tablemode#spreadsheet#RowNr('.') == 1
|
||||||
|
Expect tablemode#spreadsheet#ColumnNr('.') == 2
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should move right when not on last column'
|
||||||
|
Expect tablemode#spreadsheet#ColumnNr('.') == 1
|
||||||
|
call tablemode#spreadsheet#cell#Motion('l')
|
||||||
|
Expect tablemode#spreadsheet#ColumnNr('.') == 2
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should move to the next row first column if it exists when on last column'
|
||||||
|
call cursor(1, 12)
|
||||||
|
Expect tablemode#spreadsheet#RowNr('.') == 1
|
||||||
|
Expect tablemode#spreadsheet#ColumnNr('.') == 2
|
||||||
|
call tablemode#spreadsheet#cell#Motion('l')
|
||||||
|
Expect tablemode#spreadsheet#RowNr('.') == 2
|
||||||
|
Expect tablemode#spreadsheet#ColumnNr('.') == 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'up or down'
|
||||||
|
before
|
||||||
|
new
|
||||||
|
normal! ggdG
|
||||||
|
call tablemode#Enable()
|
||||||
|
normal i|test11|test12|
|
||||||
|
|test21|test22|
|
||||||
|
call cursor(1, 3)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should move a row up unless on first row'
|
||||||
|
call cursor(2, 3)
|
||||||
|
Expect tablemode#spreadsheet#RowNr('.') == 2
|
||||||
|
call tablemode#spreadsheet#cell#Motion('k')
|
||||||
|
Expect tablemode#spreadsheet#RowNr('.') == 1
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should remain on first row when trying to move up'
|
||||||
|
Expect tablemode#spreadsheet#RowNr('.') == 1
|
||||||
|
call tablemode#spreadsheet#cell#Motion('k')
|
||||||
|
Expect tablemode#spreadsheet#RowNr('.') == 1
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should move a row down unless on last row'
|
||||||
|
Expect tablemode#spreadsheet#RowNr('.') == 1
|
||||||
|
call tablemode#spreadsheet#cell#Motion('j')
|
||||||
|
Expect tablemode#spreadsheet#RowNr('.') == 2
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should remain on last row when trying to move down'
|
||||||
|
Expect tablemode#spreadsheet#RowNr('.') == 1
|
||||||
|
call tablemode#spreadsheet#cell#Motion('k')
|
||||||
|
Expect tablemode#spreadsheet#RowNr('.') == 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,3 +6,4 @@ let g:table_mode_toggle_map = 'm'
|
|||||||
let g:table_mode_always_active = 0
|
let g:table_mode_always_active = 0
|
||||||
let g:table_mode_delimiter = ','
|
let g:table_mode_delimiter = ','
|
||||||
let g:table_mode_corner_corner = '|'
|
let g:table_mode_corner_corner = '|'
|
||||||
|
let g:table_mode_align_char = ':'
|
||||||
|
|||||||
7
t/fixtures/sample_with_header.txt
Normal file
7
t/fixtures/sample_with_header.txt
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
| Title | Message |
|
||||||
|
|--------+---------|
|
||||||
|
| test11 | test12 |
|
||||||
|
| test21 | test22 |
|
||||||
|
|--------+---------|
|
||||||
|
|
||||||
106
t/table.vim
106
t/table.vim
@@ -5,115 +5,39 @@ call vspec#hint({'scope': 'tablemode#table#scope()', 'sid': 'tablemode#table#sid
|
|||||||
|
|
||||||
describe 'table'
|
describe 'table'
|
||||||
describe 'API'
|
describe 'API'
|
||||||
|
describe 'IsRow'
|
||||||
before
|
before
|
||||||
new
|
new
|
||||||
read t/fixtures/sample.txt
|
read t/fixtures/sample.txt
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return true when inside a table'
|
it 'should return true when inside a table'
|
||||||
Expect tablemode#table#IsATableRow(2) to_be_true
|
Expect tablemode#table#IsRow(2) to_be_true
|
||||||
|
Expect tablemode#table#IsRow(3) to_be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return false when outside a table'
|
it 'should return false when outside a table'
|
||||||
Expect tablemode#table#IsATableRow(4) to_be_false
|
Expect tablemode#table#IsRow(1) to_be_false
|
||||||
|
Expect tablemode#table#IsRow(4) to_be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'Tableize'
|
describe 'IsHeader'
|
||||||
before
|
before
|
||||||
new
|
new
|
||||||
read t/fixtures/tableize.txt
|
read t/fixtures/sample_with_header.txt
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should tableize with default delimiter'
|
it 'should return true when on a table header'
|
||||||
:2,3call tablemode#TableizeRange('')
|
Expect tablemode#table#IsHeader(3) to_be_true
|
||||||
Expect tablemode#table#IsATableRow(2) to_be_true
|
Expect tablemode#table#IsHeader(6) to_be_true
|
||||||
Expect tablemode#spreadsheet#RowCount(2) == 2
|
|
||||||
Expect tablemode#spreadsheet#ColumnCount(2) == 3
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should tableize with given delimiter'
|
it 'should return false when not on a table header'
|
||||||
:2,3call tablemode#TableizeRange('/;')
|
Expect tablemode#table#IsHeader(1) to_be_false
|
||||||
Expect tablemode#table#IsATableRow(2) to_be_true
|
Expect tablemode#table#IsHeader(2) to_be_false
|
||||||
Expect tablemode#spreadsheet#RowCount(2) == 2
|
Expect tablemode#table#IsHeader(4) to_be_false
|
||||||
Expect tablemode#spreadsheet#ColumnCount(2) == 2
|
Expect tablemode#table#IsHeader(5) to_be_false
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'Motions'
|
|
||||||
describe 'left or right'
|
|
||||||
before
|
|
||||||
new
|
|
||||||
normal! ggdG
|
|
||||||
call tablemode#TableModeEnable()
|
|
||||||
normal i|test11|test12|
|
|
||||||
|test21|test22|
|
|
||||||
call cursor(1, 3)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should move left when not on first column'
|
|
||||||
call cursor(1, 12)
|
|
||||||
Expect tablemode#spreadsheet#ColumnNr('.') == 2
|
|
||||||
call tablemode#table#TableMotion('h')
|
|
||||||
Expect tablemode#spreadsheet#ColumnNr('.') == 1
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should move to the previous row last column if it exists when on first column'
|
|
||||||
call cursor(2, 3)
|
|
||||||
Expect tablemode#spreadsheet#RowNr('.') == 2
|
|
||||||
Expect tablemode#spreadsheet#ColumnNr('.') == 1
|
|
||||||
call tablemode#table#TableMotion('h')
|
|
||||||
Expect tablemode#spreadsheet#RowNr('.') == 1
|
|
||||||
Expect tablemode#spreadsheet#ColumnNr('.') == 2
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should move right when not on last column'
|
|
||||||
Expect tablemode#spreadsheet#ColumnNr('.') == 1
|
|
||||||
call tablemode#table#TableMotion('l')
|
|
||||||
Expect tablemode#spreadsheet#ColumnNr('.') == 2
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should move to the next row first column if it exists when on last column'
|
|
||||||
call cursor(1, 12)
|
|
||||||
Expect tablemode#spreadsheet#RowNr('.') == 1
|
|
||||||
Expect tablemode#spreadsheet#ColumnNr('.') == 2
|
|
||||||
call tablemode#table#TableMotion('l')
|
|
||||||
Expect tablemode#spreadsheet#RowNr('.') == 2
|
|
||||||
Expect tablemode#spreadsheet#ColumnNr('.') == 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'up or down'
|
|
||||||
before
|
|
||||||
new
|
|
||||||
normal! ggdG
|
|
||||||
call tablemode#TableModeEnable()
|
|
||||||
normal i|test11|test12|
|
|
||||||
|test21|test22|
|
|
||||||
call cursor(1, 3)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should move a row up unless on first row'
|
|
||||||
call cursor(2, 3)
|
|
||||||
Expect tablemode#spreadsheet#RowNr('.') == 2
|
|
||||||
call tablemode#table#TableMotion('k')
|
|
||||||
Expect tablemode#spreadsheet#RowNr('.') == 1
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should remain on first row when trying to move up'
|
|
||||||
Expect tablemode#spreadsheet#RowNr('.') == 1
|
|
||||||
call tablemode#table#TableMotion('k')
|
|
||||||
Expect tablemode#spreadsheet#RowNr('.') == 1
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should move a row down unless on last row'
|
|
||||||
Expect tablemode#spreadsheet#RowNr('.') == 1
|
|
||||||
call tablemode#table#TableMotion('j')
|
|
||||||
Expect tablemode#spreadsheet#RowNr('.') == 2
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should remain on last row when trying to move down'
|
|
||||||
Expect tablemode#spreadsheet#RowNr('.') == 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ call vspec#hint({'scope': 'tablemode#scope()', 'sid': 'tablemode#sid()'})
|
|||||||
|
|
||||||
describe 'tablemode'
|
describe 'tablemode'
|
||||||
describe 'Activation'
|
describe 'Activation'
|
||||||
describe 'tablemode#TableModeEnable()'
|
describe 'tablemode#Enable()'
|
||||||
before
|
before
|
||||||
call tablemode#TableModeEnable()
|
call tablemode#Enable()
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should enable table mode'
|
it 'should enable table mode'
|
||||||
@@ -15,9 +15,9 @@ describe 'tablemode'
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'tablemode#TableModeDisable()'
|
describe 'tablemode#Disable()'
|
||||||
before
|
before
|
||||||
call tablemode#TableModeDisable()
|
call tablemode#Disable()
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should disable table mode'
|
it 'should disable table mode'
|
||||||
@@ -25,13 +25,34 @@ describe 'tablemode'
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'tablemode#TableModeToggle()'
|
describe 'tablemode#Toggle()'
|
||||||
it 'should toggle table mode'
|
it 'should toggle table mode'
|
||||||
call tablemode#TableModeToggle()
|
call tablemode#Toggle()
|
||||||
Expect b:table_mode_active to_be_true
|
Expect b:table_mode_active to_be_true
|
||||||
call tablemode#TableModeToggle()
|
call tablemode#Toggle()
|
||||||
Expect b:table_mode_active to_be_false
|
Expect b:table_mode_active to_be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'Tableize'
|
||||||
|
before
|
||||||
|
new
|
||||||
|
read t/fixtures/tableize.txt
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should tableize with default delimiter'
|
||||||
|
:2,3call tablemode#TableizeRange('')
|
||||||
|
Expect tablemode#table#IsRow(2) to_be_true
|
||||||
|
Expect tablemode#spreadsheet#RowCount(2) == 2
|
||||||
|
Expect tablemode#spreadsheet#ColumnCount(2) == 3
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should tableize with given delimiter'
|
||||||
|
:2,3call tablemode#TableizeRange('/;')
|
||||||
|
Expect tablemode#table#IsRow(2) to_be_true
|
||||||
|
Expect tablemode#spreadsheet#RowCount(2) == 2
|
||||||
|
Expect tablemode#spreadsheet#ColumnCount(2) == 2
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user