Skip to content

Conversation

elgiano
Copy link
Contributor

@elgiano elgiano commented Oct 3, 2025

I've been in situation when the postwin is already closed and I get an error when trying to close it again, saying that it can't be closed. In this PR I wrap nvim_win_close in pcall, so that errors are ignored.

If anyone is curious about my actual use case, I have a function to move postwin from side to bottom:

local postwin = require 'scnvim.postwin'
local cfg = require 'scnvim.config'
cfg.postwin.horizontal = not cfg.postwin.horizontal
if postwin.is_open() then
    postwin.close()
end
postwin.open()

And this errors if the postwin is already closed.

@davidgranstrom
Copy link
Owner

Thanks for finding this. I'm wondering though if the actual bug is that postwin.is_open() answers true in this case when it shouldn't. Would be nice to see if that could be improved first - but otherwise this should do it.

@elgiano
Copy link
Contributor Author

elgiano commented Oct 3, 2025 via email

@davidgranstrom
Copy link
Owner

Using your code snippet an easy way to reproduce would be to:

  1. Open a .scd file and start scnvim
  2. :close the .scd buffer leaving only the post window visible
  3. <C-o> to return to the .scd buffer
  4. Run the code snippet (i.e. from a mapping) to trigger the error

@elgiano
Copy link
Contributor Author

elgiano commented Oct 7, 2025

this worked perfectly, thanks!
So it's actually "E444: cannot close last window". How would you like to approach this? For my use case the pcall works, causing a second window to be open and to become the new postwin. Is it messy? Should we just let this error happen since it has a good reason?

@davidgranstrom
Copy link
Owner

Ideally postwin.is_open() should return false in this case. I haven't had a chance to look into the code yet, but I imagine this would be the proper fix instead of ignoring the error. If it proves too complicated I would consider merging this as a work around though.

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