I have some lisp code that contains a comment:
(while list ;; take the head of LIST (setq len 1))
I want to extract the positions of the sexps. I'm using
scan-sexps. If I call
M-: (scan-sexps 12 1) with the above code in a buffer, it returns 54, as expected.
However, if I try to do this programmatically:
(setq src "(while list ;; take the head of LIST (setq len 1))") (with-temp-buffer (insert src) (scan-sexps 12 1))
I get 22! This seems to be parsing the words in my comment. Why don't I get 54, and how do I fix this?
Reading the docstring for
scan-sexps, it mentions
parse-sexp-ignore-comments. However, this doesn't seem to affect the outcome:
(with-temp-buffer (insert src) (setq parse-sexp-ignore-comments t) (scan-sexps 12 1)) ; still 22
How can I make
scan-sexps return the end position of the next sexp, ignoring comments?