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

Gradual movement (regex query string, goto_next and goto_previous without specifying start / end) #360

Merged
merged 7 commits into from
Jan 17, 2023

Conversation

kiyoon
Copy link
Collaborator

@kiyoon kiyoon commented Jan 14, 2023

Before merging #359 I wanted to show you this.

At the moment, my keymaps are quite polluted.

      goto_next_start = {
        ["]m"] = "@function.outer",
        ["]f"] = "@call.outer",
        ["]d"] = "@conditional.outer",
        ["]o"] = "@loop.outer",
        ["]s"] = "@statement.outer",
        ["]a"] = "@parameter.outer",
        ["]c"] = "@comment.outer",
        ["]b"] = "@block.outer",
        ["]l"] = { query = "@class.outer", desc = "next class start" },
        ["]]m"] = "@function.inner",
        ["]]f"] = "@call.inner",
        ["]]d"] = "@conditional.inner",
        ["]]o"] = "@loop.inner",
        ["]]a"] = "@parameter.inner",
        ["]]b"] = "@block.inner",
        ["]]l"] = { query = "@class.inner", desc = "next class start inner" },
      },
      goto_next_end = {
        ["]M"] = "@function.outer",
        ["]F"] = "@call.outer",
        ["]D"] = "@conditional.outer",
        ["]O"] = "@loop.outer",
        ["]S"] = "@statement.outer",
        ["]A"] = "@parameter.outer",
        ["]C"] = "@comment.outer",
        ["]B"] = "@block.outer",
        ["]L"] = "@class.outer",
        ["]]M"] = "@function.inner",
        ["]]F"] = "@call.inner",
        ["]]D"] = "@conditional.inner",
        ["]]O"] = "@loop.inner",
        ["]]A"] = "@parameter.inner",
        ["]]B"] = "@block.inner",
        ["]]L"] = "@class.inner",
      },
      goto_previous_start = {
        ["[m"] = "@function.outer",
        ["[f"] = "@call.outer",
        ["[d"] = "@conditional.outer",
        ["[o"] = "@loop.outer",
        ["[s"] = "@statement.outer",
        ["[a"] = "@parameter.outer",
        ["[c"] = "@comment.outer",
        ["[b"] = "@block.outer",
        ["[l"] = "@class.outer",
        ["[[m"] = "@function.inner",
        ["[[f"] = "@call.inner",
        ["[[d"] = "@conditional.inner",
        ["[[o"] = "@loop.inner",
        ["[[a"] = "@parameter.inner",
        ["[[b"] = "@block.inner",
        ["[[l"] = "@class.inner",
      },
      goto_previous_end = {
        ["[M"] = "@function.outer",
        ["[F"] = "@call.outer",
        ["[D"] = "@conditional.outer",
        ["[O"] = "@loop.outer",
        ["[S"] = "@statement.outer",
        ["[A"] = "@parameter.outer",
        ["[C"] = "@comment.outer",
        ["[B"] = "@block.outer",
        ["[L"] = "@class.outer",
        ["[[M"] = "@function.inner",
        ["[[F"] = "@call.inner",
        ["[[D"] = "@conditional.inner",
        ["[[O"] = "@loop.inner",
        ["[[A"] = "@parameter.inner",
        ["[[B"] = "@block.inner",
        ["[[L"] = "@class.inner",
      },

This patch enables you to group things together if you wish.

      goto_next = {
        ["]m"] = "@function.*",
        ["]f"] = "@call.*",
        ["]o"] = { query = { "@loop.*", "@conditional.*" }, desc = "Next loop or conditional" },
        ["]s"] = "@statement.*",
        ["]a"] = "@parameter.*",
        ["]c"] = "@comment.*",
        ["]b"] = "@block.*",
        ["]l"] = { query = "@class.*", desc = "next class start/end" },
      },
      goto_previous = {
        ["[m"] = "@function.*",
        ["[f"] = "@call.*",
        ["[o"] = { query = { "@loop.*", "@conditional.*" }, desc = "Previous loop or conditional" },
        ["[s"] = "@statement.*",
        ["[a"] = "@parameter.*",
        ["[c"] = "@comment.*",
        ["[b"] = "@block.*",
        ["[l"] = { query = "@class.*", desc = "previous class start/end" },
      },

(I just noticed that you can already add multiple queries, however it isn't documented)

Along with the power of repeatable movements, for some people it may be a good bonus as they can go to the right part they want without going for a complicated keymapping.

The regex queries are supported in the original goto_next_start etc. as well.
It will stay mostly compatible with the previous setup, except that now the dot will match any character. If you have a custom query named @functionQinner then it will be matched with @function.inner

@kiyoon kiyoon requested a review from theHamsta January 14, 2023 21:47
@kiyoon kiyoon force-pushed the feat-gradual-move branch from abaf39a to 397a438 Compare January 14, 2023 21:56
@kiyoon kiyoon changed the title Gradual movement (regex query string, goto_next and goto_previous without specifying start position) Gradual movement (regex query string, goto_next and goto_previous without specifying start / end) Jan 14, 2023
@theHamsta
Copy link
Member

theHamsta commented Jan 14, 2023

How complicated would it be it integrate https://github.com/nvim-treesitter/nvim-treesitter-textobjects/pull/60/files in your PR for move? At the moment, you always call "textobjects" for find_best_match, would it be possible to allow queryies from other queries types as well?

@kiyoon
Copy link
Collaborator Author

kiyoon commented Jan 14, 2023

How complicated would it be it integrate https://github.com/nvim-treesitter/nvim-treesitter-textobjects/pull/60/files in your PR for move? At the moment, you always call "textobjects" for find_best_match, would it be possible to allow queryies from other queries types as well?

Any reason it hasn't been merged?

Where should the locals.scm file be located in order to test this?

@theHamsta
Copy link
Member

theHamsta commented Jan 14, 2023

How complicated would it be it integrate https://github.com/nvim-treesitter/nvim-treesitter-textobjects/pull/60/files in your PR for move? At the moment, you always call "textobjects" for find_best_match, would it be possible to allow queryies from other queries types as well?

Any reason it hasn't been merged?

Where should the locals.scm file be located in order to test this?

It isn't about "locals" in specifc, in order for textobjects to work, you need to have queries/<lang>/textobjects.scm in you path. The idea of this PR is to also allow queries/<lang>/<something>.scm. nvim-treesitter provides queries for highlights.scm/locals.scm/indent.scm/folds.scm. So all of these should work. They just need to be in your runtimepath, e.g. relative to some plugin path.

I was a bit hesitant whether we should allow this right now and now it is a bit out-dated. There we a lot of PRs touching the same code at that time. But since you're touching the config anyways you could also make it more general. At least it should be possible to add alternative query groups in retroperspecitve

@kiyoon
Copy link
Collaborator Author

kiyoon commented Jan 14, 2023

@theHamsta I see, the scope movement is actually amazing!
Now I added the query group to the movement.
It is only in movement atm and not in others yet.

@kiyoon
Copy link
Collaborator Author

kiyoon commented Jan 14, 2023

Should I make multiple query groups selectable? I feel like this will make it super complicated and most people wouldn't really select from multiple groups?

@kiyoon
Copy link
Collaborator Author

kiyoon commented Jan 15, 2023

Finished integrating #60

@kiyoon
Copy link
Collaborator Author

kiyoon commented Jan 15, 2023

Tests passing

Copy link
Member

@theHamsta theHamsta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, cool! I actually only meant to consider it for movement to see whether the config stays compatible without adding too much code. But cool that you made it working for all categories

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.

2 participants