[英]Emacs search by exact regex match instead of partial
I'm looking through a very large hydrodynamics code in c
which has, often, some very poor variables choices. 我正在查看
c
非常大的流体动力学代码,其中通常有一些非常差的变量选择。 Including a global variable named just 'g'. 包括一个名为'g'的全局变量。 Similarly, there's a file with a variable named 'geom' and lots of other variables which contain the substring 'geom' (eg geometry, geomAL, geom_arb, etc.).
类似地,有一个文件带有一个名为'geom'的变量和许多其他包含子串'geom'的变量(例如geometry,geomAL,geom_arb等)。
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'. 例如:搜索'geom'与'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?
显然,emacs并不是先验知道变量的开始或结束位置,但是这可以构造为c模式的函数吗?
The Emacs regular expression engine ( CMs <regexp>
) has various operands for this sort of thing, such as the word boundary \\<
and \\>
zero-width assertions. Emacs正则表达式引擎( CMs
<regexp>
)具有各种操作数,例如单词boundary \\<
和\\>
零宽度断言。 So \\<geom\\>
would match geom
alone and (depending on your mode's syntax table) perhaps also the prefix in geom_something
. 所以
\\<geom\\>
会单独匹配geom
并且(取决于你的模式的语法表)也可能是geom_something
的前缀。 Try \\<geom\\>[^_]
if you need to exclude the underscore suffix. 如果您需要排除下划线后缀,请尝试
\\<geom\\>[^_]
。
You can use Cu Cs \\_<g\\_>
which will search for the symbol g
using a regular expression search with symbol-boundary markers. 您可以使用
Cu Cs \\_<g\\_>
,它将使用带符号边界标记的正则表达式搜索来搜索符号 g
。 Or in a recent enough Emacs you can do Ms _ g
which will do essentially the same ( Ms
is the "search prefix key" in which Ms _
is isearch-forward-symbol
). 或者在最近的Emacs中,你可以做
Ms _ g
,它基本上是相同的( Ms
是“搜索前缀键”,其中Ms _
是isearch-forward-symbol
)。
Have you tried out the Emacs TAGS system? 你试过Emacs TAGS系统吗? It should be able to parse the vars out and it might offer exact lookups.
它应该能够解析变量,它可能提供精确的查找。 See here: http://www.emacswiki.org/emacs/EmacsTags
见这里: http : //www.emacswiki.org/emacs/EmacsTags
Generate the tags table with the etags helper: 使用etags帮助器生成tags表:
etags *.c
Look for a tag with 寻找标签
M-. your-var-name
http://www.emacswiki.org/emacs/RegularExpression拥有您想要使用emacs regexp所需的一切。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.