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

include_surrounding_whitespace should be an option on the mapping itself #431

Open
myarcana opened this issue Apr 4, 2023 · 2 comments
Open
Labels
enhancement New feature or request

Comments

@myarcana
Copy link

myarcana commented Apr 4, 2023

Instead of requiring users to implement and write their own monolithic function themselves as in

keymaps = {
    ["af"] = "@function.outer",
    ["if"] = "@function.inner",
    ["aa"] = "@attribute.outer",
    ["ia"] = "@attribute.inner",
    ....
],
include_surrounding_whitespace = function (a)
    if a.query_string == "@function.outer" then
        return false
    elseif a.query_string == "@function.inner" then
        return false
    elseif a.query_string == "@attribute.outer" then
        return true
    elseif a.query_string == "@attribute.inner" then
        return false
    ....
end

I think making it an option on the keymap is a nicer and more expected API:

keymaps = {
    ["af"] = "@function.outer",
    ["if"] = "@function.inner",
    ["aa"] = { query = "@attribute.outer", includes_surrounding_whitespace = true },
    ["ia"] = "@attribute.inner",
    ....
],
@myarcana myarcana added the enhancement New feature or request label Apr 4, 2023
@myarcana
Copy link
Author

myarcana commented Apr 4, 2023

I am also having a problem trying to make an include_surrounding_whitespace function now,

include_surrounding_whitespace = function (a)
    print(vim.inspect(a))
    print(vim.inspect(a.query_name))
    ...

prints

{                                                                                                                                                                                                                                 
  query_string = "@attribute.outer",
  selection_mode = "v"
}
nil

The query_name field on the parameter is somehow nil, even though the table looks pretty correct according to vim.inspect

@victorivanov
Copy link

@myarcana, I think you're looking for query_string, like in your original snippet, not for query_name? I have a variation of your snippet in my config, and it works:

     include_surrounding_whitespace = function (query)
        if string.find(query.query_string, "outer") then
          return true
        end

        return false
      end

+1 on handling it via an option

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

No branches or pull requests

2 participants