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

Highlight occurrences of symbols and alias usages #1461

Closed
robert-stuttaford opened this issue Dec 10, 2015 · 21 comments
Closed

Highlight occurrences of symbols and alias usages #1461

robert-stuttaford opened this issue Dec 10, 2015 · 21 comments

Comments

@robert-stuttaford
Copy link

When I place my cursor on a def'd var or a local symbol, I use https://www.gnu.org/software/emacs/manual/html_node/emacs/Highlight-Interactively.html with a custom idle-highlight face colour to colourise the background of all the occurrences of that symbol.

It would be great if CIDER could support this natively, and also support the highlighting of all the places where a required alias is used.

For example I point at str in [clojure.string :as str], and it highlights all the occurrences of str/<something> in the file.

@bbatsov
Copy link
Member

bbatsov commented Dec 10, 2015

@Malabarba Sounds like something that'd be a nice addition for cider-mode (which some flag to disable it). I think this shouldn't be hard to do.

@Malabarba
Copy link
Member

Shouldn't be hard at all. We could implement this (and a number of other useful feedback) with an idle-timer.

@Malabarba
Copy link
Member

I'm not even sure if we need cider for this. Could possibly go into clojure-mode.

@bbatsov
Copy link
Member

bbatsov commented Dec 10, 2015

We can't use clojure-mode - you won't be certain what a symbol resolves to...

@Malabarba
Copy link
Member

Do you mean for :refers? Because for :as requirements we could just use a regexp.

@Malabarba
Copy link
Member

Anyway, I think this would go better in cider too.

@robert-stuttaford
Copy link
Author

hi-lock-mode works fine for straight-up symbol hilights – so potentially no need to re-invent anything there. It's really the alias case I'm after :-)

@bbatsov
Copy link
Member

bbatsov commented Dec 10, 2015

hi-lock-mode simply highlights some text in the buffer. It has no notion of a var, local, namespace, etc. You can't do proper highlighting without doing some introspection and this is why I believe it's important to do all of this highlighting directly in cider.

@bbatsov bbatsov modified the milestone: v0.11 Dec 11, 2015
@bbatsov
Copy link
Member

bbatsov commented Jan 31, 2016

I wonder how to be best approach this - perhaps we should just look for symbols that are the same in the buffer and try to resolve them to see if they are a match or not. This will be simple, but it probably won't be very efficient.

@Malabarba
Copy link
Member

My first thought is "what do we want to highlight?".

  • Marking all occurrences of a local in the current defn would be the nicest feature to me.
  • I'm still trying to understand how it would work to highlight all usages of a namespace alias (or all usages of a var) automatically. If it's something that happens automatically when I place cursor on the str alias, would it vanish automatically when I move the cursor again?
    I imagine many occurrences are likely to be beyond the visible part of the buffer (and scrolling to view them would vanish the highlight). So maybe the highlight should be somehow semi-permanent? We could have a command to make it permanent, but how can we teach users about the key?

@bbatsov
Copy link
Member

bbatsov commented Feb 1, 2016

Marking all occurrences of a local in the current defn would be the nicest feature to me.

Agreed. Although for vars it makes some sense to highlight them in the entire namespace. Guess this can be configurable.

I imagine many occurrences are likely to be beyond the visible part of the buffer (and scrolling to view them would vanish the highlight). So maybe the highlight should be somehow semi-permanent? We could have a command to make it permanent, but how can we teach users about the key?

Exactly - normally this would happen automatically, but we can add some command about sticky highlighting. The stuff with teaching the users is easy - if we do it by the 11th I'll include it my next CIDER presentation. :-)

We can use our metadata handling functionality to easily highlight some vars, but I'm so sure what we can do about the locals.

@Malabarba
Copy link
Member

Yeah, we can pretty reliably highlight vars thanks to the state tracker. But we can highlight locals semi reliably too, thanks to the code we already have that prevents dynamic font locking of locals.

@bbatsov
Copy link
Member

bbatsov commented Feb 1, 2016

Sounds like a plan to me. Would you volunteer to tackle this? :-)

@Malabarba
Copy link
Member

I'll keep it in mind, but I don't think I'll have time for it before the 11th. :-(

@bbatsov
Copy link
Member

bbatsov commented Feb 1, 2016

No problem. I might do a lightning talk at ClojureD a couple of weeks later. ;-)

@Malabarba Malabarba modified the milestones: v0.11, v0.13.0 Feb 14, 2016
@bbatsov
Copy link
Member

bbatsov commented Oct 9, 2016

@Malabarba any chance you can take a stab at this in the foreseeable future?

@Malabarba
Copy link
Member

I still think it would be nice to have, and I've decided to get back to OSS this week, but this specific issue is not my topmost priority so it may take me a while. :)

@bbatsov
Copy link
Member

bbatsov commented Oct 10, 2016

OK. It's definitely not urgent. It'd be nice to see more of you in the realm of CIDER. :-)

I haven't been doing much OSS work myself lately. Had some pretty quiet months since April, hopefully I'll be able to do more OSS work until the end of the year.

@bbatsov bbatsov removed this from the v0.13.0 milestone Jun 18, 2018
@stale
Copy link

stale bot commented Aug 7, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

@stale stale bot added the stale label Aug 7, 2019
@stale
Copy link

stale bot commented Sep 6, 2019

This issues been automatically closed due to lack of activity. Feel free to re-open it if you ever come back to it.

@stale stale bot closed this as completed Sep 6, 2019
@rgkirch
Copy link

rgkirch commented May 21, 2022

For anyone who finds they way here, like I did, I'll save you a little time and link to a package that does this the "dumb" way.
https://melpa.org/#/idle-highlight-mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants