vimwiki-only-create-temp-wiki-if-extension-registered-in-ext.patch (1892B)
1 From 719a864ff237a1184649251aa18513484a64b939 Mon Sep 17 00:00:00 2001 2 From: Alex Balgavy <alex@balgavy.eu> 3 Date: Sun, 13 Dec 2020 15:12:07 +0100 4 Subject: [PATCH] Only create temp wiki if extension registered in ext2syntax 5 6 I want files with the `.txt` extension in the path in `g:vimwiki_list` 7 to be treated as Vimwiki files (makes them automatically readable on any 8 device). I don't want any other `.txt` files to be treated as Vimwiki 9 files, but I do want this for arbitrary .wiki files. So, interpret 10 `g:vimwiki_ext2syntax` also as list of valid extensions for temporary 11 wikis. In my case, `g:vimwiki_ext2syntax = {'.wiki': 'default'}`. 12 --- 13 plugin/vimwiki.vim | 10 +++++++++- 14 1 file changed, 9 insertions(+), 1 deletion(-) 15 16 diff --git a/plugin/vimwiki.vim b/plugin/vimwiki.vim 17 index 05f5bdc..8fed63e 100644 18 --- a/plugin/vimwiki.vim 19 +++ b/plugin/vimwiki.vim 20 @@ -66,6 +66,14 @@ function! s:create_temporary_wiki() abort 21 call vimwiki#vars#set_bufferlocal('wiki_nr', vimwiki#base#find_wiki(expand('%:p'))) 22 endfunction 23 24 +" Returns 1 if current file's extension is in keys(ext2syntax) 25 +function! s:extension_in_ext2syntax(ext) abort 26 + let ext2syntax = vimwiki#vars#get_global('ext2syntax') 27 + if index(keys(ext2syntax), ".".a:ext) >= 0 28 + return 1 29 + endif 30 + return 0 31 +endfunction 32 33 " This function is called when Vim opens a new buffer with a known wiki 34 " extension. Both when the buffer has never been opened in this session and 35 @@ -73,7 +81,7 @@ endfunction 36 function! s:setup_new_wiki_buffer() abort 37 let wiki_nr = vimwiki#vars#get_bufferlocal('wiki_nr') 38 if wiki_nr == -1 " it's not in a known wiki directory 39 - if vimwiki#vars#get_global('global_ext') 40 + if vimwiki#vars#get_global('global_ext') && s:extension_in_ext2syntax(expand("%:e")) 41 call s:create_temporary_wiki() 42 else 43 " the user does not want a temporary wiki, so do nothing 44 -- 45 2.29.2 46