R-nvim / R.nvim

Neovim plugin to edit R files
GNU General Public License v3.0
128 stars 15 forks source link

hook defined in the config r.nvim works for only the first opened *.r file #120

Closed samtrek closed 2 months ago

samtrek commented 2 months ago

The hook defined in the r.nvim config file works only for the first opened .r files (not tested in .rmd), without closing the first file, other opened *.r files do not respond to the keybinds within the hook.

Anyway to implement it in such a way that the hook applies to all .r files and possibly .rmd files?

jalvesaq commented 2 months ago

Are you using the new hook on_filetype?

samtrek commented 2 months ago

the hook defined in my config looks like this, lifted directly form the suggested config, I did not use the on_filetype, it only has the after_config (I have little knowledge of lua, so I try to keep my config similar to the suggested config). All the other localleader+other keybindings work as they should, just that the config below is very continent and I have gotten used to it.

hook = { after_config = function() -- This function will be called at the FileType event -- of files supported by R.nvim. This is an -- opportunity to create mappings local to buffers. if vim.o.syntax ~= "rbrowser" then vim.api.nvim_buf_set_keymap(0, "n", "", "RDSendLine", {}) vim.api.nvim_buf_set_keymap(0, "v", "", "RSendSelection", {}) end -- Pipe operator vim.api.nvim_buf_set_keymap(0, "i", "", " |>", {}) end, },

jalvesaq commented 2 months ago

I forgot to update the README. But I will change the example to:

hook = {
  on_filetype = function ()
    -- This function will be called at the FileType event
    -- of files supported by R.nvim. This is an
    -- opportunity to create mappings local to buffers.
    vim.api.nvim_buf_set_keymap(0, "n", "<Enter>", "<Plug>RDSendLine", {})
    vim.api.nvim_buf_set_keymap(0, "v", "<Enter>", "<Plug>RSendSelection", {})
  end
},
samtrek commented 2 months ago

Yes that did the trick thank you once again for your efforts.