commit 825870ec1b845867eadb801ca6ad905be3d20418
parent fc056cfecadc24887dff8df184b66fcd9ee69f14
Author: Tinmarino <tinmarino@gmail.com>
Date: Tue, 4 Aug 2020 17:44:37 -0400
Fix: Highlight borken with done item rided by code (Issue #971)
Diffstat:
4 files changed, 86 insertions(+), 17 deletions(-)
diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim
@@ -436,8 +436,15 @@ function! vimwiki#base#generate_links(create, ...) abort
let link_caption = link
endif
+ " Replace Url, Description
let entry = s:safesubstitute(link_tpl, '__LinkUrl__', link, '')
let entry = s:safesubstitute(entry, '__LinkDescription__', link_caption, '')
+
+ " Replace Extension
+ let wiki_nr = vimwiki#vars#get_bufferlocal('wiki_nr')
+ let extension = vimwiki#vars#get_wikilocal('ext', wiki_nr)
+ let entry = substitute(entry, '__FileExtension__', extension, 'g')
+
call add(lines, bullet. entry)
endif
endfor
diff --git a/autoload/vimwiki/u.vim b/autoload/vimwiki/u.vim
@@ -219,6 +219,14 @@ function! vimwiki#u#ft_is_vw() abort
endfunction
+" Helper: Getter
+" :param: syntax <string> to retrive, default to current
+function! vimwiki#u#get_syntax_dic(...) abort
+ let syntax = a:0 ? a:1 : vimwiki#vars#get_wikilocal('syntax')
+ return g:vimwiki_syntax_variables[syntax]
+endfunction
+
+
" Helper: Expand regex from reduced typeface delimiters
" :param: list<list,delimiters>> with reduced regex
" Return: list with extended regex delimiters (not inside a word)
@@ -269,19 +277,19 @@ function! vimwiki#u#hi_typeface(dic) abort
" Italic must go before, otherwise single * takes precedence over ** and ** is considered as
" -- a void italic.
" Note:
- " -- The last syntax defined take precedence so that user can change at runtime (:h :syn-define)
- " -- Some cases are contained by default:
- " -- -- ex: VimwikiCodeBoldUnderline is not defined in colorschemes -> VimwikiCode
- " -- -- see: #709 asking for concealing quotes in bold, so it must be higlighted differently
- " -- -- -- for the user to understand what is concealed around
+ " The last syntax defined take precedence so that user can change at runtime (:h :syn-define)
+ " Some cases are contained by default:
+ " -- ex: VimwikiCodeBoldUnderline is not defined in colorschemes -> VimwikiCode
+ " -- see: #709 asking for concealing quotes in bold, so it must be higlighted differently
+ " -- -- for the user to understand what is concealed around
+ " VimwikiCheckBoxDone and VimwikiDelText are as their are even when nested in bold or italic
+ " -- This is because it would add a lot of code (as n**2) at startup and is not often used
+ " -- Here n=3 (bold, italic, underline)
" Bold > Italic > Underline
- " Declare nesting capabilities
- " -- to be embeded in standard: bold, italic, underline
- let nested = 'VimwikiCode,VimwikiEqIn,VimwikiDelText,VimwikiSuperScript,VimwikiSubScript'
- " -- to be embeded in exetended (the one above)
- let nested .= ',VimwikiBold,VimwikiItalic,VimwikiUmderline'
+ let nested = vimwiki#u#get_syntax_dic().nested
+ " Italic
for i in a:dic['italic']
" -- Italic 1
call vimwiki#u#hi_tag(i[0], i[1], 'VimwikiItalic ', nested .',VimwikiItalicBold,VimwikiItalicUnderline')
@@ -295,6 +303,7 @@ function! vimwiki#u#hi_typeface(dic) abort
call vimwiki#u#hi_tag(i[0], i[1], 'VimwikiUnderlineBoldItalic', nested, 2)
endfor
+ " Bold
for b in a:dic['bold']
" -- Bold 1
call vimwiki#u#hi_tag(b[0],b[1], 'VimwikiBold', nested . ',VimwikiBoldUnderline,VimwikiBoldItalic')
@@ -308,12 +317,14 @@ function! vimwiki#u#hi_typeface(dic) abort
call vimwiki#u#hi_tag(b[0], b[1], 'VimwikiUnderlineItalicBold', nested, 2)
endfor
+ " Bold Italic
if has_key(a:dic, 'bold_italic')
for bi in a:dic['bold_italic']
call vimwiki#u#hi_tag(bi[0], bi[1], 'VimwikiBoldItalic', nested . ',VimwikiBoldItalicUnderline')
endfor
endif
+ " Underline
for u in a:dic['underline']
" -- Underline 1
call vimwiki#u#hi_tag(u[0], u[1], 'VimwikiUnderline', nested . ',VimwikiUnderlineBold,VimwikiUnderlineItalic')
@@ -327,16 +338,17 @@ function! vimwiki#u#hi_typeface(dic) abort
call vimwiki#u#hi_tag(u[0], u[1], 'VimwikiItalicBoldUnderline', nested, 2)
endfor
+ " Strikethrough
+ " Note: VimwikiBoldDelText Not Implemented (see above)
+ for u in a:dic['del']
+ call vimwiki#u#hi_tag(u[0], u[1], 'VimwikiDelText', nested)
+ endfor
+
"" Code do not contain anything but can be contained very nested
for u in a:dic['code']
call vimwiki#u#hi_tag(u[0], u[1], 'VimwikiCode', '')
endfor
- " Deleted
- for u in a:dic['del']
- call vimwiki#u#hi_tag(u[0], u[1], 'VimwikiDelText', nested)
- endfor
-
"" Equation
for u in a:dic['eq']
call vimwiki#u#hi_tag(u[0], u[1], 'VimwikiEqIn', nested)
diff --git a/syntax/vimwiki.vim b/syntax/vimwiki.vim
@@ -21,9 +21,15 @@ let b:vimwiki_syntax_concealends = has('conceal') ? ' concealends' : ''
" Populate all syntax vars
" Include syntax/vimwiki_markdown.vim as "side effect"
call vimwiki#vars#populate_syntax_vars(s:current_syntax)
-
let syntax_dic = g:vimwiki_syntax_variables[s:current_syntax]
+" Declare nesting capabilities
+" -- to be embeded in standard: bold, italic, underline
+let syntax_dic.nested_extended = 'VimwikiCode,VimwikiEqIn,VimwikiSuperScript,VimwikiSubScript'
+" -- to be embeded in exetended (the one above)
+let syntax_dic.nested_typeface = 'VimwikiBold,VimwikiItalic,VimwikiUmderline,VimwikiDelText'
+let syntax_dic.nested = syntax_dic.nested_extended . ',' . syntax_dic.nested_typeface
+
" text: `code` or ``code`` only inline
" Note: `\%(^\|[^`]\)\@<=` means after a new line or a non `
let syntax_dic.dTypeface.code = [
@@ -264,11 +270,13 @@ execute 'syntax match VimwikiList /'.vimwiki#vars#get_wikilocal('rxListItemWitho
execute 'syntax match VimwikiList /'.vimwiki#vars#get_syntaxlocal('rxListDefine').'/'
execute 'syntax match VimwikiListTodo /'.vimwiki#vars#get_wikilocal('rxListItem').'/'
+" Task list done
if vimwiki#vars#get_global('hl_cb_checked') == 1
execute 'syntax match VimwikiCheckBoxDone /'.vimwiki#vars#get_wikilocal('rxListItemWithoutCB')
\ . '\s*\[['.vimwiki#vars#get_wikilocal('listsyms_list')[-1]
\ . vimwiki#vars#get_global('listsym_rejected')
- \ . ']\]\s.*$/ contains=VimwikiNoExistsLink,VimwikiLink,VimwikiWeblink1,VimwikiWikiLink1,@Spell'
+ \ . ']\]\s\(.*\)$/ '
+ \ . 'contains=' . syntax_dic.nested . ',VimwikiNoExistsLink,VimwikiLink,VimwikiWeblink1,VimwikiWikiLink1,@Spell'
elseif vimwiki#vars#get_global('hl_cb_checked') == 2
execute 'syntax match VimwikiCheckBoxDone /'
\ . vimwiki#vars#get_wikilocal('rxListItemAndChildren')
@@ -332,6 +340,9 @@ endif
let s:typeface_dic = vimwiki#vars#get_syntaxlocal('dTypeface')
call vimwiki#u#hi_typeface(s:typeface_dic)
+" Link highlighting groups
+""""""""""""""""""""""""""
+
hi def link VimwikiMarkers Normal
hi def link VimwikiError Normal
diff --git a/test/syntax.vader b/test/syntax.vader
@@ -4,6 +4,45 @@
# 1 Typeface {{{1
#################
+# With vimwiki_hl_cb_checked {{{2
+
+Given vimwiki (task list with code):
+ Normal syntax
+ - [X] Lorem __sit__ `sed do eiusmod
+ tempor` incididunt ut labore et dolore magna aliqua
+ Normal syntax
+
+Execute (let g:vimwiki_hl_cb_checked = 1):
+ let g:vimwiki_hl_cb_checked = 1
+ unlet g:vimwiki_syntax_variables
+ call vimwiki#vars#init()
+ call SetSyntax('markdown')
+
+Execute (Assert Done Syntax 1):
+ AssertEqual '' , SyntaxAt(1, 7)
+ AssertEqual 'VimwikiCheckBoxDone', SyntaxAt(2, 7)
+ AssertEqual 'VimwikiCode' , SyntaxAt(3, 7)
+ AssertEqual '' , SyntaxAt(4, 7)
+
+Given vimwiki (task list with code):
+ Normal syntax
+ - [X] Lorem __sit__ `sed do eiusmod
+ tempor` incididunt ut labore et dolore magna aliqua
+ Normal syntax
+
+Execute (let g:vimwiki_hl_cb_checked = 2):
+ let g:vimwiki_hl_cb_checked = 2
+ unlet g:vimwiki_syntax_variables
+ call vimwiki#vars#init()
+ call SetSyntax('markdown')
+
+Execute (Assert Done Syntax 2):
+ AssertEqual '' , SyntaxAt(1, 7)
+ AssertEqual 'VimwikiCheckBoxDone', SyntaxAt(2, 7)
+ AssertEqual 'VimwikiCheckBoxDone', SyntaxAt(3, 7)
+ AssertEqual '' , SyntaxAt(4, 7)
+
+
# Extended types {{{2
Given vimwiki (Extended Types mono):