1

So, Dr. Racket has a very interesting feature where you can see all occurrences of a bound variable if you hover it:

Screencap of Dr Racket showing a definition of the quadratic equation with arrows pointing from the definition of b to its occurrences within the scope

Is there a way to do something similar in Emacs? I'm currently editing C++ code. It doesn't need to be super-sophisticated: I'd be super-happy with just the local lexical context.


This2 proved really useful to me, but it will highlight any matching words in the entire text, not just the code (let alone the enclosing lexical context.)

Drew
  • 75,699
  • 9
  • 109
  • 225
Romário
  • 123
  • 6
  • Fancy. That feels like the sort of feature that the upcoming tree-sitter integration might facilitate. Maybe `semantic` can already do it? – phils Nov 23 '21 at 00:25

1 Answers1

2

It depends on the language. For Javascript, js2-mode has a complete language parser and so understand exactly which words really are variables, and which are the correct ones. js2-refactor has some functionality that relies on that exact information; I believe it can both highlight all occurrences of a variable and rename it, though it doesn’t draw lines over the top like that.

For C++, I have heard people mention the srefactor package. I’ve never used it though, so I don’t know if it does exactly what you want. You might also be interested in a general guide to related Emacs packages for C/C++ development.

There is also lsp-mode, which is all the rage at the moment.

db48x
  • 15,741
  • 1
  • 19
  • 23