help-gnu-emacs
[Top][All Lists]
Advanced

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

identifiing strings and comments in program source files (to skip them o


From: martin rudalics
Subject: identifiing strings and comments in program source files (to skip them over)
Date: Wed, 26 Apr 2006 08:38:52 +0200
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

> Hi,
>
> isn't it a good idea to use the face property (get-text-property (point)
> 'face) to decide if the point is after a string or comment?
>
> I have a mode what uses font-lock-mode and highlights everything nicely.

Font-lock support modes like jit-lock try to avoid assigning faces to
parts of a buffer that are not displayed.  Hence, a default Emacs
usually does not highlight everything nicely.

> I
> think I could use this (= the face set by font-lock-mode) for identifiing
> if e.g. a search stopped in a string or comment. (I know font-lock-mode
> must be enabled for this.) This way I could omit reparsing the buffer (with
> parse-partial-sexp) e.g. in a function what searches something "real" (=
> strings and comments should be skipped).
>
> What do you think: can a robust solution be built using this approach?

Not really.  Fontification is synchronized with redisplay.  Determining
whether a search stopped in a string or comment, on the other hand,
should work independently of whether redisplay happened.  In particular,
contextual fontification - the thing you see happening when you insert a
single double-quote in an elisp buffer - occurs by default not earlier
than .5 seconds after you inserted the double-quote - so your search
would have to wait until that has been done.  Deferred fontification and
syntax-table properties get things more complicated even.

You could explicitly fontify the area you want to search through, but
this might require fontifying the entire buffer and thus would not
provide any advantage: After all font-lock would have to reparse the
entire buffer for this purpose.  To check whether searching stopped in a
comment or string you could parse from `beginning-of-defun' or something
similar instead - `syntax-ppss' does that.






reply via email to

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