I'm currently implementing Clustered Query-Replace in Emacs. 开发者_C百科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?
I think that 'skip-syntax-forward' does what you want.
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.
精彩评论