mirror of
https://github.com/dhruvasagar/vim-table-mode.git
synced 2025-11-08 11:03:47 -05:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c91a4efa2 | ||
|
|
8d9a0082f5 | ||
|
|
0f1254e1fe | ||
|
|
e7e806916f | ||
|
|
9336261063 | ||
|
|
a5ae0253be | ||
|
|
80ec86e385 | ||
|
|
7eff1e30f1 | ||
|
|
7258a56d20 |
13
CHANGELOG.md
13
CHANGELOG.md
@@ -1,4 +1,13 @@
|
|||||||
# Change Log
|
# Change Log
|
||||||
|
|
||||||
|
## Version 4.5.0
|
||||||
|
* Refactored toggled mappings
|
||||||
|
* Table Syntax now gets toggled with Table Mode
|
||||||
|
|
||||||
|
## Version 4.4.2
|
||||||
|
* Updated mappings to be buffer local.
|
||||||
|
* Updated mappings to toggle and function only when table mode is active.
|
||||||
|
|
||||||
## Version 4.4.1
|
## Version 4.4.1
|
||||||
* Added syntax for matching tables
|
* Added syntax for matching tables
|
||||||
|
|
||||||
@@ -106,3 +115,7 @@
|
|||||||
|
|
||||||
## Version 1.0 :
|
## Version 1.0 :
|
||||||
* First stable release, create tables as you type.
|
* First stable release, create tables as you type.
|
||||||
|
|
||||||
|
<!--
|
||||||
|
vim: ft=markdown
|
||||||
|
-->
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# VIM Table Mode v4.4.1 [](https://travis-ci.org/dhruvasagar/vim-table-mode)
|
# VIM Table Mode v4.5.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.
|
||||||
|
|||||||
@@ -32,21 +32,90 @@ function! s:SetBufferOptDefault(opt, val) "{{{2
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:ToggleMapping() "{{{2
|
function! s:Map(map, to, mode)
|
||||||
if exists('b:table_mode_active') && b:table_mode_active
|
if !hasmapto(a:map, a:mode)
|
||||||
call s:SetBufferOptDefault('table_mode_separator_map', g:table_mode_separator)
|
for l:mode in split(a:mode, '.\zs')
|
||||||
" '|' is a special character, we need to map <Bar> instead
|
execute l:mode . 'map <buffer>' a:to a:map
|
||||||
if g:table_mode_separator ==# '|' | let b:table_mode_separator_map = '<Bar>' | endif
|
endfor
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
execute "inoremap <silent> <buffer> " . b:table_mode_separator_map . ' ' .
|
function! s:UnMap(map, mode)
|
||||||
\ b:table_mode_separator_map . "<Esc>:call tablemode#TableizeInsertMode()<CR>a"
|
if !empty(maparg(a:map, a:mode))
|
||||||
|
for mode in split(a:mode, '.\zs')
|
||||||
|
execute l:mode . 'unmap <buffer>' a:map
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:ToggleMapping() "{{{2
|
||||||
|
let separator_map = g:table_mode_separator
|
||||||
|
" '|' is a special character, we need to map <Bar> instead
|
||||||
|
if g:table_mode_separator ==# '|' | let separator_map = '<Bar>' | endif
|
||||||
|
|
||||||
|
if tablemode#IsActive()
|
||||||
|
call s:Map('<Plug>(table-mode-tableize)', separator_map, 'i')
|
||||||
|
call s:Map('<Plug>(table-mode-motion-up)', '{<Bar>', 'n')
|
||||||
|
call s:Map('<Plug>(table-mode-motion-down)', '}<Bar>', 'n')
|
||||||
|
call s:Map('<Plug>(table-mode-motion-left)', '[<Bar>', 'n')
|
||||||
|
call s:Map('<Plug>(table-mode-motion-right)', ']<Bar>', 'n')
|
||||||
|
|
||||||
|
call s:Map('<Plug>(table-mode-cell-text-object-a)', 'a<Bar>', 'ox')
|
||||||
|
call s:Map('<Plug>(table-mode-cell-text-object-i)', 'i<Bar>', 'ox')
|
||||||
|
|
||||||
|
call s:Map('<Plug>(table-mode-realign)', '<Leader>tr', 'n')
|
||||||
|
call s:Map('<Plug>(table-mode-delete-row)', '<Leader>tdd', 'n')
|
||||||
|
call s:Map('<Plug>(table-mode-delete-column)', '<Leader>tdc', 'n')
|
||||||
|
call s:Map('<Plug>(table-mode-add-formula)', '<Leader>tfa', 'n')
|
||||||
|
call s:Map('<Plug>(table-mode-eval-formula)', '<Leader>tfe', 'n')
|
||||||
|
call s:Map('<Plug>(table-mode-echo-cell)', '<Leader>t?', 'n')
|
||||||
else
|
else
|
||||||
silent! execute "iunmap <silent> <buffer> " . b:table_mode_separator_map
|
call s:UnMap(separator_map, 'i')
|
||||||
|
call s:UnMap('{<Bar>', 'n')
|
||||||
|
call s:UnMap('}<Bar>', 'n')
|
||||||
|
call s:UnMap('[<Bar>', 'n')
|
||||||
|
call s:UnMap(']<Bar>', 'n')
|
||||||
|
call s:UnMap('a<Bar>', 'o')
|
||||||
|
call s:UnMap('i<Bar>', 'o')
|
||||||
|
call s:UnMap('<Leader>tdd', 'n')
|
||||||
|
call s:UnMap('<Leader>tdc', 'n')
|
||||||
|
call s:UnMap('<Leader>tfa', 'n')
|
||||||
|
call s:UnMap('<Leader>tfe', 'n')
|
||||||
|
call s:UnMap('<Leader>t?', 'n')
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! tablemode#SyntaxEnable()
|
||||||
|
exec 'syntax match Table'
|
||||||
|
\ '/' . tablemode#table#StartExpr() . '\zs|.\+|\ze' . tablemode#table#EndExpr() . '/'
|
||||||
|
\ 'contains=TableBorder,TableSeparator,TableColumnAlign containedin=ALL'
|
||||||
|
syntax match TableSeparator /|/ contained
|
||||||
|
syntax match TableColumnAlign /:/ contained
|
||||||
|
syntax match TableBorder /[\-+]\+/ contained
|
||||||
|
|
||||||
|
hi! link TableBorder Delimiter
|
||||||
|
hi! link TableSeparator Delimiter
|
||||||
|
hi! link TableColumnAlign Type
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:ToggleSyntax()
|
||||||
|
if tablemode#IsActive()
|
||||||
|
call tablemode#SyntaxEnable()
|
||||||
|
else
|
||||||
|
syntax clear Table
|
||||||
|
syntax clear TableBorder
|
||||||
|
syntax clear TableSeparator
|
||||||
|
syntax clear TableColumnAlign
|
||||||
|
|
||||||
|
hi! link TableBorder NONE
|
||||||
|
hi! link TableSeparator NONE
|
||||||
|
hi! link TableColumnAlign NONE
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:SetActive(bool) "{{{2
|
function! s:SetActive(bool) "{{{2
|
||||||
let b:table_mode_active = a:bool
|
let b:table_mode_active = a:bool
|
||||||
|
call s:ToggleSyntax()
|
||||||
call s:ToggleMapping()
|
call s:ToggleMapping()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ function! tablemode#align#alignments(lnum, ncols) "{{{2
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! tablemode#align#Align(lines) "{{{2
|
function! tablemode#align#Align(lines) "{{{2
|
||||||
|
if empty(a:lines) | return [] | endif
|
||||||
let lines = map(a:lines, 'map(v:val, "v:key =~# \"text\" ? tablemode#align#Split(v:val, g:table_mode_separator) : v:val")')
|
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
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
*table-mode.txt* Table Mode for easy table formatting. v4.4.1
|
*table-mode.txt* Table Mode for easy table formatting. v4.5.0
|
||||||
===============================================================================
|
===============================================================================
|
||||||
Table Mode, THE AWESOME AUTOMATIC TABLE CREATOR & FORMATTER
|
Table Mode, THE AWESOME AUTOMATIC TABLE CREATOR & FORMATTER
|
||||||
VERSION 4.4.1
|
VERSION 4.5.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/>
|
||||||
|
|||||||
@@ -50,23 +50,12 @@ function! s:TableEchoCell() "{{{1
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:EnableTableSyntax() "{{{1
|
|
||||||
syntax match Table /^\s*|.\+|\s*$/ contains=TableBorder,TableSeparator,TableColumnAlign containedin=ALL
|
|
||||||
syntax match TableSeparator /|/ contained
|
|
||||||
syntax match TableColumnAlign /:/ contained
|
|
||||||
syntax match TableBorder /[\-+]\+/ contained
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
augroup TableMode
|
augroup TableMode
|
||||||
au!
|
au!
|
||||||
|
|
||||||
autocmd Syntax * call <SID>EnableTableSyntax()
|
autocmd Syntax * if tablemode#IsActive() | call tablemode#SyntaxEnable() | endif
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
hi! link TableBorder Delimiter
|
|
||||||
hi! link TableSeparator Delimiter
|
|
||||||
hi! link TableColumnAlign Type
|
|
||||||
|
|
||||||
" 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 .
|
||||||
@@ -90,6 +79,10 @@ command! TableAddFormula call tablemode#spreadsheet#formula#Add()
|
|||||||
command! TableModeRealign call tablemode#table#Realign('.')
|
command! TableModeRealign call tablemode#table#Realign('.')
|
||||||
command! TableEvalFormulaLine call tablemode#spreadsheet#formula#EvaluateFormulaLine()
|
command! TableEvalFormulaLine call tablemode#spreadsheet#formula#EvaluateFormulaLine()
|
||||||
|
|
||||||
|
" '|' is a special character, we need to map <Bar> instead
|
||||||
|
if g:table_mode_separator ==# '|' | let separator_map = '<Bar>' | endif
|
||||||
|
execute 'inoremap <silent> <Plug>(table-mode-tableize)' separator_map . '<Esc>:call tablemode#TableizeInsertMode()<CR>a'
|
||||||
|
|
||||||
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>
|
||||||
@@ -103,6 +96,8 @@ nnoremap <silent> <Plug>(table-mode-motion-right) :<C-U>call tablemode#spreadshe
|
|||||||
|
|
||||||
onoremap <silent> <Plug>(table-mode-cell-text-object-a) :<C-U>call tablemode#spreadsheet#cell#TextObject(0)<CR>
|
onoremap <silent> <Plug>(table-mode-cell-text-object-a) :<C-U>call tablemode#spreadsheet#cell#TextObject(0)<CR>
|
||||||
onoremap <silent> <Plug>(table-mode-cell-text-object-i) :<C-U>call tablemode#spreadsheet#cell#TextObject(1)<CR>
|
onoremap <silent> <Plug>(table-mode-cell-text-object-i) :<C-U>call tablemode#spreadsheet#cell#TextObject(1)<CR>
|
||||||
|
xnoremap <silent> <Plug>(table-mode-cell-text-object-a) :<C-U>call tablemode#spreadsheet#cell#TextObject(0)<CR>
|
||||||
|
xnoremap <silent> <Plug>(table-mode-cell-text-object-i) :<C-U>call tablemode#spreadsheet#cell#TextObject(1)<CR>
|
||||||
|
|
||||||
nnoremap <silent> <Plug>(table-mode-delete-row) :call tablemode#spreadsheet#DeleteRow()<CR>
|
nnoremap <silent> <Plug>(table-mode-delete-row) :call tablemode#spreadsheet#DeleteRow()<CR>
|
||||||
nnoremap <silent> <Plug>(table-mode-delete-column) :call tablemode#spreadsheet#DeleteColumn()<CR>
|
nnoremap <silent> <Plug>(table-mode-delete-column) :call tablemode#spreadsheet#DeleteColumn()<CR>
|
||||||
@@ -121,48 +116,6 @@ if !hasmapto('<Plug>(table-mode-tableize-delimiter)')
|
|||||||
xmap <Leader>T <Plug>(table-mode-tableize-delimiter)
|
xmap <Leader>T <Plug>(table-mode-tableize-delimiter)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !hasmapto('<Plug>(table-mode-realign)')
|
|
||||||
nmap <Leader>tr <Plug>(table-mode-realign)
|
|
||||||
endif
|
|
||||||
|
|
||||||
if !hasmapto('<Plug>(table-mode-motion-up)')
|
|
||||||
nmap {<Bar> <Plug>(table-mode-motion-up)
|
|
||||||
endif
|
|
||||||
if !hasmapto('<Plug>(table-mode-motion-down)')
|
|
||||||
nmap }<Bar> <Plug>(table-mode-motion-down)
|
|
||||||
endif
|
|
||||||
if !hasmapto('<Plug>(table-mode-motion-left)')
|
|
||||||
nmap [<Bar> <Plug>(table-mode-motion-left)
|
|
||||||
endif
|
|
||||||
if !hasmapto('<Plug>(table-mode-motion-right)')
|
|
||||||
nmap ]<Bar> <Plug>(table-mode-motion-right)
|
|
||||||
endif
|
|
||||||
|
|
||||||
if !hasmapto('<Plug>(table-mode-cell-text-object-a)')
|
|
||||||
omap a<Bar> <Plug>(table-mode-cell-text-object-a)
|
|
||||||
endif
|
|
||||||
if !hasmapto('<Plug>(table-mode-cell-text-object-i)')
|
|
||||||
omap i<Bar> <Plug>(table-mode-cell-text-object-i)
|
|
||||||
endif
|
|
||||||
|
|
||||||
if !hasmapto('<Plug>(table-mode-delete-row)')
|
|
||||||
nmap <Leader>tdd <Plug>(table-mode-delete-row)
|
|
||||||
endif
|
|
||||||
if !hasmapto('<Plug>(table-mode-delete-column)')
|
|
||||||
nmap <Leader>tdc <Plug>(table-mode-delete-column)
|
|
||||||
endif
|
|
||||||
|
|
||||||
if !hasmapto('<Plug>(table-mode-add-formula)')
|
|
||||||
nmap <Leader>tfa <Plug>(table-mode-add-formula)
|
|
||||||
endif
|
|
||||||
if !hasmapto('<Plug>(table-mode-eval-formula)')
|
|
||||||
nmap <Leader>tfe <Plug>(table-mode-eval-formula)
|
|
||||||
endif
|
|
||||||
|
|
||||||
if !hasmapto('<Plug>(table-mode-echo-cell)')
|
|
||||||
nmap <Leader>t? <Plug>(table-mode-echo-cell)
|
|
||||||
endif
|
|
||||||
|
|
||||||
" Avoiding side effects {{{1
|
" Avoiding side effects {{{1
|
||||||
let &cpo = s:save_cpo
|
let &cpo = s:save_cpo
|
||||||
|
|
||||||
|
|||||||
18
t/cell.vim
18
t/cell.vim
@@ -64,20 +64,19 @@ describe 'cell'
|
|||||||
before
|
before
|
||||||
new
|
new
|
||||||
normal! ggdG
|
normal! ggdG
|
||||||
call tablemode#Enable()
|
read t/fixtures/sample.txt
|
||||||
normal i|test11|test12|
|
call cursor(2, 3)
|
||||||
|test21|test22|
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should move left when not on first column'
|
it 'should move left when not on first column'
|
||||||
it 'should move left when not on first column'
|
call cursor(2, 12)
|
||||||
Expect tablemode#spreadsheet#ColumnNr('.') == 2
|
Expect tablemode#spreadsheet#ColumnNr('.') == 2
|
||||||
call tablemode#spreadsheet#cell#Motion('h')
|
call tablemode#spreadsheet#cell#Motion('h')
|
||||||
Expect tablemode#spreadsheet#ColumnNr('.') == 1
|
Expect tablemode#spreadsheet#ColumnNr('.') == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should move to the previous row last column if it exists when on first column'
|
it 'should move to the previous row last column if it exists when on first column'
|
||||||
it 'should move to the previous row last column if it exists when on first column'
|
call cursor(3, 3)
|
||||||
Expect tablemode#spreadsheet#RowNr('.') == 2
|
Expect tablemode#spreadsheet#RowNr('.') == 2
|
||||||
Expect tablemode#spreadsheet#ColumnNr('.') == 1
|
Expect tablemode#spreadsheet#ColumnNr('.') == 1
|
||||||
call tablemode#spreadsheet#cell#Motion('h')
|
call tablemode#spreadsheet#cell#Motion('h')
|
||||||
@@ -92,7 +91,7 @@ describe 'cell'
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'should move to the next row first column if it exists when on last column'
|
it 'should move to the next row first column if it exists when on last column'
|
||||||
it 'should move to the next row first column if it exists when on last column'
|
call cursor(2, 12)
|
||||||
Expect tablemode#spreadsheet#RowNr('.') == 1
|
Expect tablemode#spreadsheet#RowNr('.') == 1
|
||||||
Expect tablemode#spreadsheet#ColumnNr('.') == 2
|
Expect tablemode#spreadsheet#ColumnNr('.') == 2
|
||||||
call tablemode#spreadsheet#cell#Motion('l')
|
call tablemode#spreadsheet#cell#Motion('l')
|
||||||
@@ -105,13 +104,12 @@ describe 'cell'
|
|||||||
before
|
before
|
||||||
new
|
new
|
||||||
normal! ggdG
|
normal! ggdG
|
||||||
normal! ggdG
|
read t/fixtures/sample.txt
|
||||||
call tablemode#Enable()
|
call cursor(2, 3)
|
||||||
normal i|test11|test12|
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should move a row up unless on first row'
|
it 'should move a row up unless on first row'
|
||||||
|
call cursor(3, 3)
|
||||||
Expect tablemode#spreadsheet#RowNr('.') == 2
|
Expect tablemode#spreadsheet#RowNr('.') == 2
|
||||||
call tablemode#spreadsheet#cell#Motion('k')
|
call tablemode#spreadsheet#cell#Motion('k')
|
||||||
Expect tablemode#spreadsheet#RowNr('.') == 1
|
Expect tablemode#spreadsheet#RowNr('.') == 1
|
||||||
|
|||||||
@@ -88,9 +88,8 @@ describe 'spreadsheet'
|
|||||||
before
|
before
|
||||||
new
|
new
|
||||||
normal! ggdG
|
normal! ggdG
|
||||||
call tablemode#Enable()
|
read t/fixtures/sample.txt
|
||||||
normal i|test11|test12|
|
call cursor(2, 3)
|
||||||
|test21|test22|
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should delete a row successfully'
|
it 'should delete a row successfully'
|
||||||
|
|||||||
Reference in New Issue
Block a user