mirror of
https://github.com/dhruvasagar/vim-table-mode.git
synced 2025-11-08 11:03:47 -05:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a6a9b3473 | ||
|
|
aa8817621c | ||
|
|
54187d0be1 | ||
|
|
3e2eaeee5c | ||
|
|
6dfc508af5 | ||
|
|
ed441f19a1 | ||
|
|
e4525c465a | ||
|
|
19bfa092a3 | ||
|
|
f91ec2458f | ||
|
|
0799523ffb |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
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
|
||||
@@ -1,4 +1,9 @@
|
||||
# Change Log
|
||||
## 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
|
||||
|
||||
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.2)
|
||||
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/soulmate_rails)
|
||||
|
||||
An awesome automatic table creator & formatter allowing one to create neat
|
||||
tables as you type.
|
||||
@@ -11,17 +11,21 @@ CHANGELOG.md </a>
|
||||
## Getting Started
|
||||
### Installation
|
||||
|
||||
There are 2 ways to do this
|
||||
There are several ways to do this
|
||||
|
||||
1. I recommend installing <a
|
||||
href="https://github.com/tpope/vim-pathogen">pathogen.vim</a> and then
|
||||
adding a git submodule for your plugin:
|
||||
href="https://github.com/Shougo/neobundle.vim">NeoBundle</a> and then just
|
||||
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
|
||||
$ cd ~/.vim
|
||||
$ 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
|
||||
vimfiles/autoload/, vimfiles/plugin/ and vimfiles/doc under WINDOWS and
|
||||
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,7 +4,7 @@
|
||||
" Author: Dhruva Sagar <http://dhruvasagar.com/>
|
||||
" License: MIT (http://www.opensource.org/licenses/MIT)
|
||||
" Website: http://github.com/dhruvasagar/vim-table-mode
|
||||
" Version: 3.1
|
||||
" Version: 3.2
|
||||
" Note: This plugin was heavily inspired by the 'CucumberTables.vim'
|
||||
" (https://gist.github.com/tpope/287147) plugin by Tim Pope and
|
||||
" uses a small amount of code from it.
|
||||
@@ -113,9 +113,6 @@ function! s:StartExpr() "{{{2
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:HeaderBorderExpr() "{{{2
|
||||
return '^\s*' . g:table_mode_corner . '[' . g:table_mode_fillchar . g:table_mode_corner . ']*' . g:table_mode_corner . '$'
|
||||
endfunction
|
||||
|
||||
function! s:EndExpr() "{{{2
|
||||
let cend = s:GetCommentEnd()
|
||||
@@ -126,6 +123,14 @@ function! s:EndExpr() "{{{2
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:HeaderBorderExpr() "{{{2
|
||||
return s:StartExpr() .
|
||||
\ '[' . g:table_mode_corner . g:table_mode_separator . ']' .
|
||||
\ '[' . g:table_mode_fillchar . g:table_mode_corner . ']*' .
|
||||
\ '[' . g:table_mode_corner . g:table_mode_separator . ']' .
|
||||
\ s:EndExpr()
|
||||
endfunction
|
||||
|
||||
function! s:StartCommentExpr() "{{{2
|
||||
let cstartexpr = s:GetCommentStart()
|
||||
if s:Strlen(cstartexpr) > 0
|
||||
@@ -165,12 +170,12 @@ function! s:ToggleMapping() "{{{2
|
||||
execute "inoremap <silent> <buffer> " . b:table_mode_separator_map . ' ' .
|
||||
\ b:table_mode_separator_map . "<Esc>:call tablemode#TableizeInsertMode()<CR>a"
|
||||
|
||||
execute "inoreabbrev <silent> <buffer> " . g:table_mode_corner .
|
||||
execute "inoremap <silent> <buffer> " . g:table_mode_corner .
|
||||
\ g:table_mode_fillchar . " <Esc>:call tablemode#AddHeaderBorder('.')<CR>A"
|
||||
else
|
||||
execute "iunmap <silent> <buffer> " . b:table_mode_separator_map
|
||||
|
||||
execute "iunabbrev <silent> <buffer> " . g:table_mode_corner . g:table_mode_fillchar
|
||||
execute "iunmap <silent> <buffer> " . g:table_mode_corner . g:table_mode_fillchar
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -185,6 +190,7 @@ function! s:GenerateHeaderBorder(line) "{{{2
|
||||
let line_val = getline(line - s:RowGap())
|
||||
let border = substitute(line_val[stridx(line_val, g:table_mode_separator):strridx(line_val, g:table_mode_separator)], g:table_mode_separator, g:table_mode_corner, 'g')
|
||||
let border = substitute(border, '[^' . g:table_mode_corner . ']', g:table_mode_fillchar, 'g')
|
||||
let border = substitute(border, '^' . g:table_mode_corner . '\(.*\)' . g:table_mode_corner . '$', g:table_mode_separator . '\1' . g:table_mode_separator , '')
|
||||
|
||||
let cstartexpr = s:StartCommentExpr()
|
||||
if s:Strlen(cstartexpr) > 0 && getline(line) =~# cstartexpr
|
||||
@@ -571,6 +577,15 @@ endfunction
|
||||
|
||||
" 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
|
||||
return s:GetLastRow(a:line)
|
||||
endfunction
|
||||
@@ -677,7 +692,23 @@ function! tablemode#TableRealign(line) "{{{2
|
||||
endfunction
|
||||
|
||||
function! tablemode#IsATableRow(line) "{{{2
|
||||
return getline(a:line) =~# (s:StartExpr() . g:table_mode_separator)
|
||||
return getline(a:line) =~# (s:StartExpr() . g:table_mode_separator . '[^' .
|
||||
\ g:table_mode_fillchar . ']*[^' . g:table_mode_corner . ']*$')
|
||||
endfunction
|
||||
|
||||
function! tablemode#IsATableHeader(line) "{{{2
|
||||
return getline(a:line) =~# s:HeaderBorderExpr()
|
||||
endfunction
|
||||
|
||||
function! tablemode#LineNr(row) "{{{2
|
||||
if tablemode#IsATableRow('.')
|
||||
let line = s:Line('.')
|
||||
let row = tablemode#RowNr('.')
|
||||
if a:row != row
|
||||
let line += a:row - row
|
||||
endif
|
||||
return line
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! tablemode#RowCount(line) "{{{2
|
||||
@@ -733,7 +764,9 @@ function! tablemode#TableMotion(direction) "{{{2
|
||||
if tablemode#IsATableRow('.')
|
||||
if a:direction ==# 'l'
|
||||
if s:IsLastCell()
|
||||
if !tablemode#IsATableRow(line('.') + s:RowGap()) | return | endif
|
||||
if !tablemode#IsATableHeader(line('.') + s:RowGap()) && !tablemode#IsATableRow(line('.') + s:RowGap())
|
||||
return
|
||||
endif
|
||||
call tablemode#TableMotion('j')
|
||||
normal! 0
|
||||
endif
|
||||
@@ -746,7 +779,9 @@ function! tablemode#TableMotion(direction) "{{{2
|
||||
endif
|
||||
elseif a:direction ==# 'h'
|
||||
if s:IsFirstCell()
|
||||
if !tablemode#IsATableRow(line('.') - s:RowGap()) | return | endif
|
||||
if !tablemode#IsATableHeader(line('.') - s:RowGap()) && !tablemode#IsATableRow(line('.') - s:RowGap())
|
||||
return
|
||||
endif
|
||||
call tablemode#TableMotion('k')
|
||||
normal! $
|
||||
endif
|
||||
@@ -758,9 +793,17 @@ function! tablemode#TableMotion(direction) "{{{2
|
||||
execute 'normal! 2F' . g:table_mode_separator . '2l'
|
||||
endif
|
||||
elseif a:direction ==# 'j'
|
||||
if tablemode#IsATableRow(line('.') + s:RowGap()) | execute 'normal ' . s:RowGap() . 'j' | endif
|
||||
if tablemode#IsATableRow(line('.') + s:RowGap())
|
||||
execute 'normal ' . s:RowGap() . 'j'
|
||||
elseif tablemode#IsATableHeader(line('.') + s:RowGap())
|
||||
execute 'normal ' . (s:RowGap() + 1) . 'j'
|
||||
endif
|
||||
elseif a:direction ==# 'k'
|
||||
if tablemode#IsATableRow(line('.') - s:RowGap()) | execute 'normal ' . s:RowGap() . 'k' | endif
|
||||
if tablemode#IsATableRow(line('.') - s:RowGap())
|
||||
execute 'normal ' . s:RowGap() . 'k'
|
||||
elseif tablemode#IsATableHeader(line('.') - s:RowGap())
|
||||
execute 'normal ' . (s:RowGap() + 1) . 'k'
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
@@ -781,7 +824,21 @@ endfunction
|
||||
function! tablemode#DeleteColumn() "{{{2
|
||||
if tablemode#IsATableRow('.')
|
||||
for i in range(v:count1)
|
||||
call s:MoveToFirstRow()
|
||||
call s:MoveToStartOfCell()
|
||||
|
||||
if tablemode#IsATableRow(line('.') + 1)
|
||||
call s:MoveToFirstRow()
|
||||
" If we have a header delete it first
|
||||
if tablemode#IsATableRow(line('.')-2)
|
||||
call cursor(line('.')-2, col('.'))
|
||||
silent! execute "normal! h\<C-V>f" . g:table_mode_separator
|
||||
normal! jdjj
|
||||
endif
|
||||
else " We're already on the header
|
||||
silent! execute "normal! h\<C-V>f" . g:table_mode_separator
|
||||
normal! jdjj
|
||||
endif
|
||||
|
||||
call s:MoveToStartOfCell()
|
||||
silent! execute "normal! h\<C-V>f" . g:table_mode_separator
|
||||
call s:MoveToLastRow()
|
||||
@@ -795,15 +852,11 @@ endfunction
|
||||
function! tablemode#DeleteRow() "{{{2
|
||||
if tablemode#IsATableRow('.')
|
||||
for i in range(v:count1)
|
||||
if tablemode#RowCount('.') ==# 1
|
||||
normal! kVjjd
|
||||
else
|
||||
normal! kVjd
|
||||
if tablemode#IsATableRow('.')
|
||||
normal! dd
|
||||
endif
|
||||
|
||||
if tablemode#IsATableRow(line('.')+1)
|
||||
normal! j
|
||||
else
|
||||
if !tablemode#IsATableRow('.')
|
||||
normal! k
|
||||
endif
|
||||
endfor
|
||||
|
||||
@@ -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.2
|
||||
===============================================================================
|
||||
Table Mode, THE AWESOME AUTOMATIC TABLE CREATOR & FORMATTER
|
||||
VERSION 3.1
|
||||
VERSION 3.2
|
||||
|
||||
Author: Dhruva Sagar <http://dhruvasagar.com/>
|
||||
License: MIT <http://opensource.org/licenses/MIT/>
|
||||
@@ -29,7 +29,7 @@ GETTING STARTED *table-mode-getting-started*
|
||||
|
||||
Create Table on the fly:
|
||||
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
|
||||
each additional separator you add, it aligns the table properly,
|
||||
without having to do anything else.
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
" Author: Dhruva Sagar <http://dhruvasagar.com/>
|
||||
" License: MIT (http://www.opensource.org/licenses/MIT)
|
||||
" Website: http://github.com/dhruvasagar/vim-table-mode
|
||||
" Version: 3.1
|
||||
" Version: 3.2
|
||||
" Note: This plugin was heavily inspired by the 'CucumberTables.vim'
|
||||
" (https://gist.github.com/tpope/287147) plugin by Tim Pope and
|
||||
" uses a small amount of code from it.
|
||||
|
||||
162
t/tablemode.vim
Normal file
162
t/tablemode.vim
Normal file
@@ -0,0 +1,162 @@
|
||||
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
|
||||
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
|
||||
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'
|
||||
it 'should work'
|
||||
TODO
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Manipulations'
|
||||
it 'should work'
|
||||
Reference in New Issue
Block a user