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

Don't write errors to the file #5

Open
Matt3o12 opened this issue Jun 3, 2015 · 21 comments
Open

Don't write errors to the file #5

Matt3o12 opened this issue Jun 3, 2015 · 21 comments

Comments

@Matt3o12
Copy link

Matt3o12 commented Jun 3, 2015

YAPF doesn't like syntax errors and complains loudly about them. If there is a syntax error (and I execute Yapf), there current buffer gets replaced by a traceback.

I'd be nice if this plugin opens a new buffer (with the error) instead and leaves the original file unchanged. This is especially useful when using autocmd BufWritePre because it will not destroy my file. I'd like to use autocmd BufWritePre so that my code is formatted every time I save the file. You could do that by checking the exit code. If it fails, the exit code will be '1'.

@simonrw
Copy link
Owner

simonrw commented Jun 7, 2015

Hi, thanks for taking the interest in my plugin. I'll have a look into a way to get the error output in a nicer format.

@Matt3o12
Copy link
Author

Matt3o12 commented Jun 7, 2015

The format is fine, just make sure not to write the error output into the current buffer.

@monokal
Copy link

monokal commented Jun 27, 2015

+1, this lost me some work unfortunately. If you have a syntax error and run :Yapf then the buffer is replaces with the trace with no way of returning to file content. My current workaround is to always save the file before running :Yapf but that isn't ideal.

@simonrw
Copy link
Owner

simonrw commented Jun 27, 2015

Can you not get the file contents back with u i.e. undo? That has always been OK
for me in the past.

I'm not saying this is not a problem with the plugin though, but your work may be recoverable.

@simonrw
Copy link
Owner

simonrw commented Jun 30, 2015

I've just updated the code to paste the exception in a new window rather than in the current buffer. It's not particularly graceful but it should suffice, until I get time to work on a nicer system

@Matt3o12
Copy link
Author

Matt3o12 commented Jul 1, 2015

Thanks a lot! 👍 :)

@simonrw
Copy link
Owner

simonrw commented Jul 1, 2015

Going to close this issue, hopefully the UX is a bit nicer now.

@simonrw simonrw closed this as completed Jul 1, 2015
@melissachang
Copy link
Collaborator

My .vimrc has:

autocmd BufWritePre *.py 0,$!yapf

When yapf returns an error, my file is overwritten with the error. Can I reopen this bug?

@intohole
Copy link

hi , i lost my file , because of code contain an error , i want to reopen this bug , the error msg can write same dir, i can fix error and look the error msg , thx

@intohole
Copy link

@mindriot101

@simonrw
Copy link
Owner

simonrw commented Jun 18, 2018

@melissachang your BufWritePre command calls the yapf binary, which has nothing to do with this plugin.

During my testing, when using the Yapf command from this plugin, the error is written to a new split. When testing @melissachang's BufWritePre I am able to undo one step to get the previous code back.

Why is it possible for you to lose code whereas it is not possible for me?

@J-Liu
Copy link

J-Liu commented Jun 19, 2018

This is my config file

Plug 'mindriot101/vim-yapf'
...
let g:yapf_style = "google"
autocmd BufWritePre *.py 0,$!yapf

When I type something wrong code in FILE.py and then save it, err msg overwrite my code.

@melissachang
Copy link
Collaborator

I haven't tried undoing. Perhaps document at https://github.com/mindriot101/vim-yapf how we're supposed to undo and get rid of the error message?

@melissachang
Copy link
Collaborator

I just ran into this again. The problem is, I don't notice the error and save the file (":w"). Then, I reopen the file and only see the error. Is there a way to get the original file back?

I think it would be more user-friendly if instead of writing to the file, write the error to some file in the local filesystem. And don't change the vim buffer.

@melissachang
Copy link
Collaborator

Actually, with ":w" I have a chance to ":undo". The problem is "ZZ". The error is saved to the file and I never even see it. Then I have no way to recover my code. I lose all my changes that I haven't git commited.

@simonrw
Copy link
Owner

simonrw commented Jul 17, 2018

I've started a new PR with an updated README (#14). What else would you like to see?

@simonrw
Copy link
Owner

simonrw commented Oct 3, 2018

Sorry all for my lack of responses. I do not use this plugin myself and am therefore lacking in entheusiasm and time for it's maintenance. @melissachang I have given you commit access to the repository so you can contribute your suggestions, and maybe encourage PRs from other affected users.

@shibumi
Copy link

shibumi commented Jan 16, 2019

Hi, this happens to me as well. Did some user here find a solution for it in your vimrc?

@melissachang
Copy link
Collaborator

My workaround was to set up auto-backup:

https://gist.github.com/nepsilon/003dd7cfefc20ce1e894db9c94749755

@monokal
Copy link

monokal commented Jan 16, 2019

For the sake of Python I'd honestly just recommend switching to an IDE such as PyCharm or VS Code which has all of this built in without the flakiness.

@shibumi
Copy link

shibumi commented Jan 16, 2019

@melissachang setting undo in vim works as well for me

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

No branches or pull requests

7 participants