mirror of
https://github.com/dhruvasagar/vim-table-mode.git
synced 2025-11-08 19:13:46 -05:00
Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5c42d58d4b | ||
|
|
1302782b55 | ||
|
|
9935e57def | ||
|
|
8993e2a454 | ||
|
|
df41b7deff | ||
|
|
c88a913397 | ||
|
|
8609ad4778 | ||
|
|
535dd9601a | ||
|
|
e94bbcc0b4 | ||
|
|
a0618db019 | ||
|
|
176999f347 | ||
|
|
5a6a9b3473 | ||
|
|
aa8817621c | ||
|
|
54187d0be1 | ||
|
|
3e2eaeee5c | ||
|
|
6dfc508af5 | ||
|
|
ed441f19a1 | ||
|
|
e4525c465a | ||
|
|
19bfa092a3 | ||
|
|
f91ec2458f | ||
|
|
0799523ffb | ||
|
|
9875a117a7 | ||
|
|
cca55e72ce |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
tags
|
tags
|
||||||
|
.vim-flavor/
|
||||||
|
|||||||
4
.travis.yml
Normal file
4
.travis.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
language: ruby
|
||||||
|
rvm:
|
||||||
|
- 1.9.3
|
||||||
|
script: rake ci
|
||||||
23
CHANGELOG.md
23
CHANGELOG.md
@@ -1,4 +1,27 @@
|
|||||||
# Change Log
|
# Change Log
|
||||||
|
## Version 3.3.1
|
||||||
|
* Improved logic to ignore table borders (add as many as you'd like), the
|
||||||
|
first row is not treated special, it is row # 1. Keep that in mind while
|
||||||
|
defining Formulas
|
||||||
|
* Improved test coverage
|
||||||
|
|
||||||
|
## Version 3.3
|
||||||
|
* Dropped +- mapping to create table border instead now using ||
|
||||||
|
* You can now have a top table border (before header) as well as a bottom
|
||||||
|
table border.
|
||||||
|
|
||||||
|
## Version 3.2
|
||||||
|
* Added tests to test various use cases using <a
|
||||||
|
href='https://github.com/kana/vim-vspec'>Vspec</a>..
|
||||||
|
* Added travis integration for automated tests.
|
||||||
|
|
||||||
|
## Version 3.1
|
||||||
|
* Removed borders. You can now optionally create a table header by simply
|
||||||
|
adding a header border immidiately after the header line by using the
|
||||||
|
iabbrev trigger '+-'. Just type that on the line immidiately after the
|
||||||
|
header and press space / \<CR\> to complete the header border.
|
||||||
|
* Some Bug Fixes
|
||||||
|
|
||||||
## Version 3.0
|
## Version 3.0
|
||||||
* Removed dependence on Tabular and added code borrowed from Tabular for
|
* Removed dependence on Tabular and added code borrowed from Tabular for
|
||||||
aligning the table rows.
|
aligning the table rows.
|
||||||
|
|||||||
4
Gemfile
Normal file
4
Gemfile
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
|
gem 'rake'
|
||||||
|
gem 'vim-flavor', '~> 1.1'
|
||||||
18
Gemfile.lock
Normal file
18
Gemfile.lock
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
GEM
|
||||||
|
remote: https://rubygems.org/
|
||||||
|
specs:
|
||||||
|
blankslate (2.1.2.4)
|
||||||
|
parslet (1.5.0)
|
||||||
|
blankslate (~> 2.0)
|
||||||
|
rake (10.1.0)
|
||||||
|
thor (0.18.1)
|
||||||
|
vim-flavor (1.1.3)
|
||||||
|
parslet (~> 1.0)
|
||||||
|
thor (~> 0.14)
|
||||||
|
|
||||||
|
PLATFORMS
|
||||||
|
ruby
|
||||||
|
|
||||||
|
DEPENDENCIES
|
||||||
|
rake
|
||||||
|
vim-flavor (~> 1.1)
|
||||||
14
README.md
14
README.md
@@ -1,4 +1,4 @@
|
|||||||
# VIM Table Mode
|
# VIM Table Mode [](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.
|
||||||
@@ -11,17 +11,21 @@ CHANGELOG.md </a>
|
|||||||
## Getting Started
|
## Getting Started
|
||||||
### Installation
|
### Installation
|
||||||
|
|
||||||
There are 2 ways to do this
|
There are several ways to do this
|
||||||
|
|
||||||
1. I recommend installing <a
|
1. I recommend installing <a
|
||||||
href="https://github.com/tpope/vim-pathogen">pathogen.vim</a> and then
|
href="https://github.com/Shougo/neobundle.vim">NeoBundle</a> and then just
|
||||||
adding a git submodule for your plugin:
|
add `NeoBundle 'dhruvasagar/vim-table-mode'` to your ~/.vimrc
|
||||||
|
|
||||||
|
2. If you are using <a
|
||||||
|
href="https://github.com/tpope/vim-pathogen">pathogen.vim</a>, then
|
||||||
|
add a git submodule for your plugin:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ cd ~/.vim
|
$ cd ~/.vim
|
||||||
$ git submodule add git@github.com:dhruvasagar/vim-table-mode.git bundle/table-mode
|
$ git submodule add git@github.com:dhruvasagar/vim-table-mode.git bundle/table-mode
|
||||||
```
|
```
|
||||||
2. Copy autoload/todomode.vim, plugin/todo-mode.vim, doc/todo-mode.txt to
|
3. Copy autoload/todomode.vim, plugin/todo-mode.vim, doc/todo-mode.txt to
|
||||||
respective ~/.vim/autoload/, ~/.vim/plugin and ~/.vim/doc under UNIX or
|
respective ~/.vim/autoload/, ~/.vim/plugin and ~/.vim/doc under UNIX or
|
||||||
vimfiles/autoload/, vimfiles/plugin/ and vimfiles/doc under WINDOWS and
|
vimfiles/autoload/, vimfiles/plugin/ and vimfiles/doc under WINDOWS and
|
||||||
restart VIM
|
restart VIM
|
||||||
|
|||||||
13
Rakefile
Normal file
13
Rakefile
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#!/usr/bin/env rake
|
||||||
|
|
||||||
|
task :ci => [:dump, :test]
|
||||||
|
|
||||||
|
task :dump do
|
||||||
|
sh 'vim --version'
|
||||||
|
end
|
||||||
|
|
||||||
|
task :test do
|
||||||
|
sh 'bundle exec vim-flavor test'
|
||||||
|
end
|
||||||
|
|
||||||
|
task :default => :test
|
||||||
1
VimFlavor.lock
Normal file
1
VimFlavor.lock
Normal file
@@ -0,0 +1 @@
|
|||||||
|
kana/vim-vspec (1.1.2)
|
||||||
@@ -4,10 +4,9 @@
|
|||||||
" Author: Dhruva Sagar <http://dhruvasagar.com/>
|
" Author: Dhruva Sagar <http://dhruvasagar.com/>
|
||||||
" License: MIT (http://www.opensource.org/licenses/MIT)
|
" License: MIT (http://www.opensource.org/licenses/MIT)
|
||||||
" Website: http://github.com/dhruvasagar/vim-table-mode
|
" Website: http://github.com/dhruvasagar/vim-table-mode
|
||||||
" Version: 3.1
|
" Version: 3.3.2
|
||||||
" Note: This plugin was heavily inspired by the 'CucumberTables.vim'
|
" Note: This plugin was heavily inspired by the 'CucumberTables.vim'
|
||||||
" (https://gist.github.com/tpope/287147) plugin by Tim Pope and
|
" (https://gist.github.com/tpope/287147) plugin by Tim Pope.
|
||||||
" uses a small amount of code from it.
|
|
||||||
"
|
"
|
||||||
" Copyright Notice:
|
" Copyright Notice:
|
||||||
" Permission is hereby granted to use and distribute this code,
|
" Permission is hereby granted to use and distribute this code,
|
||||||
@@ -67,11 +66,11 @@ function! s:Sum(list) "{{{2
|
|||||||
let result = 0.0
|
let result = 0.0
|
||||||
for item in a:list
|
for item in a:list
|
||||||
if type(item) == type(1) || type(item) == type(1.0)
|
if type(item) == type(1) || type(item) == type(1.0)
|
||||||
let result = result + item
|
let result += item
|
||||||
elseif type(item) == type('')
|
elseif type(item) == type('')
|
||||||
let result = result + str2float(item)
|
let result += str2float(item)
|
||||||
elseif type(item) == type([])
|
elseif type(item) == type([])
|
||||||
let result = result + s:Sum(item)
|
let result += s:Sum(item)
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
return result
|
return result
|
||||||
@@ -113,9 +112,6 @@ function! s:StartExpr() "{{{2
|
|||||||
endif
|
endif
|
||||||
endfunction
|
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
|
function! s:EndExpr() "{{{2
|
||||||
let cend = s:GetCommentEnd()
|
let cend = s:GetCommentEnd()
|
||||||
@@ -126,6 +122,14 @@ function! s:EndExpr() "{{{2
|
|||||||
endif
|
endif
|
||||||
endfunction
|
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
|
function! s:StartCommentExpr() "{{{2
|
||||||
let cstartexpr = s:GetCommentStart()
|
let cstartexpr = s:GetCommentStart()
|
||||||
if s:Strlen(cstartexpr) > 0
|
if s:Strlen(cstartexpr) > 0
|
||||||
@@ -164,13 +168,8 @@ function! s:ToggleMapping() "{{{2
|
|||||||
|
|
||||||
execute "inoremap <silent> <buffer> " . b:table_mode_separator_map . ' ' .
|
execute "inoremap <silent> <buffer> " . b:table_mode_separator_map . ' ' .
|
||||||
\ b:table_mode_separator_map . "<Esc>:call tablemode#TableizeInsertMode()<CR>a"
|
\ b:table_mode_separator_map . "<Esc>:call tablemode#TableizeInsertMode()<CR>a"
|
||||||
|
|
||||||
execute "inoreabbrev <silent> <buffer> " . g:table_mode_corner .
|
|
||||||
\ g:table_mode_fillchar . "<Esc>:call tablemode#AddHeaderBorder('.')<CR>A"
|
|
||||||
else
|
else
|
||||||
execute "iunmap <silent> <buffer> " . b:table_mode_separator_map
|
execute "iunmap <silent> <buffer> " . b:table_mode_separator_map
|
||||||
|
|
||||||
execute "iunabbrev <silent> <buffer> " . g:table_mode_corner . g:table_mode_fillchar
|
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -179,12 +178,28 @@ function! s:SetActive(bool) "{{{2
|
|||||||
call s:ToggleMapping()
|
call s:ToggleMapping()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:DefaultHeaderBorder() "{{{2
|
||||||
|
if s:IsTableModeActive()
|
||||||
|
return g:table_mode_separator . g:table_mode_fillchar . g:table_mode_corner . g:table_mode_fillchar . g:table_mode_separator
|
||||||
|
else
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
|
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
|
||||||
|
if s: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_separator . '\1' . g:table_mode_separator , '')
|
||||||
|
|
||||||
let cstartexpr = s:StartCommentExpr()
|
let cstartexpr = s:StartCommentExpr()
|
||||||
if s:Strlen(cstartexpr) > 0 && getline(line) =~# cstartexpr
|
if s:Strlen(cstartexpr) > 0 && getline(line) =~# cstartexpr
|
||||||
@@ -197,6 +212,8 @@ function! s:GenerateHeaderBorder(line) "{{{2
|
|||||||
else
|
else
|
||||||
return border
|
return border
|
||||||
endif
|
endif
|
||||||
|
else
|
||||||
|
return s:DefaultHeaderBorder()
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -239,9 +256,10 @@ function! s:GetFirstRow(line) "{{{2
|
|||||||
if tablemode#IsATableRow(a:line)
|
if tablemode#IsATableRow(a:line)
|
||||||
let line = s:Line(a:line)
|
let line = s:Line(a:line)
|
||||||
|
|
||||||
while tablemode#IsATableRow(line - s:RowGap())
|
while tablemode#IsATableRow(line - s:RowGap()) || tablemode#IsATableHeader(line - s:RowGap())
|
||||||
let line = line - s:RowGap()
|
let line -= s:RowGap()
|
||||||
endwhile
|
endwhile
|
||||||
|
if tablemode#IsATableHeader(line) | let line += s:RowGap() | endif
|
||||||
|
|
||||||
return line
|
return line
|
||||||
endif
|
endif
|
||||||
@@ -257,9 +275,10 @@ function! s:GetLastRow(line) "{{{2
|
|||||||
if tablemode#IsATableRow(a:line)
|
if tablemode#IsATableRow(a:line)
|
||||||
let line = s:Line(a:line)
|
let line = s:Line(a:line)
|
||||||
|
|
||||||
while tablemode#IsATableRow(line+ s:RowGap())
|
while tablemode#IsATableRow(line + s:RowGap()) || tablemode#IsATableHeader(line + s:RowGap())
|
||||||
let line = line + s:RowGap()
|
let line += s:RowGap()
|
||||||
endwhile
|
endwhile
|
||||||
|
if tablemode#IsATableHeader(line) | let line -= s:RowGap() | endif
|
||||||
|
|
||||||
return line
|
return line
|
||||||
endif
|
endif
|
||||||
@@ -271,6 +290,23 @@ function! s:MoveToLastRow() "{{{2
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:LineNr(row) "{{{2
|
||||||
|
if tablemode#IsATableRow('.')
|
||||||
|
let line = s:GetFirstRow('.')
|
||||||
|
let row_nr = 0
|
||||||
|
|
||||||
|
while tablemode#IsATableRow(line + s:RowGap()) || tablemode#IsATableHeader(line + s:RowGap())
|
||||||
|
if tablemode#IsATableRow(line)
|
||||||
|
let row_nr += 1
|
||||||
|
if row ==# row_nr | break | endif
|
||||||
|
endif
|
||||||
|
let line += s:RowGap()
|
||||||
|
endwhile
|
||||||
|
|
||||||
|
return line
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:MoveToStartOfCell() "{{{2
|
function! s:MoveToStartOfCell() "{{{2
|
||||||
if getline('.')[col('.')-1] ==# g:table_mode_separator && !s:IsLastCell()
|
if getline('.')[col('.')-1] ==# g:table_mode_separator && !s:IsLastCell()
|
||||||
normal! 2l
|
normal! 2l
|
||||||
@@ -295,21 +331,28 @@ function! s:GetCells(line, ...) abort
|
|||||||
let [row, colm] = a:000
|
let [row, colm] = a:000
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let first_row = s:GetFirstRow(line)
|
||||||
if row == 0
|
if row == 0
|
||||||
let values = []
|
let values = []
|
||||||
let line = s:GetFirstRow(line)
|
let line = first_row
|
||||||
while tablemode#IsATableRow(line)
|
while tablemode#IsATableRow(line) || tablemode#IsATableHeader(line)
|
||||||
|
if tablemode#IsATableRow(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, s:Strip(get(split(row_line, g:table_mode_separator), colm>0?colm-1:colm, '')))
|
call add(values, s:Strip(get(split(row_line, g:table_mode_separator), colm>0?colm-1:colm, '')))
|
||||||
let line = line + s:RowGap()
|
endif
|
||||||
|
let line += s:RowGap()
|
||||||
endwhile
|
endwhile
|
||||||
return values
|
return values
|
||||||
else
|
else
|
||||||
if row > 0
|
let row_nr = 0
|
||||||
let line = line + (row - tablemode#RowNr(line)) * s:RowGap()
|
let line = first_row
|
||||||
else
|
while tablemode#IsATableRow(line) || tablemode#IsATableHeader(line)
|
||||||
let line = line + row * s:RowGap()
|
if tablemode#IsATableRow(line)
|
||||||
|
let row_nr += 1
|
||||||
|
if row ==# row_nr | break | endif
|
||||||
endif
|
endif
|
||||||
|
let line += s:RowGap()
|
||||||
|
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)]
|
||||||
if colm == 0
|
if colm == 0
|
||||||
@@ -567,10 +610,17 @@ function! s:Align(lines) "{{{3
|
|||||||
return lines
|
return lines
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
" Public API {{{1
|
" Public API {{{1
|
||||||
|
|
||||||
|
function! tablemode#sid() "{{{2
|
||||||
|
return maparg('<SID>', 'n')
|
||||||
|
endfunction
|
||||||
|
nnoremap <SID> <SID>
|
||||||
|
|
||||||
|
function! tablemode#scope() "{{{2
|
||||||
|
return s:
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! tablemode#GetLastRow(line) "{{{2
|
function! tablemode#GetLastRow(line) "{{{2
|
||||||
return s:GetLastRow(a:line)
|
return s:GetLastRow(a:line)
|
||||||
endfunction
|
endfunction
|
||||||
@@ -611,7 +661,7 @@ function! tablemode#TableizeRange(...) range "{{{2
|
|||||||
while lnum < (a:firstline + (a:lastline - a:firstline + 1)*s:RowGap())
|
while lnum < (a:firstline + (a:lastline - a:firstline + 1)*s:RowGap())
|
||||||
call s:Tableizeline(lnum, a:1)
|
call s:Tableizeline(lnum, a:1)
|
||||||
undojoin
|
undojoin
|
||||||
let lnum = lnum + s:RowGap()
|
let lnum += s:RowGap()
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
call tablemode#TableRealign(lnum - s:RowGap())
|
call tablemode#TableRealign(lnum - s:RowGap())
|
||||||
@@ -634,34 +684,29 @@ 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) || tablemode#IsATableHeader(tline)
|
||||||
call insert(lnums, tline)
|
if tablemode#IsATableHeader(tline)
|
||||||
call insert(lines, getline(tline))
|
call insert(blines, tline)
|
||||||
let tline = tline - s:RowGap()
|
let tline -= s:RowGap()
|
||||||
endwhile
|
continue
|
||||||
|
|
||||||
" 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
|
endif
|
||||||
|
call insert(lnums, tline)
|
||||||
|
call insert(lines, getline(tline))
|
||||||
|
let tline -= s:RowGap()
|
||||||
|
endwhile
|
||||||
|
|
||||||
let tline = line + s:RowGap()
|
let tline = line + s:RowGap()
|
||||||
|
|
||||||
" If we start at header
|
while tablemode#IsATableRow(tline) || tablemode#IsATableHeader(tline)
|
||||||
if !bline && getline(tline) =~# s:HeaderBorderExpr()
|
if tablemode#IsATableHeader(tline)
|
||||||
let bline = tline
|
call insert(blines, tline)
|
||||||
let tline = tline + s:RowGap()
|
let 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 += s:RowGap()
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
let lines = s:Align(lines)
|
let lines = s:Align(lines)
|
||||||
@@ -671,28 +716,37 @@ 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
|
||||||
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
|
||||||
|
return s:LineNr(row)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#RowCount(line) "{{{2
|
function! tablemode#RowCount(line) "{{{2
|
||||||
let line = s:Line(a:line)
|
let line = s:Line(a:line)
|
||||||
|
|
||||||
let [tline, totalRowCount] = [line, 0]
|
let [tline, totalRowCount] = [line, 0]
|
||||||
while tablemode#IsATableRow(tline)
|
while tablemode#IsATableRow(tline) || tablemode#IsATableHeader(tline)
|
||||||
let totalRowCount += 1
|
if tablemode#IsATableRow(tline) | let totalRowCount += 1 | endif
|
||||||
let tline = tline - s:RowGap()
|
let tline -= s:RowGap()
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
let tline = line + s:RowGap()
|
let tline = line + s:RowGap()
|
||||||
while tablemode#IsATableRow(tline)
|
while tablemode#IsATableRow(tline) || tablemode#IsATableHeader(tline)
|
||||||
let totalRowCount += 1
|
if tablemode#IsATableRow(tline) | let totalRowCount += 1 | endif
|
||||||
let tline = tline + s:RowGap()
|
let tline += s:RowGap()
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
return totalRowCount
|
return totalRowCount
|
||||||
@@ -702,9 +756,9 @@ function! tablemode#RowNr(line) "{{{2
|
|||||||
let line = s:Line(a:line)
|
let line = s:Line(a:line)
|
||||||
|
|
||||||
let rowNr = 0
|
let rowNr = 0
|
||||||
while tablemode#IsATableRow(line)
|
while tablemode#IsATableRow(line) || tablemode#IsATableHeader(line)
|
||||||
let rowNr += 1
|
if tablemode#IsATableRow(line) | let rowNr += 1 | endif
|
||||||
let line = line - s:RowGap()
|
let line -= s:RowGap()
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
return rowNr
|
return rowNr
|
||||||
@@ -733,7 +787,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#IsATableRow(line('.') + s:RowGap()) || (tablemode#IsATableHeader(line('.') + s:RowGap()) && tablemode#IsATableRow(line('.') + 2 * s:RowGap()))
|
||||||
|
return
|
||||||
|
endif
|
||||||
call tablemode#TableMotion('j')
|
call tablemode#TableMotion('j')
|
||||||
normal! 0
|
normal! 0
|
||||||
endif
|
endif
|
||||||
@@ -746,7 +802,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#IsATableRow(line('.') - s:RowGap()) || (tablemode#IsATableHeader(line('.') - s:RowGap()) && tablemode#IsATableRow(line('.') - 2 * s:RowGap()))
|
||||||
|
return
|
||||||
|
endif
|
||||||
call tablemode#TableMotion('k')
|
call tablemode#TableMotion('k')
|
||||||
normal! $
|
normal! $
|
||||||
endif
|
endif
|
||||||
@@ -758,9 +816,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()) && tablemode#IsATableRow(line('.') + 2 * 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()) && tablemode#IsATableRow(line('.') - 2 * s:RowGap())
|
||||||
|
execute 'normal! ' . (s:RowGap() + 1) . 'k'
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
@@ -781,8 +847,8 @@ endfunction
|
|||||||
function! tablemode#DeleteColumn() "{{{2
|
function! tablemode#DeleteColumn() "{{{2
|
||||||
if tablemode#IsATableRow('.')
|
if tablemode#IsATableRow('.')
|
||||||
for i in range(v:count1)
|
for i in range(v:count1)
|
||||||
call s:MoveToFirstRow()
|
|
||||||
call s:MoveToStartOfCell()
|
call s:MoveToStartOfCell()
|
||||||
|
call s:MoveToFirstRow()
|
||||||
silent! execute "normal! h\<C-V>f" . g:table_mode_separator
|
silent! execute "normal! h\<C-V>f" . g:table_mode_separator
|
||||||
call s:MoveToLastRow()
|
call s:MoveToLastRow()
|
||||||
normal! d
|
normal! d
|
||||||
@@ -795,15 +861,11 @@ endfunction
|
|||||||
function! tablemode#DeleteRow() "{{{2
|
function! tablemode#DeleteRow() "{{{2
|
||||||
if tablemode#IsATableRow('.')
|
if tablemode#IsATableRow('.')
|
||||||
for i in range(v:count1)
|
for i in range(v:count1)
|
||||||
if tablemode#RowCount('.') ==# 1
|
if tablemode#IsATableRow('.')
|
||||||
normal! kVjjd
|
normal! dd
|
||||||
else
|
|
||||||
normal! kVjd
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if tablemode#IsATableRow(line('.')+1)
|
if !tablemode#IsATableRow('.')
|
||||||
normal! j
|
|
||||||
else
|
|
||||||
normal! k
|
normal! k
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
@@ -852,6 +914,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 tablemode#IsATableHeader(fline) | 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
|
||||||
@@ -940,11 +1003,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 tablemode#IsATableHeader(fline) | 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 tablemode#IsATableHeader(line) | 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
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
*table-mode.txt* Table Mode for easy table formatting. v3.1
|
*table-mode.txt* Table Mode for easy table formatting. v3.3.2
|
||||||
===============================================================================
|
===============================================================================
|
||||||
Table Mode, THE AWESOME AUTOMATIC TABLE CREATOR & FORMATTER
|
Table Mode, THE AWESOME AUTOMATIC TABLE CREATOR & FORMATTER
|
||||||
VERSION 3.1
|
VERSION 3.3.2
|
||||||
|
|
||||||
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/>
|
||||||
@@ -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.
|
||||||
@@ -272,6 +272,12 @@ g:table_mode_eval_expr_map *table-mode-eval-expr-map*
|
|||||||
NOTE you will need to use the |table-mode-map-prefix| before this to
|
NOTE you will need to use the |table-mode-map-prefix| before this to
|
||||||
get the desired effect.
|
get the desired effect.
|
||||||
|
|
||||||
|
g:table_mode_echo_cell_map *table-mode-echo-cell-map*
|
||||||
|
Use this option to define the mapping for echoing current cells
|
||||||
|
representation for defining formulas. >
|
||||||
|
let g:table_mode_echo_cell_map = '?'
|
||||||
|
<
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
MAPPINGS *table-mode-mappings*
|
MAPPINGS *table-mode-mappings*
|
||||||
|
|
||||||
@@ -300,6 +306,9 @@ MAPPINGS *table-mode-mappings*
|
|||||||
*table-mode-mappings-realign*
|
*table-mode-mappings-realign*
|
||||||
<Leader>tr Realigns table columns
|
<Leader>tr Realigns table columns
|
||||||
|
|
||||||
|
<Leader>t? Echo the current table cells representation for defining
|
||||||
|
formulas.
|
||||||
|
|
||||||
*table-mode-mappings-motions*
|
*table-mode-mappings-motions*
|
||||||
<Leader>t[hjkl] Move to previous | below | above | right cell in the table.
|
<Leader>t[hjkl] Move to previous | below | above | right cell in the table.
|
||||||
|
|
||||||
@@ -323,11 +332,9 @@ MAPPINGS *table-mode-mappings*
|
|||||||
would evaluate the formula line and update the table
|
would evaluate the formula line and update the table
|
||||||
accordingly. This invokes the |TableEvalFormulaLine| command.
|
accordingly. This invokes the |TableEvalFormulaLine| command.
|
||||||
|
|
||||||
+- Expands to a header border, the line immidiately above this
|
|| Expands to a header border, the line immidiately above or
|
||||||
will be considered as the table header. You can change this by
|
below this will be considered as the table header. You can
|
||||||
changing |table-mode-corner| and |table-mode-fillchar|
|
change this by changing |table-mode-separator| options.
|
||||||
options. This is an iabbrev so is triggered when you press
|
|
||||||
space or <CR> after typing the mapping.
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
COMMANDS *table-mode-commands*
|
COMMANDS *table-mode-commands*
|
||||||
@@ -399,4 +406,4 @@ REPORT ISSUES *table-mode-report-issues*
|
|||||||
If you discover any issues, please report them at
|
If you discover any issues, please report them at
|
||||||
http://github.com/dhruvasagar/table-mode/issues.
|
http://github.com/dhruvasagar/table-mode/issues.
|
||||||
|
|
||||||
vim:tw=78:ts=8:ft=help:norl:ai
|
vim:tw=78:ts=8:ft=help:norl:ai:et
|
||||||
|
|||||||
@@ -4,10 +4,9 @@
|
|||||||
" Author: Dhruva Sagar <http://dhruvasagar.com/>
|
" Author: Dhruva Sagar <http://dhruvasagar.com/>
|
||||||
" License: MIT (http://www.opensource.org/licenses/MIT)
|
" License: MIT (http://www.opensource.org/licenses/MIT)
|
||||||
" Website: http://github.com/dhruvasagar/vim-table-mode
|
" Website: http://github.com/dhruvasagar/vim-table-mode
|
||||||
" Version: 3.1
|
" Version: 3.3.2
|
||||||
" Note: This plugin was heavily inspired by the 'CucumberTables.vim'
|
" Note: This plugin was heavily inspired by the 'CucumberTables.vim'
|
||||||
" (https://gist.github.com/tpope/287147) plugin by Tim Pope and
|
" (https://gist.github.com/tpope/287147) plugin by Tim Pope.
|
||||||
" uses a small amount of code from it.
|
|
||||||
"
|
"
|
||||||
" Copyright Notice:
|
" Copyright Notice:
|
||||||
" Permission is hereby granted to use and distribute this code,
|
" Permission is hereby granted to use and distribute this code,
|
||||||
@@ -51,6 +50,7 @@ call s:SetGlobalOptDefault('table_mode_delete_row_map', 'dd')
|
|||||||
call s:SetGlobalOptDefault('table_mode_delete_column_map', 'dc')
|
call s:SetGlobalOptDefault('table_mode_delete_column_map', 'dc')
|
||||||
call s:SetGlobalOptDefault('table_mode_add_formula_map', 'fa')
|
call s:SetGlobalOptDefault('table_mode_add_formula_map', 'fa')
|
||||||
call s:SetGlobalOptDefault('table_mode_eval_expr_map', 'fe')
|
call s:SetGlobalOptDefault('table_mode_eval_expr_map', 'fe')
|
||||||
|
call s:SetGlobalOptDefault('table_mode_echo_cell_map', '?')
|
||||||
|
|
||||||
function! s:TableMotion() "{{{1
|
function! s:TableMotion() "{{{1
|
||||||
let direction = nr2char(getchar())
|
let direction = nr2char(getchar())
|
||||||
@@ -59,6 +59,12 @@ function! s:TableMotion() "{{{1
|
|||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:TableEchoCell() "{{{1
|
||||||
|
if tablemode#IsATableRow('.')
|
||||||
|
echomsg '$' . tablemode#RowNr('.') . ',' . tablemode#ColumnNr('.')
|
||||||
|
endif
|
||||||
|
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 .
|
||||||
@@ -102,6 +108,8 @@ execute "nnoremap <silent> " . g:table_mode_map_prefix . g:table_mode_add_formul
|
|||||||
\ " :TableAddFormula<CR>"
|
\ " :TableAddFormula<CR>"
|
||||||
execute "nnoremap <silent> " . g:table_mode_map_prefix . g:table_mode_eval_expr_map .
|
execute "nnoremap <silent> " . g:table_mode_map_prefix . g:table_mode_eval_expr_map .
|
||||||
\ " :TableEvalFormulaLine<CR>"
|
\ " :TableEvalFormulaLine<CR>"
|
||||||
|
execute "nnoremap <silent> " . g:table_mode_map_prefix . g:table_mode_echo_cell_map .
|
||||||
|
\ " :call <SID>TableEchoCell()<CR>"
|
||||||
|
|
||||||
" Avoiding side effects {{{1
|
" Avoiding side effects {{{1
|
||||||
let &cpo = s:save_cpo
|
let &cpo = s:save_cpo
|
||||||
|
|||||||
252
t/tablemode.vim
Normal file
252
t/tablemode.vim
Normal file
@@ -0,0 +1,252 @@
|
|||||||
|
" vim: fdm=indent
|
||||||
|
let g:table_mode_corner = '+'
|
||||||
|
let g:table_mode_separator = '|'
|
||||||
|
let g:table_mode_fillchar = '-'
|
||||||
|
let g:table_mode_map_prefix = '<Leader>t'
|
||||||
|
let g:table_mode_toggle_map = 'm'
|
||||||
|
let g:table_mode_always_active = 0
|
||||||
|
let g:table_mode_delimiter = ','
|
||||||
|
let g:table_mode_tableize_map = 't'
|
||||||
|
let g:table_mode_tableize_op_map = '<Leader>T'
|
||||||
|
let g:table_mode_realign_map = 'r'
|
||||||
|
let g:table_mode_cell_text_object = 'tc'
|
||||||
|
let g:table_mode_delete_row_map = 'dd'
|
||||||
|
let g:table_mode_delete_column_map = 'dc'
|
||||||
|
let g:table_mode_add_formula_map = 'fa'
|
||||||
|
let g:table_mode_eval_expr_map = 'fe'
|
||||||
|
|
||||||
|
call vspec#hint({'scope': 'tablemode#scope()', 'sid': 'tablemode#sid()'})
|
||||||
|
|
||||||
|
describe 'tablemode'
|
||||||
|
describe 'Activation'
|
||||||
|
describe 'tablemode#TableModeEnable()'
|
||||||
|
before
|
||||||
|
call tablemode#TableModeEnable()
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should enable table mode'
|
||||||
|
Expect b:table_mode_active to_be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'tablemode#TableModeDisable()'
|
||||||
|
before
|
||||||
|
call tablemode#TableModeDisable()
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should disable table mode'
|
||||||
|
Expect b:table_mode_active to_be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'tablemode#TableModeToggle()'
|
||||||
|
it 'should toggle table mode'
|
||||||
|
call tablemode#TableModeToggle()
|
||||||
|
Expect b:table_mode_active to_be_true
|
||||||
|
call tablemode#TableModeToggle()
|
||||||
|
Expect b:table_mode_active to_be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'API'
|
||||||
|
before
|
||||||
|
new
|
||||||
|
normal! ggdG
|
||||||
|
call tablemode#TableModeEnable()
|
||||||
|
normal i
|
||||||
|
|test11|test12|
|
||||||
|
|test21|test22|
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return true when inside a table'
|
||||||
|
Expect tablemode#IsATableRow(2) to_be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return false when outside a table'
|
||||||
|
Expect tablemode#IsATableRow(4) to_be_false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return the row count'
|
||||||
|
Expect tablemode#RowCount(2) == 2
|
||||||
|
Expect tablemode#RowCount(3) == 2
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return the row number'
|
||||||
|
Expect tablemode#RowNr(2) == 1
|
||||||
|
Expect tablemode#RowNr(3) == 2
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return the column count'
|
||||||
|
Expect tablemode#ColumnCount(2) == 2
|
||||||
|
Expect tablemode#ColumnCount(3) == 2
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return the line number of the first row'
|
||||||
|
Expect tablemode#GetFirstRow(2) == 2
|
||||||
|
Expect tablemode#GetFirstRow(3) == 2
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return the line nuber of the last row'
|
||||||
|
Expect tablemode#GetLastRow(2) == 3
|
||||||
|
Expect tablemode#GetLastRow(3) == 3
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return the cells'
|
||||||
|
Expect Call('s:GetCells', 2, 1, 1) ==# 'test11'
|
||||||
|
" Get Rows
|
||||||
|
Expect Call('s:GetCells', 2, 1) == ['test11', 'test12']
|
||||||
|
Expect Call('s:GetCells', 2, 2) == ['test21', 'test22']
|
||||||
|
" Get Columns
|
||||||
|
Expect Call('s:GetCells', 2, 0, 1) == ['test11', 'test21']
|
||||||
|
Expect Call('s:GetCells', 2, 0, 2) == ['test12', 'test22']
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return the cells in a range'
|
||||||
|
" Entire table as range
|
||||||
|
Expect Call('s:GetCellRange', '1,1:2,2', 2, 1) == [['test11', 'test21'], ['test12', 'test22']]
|
||||||
|
|
||||||
|
" Get Rows given different seed lines and columns
|
||||||
|
Expect Call('s:GetCellRange', '1,1:1,2', 2, 1) == ['test11', 'test12']
|
||||||
|
Expect Call('s:GetCellRange', '1,1:1,2', 2, 2) == ['test11', 'test12']
|
||||||
|
Expect Call('s:GetCellRange', '1,1:1,2', 3, 1) == ['test11', 'test12']
|
||||||
|
Expect Call('s:GetCellRange', '1,1:1,2', 3, 2) == ['test11', 'test12']
|
||||||
|
Expect Call('s:GetCellRange', '2,1:2,2', 2, 1) == ['test21', 'test22']
|
||||||
|
Expect Call('s:GetCellRange', '2,1:2,2', 2, 2) == ['test21', 'test22']
|
||||||
|
Expect Call('s:GetCellRange', '2,1:2,2', 3, 1) == ['test21', 'test22']
|
||||||
|
Expect Call('s:GetCellRange', '2,1:2,2', 3, 2) == ['test21', 'test22']
|
||||||
|
|
||||||
|
" Get Columns given different seed lines and column
|
||||||
|
Expect Call('s:GetCellRange', '1:2', 2, 1) == ['test11', 'test21']
|
||||||
|
Expect Call('s:GetCellRange', '1:2', 2, 2) == ['test12', 'test22']
|
||||||
|
Expect Call('s:GetCellRange', '1:2', 3, 1) == ['test11', 'test21']
|
||||||
|
Expect Call('s:GetCellRange', '1:2', 3, 2) == ['test12', 'test22']
|
||||||
|
|
||||||
|
" Get Column given negative values in range for representing rows from
|
||||||
|
" the end, -1 being the second last row.
|
||||||
|
Expect Call('s:GetCellRange', '1:-1', 2, 1) == ['test11']
|
||||||
|
Expect Call('s:GetCellRange', '1:-1', 3, 1) == ['test11']
|
||||||
|
Expect Call('s:GetCellRange', '1:-1', 2, 2) == ['test12']
|
||||||
|
Expect Call('s:GetCellRange', '1:-1', 3, 2) == ['test12']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'Tableize'
|
||||||
|
before
|
||||||
|
new
|
||||||
|
normal! ggdG
|
||||||
|
normal i
|
||||||
|
asd,asd;asd,asd
|
||||||
|
asd,asd;asd,asd
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should tableize with default delimiter'
|
||||||
|
:2,3call tablemode#TableizeRange('')
|
||||||
|
Expect tablemode#IsATableRow(2) to_be_true
|
||||||
|
Expect tablemode#RowCount(2) == 2
|
||||||
|
Expect tablemode#ColumnCount(2) == 3
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should tableize with given delimiter'
|
||||||
|
:2,3call tablemode#TableizeRange('/;')
|
||||||
|
Expect tablemode#IsATableRow(2) to_be_true
|
||||||
|
Expect tablemode#RowCount(2) == 2
|
||||||
|
Expect tablemode#ColumnCount(2) == 2
|
||||||
|
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#ColumnNr('.') == 2
|
||||||
|
call tablemode#TableMotion('h')
|
||||||
|
Expect tablemode#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#RowNr('.') == 2
|
||||||
|
Expect tablemode#ColumnNr('.') == 1
|
||||||
|
call tablemode#TableMotion('h')
|
||||||
|
Expect tablemode#RowNr('.') == 1
|
||||||
|
Expect tablemode#ColumnNr('.') == 2
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should move right when not on last column'
|
||||||
|
Expect tablemode#ColumnNr('.') == 1
|
||||||
|
call tablemode#TableMotion('l')
|
||||||
|
Expect tablemode#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#RowNr('.') == 1
|
||||||
|
Expect tablemode#ColumnNr('.') == 2
|
||||||
|
call tablemode#TableMotion('l')
|
||||||
|
Expect tablemode#RowNr('.') == 2
|
||||||
|
Expect tablemode#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#RowNr('.') == 2
|
||||||
|
call tablemode#TableMotion('k')
|
||||||
|
Expect tablemode#RowNr('.') == 1
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should remain on first row when trying to move up'
|
||||||
|
Expect tablemode#RowNr('.') == 1
|
||||||
|
call tablemode#TableMotion('k')
|
||||||
|
Expect tablemode#RowNr('.') == 1
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should move a row down unless on last row'
|
||||||
|
Expect tablemode#RowNr('.') == 1
|
||||||
|
call tablemode#TableMotion('j')
|
||||||
|
Expect tablemode#RowNr('.') == 2
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should remain on last row when trying to move down'
|
||||||
|
Expect tablemode#RowNr('.') == 1
|
||||||
|
call tablemode#TableMotion('k')
|
||||||
|
Expect tablemode#RowNr('.') == 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'Manipulations'
|
||||||
|
before
|
||||||
|
new
|
||||||
|
normal! ggdG
|
||||||
|
normal i|test11|test12|
|
||||||
|
|test21|test22|
|
||||||
|
call cursor(1, 3)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should delete a row successfully'
|
||||||
|
Expect tablemode#RowCount('.') == 2
|
||||||
|
call tablemode#DeleteRow()
|
||||||
|
Expect tablemode#RowCount('.') == 1
|
||||||
|
end
|
||||||
|
|
||||||
Reference in New Issue
Block a user