From 83796513c573ebc3513f20a602bfb9830357acb5 Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Sun, 8 Apr 2018 01:23:25 +0100 Subject: [PATCH] Warn when running go#cmd#autowrite() without autowrite enabled (#1754) The `go#cmd#autowrite()` will write buffers to disk for commands that operate on files (rather than buffers). This is useful, but if you *don't* have this option enabled you never get an error message. This changed that to show a non-fatal warning. This is the same behaviour as the `:make` command. Right now this doesn't work very well because the various status messages from the jobs push the error away, making it hard to see (I don't get the expected "hit enter" prompt), so we need a better solution for that first. --- CHANGELOG.md | 3 +++ autoload/go/cmd.vim | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 195e9d8059..bc18f3cef5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ IMPROVEMENTS: * Add build tags (with `g:go_build_tags`) to all commands that support it. [[GH-1705]](https://github.com/fatih/vim-go/pull/1705) +* Some command which operate on files (rather than Vim buffers) will now show a + warning if there are unsaved buffers, similar to Vim's `:make`. + [[GH-1754]](https://github.com/fatih/vim-go/pull/1754) BUG FIXES: diff --git a/autoload/go/cmd.vim b/autoload/go/cmd.vim index 2aab4cc644..11e1d436e0 100644 --- a/autoload/go/cmd.vim +++ b/autoload/go/cmd.vim @@ -1,6 +1,17 @@ function! go#cmd#autowrite() abort if &autowrite == 1 || &autowriteall == 1 silent! wall + else + for l:nr in range(0, bufnr('$')) + if buflisted(l:nr) && getbufvar(l:nr, '&modified') + " Sleep one second to make sure people see the message. Otherwise it is + " often immediacy overwritten by the async messages (which also don't + " invoke the "hit ENTER" prompt). + call go#util#EchoWarning('[No write since last change]') + sleep 1 + return + endif + endfor endif endfunction