emacs-devel
[Top][All Lists]
Advanced

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

Re: How do you check if the current point is in a comment or a string? (


From: Stefan Monnier
Subject: Re: How do you check if the current point is in a comment or a string? (Was Re: Problems with syntax-ppss: Was [... Apply `comment-depth' text properties when calling `back_comment'.])
Date: Thu, 10 Mar 2016 09:28:00 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

>> (nth 8 (syntax-ppss)) works fine for me in something like ";; some
>> comment in an emacs-lisp-mode buffer"; it returns the starting point
>> of the comment.
> Does it really? For me it returns nil when the point is as shown below:
>   <point>;; some comment in an emacs-lisp-mode buffer

That's correct, because point is *not* inside the comment.

> In all these cases, the font trick works.

Here it's because `get-text-property' returns the property of the
character after point, and indeed this is ";" which is in the comment.

IOW they're both correct because they don't ask the same thing.

> In C mode, it returns nil in the following two positions:
>
>   /<point>/ asd
>   <point>// asd
>
> As well as these two:
>
>   <point>/* asd */
>   /<point>* asd */

Indeed, this is a current problem with parse-partial-sexp (and hence
syntax-ppss) and is directly related to what Alan was referring to.

Given the way parse-partial-sexp works (i.e. it can only look at the
text that precedes), even if we fix it, parse-partial-sexp wouldn't be
able to tell you that <point> is inside a comment.  But it could tell
you that it's in the middle of something that could turn out to be
a comment.


        Stefan




reply via email to

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