mirror of
https://github.com/dhruvasagar/vim-table-mode.git
synced 2025-11-08 11:03:47 -05:00
Fixed #4
This commit is contained in:
@@ -45,7 +45,7 @@ call s:SetGlobalOptDefault('table_mode_border', 1)
|
||||
call s:SetGlobalOptDefault('table_mode_corner', '+')
|
||||
call s:SetGlobalOptDefault('table_mode_separator', '|')
|
||||
call s:SetGlobalOptDefault('table_mode_fillchar', '-')
|
||||
call s:SetGlobalOptDefault('table_mode_toggle_map', '<Leader>tm')
|
||||
call s:SetGlobalOptDefault('table_mode_toggle_map', '<LocalLeader>tm')
|
||||
call s:SetGlobalOptDefault('table_mode_always_active', 0)
|
||||
call s:SetGlobalOptDefault('table_mode_delimiter', ',')
|
||||
call s:SetGlobalOptDefault('table_mode_tableize_map', '<Leader>T')
|
||||
@@ -59,6 +59,14 @@ if !g:table_mode_always_active
|
||||
command! -nargs=0 TableModeToggle call tablemode#TableModeToggle()
|
||||
command! -nargs=0 TableModeEnable call tablemode#TableModeEnable()
|
||||
command! -nargs=0 TableModeDisable call tablemode#TableModeDisable()
|
||||
else
|
||||
let table_mode_separator_map = g:table_mode_separator
|
||||
" '|' is a special character, we need to map <Bar> instead
|
||||
if g:table_mode_separator ==# '|' | let table_mode_separator_map = '<Bar>' | endif
|
||||
|
||||
execute "inoremap <silent> " . table_mode_separator_map . ' ' .
|
||||
\ table_mode_separator_map . "<Esc>:call tablemode#TableizeInsertMode()<CR>a"
|
||||
unlet table_mode_separator_map
|
||||
endif
|
||||
|
||||
command! -nargs=0 -range Tableize <line1>,<line2>call tablemode#TableizeRange()
|
||||
|
||||
@@ -48,21 +48,16 @@ function! s:IsTableModeActive() "{{{2
|
||||
endfunction
|
||||
" }}}2
|
||||
|
||||
function! s:TableModeSeparatorMap() "{{{2
|
||||
if g:table_mode_separator ==# '|'
|
||||
return '<Bar>'
|
||||
else
|
||||
return g:table_mode_separator
|
||||
endif
|
||||
endfunction
|
||||
" }}}2
|
||||
|
||||
function! s:ToggleMapping() "{{{2
|
||||
if exists('b:table_mode_active') && b:table_mode_active
|
||||
execute "inoremap <silent> <buffer> " . s:TableModeSeparatorMap() . ' ' .
|
||||
\ s:TableModeSeparatorMap() . "<Esc>:call <SID>Tableize()<CR>a"
|
||||
call s:SetBufferOptDefault('table_mode_separator_map', g:table_mode_separator)
|
||||
" '|' is a special character, we need to map <Bar> instead
|
||||
if g:table_mode_separator ==# '|' | let b:table_mode_separator_map = '<Bar>' | endif
|
||||
|
||||
execute "inoremap <silent> <buffer> " . b:table_mode_separator_map . ' ' .
|
||||
\ b:table_mode_separator_map . "<Esc>:call tablemode#TableizeInsertMode()<CR>a"
|
||||
else
|
||||
execute "iunmap <silent> " . s:TableModeSeparatorMap()
|
||||
execute "iunmap <silent> <buffer> " . b:table_mode_separator_map
|
||||
endif
|
||||
endfunction
|
||||
" }}}2
|
||||
@@ -110,19 +105,6 @@ function! s:FillTableBorder() "{{{2
|
||||
endfunction
|
||||
" }}}2
|
||||
|
||||
function! s:Tableize() "{{{2
|
||||
if s:IsTableModeActive() && getline('.') =~# ('^\s*' . g:table_mode_separator)
|
||||
let column = s:Strlen(substitute(getline('.')[0:col('.')], '[^' . g:table_mode_separator . ']', '', 'g'))
|
||||
let position = s:Strlen(matchstr(getline('.')[0:col('.')], '.*' . g:table_mode_separator . '\s*\zs.*'))
|
||||
if g:table_mode_border | call s:UpdateLineBorder(line('.')) | endif
|
||||
execute 'Tabularize/[' . g:table_mode_separator . g:table_mode_corner . ']/' . g:table_mode_align
|
||||
if g:table_mode_border | call s:FillTableBorder() | endif
|
||||
normal! 0
|
||||
call search(repeat('[^' . g:table_mode_separator . ']*' . g:table_mode_separator, column) . '\s\{-\}' . repeat('.', position), 'ce', line('.'))
|
||||
endif
|
||||
endfunction
|
||||
" }}}2
|
||||
|
||||
function! s:ConvertDelimiterToSeparator(line) "{{{2
|
||||
execute 'silent! ' . a:line . 's/^\s*\zs\ze.\|' . g:table_mode_delimiter .
|
||||
\ '\|$/' . g:table_mode_separator . '/g'
|
||||
@@ -140,6 +122,19 @@ endfunction
|
||||
|
||||
" Public API {{{1
|
||||
|
||||
function! tablemode#TableizeInsertMode() "{{{2
|
||||
if s:IsTableModeActive() && getline('.') =~# ('^\s*' . g:table_mode_separator)
|
||||
let column = s:Strlen(substitute(getline('.')[0:col('.')], '[^' . g:table_mode_separator . ']', '', 'g'))
|
||||
let position = s:Strlen(matchstr(getline('.')[0:col('.')], '.*' . g:table_mode_separator . '\s*\zs.*'))
|
||||
if g:table_mode_border | call s:UpdateLineBorder(line('.')) | endif
|
||||
execute 'Tabularize/[' . g:table_mode_separator . g:table_mode_corner . ']/' . g:table_mode_align
|
||||
if g:table_mode_border | call s:FillTableBorder() | endif
|
||||
normal! 0
|
||||
call search(repeat('[^' . g:table_mode_separator . ']*' . g:table_mode_separator, column) . '\s\{-\}' . repeat('.', position), 'ce', line('.'))
|
||||
endif
|
||||
endfunction
|
||||
" }}}2
|
||||
|
||||
function! tablemode#TableModeEnable() "{{{2
|
||||
call s:SetActive(1)
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user