From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Kaushal Modi Newsgroups: gmane.emacs.help Subject: Re: How to check whether the current line is a comment-only one? Date: Thu, 18 Aug 2016 11:39:27 +0000 Message-ID: References: <87vayyppop.fsf@mbork.pl> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: blaine.gmane.org 1471527862 16717 195.159.176.226 (18 Aug 2016 13:44:22 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 18 Aug 2016 13:44:22 +0000 (UTC) To: Marcin Borkowski , Help Gnu Emacs mailing list Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Aug 18 15:44:17 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 1baNcG-00044G-FR for geh-help-gnu-emacs@m.gmane.org; Thu, 18 Aug 2016 15:44:16 +0200 Original-Received: from localhost ([::1]:52761 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baNcD-0006VV-L8 for geh-help-gnu-emacs@m.gmane.org; Thu, 18 Aug 2016 09:44:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46350) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baLfh-0008Q8-DB for help-gnu-emacs@gnu.org; Thu, 18 Aug 2016 07:39:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1baLff-0008T7-DM for help-gnu-emacs@gnu.org; Thu, 18 Aug 2016 07:39:40 -0400 Original-Received: from mail-oi0-x232.google.com ([2607:f8b0:4003:c06::232]:34000) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baLff-0008Sl-6v for help-gnu-emacs@gnu.org; Thu, 18 Aug 2016 07:39:39 -0400 Original-Received: by mail-oi0-x232.google.com with SMTP id l203so18609135oib.1 for ; Thu, 18 Aug 2016 04:39:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=c9wLgguYgk/MX5YzpwQPbtsCYRy6GiBA/axwxF79V80=; b=IxWMsstH57Sy8bOFeitoLd3qaUFChjG9jjMdjTEl5dbPk+T7Y3tb1exm/PKP6ppebC P2DFeUdJab6mipJIAH7/WlAFkX96dwHlDs7b/7MFn9SfVWIr6ZTluzRi6S8E3ei6GyCZ 2Ca5KXYCZ+KaA5CwtEuza/xndmyGijlFm8HdSewAdZSp6M9dsVJSLvIZX0/PBLeKW2PX H7FksX5T3c6bJhZNXyk2f4QcFIIQe03qKLxPTEueO6W7KNUCsfv5fzeYLnX8gYFal/9H orPJxlu0gZc0K+hcAk9y+kQACadHhMk0mnA4Bp34s0Pl5yd0sO2Yp3JRo87TTjpM+NW5 1zwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=c9wLgguYgk/MX5YzpwQPbtsCYRy6GiBA/axwxF79V80=; b=OAf+mAxIUlHu6YEqopbDQnDXE8CVfe7HZJ/aYmWOSab92mbWoC2oL2FYh+qMZ6xUWT OUs1yrqwl6164TcaXMsNP2ondOkwBIyrwlOIBrO9N8JsW8zQ2EJrz6LZYqdM9kTXBfhi x4AjkwnrGxTMOrHBrNlQZvOIHasJ9sOVq9l+KlIlnWSoq3IHpNobpMIzXus4xM6LCOqc UnmtbiEE3KxXuY32ZW+Oet//FWIuLubiiye5/pD6U8v9IrYaWwFG4bZaTU1l7SC1kI7k y4ZKcN2n2RxCLtMRq9AqTrlb8kbw5EAqWbrER1Y99plXIS6IowfcCaGVxtcrIuvP7dw1 BZ1w== X-Gm-Message-State: AEkoouvnXXC7lrsMbN6sC/GqKbYNeaVs47ALdMnx1lCl0Rsf4shkOSrHVvauQb+628TXWA/dTLxTiAWJ4E/neA== X-Received: by 10.157.7.229 with SMTP id 92mr989688oto.133.1471520378476; Thu, 18 Aug 2016 04:39:38 -0700 (PDT) In-Reply-To: <87vayyppop.fsf@mbork.pl> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4003:c06::232 X-Mailman-Approved-At: Thu, 18 Aug 2016 09:42:35 -0400 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 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:111172 Archived-At: 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 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