Merge pull request #187 from mMontu/nested

Dynamically detect nested syntaxes (fix #128)
This commit is contained in:
EinfachToll 2016-01-28 10:29:53 +01:00
commit 2aeaea5f0d
4 changed files with 30 additions and 0 deletions

View File

@ -1965,6 +1965,18 @@ function! vimwiki#base#normalize_link(is_visual_mode) "{{{
endif
endfunction "}}}
" vimwiki#base#detect_nested_syntax
function! vimwiki#base#detect_nested_syntax() "{{{
let last_word = '\v.*<(\w+)\s*$'
let lines = map(filter(getline(1, "$"), 'v:val =~ "{{{" && v:val =~ last_word'),
\ 'substitute(v:val, last_word, "\\=submatch(1)", "")')
let dict = {}
for elem in lines
exe "let dict.".elem." = elem"
endfor
return dict
endfunction "}}}
" }}}
" Command completion functions {{{

View File

@ -2015,6 +2015,20 @@ or in: >
}}}
*vimwiki-option-automatic_nested_syntaxes*
------------------------------------------------------------------------------
Key Default value~
automatic_nested_syntaxes 1
Description~
Allows for smaller |vimwiki-option-nested_syntaxes| dictionaries, by turning
entry for python on the previous example unnecessary: >
let wiki.nested_syntaxes = {'python': 'python', 'c++': 'cpp'}
It requires that the file is reloaded (|:edit|) after new |filetype| is
included in a file.
*vimwiki-option-diary_rel_path*
------------------------------------------------------------------------------
Key Default value~

View File

@ -334,6 +334,7 @@ let s:vimwiki_defaults.template_default = 'default'
let s:vimwiki_defaults.template_ext = '.tpl'
let s:vimwiki_defaults.nested_syntaxes = {}
let s:vimwiki_defaults.automatic_nested_syntaxes = 1
let s:vimwiki_defaults.auto_export = 0
let s:vimwiki_defaults.auto_toc = 0
" is wiki temporary -- was added to g:vimwiki_list by opening arbitrary wiki

View File

@ -588,6 +588,9 @@ let b:current_syntax="vimwiki"
" EMBEDDED syntax setup "{{{
let s:nested = VimwikiGet('nested_syntaxes')
if VimwikiGet('automatic_nested_syntaxes')
let s:nested = extend(s:nested, vimwiki#base#detect_nested_syntax())
endif
if !empty(s:nested)
for [s:hl_syntax, s:vim_syntax] in items(s:nested)
call vimwiki#base#nested_syntax(s:vim_syntax,