[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Iterating/Finding all Comment- and String-Regions

From: Drew Adams
Subject: RE: Iterating/Finding all Comment- and String-Regions
Date: Fri, 18 Dec 2009 08:00:31 -0800

> How can I find iterate over all the comment- and string-regions (BEG
> END) in a buffer using the mode-specific syntax?

Consider taking advantage of font-locking. Look for text property `face' with
the particular face(s) you want - e.g. `font-lock-comment-face',
`font-lock-string-face', or `font-lock-doc-face'. This approach lets font-lock
do the work of parsing the mode-specific syntax. All you need to do is gather up
and treat the pieces of text that have the text property you want.

Since you use Icicles, take a look, Per, at function
`icicle-search-char-property-scan'. It does just that: iterates over the
occurrences of a given character property (i.e. a text or overlay property),
such as `face', that have a given value, such as `font-lock-comment-face'. Each
occurrence is a region such as you described.

It is used by the Icicles commands (`icicle-search-text-property',
`icicle-search-overlay-property', and `icicle-search-char-property') that let
you search for (regexp) matches among such occurrences only. It is the function
that builds the list of such occurrences as a set of completions, which are then
filtered interactively by your minibuffer input.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]