diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index fe3c341..0681c8a 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -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 {{{ diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt index 221d046..b5793ca 100644 --- a/doc/vimwiki.txt +++ b/doc/vimwiki.txt @@ -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~ diff --git a/plugin/vimwiki.vim b/plugin/vimwiki.vim index 1506261..d7abb6c 100644 --- a/plugin/vimwiki.vim +++ b/plugin/vimwiki.vim @@ -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 diff --git a/syntax/vimwiki.vim b/syntax/vimwiki.vim index fbd4679..479bc67 100644 --- a/syntax/vimwiki.vim +++ b/syntax/vimwiki.vim @@ -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,