From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.help Subject: Re: How to check whether the current line is a comment-only one? Date: Thu, 18 Aug 2016 16:09:52 +0200 Message-ID: <87r39mp3rj.fsf@mbork.pl> References: <87vayyppop.fsf@mbork.pl> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1471529509 6431 195.159.176.226 (18 Aug 2016 14:11:49 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 18 Aug 2016 14:11:49 +0000 (UTC) User-Agent: mu4e 0.9.16; emacs 25.1.50.6 Cc: Help Gnu Emacs mailing list To: Kaushal Modi Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Aug 18 16:11:45 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1baO2r-0001Li-Bt for geh-help-gnu-emacs@m.gmane.org; Thu, 18 Aug 2016 16:11:45 +0200 Original-Received: from localhost ([::1]:52908 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baO2o-0005LY-Gy for geh-help-gnu-emacs@m.gmane.org; Thu, 18 Aug 2016 10:11:42 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54426) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baO11-0004a2-Bo for help-gnu-emacs@gnu.org; Thu, 18 Aug 2016 10:09:52 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1baO0x-0000wK-AL for help-gnu-emacs@gnu.org; Thu, 18 Aug 2016 10:09:51 -0400 Original-Received: from mail.mojserwer.eu ([195.110.48.8]:34092) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baO0x-0000w2-3F for help-gnu-emacs@gnu.org; Thu, 18 Aug 2016 10:09:47 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by mail.mojserwer.eu (Postfix) with ESMTP id 59495E647C; Thu, 18 Aug 2016 16:09:46 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mail.mojserwer.eu Original-Received: from mail.mojserwer.eu ([127.0.0.1]) by localhost (mail.mojserwer.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9CsJ5PvC4ArV; Thu, 18 Aug 2016 16:09:43 +0200 (CEST) Original-Received: from localhost (unknown [IPv6:2a01:114f:970:8d00:a288:b4ff:fe90:5e24]) by mail.mojserwer.eu (Postfix) with ESMTPSA id 9716AE6029; Thu, 18 Aug 2016 16:09:43 +0200 (CEST) In-reply-to: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 195.110.48.8 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:111173 Archived-At: On 2016-08-18, at 13:39, Kaushal Modi 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