Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keymaps not set properly if plugin is lazy loaded #72

Closed
matthewsia98 opened this issue Mar 24, 2023 · 1 comment
Closed

Keymaps not set properly if plugin is lazy loaded #72

matthewsia98 opened this issue Mar 24, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@matthewsia98
Copy link
Contributor

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
@matthewsia98 matthewsia98 added the bug Something isn't working label Mar 24, 2023
@kiyoon
Copy link
Owner

kiyoon commented Mar 24, 2023

function M.string_wildcard_match(str, pattern)
return str:match(M.wildcard_to_regex(pattern))
end
function M.list_wildcard_match(str, patterns)
for _, pattern in ipairs(patterns) do
if M.string_wildcard_match(str, pattern) ~= nil then
return true
end
end
return false
end

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants