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

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

Re: How to check whether the current line is a comment-only one?


From: Marcin Borkowski
Subject: Re: How to check whether the current line is a comment-only one?
Date: Thu, 18 Aug 2016 16:09:52 +0200
User-agent: mu4e 0.9.16; emacs 25.1.50.6

On 2016-08-18, at 13:39, Kaushal Modi <kaushal.modi@gmail.com> wrote:

> Hi Marcin,
>
> You can use the syntax-ppss function to check that syntax at the current
> point. You can know if the current point is in a string or a comment, and
> so on.
>
> Check out the (elisp) Parser State Info node for more info.
>
> If (nth 4 (syntax-ppss)) returns a non-nil value, the point is currently in
> a comment.

Well, I was afraid someone would tell me that...  I hoped for some other
solution.  But thanks anyway.

> Now, do you need to know if the *entire* line is a comment?  If so, the
> solution gets a bit complicated, but you can do it with the help of (nth 4
> (syntax-ppss)) by moving the point to various positions on the line.

Yes, I want to know exactly that.  The rationale is that I'm working on
bug #21072 (still - slowly but steadily...), and I want mark-defun to
include comment-only lines preceding the defun.  (I'm going to report on
my work on #21072 soon - I implemented a nice (imho) macro to help test
functions/commands which move point and/or mark around.)

> Here's a simple example of one of my uses of syntax-ppss:
>
> https://github.com/kaushalmodi/.emacs.d/blob/e8418e97abd36e5eeaf6376555b17c79e06a56fa/setup-files/setup-editing.el#L381
>
> Here's a little more complicated example:
>
> https://github.com/kaushalmodi/.emacs.d/blob/e8418e97abd36e5eeaf6376555b17c79e06a56fa/setup-files/setup-editing.el#L81

Thanks, I'll look into these a bit later.

> Kaushal

Best,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



reply via email to

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