shortcuts / no-neck-pain.nvim

☕ Dead simple yet super extensible plugin to center the currently focused buffer to the middle of the screen.
MIT License
459 stars 12 forks source link

Prevent :q from closing NNP? #348

Closed vinoff closed 1 month ago

vinoff commented 1 month ago

Is it possible to prevent :q from closing NNP?

As it is, if I open a file, edit something (say, add a new line) and then do :q, NNP is closed. This should not happen. It should return an error saying I have unsaved changes, without closing anything.

Here is my config file:

return {
    "shortcuts/no-neck-pain.nvim",
    config = function()
        require("no-neck-pain").setup({
            fallbackOnBufferDelete = true,
            width = 100,
            autocmds = {
                enableOnVimEnter = true,
                enableOnTabEnter = true,
            },
            buffers = {
                colors = {
                    background = "#000000",
                },
                right = {
                    enabled = false,
                },
            },
        })
    end,
}
shortcuts commented 1 month ago

Hey there, thanks for using the plugin and filling an issue! I can confirm this is not an expected behavior and I'm able to reproduce, I'll try to fix it!

vinoff commented 1 month ago

This is still happening to me. Whatever you did, did not fix this issue. Not for me at least?

Here is how to reproduce:

EDIT:

It is even worse than that actually? It doesn't only close NNP, I think it opens a buffer in its place (or maybe NNP is taking the whole space?)? I dunno, all I know is that I no longer see the buffer, though it is there if I check the buffers.

shortcuts commented 1 month ago

Hey @vinoff thanks for try the fix! It's weird because to me it now behaves "correctly", we don't force close the file anymore and it properly throws a e37 error like nvim would do, see the attached screen recording

https://github.com/shortcuts/no-neck-pain.nvim/assets/20689156/84d22571-787e-472e-9162-dd3e46d34efb

Feel free to let me know if something differs from your workflow like a session manager plugin or something that could conflict

shortcuts commented 1 month ago

(the in-between buffer not closed however is weird I admit but I wanted to give a quick fix before tackling the better UX solution)

vinoff commented 1 month ago

In the video you showed, :q closes NNP, does it not? Or am I missing something?

That is the whole point, it shouldn't close NNP. NNP should only be closed if NNP is focused.

shortcuts commented 1 month ago

In the video you showed, :q closes NNP, does it not? Or am I missing something?

That is the whole point, it shouldn't close NNP. NNP should only be closed if NNP is focused.

ahhh I get your point I think, actually those NNP side buffers are meant to be "invisible", I don't want the plugin to impact how nvim natively runs.

The idea is to keep the native nvim behavior, so if you close the last available window (the centered one), the sides doesn't account, so it should try to exit nvim. This is the expected when using :q, otherwise you should use :bd

If there was an other window, e.g. a split, it wouldn't try to quit nvim


I believe what you expect is that, it doesn't disable nnp, keeps everything in place, throws the e37 error asking to save?

vinoff commented 1 month ago

In the video you showed, :q closes NNP, does it not? Or am I missing something? That is the whole point, it shouldn't close NNP. NNP should only be closed if NNP is focused.

ahhh I get your point I think, actually those NNP side buffers are meant to be "invisible", I don't want the plugin to impact how nvim natively runs.

The idea is to keep the native nvim behavior, so if you close the last available window (the centered one), the sides doesn't account, so it should try to exit nvim. This is the expected when using :q, otherwise you should use :bd

If there was an other window, e.g. a split, it wouldn't try to quit nvim

I believe what you expect is that, it doesn't disable nnp, keeps everything in place, throws the e37 error asking to save?

Yes!

I agree that, if the main nvim window is closed, NNP should close as well. I would hate for that to not happen. So yes, NNP should never be the last remaining window.

However, I am not refering to that. I think that, if you have the main window focused and do :q, NNP should never close. NNP should close if it is the focused window. It should just throw the error, asking to save. Yes.

Again, if one wants NNP closed, one should either focus it, or just use the native NNP commands to toggle/close it.

EDIT:

As it is, it is extremely messy. If I don't know I have unsaved things, it just closes NNP and hides the main window.