Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent go fmt autosave from attempting to write to fugitive buffers #2132

Closed
wants to merge 1 commit into from

Conversation

washtubs
Copy link
Contributor

Fixes this issue from the vim-go side. Not sure if this is the way to go, but it works for me.

@bhcleek
Copy link
Collaborator

bhcleek commented Jan 26, 2019

Thank you for the contribution. 🙇

It's preferable to add a more general solution instead of adding a special case for one other plugin. There was a previous attempt to do something similar for vim-fugitive buffers, #1516, that we ended up rejecting for similar reasons. The correct fix in that case was #1527, and it shows the way for skipping formatting when writing a fugitive buffer, too. A solution for this that's similar to the fix in #1527 would be welcome.

Alternatively (and perhaps a better solution), change https://github.com/fatih/vim-go/blob/master/autoload/go/fmt.vim#L108 to read in the formatted temp files contents into the current buffer and then write the buffer so that fugitive can write it correctly when the buffer doesn't actually exist (check it with filereadable(a:target)).

Solving this will also likely solve #632.

Are you willing to implement one of the solutions I proposed here?

@washtubs
Copy link
Contributor Author

Using filereadable makes way more sense. TY. I will amend my PR.

@washtubs
Copy link
Contributor Author

I think I may have glossed over your last paragraph and just honed in on checking filereadable.

I think bailing on auto-save as I have it is the way to go at least for these special fugitive buffers. (Not sure what other special cases the filereadable check may capture). Anyways I would find that behavior pretty unexpected, and unwanted even because when I write to staging, I would want to ensure that the changes I'm making are very targeted. Formatting the file could cause changes to be staged that I didn't intend for that commit.

@bhcleek
Copy link
Collaborator

bhcleek commented Jan 27, 2019

I think bailing on auto-save as I have it is the way to go at least for these special fugitive buffers.

sgtm for now

(Not sure what other special cases the filereadable check may capture)

None really. From the docs:

The result is a Number, which is TRUE when a file with the name {file} exists, and can be read.

Anyways I would find that behavior pretty unexpected, and unwanted even because when I write to staging, I would want to ensure that the changes I'm making are very targeted.

I don't think that's the desired behavior in general for vim-go, but if that's what you want for your environment, then I'd recommend unsetting g:go_fmt_autosave when in a fugitive buffer. You can do that pretty easily in your vimrc with something like (untested):

autocmd BufEnter fugitive://*.go let s:go_fmt_autosave=g:go_fmt_autosave | let g:go_fmt_autosave=0
autocmd BufLeave fugitive://*.go let g:go_fmt_autosave=s:go_fmt_autosave

@bhcleek
Copy link
Collaborator

bhcleek commented Feb 11, 2019

Thank you for the contribution. This change is included in #2143.

@bhcleek bhcleek closed this Feb 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants