A plugin for kakoune to allow easy navigation through paired characters (parenthesis, brackets, etc). - GitHub - useredsa/dynamic-matching.kak: A plugin for kakoune to allow easy navigation through...
I think this should be the default behaviour of the m
/M
keys (selecting the next match, even if it’s without selecting delimiters). But for the moment, I’ll use this plugin.
Related Issues:
opened 11:09PM - 02 Jan 14 UTC
for whole or inner object, when expansion fails, and `opener_token` was specifie… d, it will search the buffer backwards for the block or, if `closer_token` was specified, it will search the buffer forwards.
[![](http://i.imgur.com/tmj0KhLl.png)](http://i.imgur.com/tmj0KhL.png)
opened 02:56AM - 30 Nov 18 UTC
From the buffer:
```
(one)
(two)
(three)
```
Input:
1. `ggm` - The firs… t line `(one)` is selected, the cursor is on the first `)` in the file.
2. `m` - The selection doesn't change, the cursor is on the first `(` in the file.
3. `m` - Same state as 1
4. `<a-m>` - Same state as 2
In this example, it doesn't matter if you do `m` or `<a-m>` at any point. They always do the same thing.
What I expect is:
1. `ggm` - The first line `(one)` is selected, the cursor is on the first `)` in the file.
2. `<a-m>` - The selection is unchanged, the cursor is on the first `(` in the file.
3. `mm` - The second line `(two)` is selected, the cursor is on the second `)` in the file.
4. `<a-m><a-m>` - The first line `(one)` is selected, the cursor is on first `(` in the file.
4. `mmm` - The third line `(three)` is selection, the cursor is on the third `)` in the file.
Given that `m`'s documentation is "select to the next sequence enclosed by matching character", it should never move backwards, it should either select the next sequence or fail because there is none. Similarly, `<a-m>` should never go forwards.
The example demonstrates that the code definitely doesn't do this. Basically the code does the following:
1. `m` --- Look for a matching pair, move forward if not / `a-m` - Look for a matching pair, move backward if not [i.e. These don't do any movement when the cursor is on a pair character.]
2. If the pair you found is the opening one, move right. If the pair you found is the closing one, move left.
3. Repeat 2 until you find the other side of the pair.
Because only step 1 cares about the command, `m`/`a-m` only influences which direction the initial search happens, not the resulting selection, and because the cursor char is checked first, there's no guarantee of movement, so `m` and `a-m` do the same thing when you're sitting on a matching pair char.
I believe the code should instead do:
1. If `m`, dir = +1, which = opening / if `a-m`, dir = -1, which = closing
2. cursor += dir
3. If cursor is not a which matching pair, then go to 2
4. start selection
5. cursor & selection += dir
5. If cursor is not the match of the which char (level sensitive), then go to 5
If `M` or `a-M`, then step 2 also extends the selection rather than just moving the cursor
This would make it so the repeated uses of `m` would skip through all the blocks of the file. It is a bit awkward when you are inside a block, because it skips over the inside of the block you're inside and moves to the next one, so in my example
`gglm` would highlight `(two)` with the cursor on the second `)` in the file, because that is the "next" sequence enclosed in matching characters. Another idea would be to have this fail by adding a rule in step 2 where if the cursor points to the opposite character, then you stop, so `gglm` would move the cursor to the first `)`.
4 Likes
scr
October 1, 2020, 11:28pm
2
the asciinema doesn’t feet in my screen, ( ~30% bigger ) I think it would be more easy to understand what’s going on if the asciinema size would be less tall
Thanks @scr , I’ll try to record another one. Although I was thinking of submitting a PR to Kakoune to reimplement a bit object selection at some point in my life. This plugin would become useless afterwards.