From 0f1254e1fe1308c56104d7b41c14b76bfd1df076 Mon Sep 17 00:00:00 2001 From: Dhruva Sagar Date: Fri, 30 May 2014 12:05:31 +0530 Subject: [PATCH] Updated table syntax to get toggled with table mode --- autoload/tablemode.vim | 29 +++++++++++++++++++++++++++++ plugin/table-mode.vim | 15 +-------------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/autoload/tablemode.vim b/autoload/tablemode.vim index 73e0789..11eea8e 100644 --- a/autoload/tablemode.vim +++ b/autoload/tablemode.vim @@ -85,8 +85,37 @@ function! s:ToggleMapping() "{{{2 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 +endfunction + function! s:SetActive(bool) "{{{2 let b:table_mode_active = a:bool + call s:ToggleSyntax() call s:ToggleMapping() endfunction diff --git a/plugin/table-mode.vim b/plugin/table-mode.vim index 5c3731a..75fd16d 100644 --- a/plugin/table-mode.vim +++ b/plugin/table-mode.vim @@ -50,25 +50,12 @@ function! s:TableEchoCell() "{{{1 endif endfunction -function! s:EnableTableSyntax() "{{{1 - 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 -endfunction - augroup TableMode au! - autocmd Syntax * call EnableTableSyntax() + autocmd Syntax * if tablemode#IsActive() | call tablemode#SyntaxEnable() | endif augroup END -hi! link TableBorder Delimiter -hi! link TableSeparator Delimiter -hi! link TableColumnAlign Type - " Define Commands & Mappings {{{1 if !g:table_mode_always_active "{{{2 exec "nnoremap " . g:table_mode_map_prefix . g:table_mode_toggle_map .