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

feat(pickers): default attach_mappings for all pickers #3201

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

evertonse
Copy link

Description

Allows attach_mappings function to be defined in telescope.defaults that will be used as default for all pickers
If you define attach_mappings on specific picker, that'll be used instead.

Use case is that it was needed to perform some operations using prompt_bufnr as soon as the picker started.
It was ideal to perform that for all pickers and just override when necessary, but saw no way of doing that.
Example:

-- Defaulting to turn off winbleding specifically on the prompt window, (everything else was on windblend 20)
      ...
      defaults = {

        attach_mappings = function(prompt_bufnr, map)
          local prompt_win = vim.fn.bufwinid(prompt_bufnr)
          if prompt_win ~= -1 then
            vim.schedule(function()
              vim.api.nvim_win_set_option(prompt_win, 'winblend', 0) -- Set the desired winblend for the prompt window
            end)
          end
          return true
        end,
      }
      ...
        

Testing

Should see 'We are balling' when a picker is opened.

require('telescope').setup {
  defaults = {
    attach_mappings = function(prompt_bufnr, map)
      local prompt_win = vim.fn.bufwinid(prompt_bufnr)
      if prompt_win ~= -1 then
        vim.schedule(function()
          print 'We are balling'
        end)
      end
      return true
    end,
  },
}

@evertonse evertonse changed the title feat(pickers): default attach_mapping for all pickers feat(pickers): default attach_mappings for all pickers Jul 10, 2024
@Conni2461
Copy link
Member

attach_mappings SHOULD not be used like this! it would make more sense to consistently support user autocmds for all points where ppl want to inject custom functions OR implement a custom event system. depending on our needs. We have this on our roadmap but no deadline when this will be implemented

@evertonse evertonse closed this Jul 11, 2024
@evertonse evertonse reopened this Jul 11, 2024
@evertonse
Copy link
Author

attach_mappings SHOULD not be used like this! it would make more sense to consistently support user autocmds for all points where ppl want to inject custom functions OR implement a custom event system. depending on our needs. We have this on our roadmap but no deadline when this will be implemented

If a default attach_mappings isn't welcome, maybe something like on_attach hook would go a long way.
Allowing specification of a default hook for every picker and optionally on a specific picker to override behaviour.

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

Successfully merging this pull request may close these issues.

None yet

2 participants