* identifiing strings and comments in program source files (to skip them over)
@ 2006-04-26 6:38 martin rudalics
0 siblings, 0 replies; 7+ messages in thread
From: martin rudalics @ 2006-04-26 6:38 UTC (permalink / raw)
Cc: help-gnu-emacs
> 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.
^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <mailman.964.1146057880.9609.help-gnu-emacs@gnu.org>]
* Re: identifiing strings and comments in program source files (to skip them over)
[not found] <mailman.964.1146057880.9609.help-gnu-emacs@gnu.org>
@ 2006-04-26 19:05 ` Peter Tury
0 siblings, 0 replies; 7+ messages in thread
From: Peter Tury @ 2006-04-26 19:05 UTC (permalink / raw)
On Wed, 26 Apr 2006 08:38:52 +0200, martin rudalics wrote:
> 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.
Thanks for this detailed explanation also! My problem is that I have legacy
code (with ~1 MB source files sometimes) and I can't really imagine
anything for beginning-of-defun. E.g. C-like /*...*/ works for commenting
and whole subprograms can be commented out... In other words: I think I
should have to start parsing everytime from the beginning of the buffer...
Any idea? Or 1MB source files are not too big for this on today's PCs?
Br,
P
^ permalink raw reply [flat|nested] 7+ messages in thread
* identifiing strings and comments in program source files (to skip them over)
@ 2006-04-25 21:14 Peter Tury
2006-04-26 3:53 ` Thien-Thi Nguyen
2006-04-26 6:01 ` Stefan Monnier
0 siblings, 2 replies; 7+ messages in thread
From: Peter Tury @ 2006-04-25 21:14 UTC (permalink / raw)
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. 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?
Thanks,
P
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: identifiing strings and comments in program source files (to skip them over)
2006-04-25 21:14 Peter Tury
@ 2006-04-26 3:53 ` Thien-Thi Nguyen
2006-04-26 8:04 ` Peter Tury
2006-04-26 6:01 ` Stefan Monnier
1 sibling, 1 reply; 7+ messages in thread
From: Thien-Thi Nguyen @ 2006-04-26 3:53 UTC (permalink / raw)
Peter Tury <tury.peter@gmail.com> writes:
> What do you think: can a robust solution be built using this approach?
yes, if you now how (and how much) to wait for font lock to do its job:
if the scanning you have in mind occurs before font lock is done, it may
give incorrect results. this can be difficult to debug because by the
time you notice the incorrect results, font lock may have finished.
thi
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: identifiing strings and comments in program source files (to skip them over)
2006-04-26 3:53 ` Thien-Thi Nguyen
@ 2006-04-26 8:04 ` Peter Tury
0 siblings, 0 replies; 7+ messages in thread
From: Peter Tury @ 2006-04-26 8:04 UTC (permalink / raw)
On Wed, 26 Apr 2006 05:53:01 +0200, Thien-Thi Nguyen wrote:
> Peter Tury <tury.peter@gmail.com> writes:
>
>> What do you think: can a robust solution be built using this approach?
>
> yes, if you now how (and how much) to wait for font lock to do its job:
Yes, I had a feeling this could be a problem.
When I eval (text-properties-at (point)) I see e.g. (face
font-lock-comment-face fontified t). Can I use this "fontified" for
checking if font lock is done? Or this remains always t if fontified once?
What is this "fontified" exactly? How can I get more info? Please point me
some place in the manual.
Anyway, I would like to get some hideshow ;-)) (I couldn't use hideshow.el
until now for this major mode; now I plan to reuse it somehow, with
modifications.) So I hope fontification will be ready when I search (for
hide/show.)
Thanks!
P
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: identifiing strings and comments in program source files (to skip them over)
2006-04-25 21:14 Peter Tury
2006-04-26 3:53 ` Thien-Thi Nguyen
@ 2006-04-26 6:01 ` Stefan Monnier
2006-04-26 8:06 ` Peter Tury
1 sibling, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2006-04-26 6:01 UTC (permalink / raw)
> I have a mode what uses font-lock-mode and highlights 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).
You can use this (I've used it in several occasions).
In Emacs-CVS you can also use syntax-ppss which is like parse-partial-sexp
except it does caching (and it's used by font-lock so the cache is already
filled by the font-lock activity).
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: identifiing strings and comments in program source files (to skip them over)
2006-04-26 6:01 ` Stefan Monnier
@ 2006-04-26 8:06 ` Peter Tury
0 siblings, 0 replies; 7+ messages in thread
From: Peter Tury @ 2006-04-26 8:06 UTC (permalink / raw)
On Wed, 26 Apr 2006 02:01:53 -0400, Stefan Monnier wrote:
> In Emacs-CVS you can also use syntax-ppss which is like parse-partial-sexp
> except it does caching (and it's used by font-lock so the cache is already
> filled by the font-lock activity).
Thanks! I will check this syntax-ppss also!
P
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2006-04-26 19:05 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-26 6:38 identifiing strings and comments in program source files (to skip them over) martin rudalics
[not found] <mailman.964.1146057880.9609.help-gnu-emacs@gnu.org>
2006-04-26 19:05 ` Peter Tury
-- strict thread matches above, loose matches on Subject: below --
2006-04-25 21:14 Peter Tury
2006-04-26 3:53 ` Thien-Thi Nguyen
2006-04-26 8:04 ` Peter Tury
2006-04-26 6:01 ` Stefan Monnier
2006-04-26 8:06 ` Peter Tury
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).