I'm looking through a very large hydrodynamics code in c
which has, often, some very poor variables choices. Including a global variable named just 'g'. Similarly, there's a file with a variable named 'geom' and lots of other variables which contain the substring 'geom' (e.g. geometry, geomAL, geom_arb, etc.).
Is there any way to search for variables that exactly match a regex, instead of partially?
For example: searching for 'geom' does not match 'geomAL'. Obviously emacs doesn't a priori know where a variable starts or ends, but could this be constructed as a function for c-mode?
The Emacs regular expression engine (C-M-s <regexp>
) has various operands for this sort of thing, such as the word boundary \<
and \>
zero-width assertions. So \<geom\>
would match geom
alone and (depending on your mode's syntax table) perhaps also the prefix in geom_something
. Try \<geom\>[^_]
if you need to exclude the underscore suffix.
You can use C-u C-s \_<g\_>
which will search for the symbol g
using a regular expression search with symbol-boundary markers. Or in a recent enough Emacs you can do M-s _ g
which will do essentially the same (M-s
is the "search prefix key" in which M-s _
is isearch-forward-symbol
).
Have you tried out the Emacs TAGS system? It should be able to parse the vars out and it might offer exact lookups. See here: http://www.emacswiki.org/emacs/EmacsTags
Generate the tags table with the etags helper:
etags *.c
Look for a tag with
M-. your-var-name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With