Set default ext2syntax values for markdown and mediawiki.

Closes #769.

Also fixes an error when adding missing '.' to mapped extensions. The
previous behavior tried to access a value after it was removed from the
dictionary.
This commit is contained in:
Rane Brown 2019-12-02 12:53:41 -07:00
parent fb5d2f3f82
commit c58d5da049
2 changed files with 19 additions and 10 deletions

View File

@ -157,7 +157,8 @@ function! s:read_global_settings_from_user()
\ 10: 'October', 11: 'November', 12: 'December'
\ }},
\ 'dir_link': {'type': type(''), 'default': ''},
\ 'ext2syntax': {'type': type({}), 'default': {}},
\ 'ext2syntax': {'type': type({}), 'default': {'.md': 'markdown', '.mkdn': 'markdown',
\ '.mdwn': 'markdown', '.mdown': 'markdown', '.markdown': 'markdown', '.mw': 'media'}},
\ 'folding': {'type': type(''), 'default': '', 'possible_values': ['', 'expr', 'syntax',
\ 'list', 'custom', ':quick', 'expr:quick', 'syntax:quick', 'list:quick',
\ 'custom:quick']},
@ -245,16 +246,19 @@ endfunction
function! s:normalize_global_settings()
let keys = keys(g:vimwiki_global_vars.ext2syntax)
for ext in keys
" for convenience, we also allow the term 'mediawiki'
if g:vimwiki_global_vars.ext2syntax[ext] ==# 'mediawiki'
let g:vimwiki_global_vars.ext2syntax[ext] = 'media'
endif
" ensure the file extensions in ext2syntax start with a dot
" make sure this occurs after anything else that tries to access
" the entry using the index 'ext' since this removes that index
if ext[0] != '.'
let new_ext = '.' . ext
let g:vimwiki_global_vars.ext2syntax[new_ext] = g:vimwiki_global_vars.ext2syntax[ext]
call remove(g:vimwiki_global_vars.ext2syntax, ext)
endif
" for convenience, we also allow the term 'mediawiki'
if g:vimwiki_global_vars.ext2syntax[ext] ==# 'mediawiki'
let g:vimwiki_global_vars.ext2syntax[ext] = 'media'
endif
endfor
" ensure key_mappings dictionary has all required keys

View File

@ -2657,13 +2657,18 @@ E.g.: >
\ '.mkd': 'markdown',
\ '.wiki': 'media'}
An extension that is registered with Vimwiki can trigger creation of a
|vimwiki-temporary-wiki| with the associated syntax. File extensions used in
|g:vimwiki_list| are automatically registered with Vimwiki using the default
syntax.
An extension that is registered with Vimwiki can trigger creation of
a |vimwiki-temporary-wiki|. File extensions used in |g:vimwiki_list| are
automatically registered with Vimwiki using the default syntax. Extensions
mapped with this option will instead use the mapped syntax.
Default: {}
Default: >
{'.md': 'markdown', '.mkdn': 'markdown',
\ '.mdwn': 'markdown', '.mdown': 'markdown',
\ '.markdown': 'markdown', '.mw': 'media'}},
Note: setting this option will overwrite the default values so include them if
desired.
------------------------------------------------------------------------------
*g:vimwiki_menu*