From: Marcin Borkowski <mbork@mbork.pl>
To: Kaushal Modi <kaushal.modi@gmail.com>
Cc: 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 16:09:52 +0200 [thread overview]
Message-ID: <87r39mp3rj.fsf@mbork.pl> (raw)
In-Reply-To: <CAFyQvY0tiV6cWQibXd1efo1tEgqHB8OUAwMXX4aJ-rjfLF8v-w@mail.gmail.com>
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
next prev parent reply other threads:[~2016-08-18 14:09 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
2016-08-18 14:09 ` Marcin Borkowski [this message]
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=87r39mp3rj.fsf@mbork.pl \
--to=mbork@mbork.pl \
--cc=help-gnu-emacs@gnu.org \
--cc=kaushal.modi@gmail.com \
/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).