Skip to content

Commit

Permalink
Warn when running go#cmd#autowrite() without autowrite enabled (#1754)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
arp242 authored Apr 8, 2018
1 parent 32ae864 commit 8379651
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
11 changes: 11 additions & 0 deletions autoload/go/cmd.vim
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit 8379651

Please sign in to comment.