From: Kaushal Modi <kaushal.modi@gmail.com>
To: Marcin Borkowski <mbork@mbork.pl>,
Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: Re: How to check whether the current line is a comment-only one?
Date: Thu, 18 Aug 2016 11:39:27 +0000 [thread overview]
Message-ID: <CAFyQvY0tiV6cWQibXd1efo1tEgqHB8OUAwMXX4aJ-rjfLF8v-w@mail.gmail.com> (raw)
In-Reply-To: <87vayyppop.fsf@mbork.pl>
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 <mbork@mbork.pl> 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
next prev parent reply other threads:[~2016-08-18 11:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-18 6:16 How to check whether the current line is a comment-only one? Marcin Borkowski
2016-08-18 7:44 ` Stefan Monnier
2016-08-18 14:11 ` Marcin Borkowski
2016-08-18 11:39 ` Kaushal Modi [this message]
2016-08-18 14:09 ` Marcin Borkowski
2016-08-18 14:43 ` Thien-Thi Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAFyQvY0tiV6cWQibXd1efo1tEgqHB8OUAwMXX4aJ-rjfLF8v-w@mail.gmail.com \
--to=kaushal.modi@gmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=mbork@mbork.pl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).