diff --git a/autoload/vimwiki/vars.vim b/autoload/vimwiki/vars.vim index c8af7a5..98a4978 100644 --- a/autoload/vimwiki/vars.vim +++ b/autoload/vimwiki/vars.vim @@ -598,84 +598,59 @@ function! vimwiki#vars#populate_syntax_vars(syntax) abort let g:vimwiki_syntax_variables[a:syntax] = {} let syntax_dic = g:vimwiki_syntax_variables[a:syntax] + " Init Typeface (filled in custom syntax) + let syntax_dic.dTypeface = {} + " Autoload default syntax file execute 'runtime! syntax/vimwiki_'.a:syntax.'.vim' - " text: `code` or ``code`` only inline - " Note: `\%(^\|[^`]\)\@<=` means after a new line or a non ` - let syntax_dic.dTypeface['code'] = [ - \ ['\%(^\|[^`]\)\@<=`\%($\|[^`]\)\@=', - \ '\%(^\|[^`]\)\@<=`\%($\|[^`]\)\@='], - \ ['\%(^\|[^`]\)\@<=``\%($\|[^`]\)\@=', - \ '\%(^\|[^`]\)\@<=``\%($\|[^`]\)\@='], - \ ] - - " text: ~~deleted text~~ - let syntax_dic.dTypeface['del'] = ([ - \ ['\~\~', '\~\~']]) - - " text: $ equation_inline $ - " Match only one $ - " ( ^ or not $) before $ and after: not $ - let syntax_dic.dTypeface['eq'] = ([ - \ ['\%(^\|[^$]\)\@<=\$\%($\|[^$]\)\@=', - \ '\%(^\|[^$]\)\@<=\$\%($\|[^$]\)\@=']]) - - " text: ^superscript^ - let syntax_dic.dTypeface['sup'] = ([ - \ ['\^', '\^']]) - - " text: ,,subscript,, - let syntax_dic.dTypeface['sub'] = ([ - \ [',,', ',,']]) - " TODO make that clean (i.e clearify what is local to syntax ot to buffer) " Get from local vars let bullet_types = vimwiki#vars#get_wikilocal('bullet_types') if !empty(bullet_types) - let g:vimwiki_syntax_variables[a:syntax]['bullet_types'] = bullet_types + let syntax_dic['bullet_types'] = bullet_types endif - let g:vimwiki_syntax_variables[a:syntax]['cycle_bullets'] = + let syntax_dic['cycle_bullets'] = \ vimwiki#vars#get_wikilocal('cycle_bullets') " Populate generic stuff - let header_symbol = g:vimwiki_syntax_variables[a:syntax].rxH - if g:vimwiki_syntax_variables[a:syntax].symH + let header_symbol = syntax_dic.rxH + if syntax_dic.symH " symmetric headers for i in range(1,6) - let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Template'] = + let syntax_dic['rxH'.i.'_Template'] = \ repeat(header_symbol, i).' __Header__ '.repeat(header_symbol, i) - let g:vimwiki_syntax_variables[a:syntax]['rxH'.i] = + let syntax_dic['rxH'.i] = \ '^\s*'.header_symbol.'\{'.i.'}[^'.header_symbol.'].*[^'.header_symbol.']' \ .header_symbol.'\{'.i.'}\s*$' - let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Text'] = + let syntax_dic['rxH'.i.'_Text'] = \ '^\s*'.header_symbol.'\{'.i.'}\zs[^'.header_symbol.'].*[^'.header_symbol.']\ze' \ .header_symbol.'\{'.i.'}\s*$' - let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Start'] = + let syntax_dic['rxH'.i.'_Start'] = \ '^\s*'.header_symbol.'\{'.i.'}[^'.header_symbol.'].*[^'.header_symbol.']' \ .header_symbol.'\{'.i.'}\s*$' - let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_End'] = + let syntax_dic['rxH'.i.'_End'] = \ '^\s*'.header_symbol.'\{1,'.i.'}[^'.header_symbol.'].*[^'.header_symbol.']' \ .header_symbol.'\{1,'.i.'}\s*$' endfor - let g:vimwiki_syntax_variables[a:syntax].rxHeader = + let syntax_dic.rxHeader = \ '^\s*\('.header_symbol.'\{1,6}\)\zs[^'.header_symbol.'].*[^'.header_symbol.']\ze\1\s*$' else " asymmetric for i in range(1,6) - let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Template'] = + let syntax_dic['rxH'.i.'_Template'] = \ repeat(header_symbol, i).' __Header__' - let g:vimwiki_syntax_variables[a:syntax]['rxH'.i] = + let syntax_dic['rxH'.i] = \ '^\s*'.header_symbol.'\{'.i.'}[^'.header_symbol.'].*$' - let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Text'] = + let syntax_dic['rxH'.i.'_Text'] = \ '^\s*'.header_symbol.'\{'.i.'}\zs[^'.header_symbol.'].*\ze$' - let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_Start'] = + let syntax_dic['rxH'.i.'_Start'] = \ '^\s*'.header_symbol.'\{'.i.'}[^'.header_symbol.'].*$' - let g:vimwiki_syntax_variables[a:syntax]['rxH'.i.'_End'] = + let syntax_dic['rxH'.i.'_End'] = \ '^\s*'.header_symbol.'\{1,'.i.'}[^'.header_symbol.'].*$' endfor - let g:vimwiki_syntax_variables[a:syntax].rxHeader = + let syntax_dic.rxHeader = \ '^\s*\('.header_symbol.'\{1,6}\)\zs[^'.header_symbol.'].*\ze$' endif diff --git a/syntax/vimwiki.vim b/syntax/vimwiki.vim index 9397bcc..c0f6dca 100644 --- a/syntax/vimwiki.vim +++ b/syntax/vimwiki.vim @@ -22,6 +22,36 @@ let b:vimwiki_syntax_concealends = has('conceal') ? ' concealends' : '' " 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] + +" text: `code` or ``code`` only inline +" Note: `\%(^\|[^`]\)\@<=` means after a new line or a non ` +let syntax_dic.dTypeface.code = [ + \ ['\%(^\|[^`]\)\@<=`\%($\|[^`]\)\@=', + \ '\%(^\|[^`]\)\@<=`\%($\|[^`]\)\@='], + \ ['\%(^\|[^`]\)\@<=``\%($\|[^`]\)\@=', + \ '\%(^\|[^`]\)\@<=``\%($\|[^`]\)\@='], + \ ] + +" text: ~~deleted text~~ +let syntax_dic.dTypeface.del = ([ + \ ['\~\~', '\~\~']]) + +" text: $ equation_inline $ +" Match only one $ +" ( ^ or not $) before $ and after: not $ +let syntax_dic.dTypeface.eq = ([ + \ ['\%(^\|[^$]\)\@<=\$\%($\|[^$]\)\@=', + \ '\%(^\|[^$]\)\@<=\$\%($\|[^$]\)\@=']]) + +" text: ^superscript^ +let syntax_dic.dTypeface.sup = ([ + \ ['\^', '\^']]) + +" text: ,,subscript,, +let syntax_dic.dTypeface.sub = ([ + \ [',,', ',,']]) + " LINKS: highlighting is complicated due to "nonexistent" links feature function! s:add_target_syntax_ON(target, type) abort @@ -88,9 +118,6 @@ function! s:highlight_existing_links() abort endfunction -function! s:in_typeface(s_typeface_char) -endfunction - " use max highlighting - could be quite slow if there are too many wikifiles if vimwiki#vars#get_wikilocal('maxhi') " WikiLink diff --git a/syntax/vimwiki_default.vim b/syntax/vimwiki_default.vim index 741df9d..94dba3c 100644 --- a/syntax/vimwiki_default.vim +++ b/syntax/vimwiki_default.vim @@ -15,24 +15,21 @@ let s:default_syntax = g:vimwiki_syntax_variables['default'] let b:vimwiki_syntax_conceal = exists('+conceallevel') ? ' conceal' : '' let b:vimwiki_syntax_concealends = has('conceal') ? ' concealends' : '' -" Typeface: -let s:default_syntax.dTypeface = {} - " text: *strong* -let s:default_syntax.dTypeface['bold'] = [ +let s:default_syntax.dTypeface.bold = [ \ ['\S\@<=\*\|\*\S\@=', '\S\@<=\*\|\*\S\@='], \ ] " text: _italic_ -let s:default_syntax.dTypeface['italic'] = [ +let s:default_syntax.dTypeface.italic = [ \ ['\S\@<=_\|_\S\@=', '\S\@<=_\|_\S\@='], \ ] " text: no underline defined -let s:default_syntax.dTypeface['underline'] = [] +let s:default_syntax.dTypeface.underline = [] " text: *_bold italic_* or _*italic bold*_ -let s:default_syntax.dTypeface['bold_italic'] = [ +let s:default_syntax.dTypeface.bold_italic = [ \ ['\S\@<=\*_\|\*_\S\@=', '\S\@<=_\*\|_\*\S\@='], \ ['\S\@<=_\*\|_\*\S\@=', '\S\@<=\*_\|\*_\S\@='], \ ] diff --git a/syntax/vimwiki_markdown.vim b/syntax/vimwiki_markdown.vim index df104ef..c42b5c7 100644 --- a/syntax/vimwiki_markdown.vim +++ b/syntax/vimwiki_markdown.vim @@ -14,22 +14,19 @@ let b:vimwiki_syntax_conceal = exists('+conceallevel') ? ' conceal' : '' let b:vimwiki_syntax_concealends = has('conceal') ? ' concealends' : '' -" Typeface: -let s:markdown_syntax.dTypeface = {} - " text: **bold** or __bold__ -let s:markdown_syntax.dTypeface['bold'] = vimwiki#u#hi_expand_regex([ +let s:markdown_syntax.dTypeface.bold = vimwiki#u#hi_expand_regex([ \ ['__', '__'], ['\*\*', '\*\*']]) " text: *italic* or _italic_ -let s:markdown_syntax.dTypeface['italic'] = vimwiki#u#hi_expand_regex([ +let s:markdown_syntax.dTypeface.italic = vimwiki#u#hi_expand_regex([ \ ['\*', '\*'], ['_', '_']]) " text: no underline defined -let s:markdown_syntax.dTypeface['underline'] = [] +let s:markdown_syntax.dTypeface.underline = [] " text: *_bold italic_* or _*italic bold*_ or ___bi___ or ***bi*** -let s:markdown_syntax.dTypeface['bold_italic'] = vimwiki#u#hi_expand_regex([ +let s:markdown_syntax.dTypeface.bold_italic = vimwiki#u#hi_expand_regex([ \ ['\*_', '_\*'], ['_\*', '\*_'], ['\*\*\*', '\*\*\*'], ['___', '___']]) @@ -37,8 +34,6 @@ let s:markdown_syntax.dTypeface['bold_italic'] = vimwiki#u#hi_expand_regex([ let s:markdown_syntax.rxH = '#' let s:markdown_syntax.symH = 0 - - "