Merge pull request #207 from jdorel/feature-cellcolor

feat(highlight): color cell if contains yes,no,?
This commit is contained in:
Dhruva Sagar
2021-10-05 22:43:52 +05:30
committed by GitHub
2 changed files with 26 additions and 2 deletions

View File

@@ -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

View File

@@ -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,14 @@ 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[^|]*' contained
syntax match noCell '|\@<= *no[^|]*' contained
syntax match maybeCell '|\@<= *?[^|]*' contained
" '|\@<=' : Match previous characters, excluding them from the group
endif
else
syntax clear Table
syntax clear TableBorder
@@ -234,3 +243,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 |