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

Add ToggleSameIds #943

Merged
merged 1 commit into from
Jul 28, 2016
Merged

Add ToggleSameIds #943

merged 1 commit into from
Jul 28, 2016

Conversation

idawes
Copy link
Contributor

@idawes idawes commented Jul 15, 2016

Auto sameIds is cool, but it doesn't behave nicely in large files, where scolling the screen causes the cursor to move and therefore change the identifier that's being matched. This change allows me to quickly turn on and off same-id highlighting, and have the highlighting stay in effect as I scroll through the file.

@bhcleek
Copy link
Collaborator

bhcleek commented Jul 16, 2016

@idawes I'm interested in addressing the "doesn't behave nicely with large files" that you describe. How big of a file are you working with when you see problems?

@idawes
Copy link
Contributor Author

idawes commented Jul 16, 2016

Perhaps this is something that I've got misconfigured. I'm using neovim in the terminal, and when I scroll the file using the mouse, the cursor stays on its current line until it hits the top (or bottom) of the screen, then moves down (or up) x lines (the mouse scroll distance) to stay in the visible portion of the file. When this happens, auto_sameids causes the highlighted selection to change. This isn't particularly surprising behaviour, given that it is just highlighting instances of whatever identifier is under the current cursor position. It is however undesirable, because I want to be able to see instances of the original highlighted identifier throughout the entire file, not just within one screen.

After submitting this PR, I've actually found that it works better for me to just bind gs to :GoSameIds, and add :GoSameIdsClear to my C-l (clear highlight) binding. That way I can highlight all instances of an identifier throughout a file, then move to another identifier and highlight those without first having to toggle off the highlighting.

@bhcleek
Copy link
Collaborator

bhcleek commented Jul 16, 2016

That makes sense, and I think your expectation is natural. #939 may point a way forward for you. With #939, if there were a function that would toggle g:go_auto_sameids, you could add a mapping that would call that function before you start scrolling. Would that meet your needs?

@idawes
Copy link
Contributor Author

idawes commented Jul 16, 2016

That sounds like another way to address the issue for sure. I think I'll likely stick with turning off auto sameids and manually triggering sameids on and off though, as that currently fits with how I think about the functionality.

I don't mind if you close this pr.

@fatih
Copy link
Owner

fatih commented Jul 16, 2016

I'm also experiencing the same as @idawes. And it's ok because the fix is not possible with current 7.4. I'm using it also for the past week so I have some ideas. My idea to fix it and going forward with vim 8.0 is the following (@bhcleek also shares the same idea as I see)

  • Change :GoSameIds behaviour. When called automatic highlighting of identifiers is enabled.
  • Calling :GoSameIds again will stop automatic highlighting.
  • We still have g:go_auto_sameids, without the commands

With vim 8.0 we're going implement a Job based call. Right now the implementation in emacs has a 200ms latency, so :GoWhat is only called after 200ms when the cursor is stopped. But in our case it's not like that. And honestly I think it should have some caching or blocking mechanism.

What do you think? Does the above makes sense ?

@idawes
Copy link
Contributor Author

idawes commented Jul 16, 2016

That's essentially what I was doing with this PR... I the toggle command bound to gs, so typing that once turned on the highlighting, and typing it again turned it off. I found that it was annoying if I had one thing highlighted and wanted to highlight something else. I had to type it 2 times, once to turn it off and once to start highlighting the new thing.

Now I just have gs bound to GoSameIds, and I call GoSameIdsClear with Ctrl-l. This means that I can turn highlighting on, then move to a new identifier and highlight that, and when I want to clear the highlighting it's the same as clearing the highlighting for a search.

I find this is working really well for me, so I'd prefer if GoSameIds didn't change behaviour. If you want the behaviour you're talking about @fatih, I'd suggest merging this PR and binding to that instead.

@fatih
Copy link
Owner

fatih commented Jul 16, 2016

This PR doesn't automatically enables it. It just highlights for the current cursor. When you move your cursor it doesn't do anything. I the approach I've described is useful and makes sense going forward.

@idawes
Copy link
Contributor Author

idawes commented Jul 16, 2016

Oh right... sorry... missed that you were looking to change it to toggle auto-highlighting. If you do change the behaviour of GoSameIds, would you consider adding another function to trigger highlighting of the current identifier without enabling auto-highlighting?

@bhcleek
Copy link
Collaborator

bhcleek commented Jul 17, 2016

@fatih are you suggesting that GoSameIds be changed to turn on automatic highlighting, or just that GoSameIds should toggle highlighting of the identifier under the cursor? I tend to agree with @idawes - GoSameIds shouldn't toggle g:go_auto_sameids. Now that #939 is merged, though, I think it makes sense to add a specific GoToggleAuto.... for each of the auto features.

@fatih fatih mentioned this pull request Jul 28, 2016
@fatih fatih merged commit 4801d28 into fatih:master Jul 28, 2016
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.

3 participants