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: Andreas Röhler
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: Sat, 12 Mar 2016 21:45:32 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Icedove/38.5.0



On 10.03.2016 15:28, 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.

Can't see any issue with parse-partial-sexp - see attachment.


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.

That's dead wrong: parse-partial-sexp may scan from BOB - and it must in certain cases to detect being in comment or not. If it must scan from BOB or not depends from language resp. syntax of comments.

   But it could tell
you that it's in the middle of something that could turn out to be
a comment.


         Stefan



Attachment: comment.png
Description: PNG image


reply via email to

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