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: Clément Pit--Claudel
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 10:03:12 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0

On 03/10/2016 09:28 AM, Stefan Monnier wrote:
>>> (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.

Thanks for the clarification. What's the recommended way to check if the point 
is in a comment, then? I'm thinking for example of adjusting 
fill-nobreak-predicate, or similar things.

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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