preservim / tagbar

Vim plugin that displays tags in a window, ordered by scope
https://preservim.github.io/tagbar
Other
6.1k stars 485 forks source link

Don't show errors when opening preview window #810

Closed zharmany closed 2 years ago

zharmany commented 2 years ago

I was experiencing an issue where, if the current buffer had unsaved changes, the action of opening the preview window on a tagbar tag would cause an error that would require a keypress to dismiss. I found this jarring and simply updated the pedit command to fail silently.

I'm hoping that someone else finds this useful, or perhaps there's a better solution than just ignoring the error.

Cheers!

raven42 commented 2 years ago

Can you describe an example of this error a little more? based on what you described, I tried the same thing and I don't see any error opening the preview window. To attempt to reproduce, I had a file opened with the tagbar window opened and fully populated, then I edited the file to add some innocuous code, then I went to the tagbar window and hit <SHIFT-P> on another tag either before or after the new code, and the preview window opened fine and showed the correct preview.

Does it need to be an entirely new file? Are you able to share a screenshot of the error you are seeing?

zharmany commented 2 years ago

Hey there, thanks for the reply.

I have the option to automatically open the preview window on. When I make changes to a file, then change windows to the tagbar window, tarbar attempts to open a preview window of the (modified) file. At this point, I'll get the following error:

Error detected while processing function <SNR>129_ShowInPreviewWin:
line 27:
E37: No write since last change (add ! to override)
Press ENTER or type a command to continue

I made a quick screen recording to show what I mean. It could also be the behavior of automatically opening the preview window which uses the pedit function instead of the psearch function. I'm still very much learning vimscript, so this could be an incorrect assessment of the behavior.

https://user-images.githubusercontent.com/1714524/158079674-58a6c2da-969f-4f9a-b4b9-c70c910c407e.mov

raven42 commented 2 years ago

Ok.... I am able to reproduce now. Turns out if you have set confirm in your .vimrc, it changes the behavior of this. So we may actually want to incorporate that into this as well.

zharmany commented 2 years ago

Thanks again for looking at it, it looks like your proposed change would be more appropriate!

I can confirm, as expected, the issue remains resolved.

zharmany commented 2 years ago

Sweet, thanks @raven42 and @alerque!

raven42 commented 2 years ago

Glad I could help. Thank you too for the contribution.