mirror of
https://github.com/dhruvasagar/vim-table-mode.git
synced 2025-11-08 11:03:47 -05:00
Define separator map in one place as a global; add separator map target for separators other than |
This commit is contained in:
@@ -22,13 +22,9 @@ function! s:UnMap(map, mode) "{{{2
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:ToggleMapping() "{{{2
|
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 !g:table_mode_disable_mappings
|
if !g:table_mode_disable_mappings
|
||||||
if tablemode#IsActive()
|
if tablemode#IsActive()
|
||||||
call s:Map('<Plug>(table-mode-tableize)', separator_map, 'i')
|
call s:Map('<Plug>(table-mode-tableize)', g:table_mode_separator_map, 'i')
|
||||||
call s:Map('<Plug>(table-mode-motion-up)', g:table_mode_motion_up_map, 'n')
|
call s:Map('<Plug>(table-mode-motion-up)', g:table_mode_motion_up_map, 'n')
|
||||||
call s:Map('<Plug>(table-mode-motion-down)', g:table_mode_motion_down_map, 'n')
|
call s:Map('<Plug>(table-mode-motion-down)', g:table_mode_motion_down_map, 'n')
|
||||||
call s:Map('<Plug>(table-mode-motion-left)', g:table_mode_motion_left_map, 'n')
|
call s:Map('<Plug>(table-mode-motion-left)', g:table_mode_motion_left_map, 'n')
|
||||||
@@ -47,7 +43,7 @@ function! s:ToggleMapping() "{{{2
|
|||||||
call s:Map('<Plug>(table-mode-echo-cell)', g:table_mode_echo_cell_map, 'n')
|
call s:Map('<Plug>(table-mode-echo-cell)', g:table_mode_echo_cell_map, 'n')
|
||||||
call s:Map('<Plug>(table-mode-sort)', g:table_mode_sort_map, 'n')
|
call s:Map('<Plug>(table-mode-sort)', g:table_mode_sort_map, 'n')
|
||||||
else
|
else
|
||||||
call s:UnMap(separator_map, 'i')
|
call s:UnMap(g:table_mode_separator_map, 'i')
|
||||||
call s:UnMap(g:table_mode_motion_up_map, 'n')
|
call s:UnMap(g:table_mode_motion_up_map, 'n')
|
||||||
call s:UnMap(g:table_mode_motion_down_map, 'n')
|
call s:UnMap(g:table_mode_motion_down_map, 'n')
|
||||||
call s:UnMap(g:table_mode_motion_left_map, 'n')
|
call s:UnMap(g:table_mode_motion_left_map, 'n')
|
||||||
@@ -207,7 +203,7 @@ endfunction
|
|||||||
function! tablemode#TableizeRange(...) range "{{{2
|
function! tablemode#TableizeRange(...) range "{{{2
|
||||||
let lnum = a:firstline
|
let lnum = a:firstline
|
||||||
let total = (a:lastline - a:firstline + 1)
|
let total = (a:lastline - a:firstline + 1)
|
||||||
echom total
|
" echom total
|
||||||
let cntr = 1
|
let cntr = 1
|
||||||
while cntr <= total
|
while cntr <= total
|
||||||
call s:Tableizeline(lnum, a:1)
|
call s:Tableizeline(lnum, a:1)
|
||||||
|
|||||||
@@ -18,6 +18,13 @@ endfunction
|
|||||||
call s:SetGlobalOptDefault('table_mode_corner', '+')
|
call s:SetGlobalOptDefault('table_mode_corner', '+')
|
||||||
call s:SetGlobalOptDefault('table_mode_verbose', 1)
|
call s:SetGlobalOptDefault('table_mode_verbose', 1)
|
||||||
call s:SetGlobalOptDefault('table_mode_separator', '|')
|
call s:SetGlobalOptDefault('table_mode_separator', '|')
|
||||||
|
" '|' is a special character, we need to map <Bar> instead
|
||||||
|
" the character to map from
|
||||||
|
let g:table_mode_separator_map = get(g:, 'table_mode_separator_map', g:table_mode_separator)
|
||||||
|
if g:table_mode_separator_map ==# '|' | let g:table_mode_separator_map = '<Bar>' | endif
|
||||||
|
" the character to map to (when inserting the separator)
|
||||||
|
let g:table_mode_separator_map_target = g:table_mode_separator
|
||||||
|
if g:table_mode_separator_map_target ==# '|' | let g:table_mode_separator_map_target = '<Bar>' | endif
|
||||||
call s:SetGlobalOptDefault('table_mode_escaped_separator_regex', '\V\C\\\@1<!'.escape(g:table_mode_separator, '\'))
|
call s:SetGlobalOptDefault('table_mode_escaped_separator_regex', '\V\C\\\@1<!'.escape(g:table_mode_separator, '\'))
|
||||||
call s:SetGlobalOptDefault('table_mode_fillchar', '-')
|
call s:SetGlobalOptDefault('table_mode_fillchar', '-')
|
||||||
call s:SetGlobalOptDefault('table_mode_header_fillchar', '-')
|
call s:SetGlobalOptDefault('table_mode_header_fillchar', '-')
|
||||||
@@ -62,19 +69,15 @@ function! s:TableEchoCell() "{{{1
|
|||||||
endfunction
|
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 ":<C-U>call tablemode#Toggle()<CR>"
|
exec "nnoremap <silent>" g:table_mode_map_prefix . g:table_mode_toggle_map ":<C-U>call tablemode#Toggle()<CR>"
|
||||||
command! -nargs=0 TableModeToggle call tablemode#Toggle()
|
command! -nargs=0 TableModeToggle call tablemode#Toggle()
|
||||||
command! -nargs=0 TableModeEnable call tablemode#Enable()
|
command! -nargs=0 TableModeEnable call tablemode#Enable()
|
||||||
command! -nargs=0 TableModeDisable call tablemode#Disable()
|
command! -nargs=0 TableModeDisable call tablemode#Disable()
|
||||||
else
|
else
|
||||||
let table_mode_separator_map = g:table_mode_separator
|
execute "inoremap <silent> " . g:table_mode_separator_map . ' ' .
|
||||||
" '|' is a special character, we need to map <Bar> instead
|
\ g:table_mode_separator_map_target . "<Esc>:call tablemode#TableizeInsertMode()<CR>a"
|
||||||
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
|
endif
|
||||||
" }}}2
|
" }}}2
|
||||||
|
|
||||||
@@ -84,9 +87,7 @@ 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
|
execute 'inoremap <silent> <Plug>(table-mode-tableize)' g:table_mode_separator_map . '<Esc>:call tablemode#TableizeInsertMode()<CR>a'
|
||||||
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>
|
||||||
|
|||||||
Reference in New Issue
Block a user