AckslD / nvim-neoclip.lua

Clipboard manager neovim plugin with telescope integration
994 stars 20 forks source link

In custom action, differentiate between a yanked entry and a macro entry #89

Closed Jeansidharta closed 1 year ago

Jeansidharta commented 1 year ago

Hello!

While trying to extend a bit of the telescope functionality for my own use, I've had some difficulty differentiating between an entry created by a yanked text, and an entry created by a macro recording. I want to do something like this:

require('neoclip').setup({
  ...
  keys = {
    ...
    telescope = {
      n = {
        ...
        custom = {
          ['e'] = function(opts)
            local is_listing_macros = ???;
            if is_listing_macros then
              -- macro-related stuff
            else
              -- yank-related stuff
            end
          end,
        },
      },
    },
  },
})

After reading a bit of the source code, the only way I found to achieve what I'm looking for is to check if opts.entry.filetype is nil. Something like local is_listing_macros = opts.entry.filetype == nil. While this works, I feel like it could be better, or at least better documented. So I'd like to know if I missed something, or if we could improve this API, or it's documentation.

My suggestion would be to either pass a second argument to the custom action, after the opts, that's either "yank" or "macro", or to separate custom action handlers for yank or macro in different parts of the setup. If no change to the API is desired, then the documentation could mention something about this in the "Custom actions" section. I'd be willing to create a pull request with the desired changes if needed.

Love the project, and thank you for your time and effort!

AckslD commented 1 year ago

Hi @Jeansidharta! Thanks for a clear issue :)

It would make sense to add another entry to the opts passed to the custom action which indicates if it's a yank or macro. One could add the typ variable to the get_custom_action_handler and include that in the opts.

Would you like to do that in a PR?

Jeansidharta commented 1 year ago

Great! I'll make a PR in a moment. Thank you :)