Emacs 缓冲区的语法信息
我目前正在 Emacs 中实现集群查询替换。 敏感
- 聚类应该对大小写、
- 符号和单词上下文以及
- 命中是否是纯代码、注释内或字符串文字的一部分
。前两点很容易提高效率。最后一点需要一种有效的方法来提取 Emacs 缓冲区的所有特定于模式语法(语法表
)的注释和字符串区域。我知道 syntax-ppss
但我想要一种更快的方法来获取所有区域。是否有内置函数可以实现此目的,或者我必须手动搜索每个字符串并注释开头-结尾对。我不想依赖 font-lock
因为这对于我的应用程序来说太慢了。
有什么想法吗?
I'm currently implementing Clustered Query-Replace in Emacs. Clustering should be sensitive to
- case,
- symbol and word context and
- whether hit is plain code, inside a comment or part of a string literal
The first two points are easy to make efficient. The last point requires an efficient way to extract all the mode-syntax-specific (syntax-table
) comment- and string-regions of an Emacs buffer. I know of syntax-ppss
but I want a faster way to get all regions. Is there a built-in function for that or do I have to manually search for each string and comment beginning-end pair. I don't want to depend on font-lock
because that is too slow for my application.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为“跳过语法前进”可以满足您的要求。
I think that 'skip-syntax-forward' does what you want.
如果您有可用的 CEDET 工具套件,则可以使用语义工具附带的词法分析来完成这项工作。所有受支持的模式都有一个词法分析器,但这些词法分析器通常会忽略注释。创建仅处理注释和字符串的新词法分析器并不难,
semantic-doc-snarf-comment-for-tag
中有一个用于处理标签文档的示例。词法分析器的好处是它为您提供了一个词法标记列表,您可以通过简单的方式进行过滤。
If you have the CEDET tool suite available, you could use the lexical analyze that comes with the Semantic tool to do this work. All supported modes have a lexer, but these lexers usually ignore comments. Creating new lexical analyzers that just handle comments and strings isn't hard, and there is an example that does this for handling tag documentation in
semantic-doc-snarf-comment-for-tag
.Whats nice about the lexical analyzer is it gives you a list of lexical tokens which you can filter through in a simple way.