glacambre / firenvim

Embed Neovim in Chrome, Firefox & others.
GNU General Public License v3.0
4.71k stars 146 forks source link

firenvim temp files restored when nvim opened #1621

Closed Praful closed 3 months ago

Praful commented 3 months ago

I've checked the troubleshooting guide.

What I tried to do

Use the firenvim browser plugin in firefox. This works fine.

What happened

When I open neovim, there are several buffers that have been created, I assume, by firenvim. Here are some of them, produced by ls:

2      "/run/user/1000/firenvim/web.whatsapp.com__-2-DIV-1-DIV-2-DIV-1-DIV-1-DIV-1_2024-06-24T23-07-34-537Z.txt" line 1
3      "/run/user/1000/firenvim/chatgpt.com_3641-ce7e-4aa4-9a0c-43b848034d0f_TEXTAREA-id-prompt-textarea_2024-06-24T23-06-54-244Z.txt" line 1
4      "/run/user/1000/firenvim/chatgpt.com_3641-ce7e-4aa4-9a0c-43b848034d0f_TEXTAREA-id-prompt-textarea_2024-06-24T23-05-55-710Z.txt" line 4
5      "/run/user/1000/firenvim/web.whatsapp.com__-2-DIV-1-DIV-2-DIV-1-DIV-1-DIV-1_2024-06-24T23-03-38-773Z.txt" line 1
6      "/run/user/1000/firenvim/web.whatsapp.com__-2-DIV-1-DIV-2-DIV-1-DIV-1-DIV-1_2024-06-24T23-03-06-178Z.txt" line 1
7      "/run/user/1000/firenvim/chatgpt.com_3641-ce7e-4aa4-9a0c-43b848034d0f_TEXTAREA-id-prompt-textarea_2024-06-24T23-02-35-371Z.txt" line 1
8      "/run/user/1000/firenvim/web.whatsapp.com__-2-DIV-1-DIV-2-DIV-1-DIV-1-DIV-1_2024-06-24T23-00-04-737Z.txt" line 1
9      "/run/user/1000/firenvim/web.whatsapp.com__-2-DIV-1-DIV-2-DIV-1-DIV-1-DIV-1_2024-06-24T22-58-50-781Z.txt" line 1

Is there a way to stop these buffers being persisted or opened in neovim? They also open in neovide.

glacambre commented 3 months ago

If the problem also happens with Neovide, the problem is in your config, not in Firenvim. Try to remove your plugins one by one until the problem stops happening. Please do report here if you figure out that it's really a Firenvim problem, but I doubt you will.

Praful commented 3 months ago

@glacambre thanks. The issue was the set viminfo in my vimrc file (shared between vim/neovim), which I've now updated to be:

if exists('g:started_by_firenvim') && g:started_by_firenvim
  set viminfo='50,<50,s10,h
else
  set viminfo='50,<50,s10,h,%
end

The % saves and restores buffers.

On another note, the second autosave function on the home page didn't work. I got a syntax error from neovim. With the help of chatGPT (I don't know lua), I ended up with this version:

vim.api.nvim_create_autocmd({'TextChanged', 'TextChangedI'}, {
  callback = function(event)
    if not vim.g.started_by_firenvim or vim.g.timer_started then
      return
    end

    vim.g.timer_started = true
    vim.fn.timer_start(5000, function()
      vim.g.timer_started = false
      vim.cmd('silent write')
    end)
  end
})

I've used "silent write" because otherwise the vim message saying the file has been saved keeps appearing after each autosave.

Finally, in case anyone finds it useful, I removed "clutter" in the textview by removing the neovim left sign column and numbers to maximise the edit space once firenvim is invoked:

vim.api.nvim_create_autocmd({'UIEnter'}, {
  callback = function(event)
    if vim.g.started_by_firenvim then
      vim.opt.laststatus = 0
      vim.opt.number = false
      vim.opt.signcolumn = "no"
    end
  end
})
glacambre commented 3 months ago

The issue was the set viminfo in my vimrc

Huh, interesting, thanks for sharing. I didn't even know Neovim could do this!

On another note, the second autosave function on the home page didn't work

Thanks a lot for reporting this. I probably broke it when I converted the example from vimscript to lua. I fixed it in 992e57666c0d4c301c5a231354b8237d7bae0282 and took the liberty of marking you as the author of the fix, I hope that's okay :).

Praful commented 3 months ago

Thanks @glacambre :) For the function, you may want to include (or provide as comment):

if not vim.g.started_by_firenvim or vim.g.timer_started then
    return
end

Otherwise the timed write will happen even when the user is in nvim/neovide as well as firenvim!