diff --git a/after/plugin/table-mode.vim b/after/plugin/table-mode.vim index 7bd8830..c5cc39b 100644 --- a/after/plugin/table-mode.vim +++ b/after/plugin/table-mode.vim @@ -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', 'tm') +call s:SetGlobalOptDefault('table_mode_toggle_map', 'tm') call s:SetGlobalOptDefault('table_mode_always_active', 0) call s:SetGlobalOptDefault('table_mode_delimiter', ',') call s:SetGlobalOptDefault('table_mode_tableize_map', '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 instead + if g:table_mode_separator ==# '|' | let table_mode_separator_map = '' | endif + + execute "inoremap " . table_mode_separator_map . ' ' . + \ table_mode_separator_map . ":call tablemode#TableizeInsertMode()a" + unlet table_mode_separator_map endif command! -nargs=0 -range Tableize ,call tablemode#TableizeRange() diff --git a/autoload/tablemode.vim b/autoload/tablemode.vim index 4398453..b2ddb59 100644 --- a/autoload/tablemode.vim +++ b/autoload/tablemode.vim @@ -48,21 +48,16 @@ function! s:IsTableModeActive() "{{{2 endfunction " }}}2 -function! s:TableModeSeparatorMap() "{{{2 - if g:table_mode_separator ==# '|' - return '' - 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 " . s:TableModeSeparatorMap() . ' ' . - \ s:TableModeSeparatorMap() . ":call Tableize()a" + call s:SetBufferOptDefault('table_mode_separator_map', g:table_mode_separator) + " '|' is a special character, we need to map instead + if g:table_mode_separator ==# '|' | let b:table_mode_separator_map = '' | endif + + execute "inoremap " . b:table_mode_separator_map . ' ' . + \ b:table_mode_separator_map . ":call tablemode#TableizeInsertMode()a" else - execute "iunmap " . s:TableModeSeparatorMap() + execute "iunmap " . 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