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: Kaushal Modi
Subject: Re: How to check whether the current line is a comment-only one?
Date: Thu, 18 Aug 2016 11:39:27 +0000

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.

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.

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

Kaushal

On Thu, Aug 18, 2016, 3:17 AM Marcin Borkowski <address@hidden> wrote:

> Hi folks,
>
> is there a predicate function to determine whether the line the point is
> in is entirely a comment line?  I'd prefer this function to work in
> various modes (for Elisp mode, it's trivial; for C, less so).
>
-- 

Kaushal Modi


reply via email to

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