-
Notifications
You must be signed in to change notification settings - Fork 220
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
mini.jump (clever-f) #8
Conversation
Wow, that is great! Thanks! Yes, it does fit in the spirit of this project quite nicely. I don't use any of the clever jumps plugins, so it wasn't implemented earlier. I have quite a lot of questions about particular implementations, but that can wait until you feel like this is good for review. Some general tips which I try to follow:
Scanning through README of 'clever-f' it seems that highlighting possible jumps is pretty crucial to usability. Can this be implemented? If you feel like adding two-char search which will have relatively simple and fast code, then sure, go for it. By the way, I've read many good things about ggandor/lightspeed.nvim. Maybe this should serve as a guide instead of vim-sneak? |
Thanks for the feedback! I used mini.pairs as a "template" to be consistent with your coding style, which explains the expr mappings. I'll get rid of them. Thanks for the tip about
|
I'll look into how to do the highlighting. Personally I find it more annoying than useful. Lightspeed is an interesting concept, but I think it (and labeled jumps in general) might be too complex to fit with mini. |
I currently find using exported function MiniJump.on_cursormoved()
H.ask_for_target = true
end And then having |
The point of clever-f is that if you press f and the last movement was f, then it will repeat the movement instead of prompting for another character. So I need some way to tell if the last movement was f. I haven't looked into how clever-f does it, but the CursorMoved trick seems to work well. |
It looks like |
I think it's pretty much ready for review. It's just missing documentation in README and it's unclear how |
Thank you for this! I'll take a closer look along with hands-on testing this week. What I can say right now:
|
Here is the relevant function from clever-f: function! clever_f#_mark_direct(forward, count) abort
let line = getline('.')
let [_, l, c, _] = getpos('.')
if (a:forward && c >= len(line)) || (!a:forward && c == 1)
" there is no matching characters
return []
endif
if g:clever_f_ignore_case
let line = tolower(line)
endif
let char_count = {}
let matches = []
let indices = a:forward ? range(c, len(line) - 1, 1) : range(c - 2, 0, -1)
for i in indices
let ch = line[i]
" only matches to ASCII
if ch !~# '^[\x00-\x7F]$' | continue | endif
let ch_lower = tolower(ch)
let char_count[ch] = get(char_count, ch, 0) + 1
if g:clever_f_smart_case && ch =~# '\u'
" uppercase characters are doubly counted
let char_count[ch_lower] = get(char_count, ch_lower, 0) + 1
endif
if char_count[ch] == a:count ||
\ (g:clever_f_smart_case && char_count[ch_lower] == a:count)
" NOTE: should not use `matchaddpos(group, [...position])`,
" because the maximum number of position is 8
let m = matchaddpos('CleverFDirect', [[l, i + 1]])
call add(matches, m)
endif
endfor
return matches
endfunction It seems to find and highlight the matches manually, which could be very error-prone, especially with Unicode characters. Also it works only on the current line. I just got an idea on how I might be able to (ab)use syntax highlighting to do it. |
Wow, that was actually very easy! Now the question is, should we highlight matches after/before the cursor, or all of them? The former may or may not be tricky. |
Just curious, what modules are you adding? |
I believe, having highlighting only at those places that are reachable with current command ( I just quickly tried this module and here are some first thoughts:
|
https://github.com/echasnovski/nvim/tree/master/lua/mini-dev . That is my alpha-testing :). |
My intent was to improve the built-in |
Just wanted to say about the problem with multiple consecutive matches :) |
No, it's your plugin after all :) |
Details: - Use `H.is_disabled()`. - Replace default highlight link to `IncSearch`. - Use `pcall` for `vim.fn.matchdelete` as it proved useful in other modules. Currently might be a source of trouble if not resetting highlighting correctly.
Most of the changes are cosmetic. Ones that have side effects are in commit's details. Current thoughts and problems I found so far:
|
|
Details: - Stop using `vim.schedule` inside jumping logic. Instead use separate functions for `CursorMoved` and other events. This seems to be good because `vim.schedule`'s input might get executed too late, resulting into not removing highlight properly. - Store matching information per window. Highlight only in current window, unhighlight in all possible windows (jumping is assumed to be valid only inside current window).
Think I solved most of the immediate issues I found while using it. It seems that most of them were because of I currently kind of like that after Another good idea might be to allow repeating current jump and encourage to use it with I plan to test it through everyday usage and see if there is something we missed. Adam, could you, please, do the same? |
I'm definitely using the module (I have my fork installed as a plugin) and it seems fine for me. But then, I don't use Telescope, so I can't find Telescope-related bugs. The |
@xigoi, I've decided to make a quite big refactor. Didn't do it in this PR to not break your setup. Would you mind looking at this commit in my neovim config and tell me your thoughts? After reaching an agreement regarding these changes I'll plan to merge this PR as is, move it to 'mini-dev' instead of 'mini', make those new changes, and it will be ready for a public beta-testing (hopefully in the upcoming week). |
@xigoi, I'll merge this as is and make updates after. I recently Thank you very much for your ideas, enthusiasm and work! |
v:count
This is a module named
mini.jump
, implementing the basic functionality of clever-f and a basis for the functionality of vim-sneak.Would this fit the spirit of this project? Should I also add two-char search like vim-sneak?(Note: the implementation is currently a bit buggy, but the basic functionality works)