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

Fails to override telescope picker when called from lua #2

Closed
1412031 opened this issue Jan 12, 2023 · 3 comments
Closed

Fails to override telescope picker when called from lua #2

1412031 opened this issue Jan 12, 2023 · 3 comments

Comments

@1412031
Copy link

1412031 commented Jan 12, 2023

Hey! First of all a bit of appreciation, I've been longing for such functionality ever since I started using telescope and I feel more than happy as the lack of it has long been slowing me down and causing mental unnecessary overhead. Definitely the plugin of the year for me, hehe, thanks a lot!

You could very well be aware of it and it might not be intended to work this way in any way.

When calling the telescope picker directly from lua code for example
vim.keymap.set('n', '<leader>f', require'telescope'.builtins.find_files)

The override process doesn't work at all. And the default picker is used.
I'm mostly opening this issue cause I've spent quite some time trying to figure out why it hasn't installed properly and it turned out to be the way I was invoking telescope, so it might be useful to add a little note in the readme tipping the users about it so they don't end up wasting any time like I did.

you're the man, really thanks for that

@prochri
Copy link
Owner

prochri commented Jan 12, 2023

Hey! Glad you enjoy the plugin!

I have not tested anything, but most likely, you set the keybinding before setting up this plugin.
Thus the keymap refers to the old (not overriden) function and does not work.

So to work around that, you can:

  1. Load the plugin first and then set the keymaps
  2. Wrap the call in a lua function, like that: vim.keymap.set('n', '<leader>f', function() require'telescope'.builtins.find_files() end). This will resolve the function once the keybinding is pressed.
  3. Use any other method of creating the keybinding.

I will add a short section to the README about this.

@KentVu
Copy link

KentVu commented May 13, 2024

Load the plugin first and then set the keymaps

I don't know if adding the keymap to this plugin's lazy spec's keys field is sufficient to make it load first?

For ex.:

{
  'prochri/telescope-all-recent.nvim',
  keys = {
   { "<leader>...",  require("telescope")...},
  },
  ...
}

@prochri
Copy link
Owner

prochri commented May 19, 2024

Tbh, when in doubt, wrap it with a function as in (2.), then it will always use the currently bound function. Then you only have to make sure, that the plugin is loaded correctly. This should also work in lazy's keys section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants