nvim-luapad icon indicating copy to clipboard operation
nvim-luapad copied to clipboard

Do not wipe Luapad buffers

Open anuvyklack opened this issue 2 years ago • 2 comments

Could you add and option to allow Luapad buffers be hidden? I just lost some amount of
work because of forget that Luapad buffers wipe when become hidden and switch the buffer in a window.

I can make it manualy with next autocommand:

vim.api.nvim_create_autocmd('BufEnter', {                                                
   pattern = '*_Luapad.lua',                                                             
   command = 'setlocal bufhidden=hide'                                                   
})                                                                                       

But it will be more consistent if there was such an option.

anuvyklack avatar Apr 12 '22 14:04 anuvyklack

Hi! I'm wondering how you were able to switch buffer. Did you mark it as nomodified in some way? Like... I don't know, some kind of auto-save? Or maybe you save it manually? I should probably add something to preventing this.

By design, this shouldn't be a problem, because the Luapad buf/window is not intended (and blocked) for use as a normal one. I must have missed some corner case. It supposed to be a scratch pad (after all, the name of this plugin is luapad), but I will consider an option to not treat it like one.

For the other uses, the lua api has been prepared. You can easily achieve desired functionality with:

vim.api.nvim_create_user_command('Luapad', function()
  vim.cmd 'vnew'
  require('luapad.evaluator'):new { buf = 0 }:start()
end, {})

rafcamlet avatar Apr 12 '22 20:04 rafcamlet

I just print( :w and then :bnext. Nothing special.

anuvyklack avatar Apr 30 '22 20:04 anuvyklack

I've had the same issue. As soon as you switch to another buffer in a window containing Luapad it get's wiped.

The problem is this line

-- nvim-luapad/lua/luapad.lua : 35
vim.api.nvim_buf_set_option(buf, 'bufhidden', 'wipe')

What's the reason for that line? Why can't the luapad buffer become a regular hidden buffer?

jeff-dh avatar Dec 09 '22 02:12 jeff-dh

Btw: at least I can switch (hide) buffers even if they are modified....

And what's the issue with saving a pad?

jeff-dh avatar Dec 09 '22 02:12 jeff-dh

Hi @jeff-dh !

What's the reason for that line?

To wipe out the buffer when it is hidden. :)

Why can't the luapad buffer become a regular hidden buffer?

There is no particular reason for that other than keeping the buffer list clean.

Okay, I understand that people can have different nvim workflows, that's why something natural for me, may seem to be unexpected for other users. Those are scratch pads, they are intended to be thrown away.

I will add a configuration option to alter this behaviour to keep us all happy.

And what's the issue with saving a pad?

Because it interferes with the wipe mechanism. They should be marked as modified, which blocks switching buffers, because it would try to wipe not saved one. Something must be broken if you are able to switch them.

rafcamlet avatar Dec 09 '22 02:12 rafcamlet

I see....

hitting :w and switching the buffer is just a reflex for me and wooops is the pad gone..... at the same time I really like to hide the pad because I don't need it all the time, but need it a couple of minutes later again (with he same buffer).

jeff-dh avatar Dec 09 '22 03:12 jeff-dh

@jeff-dh I added a wipe configuration option which you can set to false and it should work as you want. If you have any suggestions, feel free to comment. Here is the commit https://github.com/rafcamlet/nvim-luapad/commit/a5b3d6aa1fe5fe75e6124927392a9d3a60a0ecce

rafcamlet avatar Dec 11 '22 14:12 rafcamlet

thx.

Btw: just figured out, setting buftype to nowrite prevents a buffer from being saved... (or readonly = true)

jeff-dh avatar Dec 12 '22 18:12 jeff-dh