Re: Fastest but still reliable way to check if in a comment
Stefan Monnier via Users list for the GNU Emacs text editor <[email protected]>
| Newsgroups | gmane.emacs.help |
|---|---|
| Message-ID | <[email protected]> |
> and see if the result is non-nil. The computation is not cheap, which > is an issue if we are using this function in a loop. Depends on the loop. If the loop moves monotonically forward across a region, then an option is to use `syntax-ppss` for the beginning of the region and then `parse-partial-sexp` to update the previous PPSS to the new position. > (memq (get-text-property (point) 'face) > '(font-lock-comment-delimiter-face > font-lock-comment-face)) That can work well as well, tho it depends on what failure modes you care (or not) about, e.g.: - Fails if jit-lock hasn't gotten to it yet (e.g. it's outside the displayed area). - Fails if `face` contains a list of faces. - Works even on comments recognized via `font-lock-keywords` rather than via syntax tables. - ... === Stefan