我希望在c/c++缓冲区中搜索正则表达式,但我希望避免表达式与注释区域匹配。有没有办法使用c模式来知道一堆文本是否在注释区域内(或者一个点是否在注释区域内)?
发布于 2012-10-10 21:20:12
解决这个问题的方法是使用syntax-ppss,它可以在C/C++和大多数主要模式下工作。例如,当且仅当你不在字符串或注释中时,(null (nth 8 (syntax-ppss)))才是非空的。
发布于 2012-10-10 19:29:03
(defun re-search-forward-not-in-comment (regexp)
"Search forward first regexp not inside a comment. "
(interactive
(list (read-from-minibuffer "Regexp: ")))
(while (and (re-search-forward regexp nil t 1)
(and (nth 8 (syntax-ppss))(nth 4 (syntax-ppss))))))https://stackoverflow.com/questions/12815781
复制相似问题