Allow additional filetypes to be registered to vimwiki files.

This options allow third party plugins to register and enable additonal
functionality by setting the filetype to vimwiki.other_ft.other_ft2 etc.
This option should be used with care since vimwiki functionality can be
overwritten by other plugins. See Issue #461 for an example use case.
This commit is contained in:
Rane Brown
2019-04-12 07:42:49 -06:00
parent ae67790ad5
commit 1e74443b5a
6 changed files with 49 additions and 8 deletions

View File

@ -309,7 +309,7 @@ function! vimwiki#base#open_link(cmd, link, ...)
if update_prev_link
if a:0
let vimwiki_prev_link = [a:1, []]
elseif &ft ==# 'vimwiki'
elseif vimwiki#u#ft_is_vw()
let vimwiki_prev_link = [vimwiki#path#current_wiki_file(), getpos('.')]
endif
endif
@ -811,8 +811,8 @@ function! vimwiki#base#edit_file(command, filename, anchor, ...)
" Make sure no other plugin takes ownership over the new file. Vimwiki
" rules them all! Well, except for directories, which may be opened with
" Netrw
if &filetype != 'vimwiki' && fname !~ '\m/$'
setfiletype vimwiki
if !vimwiki#u#ft_is_vw() && fname !~? '\m/$'
call vimwiki#u#ft_set()
endif
endif
if a:anchor != ''

View File

@ -676,7 +676,7 @@ endfunction
function! vimwiki#tbl#format(lnum, ...)
if !(&filetype ==? 'vimwiki')
if !vimwiki#u#ft_is_vw()
return
endif
let line = getline(a:lnum)
@ -759,7 +759,7 @@ endfunction
function! vimwiki#tbl#reset_tw(lnum)
if !(&filetype ==? 'vimwiki')
if !vimwiki#u#ft_is_vw()
return
endif
let line = getline(a:lnum)

View File

@ -70,3 +70,28 @@ else
endfunc
endif
" Sets the filetype to vimwiki
" If g:vimwiki_filetypes variable is set
" the filetype will be vimwiki.<ft1>.<ft2> etc.
function! vimwiki#u#ft_set()
let ftypelist = vimwiki#vars#get_global('filetypes')
let ftype = 'vimwiki'
for ftypeadd in ftypelist
let ftype = ftype . '.' . ftypeadd
endfor
let &filetype = ftype
endfunction
" Returns: 1 if filetype is vimwiki, 0 else
" If multiple fileytpes are in use 1 is returned only if the
" first ft is vimwiki which should always be the case unless
" the user manually changes it to something else
function! vimwiki#u#ft_is_vw()
if split(&filetype, '\.')[0] ==? 'vimwiki'
return 1
else
return 0
endif
endfunction

View File

@ -160,6 +160,7 @@ function! s:read_global_settings_from_user()
\ 'folding': {'type': type(''), 'default': '', 'possible_values': ['', 'expr', 'syntax',
\ 'list', 'custom', ':quick', 'expr:quick', 'syntax:quick', 'list:quick',
\ 'custom:quick']},
\ 'filetypes': {'type': type([]), 'default': []},
\ 'global_ext': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
\ 'hl_cb_checked': {'type': type(0), 'default': 0, 'min': 0, 'max': 2},
\ 'hl_headers': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},