kiyoon / jupynium.nvim

Selenium-automated Jupyter Notebook that is synchronised with NeoVim in real-time.
MIT License
486 stars 15 forks source link

Keymaps not set properly if plugin is lazy loaded #72

Closed matthewsia98 closed 1 year ago

matthewsia98 commented 1 year ago

Default keymaps are not applied when plugin is lazy loaded like this

return {
    "kiyoon/jupynium.nvim",
    build = "pip3 install --user .",
    event = "BufWinEnter *.ju.py",
    config = function()
       require("jupynium").setup({})
   end
}

I tried adding this bit of logic to the plugin setup function but it doesn't work because autocommand-patterns are not the same as lua patterns.

I also tried using glob2regpat but that didn't quite work either.

So I guess the question boils down to how do we check if a filename matches an autocommand-pattern. I haven't been able to figure that out.

local filename = vim.fn.expand "%"
local buf_id = vim.api.nvim_get_current_buf()
for _, pattern in ipairs(options.opts.jupynium_file_pattern) do
  if filename:match(pattern) then
    if options.opts.use_default_keybindings then
      M.set_default_keymaps(buf_id)
    end
    if options.opts.textobjects.use_default_keybindings then
      textobj.set_default_keymaps(buf_id)
    end
    break
  end
end
kiyoon commented 1 year ago

https://github.com/kiyoon/jupynium.nvim/blob/01162b073af272701709511ff60aa1a9bcbf1ca3/lua/jupynium/utils.lua#L28-L39

You can use these functions to match wildcard, if that's what you need. I think the problem of autocmds is that, Jupynium also sets autocmds and the lazy loading only happens on autocmds, so the commands wouldn't be executed the first time the event happens.