Elisp: Determine Cursor is Inside String or Comment

By Xah Lee. Date: . Last updated: .

Check If Cursor is Inside String

;; return true if cursor is inside a string.
(nth 3 (syntax-ppss))

Check If Cursor is Inside Comment

;; return true if cursor is inside a comment.
(nth 4 (syntax-ppss))

2014-06-26 thanks to Elias Martenson https://plus.google.com/+EliasMartenson/posts for feedback.

Reference

Elisp, character and syntax table