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)?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With