Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

emacs lisp and c-mode: when am I in a comment region

Tags:

emacs

elisp

I'd like to search for regular expressions within a c/c++ buffer, but I want to avoid expression matching a comment region. Is there a way using the c mode to know if a bunch of text is within a comment region (or a point is within a comment region)?

like image 738
fluca1978 Avatar asked Oct 10 '12 09:10

fluca1978


1 Answers

The way to figure that out is with syntax-ppss which works in C/C++ and most major modes. E.g. (null (nth 8 (syntax-ppss))) will be non-nil if and only if you're not within a string-or-comment.

like image 57
Stefan Avatar answered Oct 26 '22 15:10

Stefan