From c949912bfacf9ee5ac9f672b09b97540001b9eac Mon Sep 17 00:00:00 2001 From: Jonas DOREL Date: Tue, 5 Oct 2021 15:32:30 +0200 Subject: [PATCH 1/2] feat(highlight): color cell if contains yes,no,? --- README.md | 11 +++++++++++ autoload/tablemode.vim | 16 ++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8bcacb8..ab2dec6 100644 --- a/README.md +++ b/README.md @@ -187,6 +187,17 @@ it using `:TableModeRealign` or using the default mapping cursor. Both can also be preceeded with a [count] to insert multiple columns. +### Highlight cells based on content + + You can highlight cells based on content by setting `let g:table_mode_color_cells` : + - cells starting with `yes` will use the `yesCell` highlight group. + - cells starting with `no` will use the `noCell` highlight group. + - cells starting with `?` will use the `maybeCell` hightlight group. + + You can overwrite any highlight group. For exemple use `hi yesCell ctermfg=2` to remove the background color. + + + ## Advanced Usage: Spreadsheet Capabilities ### Table Formulas diff --git a/autoload/tablemode.vim b/autoload/tablemode.vim index 07ab643..cb430e8 100644 --- a/autoload/tablemode.vim +++ b/autoload/tablemode.vim @@ -71,7 +71,8 @@ function! s:ToggleSyntax() "{{{2 if tablemode#IsActive() exec 'syntax match Table' \ '/' . tablemode#table#StartExpr() . '\zs|.\+|\ze' . tablemode#table#EndExpr() . '/' - \ 'contains=TableBorder,TableSeparator,TableColumnAlign containedin=ALL' + \ 'contains=TableBorder,TableSeparator,TableColumnAlign,yesCell,noCell,maybeCell' + \ 'containedin=ALL' syntax match TableSeparator /|/ contained syntax match TableColumnAlign /:/ contained syntax match TableBorder /[\-+]\+/ contained @@ -79,6 +80,13 @@ function! s:ToggleSyntax() "{{{2 hi! link TableBorder Delimiter hi! link TableSeparator Delimiter hi! link TableColumnAlign Type + + if exists("g:table_mode_color_cells") && g:table_mode_color_cells + syntax match yesCell '[^|]*yes[^|]*' + syntax match noCell ' *no[^|]*' + syntax match maybeCell ' *?[^|]*' + endif + else syntax clear Table syntax clear TableBorder @@ -170,7 +178,7 @@ endfunction function! tablemode#TableizeInsertMode() "{{{2 if tablemode#IsActive() - if getline('.') =~# (tablemode#table#StartExpr() . g:table_mode_separator . g:table_mode_separator . tablemode#table#EndExpr()) + if getline('.') =~# (tablemode#table#StartExpr() . g:table_mode_separator . g:table_mode_separator . tablemode#table#EndExpr()) call tablemode#table#AddBorder('.') normal! A elseif getline('.') =~# (tablemode#table#StartExpr() . g:table_mode_separator) @@ -234,3 +242,7 @@ function! tablemode#TableizeByDelimiter() "{{{2 exec line("'<") . ',' . line("'>") . "call tablemode#TableizeRange('/' . delim)" endif endfunction + +if !hlexists('yesCell') | hi yesCell cterm=bold ctermfg=10 ctermbg=2 | endif | +if !hlexists('noCell') | hi noCell cterm=bold ctermfg=9 ctermbg=1 | endif | +if !hlexists('maybeCell') | hi maybeCell cterm=bold ctermfg=11 ctermbg=3 | endif | From e5dc853ee3a28191de5a23925c71adb6a723132d Mon Sep 17 00:00:00 2001 From: Jonas DOREL Date: Tue, 5 Oct 2021 17:29:47 +0200 Subject: [PATCH 2/2] fix(highlight): disable highlight when word before --- autoload/tablemode.vim | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/autoload/tablemode.vim b/autoload/tablemode.vim index cb430e8..b9b26df 100644 --- a/autoload/tablemode.vim +++ b/autoload/tablemode.vim @@ -82,9 +82,10 @@ function! s:ToggleSyntax() "{{{2 hi! link TableColumnAlign Type if exists("g:table_mode_color_cells") && g:table_mode_color_cells - syntax match yesCell '[^|]*yes[^|]*' - syntax match noCell ' *no[^|]*' - syntax match maybeCell ' *?[^|]*' + syntax match yesCell '|\@<= *yes[^|]*' contained + syntax match noCell '|\@<= *no[^|]*' contained + syntax match maybeCell '|\@<= *?[^|]*' contained + " '|\@<=' : Match previous characters, excluding them from the group endif else