vimwiki

Personal wiki for vim
git clone https://github.com/vimwiki/vimwiki.git
Log | Files | Refs | README | LICENSE

commit 8009e5c7cf9d7dce133fdeb7cfa6cc4651580204
parent 4bacbe00005f23d72d247fdde3a9e857d690b44b
Author: EinfachToll <istjanichtzufassen@googlemail.com>
Date:   Fri, 16 Mar 2018 21:39:24 +0100

Handle all combinations of 'autowriteall' and 'hidden'

Ref #445

Diffstat:
Mautoload/vimwiki/base.vim | 26+++++++++++++++-----------
Mdoc/vimwiki.txt | 8++++++--
2 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim @@ -690,14 +690,6 @@ endfunction "}}} " vimwiki#base#edit_file function! vimwiki#base#edit_file(command, filename, anchor, ...) "{{{ - " XXX: Should we allow * in filenames!? - " Maxim: It is allowed, escaping here is for vim to be able to open files - " which have that symbols. - " Try to remove * from escaping and open&save : - " [[testBLAfile]]... - " then - " [[test*file]]... - " you'll have E77: Too many file names let fname = escape(a:filename, '% *|#`') let dir = fnamemodify(a:filename, ":p:h") @@ -709,12 +701,24 @@ function! vimwiki#base#edit_file(command, filename, anchor, ...) "{{{ return endif - " check if the file we want to open is already the current file + " Check if the file we want to open is already the current file " which happens if we jump to an achor in the current file. " This hack is necessary because apparently Vim messes up the result of " getpos() directly after this command. Strange. if !(a:command ==# ':e ' && vimwiki#path#is_equal(a:filename, expand('%:p'))) - execute a:command.' '.fname + try + if &autowriteall && !&hidden " in this case, the file is saved before switching to the + " new buffer. This causes Vim to show two messages in the command line which triggers + " the annoying hit-enter prompt. Solution: show no messages at all. + silent execute a:command fname + else + execute a:command fname + endif + catch /E37:/ + echomsg 'Vimwiki: The current file is modified. Hint: Take a look at' + \ ''':h g:vimwiki_autowriteall'' to see how to save automatically.' + return + endtry " If the opened file was not already loaded by Vim, an autocommand is " triggered at this point @@ -1166,7 +1170,7 @@ function! vimwiki#base#go_back_link() "{{{ let prev_link = vimwiki#vars#get_bufferlocal('prev_link') if !empty(prev_link) " go back to saved wiki link - execute ":e ".substitute(prev_link[0], '\s', '\\\0', 'g') + call vimwiki#base#edit_file(':e ', prev_link[0], '') call setpos('.', prev_link[1]) else " maybe we came here by jumping to a tag -> pop from the tag stack diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt @@ -2731,8 +2731,12 @@ Default: 2 ------------------------------------------------------------------------------ *g:vimwiki_autowriteall* -In Vim 'autowriteall' is a global setting. With g:vimwiki_autowriteall Vimwiki -makes it local to its buffers. +Automatically save a modified wiki buffer when switching wiki pages. Has the +same effect like setting the Vim option 'autowriteall', but it works for wiki +files only, while the Vim option is global. +Hint: if you're just annoyed that you have to save files manually to switch +wiki pages, consider setting the Vim option 'hidden' which makes that modified +files don't need to be saved. Value Description~ 0 autowriteall is off