dotfiles

<-- duh.
git clone https://hhvn.uk/dotfiles
git clone git://hhvn.uk/dotfiles
Log | Files | Refs | Submodules | LICENSE

vimwiki_markdown_custom.vim (7400B)


      1 
      2 
      3 
      4 
      5 
      6 
      7 function! s:add_target_syntax_ON(target, type)
      8   let prefix0 = 'syntax match '.a:type.' `'
      9   let suffix0 = '` display contains=@NoSpell,VimwikiLinkRest,'.a:type.'Char'
     10   let prefix1 = 'syntax match '.a:type.'T `'
     11   let suffix1 = '` display contained'
     12   execute prefix0. a:target. suffix0
     13   execute prefix1. a:target. suffix1
     14 endfunction
     15 
     16 
     17 function! s:add_target_syntax_OFF(target, type)
     18   let prefix0 = 'syntax match VimwikiNoExistsLink `'
     19   let suffix0 = '` display contains=@NoSpell,VimwikiLinkRest,'.a:type.'Char'
     20   let prefix1 = 'syntax match VimwikiNoExistsLinkT `'
     21   let suffix1 = '` display contained'
     22   execute prefix0. a:target. suffix0
     23   execute prefix1. a:target. suffix1
     24 endfunction
     25 
     26 
     27 function! s:wrap_wikilink1_rx(target)
     28   return vimwiki#vars#get_syntaxlocal('rxWikiLink1InvalidPrefix') . a:target.
     29         \ vimwiki#vars#get_syntaxlocal('rxWikiLink1InvalidSuffix')
     30 endfunction
     31 
     32 
     33 function! s:existing_mkd_refs()
     34   return keys(vimwiki#markdown_base#scan_reflinks())
     35 endfunction
     36 
     37 
     38 function! s:highlight_existing_links()
     39   " Wikilink1
     40   " Conditional highlighting that depends on the existence of a wiki file or
     41   "   directory is only available for *schemeless* wiki links
     42   " Links are set up upon BufEnter (see plugin/...)
     43   let safe_links = '\%('.
     44         \ vimwiki#base#file_pattern(vimwiki#vars#get_bufferlocal('existing_wikifiles')) .
     45         \ '\%(#[^|]*\)\?\|#[^|]*\)'
     46   " Wikilink1 Dirs set up upon BufEnter (see plugin/...)
     47   let safe_dirs = vimwiki#base#file_pattern(vimwiki#vars#get_bufferlocal('existing_wikidirs'))
     48   " Ref links are cached
     49   let safe_reflinks = vimwiki#base#file_pattern(s:existing_mkd_refs())
     50 
     51 
     52   " match [URL][]
     53   let target = vimwiki#base#apply_template(
     54         \ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template1')),
     55         \ safe_links, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
     56   call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
     57   " match [DESCRIPTION][URL]
     58   let target = vimwiki#base#apply_template(
     59         \ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template2')),
     60         \ safe_links, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
     61   call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
     62 
     63   " match [DIRURL][]
     64   let target = vimwiki#base#apply_template(
     65         \ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template1')),
     66         \ safe_dirs, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
     67   call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
     68   " match [DESCRIPTION][DIRURL]
     69   let target = vimwiki#base#apply_template(
     70         \ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template2')),
     71         \ safe_dirs, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
     72   call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
     73 
     74   " match [MKDREF][]
     75   let target = vimwiki#base#apply_template(
     76         \ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template1')),
     77         \ safe_reflinks, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
     78   call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
     79   " match [DESCRIPTION][MKDREF]
     80   let target = vimwiki#base#apply_template(
     81         \ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template2')),
     82         \ safe_reflinks, vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
     83   call s:add_target_syntax_ON(s:wrap_wikilink1_rx(target), 'VimwikiWikiLink1')
     84 endfunction
     85 
     86 
     87 " use max highlighting - could be quite slow if there are too many wikifiles
     88 if vimwiki#vars#get_wikilocal('maxhi')
     89   " WikiLink
     90   call s:add_target_syntax_OFF(vimwiki#vars#get_syntaxlocal('rxWikiLink1'), 'VimwikiWikiLink1')
     91 
     92   " Subsequently, links verified on vimwiki's path are highlighted as existing
     93   call s:highlight_existing_links()
     94 else
     95   " Wikilink
     96   call s:add_target_syntax_ON(vimwiki#vars#get_syntaxlocal('rxWikiLink1'), 'VimwikiWikiLink1')
     97 endif
     98 
     99 
    100 " Weblink
    101 call s:add_target_syntax_ON(vimwiki#vars#get_syntaxlocal('rxWeblink1'), 'VimwikiWeblink1')
    102 
    103 
    104 " WikiLink
    105 " All remaining schemes are highlighted automatically
    106 let s:rxSchemes = '\%('.
    107       \ vimwiki#vars#get_global('schemes') . '\|'.
    108       \ vimwiki#vars#get_global('web_schemes1').
    109       \ '\):'
    110 
    111 " a) match [nonwiki-scheme-URL]
    112 let s:target = vimwiki#base#apply_template(
    113       \ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template1')),
    114       \ s:rxSchemes . vimwiki#vars#get_syntaxlocal('rxWikiLink1Url'),
    115       \ vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
    116 call s:add_target_syntax_ON(s:wrap_wikilink1_rx(s:target), 'VimwikiWikiLink1')
    117 " b) match [DESCRIPTION][nonwiki-scheme-URL]
    118 let s:target = vimwiki#base#apply_template(
    119       \ vimwiki#u#escape(vimwiki#vars#get_syntaxlocal('WikiLink1Template2')),
    120       \ s:rxSchemes . vimwiki#vars#get_syntaxlocal('rxWikiLink1Url'),
    121       \ vimwiki#vars#get_syntaxlocal('rxWikiLink1Descr'), '')
    122 call s:add_target_syntax_ON(s:wrap_wikilink1_rx(s:target), 'VimwikiWikiLink1')
    123 
    124 
    125 
    126 " Header levels, 1-6
    127 for s:i in range(1,6)
    128   execute 'syntax match VimwikiHeader'.s:i.' /'.vimwiki#vars#get_syntaxlocal('rxH'.s:i).
    129               \ '/ contains=VimwikiTodo,VimwikiHeaderChar,VimwikiNoExistsLink,VimwikiCode,'.
    130               \ 'VimwikiLink,VimwikiWeblink1,VimwikiWikiLink1,@Spell'
    131 endfor
    132 
    133 
    134 
    135 " concealed chars
    136 if exists("+conceallevel")
    137   syntax conceal on
    138 endif
    139 
    140 syntax spell toplevel
    141 
    142 " VimwikiWikiLink1Char is for syntax markers (and also URL when a description
    143 " is present) and may be concealed
    144 let s:options = ' contained transparent contains=NONE'
    145 " conceal wikilink1
    146 execute 'syn match VimwikiWikiLink1Char /'.
    147             \ vimwiki#vars#get_syntaxlocal('rx_wikilink_md_prefix').'/'.s:options
    148 execute 'syn match VimwikiWikiLink1Char /'.
    149             \ vimwiki#vars#get_syntaxlocal('rx_wikilink_md_suffix').'/'.s:options
    150 execute 'syn match VimwikiWikiLink1Char /'.
    151             \ vimwiki#vars#get_syntaxlocal('rxWikiLink1Prefix1').'/'.s:options
    152 execute 'syn match VimwikiWikiLink1Char /'.
    153             \ vimwiki#vars#get_syntaxlocal('rxWikiLink1Suffix1').'/'.s:options
    154 
    155 " conceal weblink1
    156 execute 'syn match VimwikiWeblink1Char "'.
    157             \ vimwiki#vars#get_syntaxlocal('rxWeblink1Prefix1').'"'.s:options
    158 execute 'syn match VimwikiWeblink1Char "'.
    159             \ vimwiki#vars#get_syntaxlocal('rxWeblink1Suffix1').'"'.s:options
    160 
    161 if exists("+conceallevel")
    162   syntax conceal off
    163 endif
    164 
    165 
    166 
    167 " Tables
    168 syntax match VimwikiTableRow /^\s*|.\+|\s*$/ 
    169       \ transparent contains=VimwikiCellSeparator,
    170                            \ VimwikiLinkT,
    171                            \ VimwikiWeblink1T,
    172                            \ VimwikiWikiLink1T,
    173                            \ VimwikiNoExistsLinkT,
    174                            \ VimwikiTodo,
    175                            \ VimwikiBoldT,
    176                            \ VimwikiItalicT,
    177                            \ VimwikiBoldItalicT,
    178                            \ VimwikiItalicBoldT,
    179                            \ VimwikiDelTextT,
    180                            \ VimwikiSuperScriptT,
    181                            \ VimwikiSubScriptT,
    182                            \ VimwikiCodeT,
    183                            \ VimwikiEqInT,
    184                            \ @Spell
    185 
    186 
    187 
    188 " syntax group highlighting
    189 hi def link VimwikiWeblink1 VimwikiLink
    190 hi def link VimwikiWeblink1T VimwikiLink
    191 
    192 hi def link VimwikiWikiLink1 VimwikiLink
    193 hi def link VimwikiWikiLink1T VimwikiLink
    194