From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alex Branham Newsgroups: gmane.emacs.bugs Subject: bug#32504: [PATCH] syntax-is-{comment|string}-p Date: Wed, 22 Aug 2018 15:05:35 -0500 Message-ID: <87o9dup3ow.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1534969110 29880 195.159.176.226 (22 Aug 2018 20:18:30 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 22 Aug 2018 20:18:30 +0000 (UTC) User-Agent: mu4e 1.0; emacs 26.1 To: 32504@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Aug 22 22:18:25 2018 Return-path: Envelope-to: geb-bug-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 1fsZaC-0007eR-8Q for geb-bug-gnu-emacs@m.gmane.org; Wed, 22 Aug 2018 22:18:24 +0200 Original-Received: from localhost ([::1]:60662 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fsZcI-0007pQ-LX for geb-bug-gnu-emacs@m.gmane.org; Wed, 22 Aug 2018 16:20:34 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33707) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fsZbr-0007Zp-Eb for bug-gnu-emacs@gnu.org; Wed, 22 Aug 2018 16:20:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fsZbo-0003ph-3x for bug-gnu-emacs@gnu.org; Wed, 22 Aug 2018 16:20:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:53028) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fsZbn-0003og-Kw for bug-gnu-emacs@gnu.org; Wed, 22 Aug 2018 16:20:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fsZbn-0003ka-8b for bug-gnu-emacs@gnu.org; Wed, 22 Aug 2018 16:20:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alex Branham Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 22 Aug 2018 20:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 32504 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.153496919414392 (code B ref -1); Wed, 22 Aug 2018 20:20:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 22 Aug 2018 20:19:54 +0000 Original-Received: from localhost ([127.0.0.1]:58046 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fsZbb-0003jy-Rh for submit@debbugs.gnu.org; Wed, 22 Aug 2018 16:19:54 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:40524) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fsZbZ-0003jj-4u for submit@debbugs.gnu.org; Wed, 22 Aug 2018 16:19:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fsZbR-0003Zd-4H for submit@debbugs.gnu.org; Wed, 22 Aug 2018 16:19:43 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:59399) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fsZbN-0003Y3-Q2 for submit@debbugs.gnu.org; Wed, 22 Aug 2018 16:19:39 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33236) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fsZbK-0007EN-Fs for bug-gnu-emacs@gnu.org; Wed, 22 Aug 2018 16:19:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fsZNr-00039x-ST for bug-gnu-emacs@gnu.org; Wed, 22 Aug 2018 16:05:42 -0400 Original-Received: from mail-oi0-x231.google.com ([2607:f8b0:4003:c06::231]:34156) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fsZNr-00039l-Gt for bug-gnu-emacs@gnu.org; Wed, 22 Aug 2018 16:05:39 -0400 Original-Received: by mail-oi0-x231.google.com with SMTP id 13-v6so5361528ois.1 for ; Wed, 22 Aug 2018 13:05:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=user-agent:from:to:subject:date:message-id:mime-version; bh=CZ5khE9WPz9OSl885R2DBo9emQC/bttzwxUvxNOrxpE=; b=k60szJLe1xzxMZzR3pR7nt+ABcRqep9hOmpW6F7WoQnXOvFUqXv+drlOdNSV9u0Ccr XpS8qrIFBuR+u+zLGYSj/udnfVfYkVQTxdkBJMOAs5EqVGT0ayAdJrioafKu2V2NYnAX D6WgW8zUUbtD0aG26F5x3vONwC2KVelbxiN09+Aab6r7xOS4h2wlLkh7Ciaml7NQMF4I OxnXt46tA+oWIHwcX3eXlg/AY7N2dEWx/+0Dr78fIvEgzeNC/3kfxMJ5bBI4tfJYy15v iODQwRghieaFLbGtjI5chU4NPnpYaZ9r1m782hSbyI2x3dTHSplul+UuCqnhBZ5+3Uyd 7SKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:user-agent:from:to:subject:date:message-id :mime-version; bh=CZ5khE9WPz9OSl885R2DBo9emQC/bttzwxUvxNOrxpE=; b=tQJNZYlpS2EAhfD2wVkdcb+2jbQKtgIvIibxCtGD6j0+48YEF3MYFV3bOfMDjV9DYk LZ6INupO7JRGAx1XWmYq+B1LqQCob/RHSsPFjU2owJ/+bK78q0Njr4u4vkDx+YtTwA0q xZs/6fZZ1KjW0G7gjjWVw5AOK043tH0BD2YW8rC1V+I33pT1a5UNHDknEPhtNVFASqq9 EBIsZPAsqy0tIT66cFtXxqSkdVgk4xUVt2TMMAQi7gxfxM+yDdQSoOnVykBJJcJb6+rh iyxRp8po7pc4M0PfszXGp694XGuwRGFlmnAXOP87GC5PxcmAUXmK36UXdmEUzIyX93vw 2PYg== X-Gm-Message-State: APzg51Ag8PRMtTw9Q86gYG3IUTOxmE1Q86vWH5H44+EhfnTUj4jtM0Bg /Knlhz+bFN9HBDo1u08brrW2tsd3 X-Google-Smtp-Source: ANB0VdY3gpyfD3DQ1ErxInwyIKR70m/nW9/Zu4UTRfQwRQPwpI9JWhWuOyAGuFRmhNzr9M9ph7pAMg== X-Received: by 2002:aca:56d1:: with SMTP id k200-v6mr5858527oib.319.1534968338278; Wed, 22 Aug 2018 13:05:38 -0700 (PDT) Original-Received: from earth (cpe-70-114-192-208.austin.res.rr.com. [70.114.192.208]) by smtp.gmail.com with ESMTPSA id s145-v6sm4604510oih.16.2018.08.22.13.05.36 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 22 Aug 2018 13:05:37 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:149673 Archived-At: --=-=-= Content-Type: text/plain Hello - I got tired of checking/remembering whether (nth 3 (syntax-ppss)) was a string or a comment, so I've created two simple functions that wrap that in a more descriptive name. I've noticed that there are a handful of these that other modes have written, so evidently others wanted them as well at some point. There are two patches attached. The first creates new functions syntax-is-comment-p and syntax-is-string-p. The second changes most of the uses of (nth 3 (syntax-ppss)) and (nth 4 (syntax-ppss)) to use these new functions. I'm attaching it as a separate patch since I'm not sure if yall will want it or not; it's easy to squash if you do. Thanks, Alex ------------------------------------------------------------ >From 393f55de705513f5514a3e0250d81053e838c447 Mon Sep 17 00:00:00 2001 From: Alex Branham Date: Wed, 22 Aug 2018 14:44:26 -0500 Subject: [PATCH 1/2] Add new functions syntax-is-{comment|string}-p * lisp/emacs-lisp/syntax.el (syntax-is-comment-p, syntax-is-string-p): New functions * doc/lispref/syntax.texi: Add documentation for new functions --- doc/lispref/syntax.texi | 10 ++++++++++ etc/NEWS | 4 ++++ lisp/emacs-lisp/syntax.el | 12 ++++++++++++ 3 files changed, 26 insertions(+) diff --git a/doc/lispref/syntax.texi b/doc/lispref/syntax.texi index dcfade3f67..e6220e5cf9 100644 --- a/doc/lispref/syntax.texi +++ b/doc/lispref/syntax.texi @@ -790,6 +790,16 @@ Position Parse Hooks}). @end defun +@defun syntax-is-comment-p &optional pos +This function returns non-nil when @code{POS} (which defaults to +point) is in a comment accord to @code{syntax-ppss} +@end defun + +@defun syntax-is-string-p &optional pos +This function returns non-nil when @code{POS} (which defaults to +point) is in a string accord to @code{syntax-ppss} +@end defun + @node Parser State @subsection Parser State @cindex parser state diff --git a/etc/NEWS b/etc/NEWS index d757f52466..e138105e72 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -963,6 +963,10 @@ versions. The new variable 'comment-use-syntax-ppss' can be set to nil to recover the old behavior if needed. +** New functions 'syntax-is-comment-p' and 'syntax-is-string-p'. +These can be used as a shorthand instead of checking, for example, +(nth 3 (syntax-ppss)). + ** The 'server-name' and 'server-socket-dir' variables are set when a socket has been passed to Emacs. diff --git a/lisp/emacs-lisp/syntax.el b/lisp/emacs-lisp/syntax.el index ad1a9665ff..2a262c6036 100644 --- a/lisp/emacs-lisp/syntax.el +++ b/lisp/emacs-lisp/syntax.el @@ -616,6 +616,18 @@ syntax-ppss ;; a nil state. (parse-partial-sexp (point-min) pos)))))) +(defun syntax-is-comment-p (&optional pos) + "Return non-nil if POS is inside a comment. +POS defaults to `point'." + (let ((pos (or pos (point)))) + (nth 4 (syntax-ppss pos)))) + +(defun syntax-is-string-p (&optional pos) + "Return non-nil if POS is inside a string. +POS defaults to `point'." + (let ((pos (or pos (point)))) + (nth 3 (syntax-ppss pos)))) + ;; Debugging functions (defun syntax-ppss-debug () -- 2.18.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-new-functions-syntax-is-comment-string-p.patch >From 393f55de705513f5514a3e0250d81053e838c447 Mon Sep 17 00:00:00 2001 From: Alex Branham Date: Wed, 22 Aug 2018 14:44:26 -0500 Subject: [PATCH 1/2] Add new functions syntax-is-{comment|string}-p * lisp/emacs-lisp/syntax.el (syntax-is-comment-p, syntax-is-string-p): New functions * doc/lispref/syntax.texi: Add documentation for new functions --- doc/lispref/syntax.texi | 10 ++++++++++ etc/NEWS | 4 ++++ lisp/emacs-lisp/syntax.el | 12 ++++++++++++ 3 files changed, 26 insertions(+) diff --git a/doc/lispref/syntax.texi b/doc/lispref/syntax.texi index dcfade3f67..e6220e5cf9 100644 --- a/doc/lispref/syntax.texi +++ b/doc/lispref/syntax.texi @@ -790,6 +790,16 @@ Position Parse Hooks}). @end defun +@defun syntax-is-comment-p &optional pos +This function returns non-nil when @code{POS} (which defaults to +point) is in a comment accord to @code{syntax-ppss} +@end defun + +@defun syntax-is-string-p &optional pos +This function returns non-nil when @code{POS} (which defaults to +point) is in a string accord to @code{syntax-ppss} +@end defun + @node Parser State @subsection Parser State @cindex parser state diff --git a/etc/NEWS b/etc/NEWS index d757f52466..e138105e72 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -963,6 +963,10 @@ versions. The new variable 'comment-use-syntax-ppss' can be set to nil to recover the old behavior if needed. +** New functions 'syntax-is-comment-p' and 'syntax-is-string-p'. +These can be used as a shorthand instead of checking, for example, +(nth 3 (syntax-ppss)). + ** The 'server-name' and 'server-socket-dir' variables are set when a socket has been passed to Emacs. diff --git a/lisp/emacs-lisp/syntax.el b/lisp/emacs-lisp/syntax.el index ad1a9665ff..2a262c6036 100644 --- a/lisp/emacs-lisp/syntax.el +++ b/lisp/emacs-lisp/syntax.el @@ -616,6 +616,18 @@ syntax-ppss ;; a nil state. (parse-partial-sexp (point-min) pos)))))) +(defun syntax-is-comment-p (&optional pos) + "Return non-nil if POS is inside a comment. +POS defaults to `point'." + (let ((pos (or pos (point)))) + (nth 4 (syntax-ppss pos)))) + +(defun syntax-is-string-p (&optional pos) + "Return non-nil if POS is inside a string. +POS defaults to `point'." + (let ((pos (or pos (point)))) + (nth 3 (syntax-ppss pos)))) + ;; Debugging functions (defun syntax-ppss-debug () -- 2.18.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-Prefer-using-new-syntax-is-comment-string-p-function.patch >From eff51e05fef4d452e52c81ed7259b51612d7917a Mon Sep 17 00:00:00 2001 From: Alex Branham Date: Wed, 22 Aug 2018 14:51:58 -0500 Subject: [PATCH 2/2] Prefer using new syntax-is-{comment|string}-p functions * lisp/emacs-lisp/smie.el: * lisp/ffap.el: * lisp/progmodes/js.el: * lisp/progmodes/meta-mode.el: * lisp/progmodes/octave.el: * lisp/progmodes/opascal.el: * lisp/progmodes/pascal.el: * lisp/progmodes/perl-mode.el: * lisp/progmodes/prolog.el: * lisp/progmodes/ruby-mode.el: * lisp/progmodes/sh-script.el: * lisp/simple.el: * lisp/textmodes/tex-mode.el: * lisp/thingatpt.el: * lisp/vc/smerge-mode.el: Use new syntax-is-{comment|string}-p functions rather than checking (nth 3|4 (syntax-ppss)) --- lisp/emacs-lisp/smie.el | 8 ++++---- lisp/ffap.el | 2 +- lisp/progmodes/js.el | 4 ++-- lisp/progmodes/meta-mode.el | 4 ++-- lisp/progmodes/octave.el | 10 ++++------ lisp/progmodes/opascal.el | 2 +- lisp/progmodes/pascal.el | 2 +- lisp/progmodes/perl-mode.el | 4 ++-- lisp/progmodes/prolog.el | 4 ++-- lisp/progmodes/ruby-mode.el | 2 +- lisp/progmodes/sh-script.el | 10 +++++----- lisp/simple.el | 2 +- lisp/textmodes/tex-mode.el | 4 ++-- lisp/thingatpt.el | 12 +++--------- lisp/vc/smerge-mode.el | 2 +- 15 files changed, 32 insertions(+), 40 deletions(-) diff --git a/lisp/emacs-lisp/smie.el b/lisp/emacs-lisp/smie.el index c01a40172b..a82a6e2c99 100644 --- a/lisp/emacs-lisp/smie.el +++ b/lisp/emacs-lisp/smie.el @@ -1644,7 +1644,7 @@ smie-indent-comment-continue (let ((continue (and comment-continue (comment-string-strip comment-continue t t)))) (and (< 0 (length continue)) - (looking-at (regexp-quote continue)) (nth 4 (syntax-ppss)) + (looking-at (regexp-quote continue)) (syntax-is-comment-p) (let ((ppss (syntax-ppss))) (save-excursion (forward-line -1) @@ -1660,7 +1660,7 @@ smie-indent-comment-close (not (looking-at " \t*$")) ;Not just a \n comment-closer. (looking-at comment-end-skip) (let ((end (match-string 0))) - (and (nth 4 (syntax-ppss)) + (and (syntax-is-comment-p) (save-excursion (goto-char (nth 8 (syntax-ppss))) (and (looking-at comment-start-skip) @@ -1674,11 +1674,11 @@ smie-indent-comment-close (current-column))))))))) (defun smie-indent-comment-inside () - (and (nth 4 (syntax-ppss)) + (and (syntax-is-comment-p) 'noindent)) (defun smie-indent-inside-string () - (and (nth 3 (syntax-ppss)) + (and (syntax-is-string-p) 'noindent)) (defun smie-indent-after-keyword () diff --git a/lisp/ffap.el b/lisp/ffap.el index b51929d260..5272735147 100644 --- a/lisp/ffap.el +++ b/lisp/ffap.el @@ -1161,7 +1161,7 @@ ffap-string-at-point (null region-selected) ;; Check if END character is part of a comment. (save-excursion - (nth 4 (syntax-ppss end)))) + (syntax-is-comment-p end))) ;; Move BEG to beginning of comment (after the comment start ;; characters), or END, whichever comes first. (save-excursion diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index f30e591b15..49020fec05 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -1837,7 +1837,7 @@ js--continued-expression-p (if (js--looking-at-operator-p) (if (eq (char-after) ?/) (prog1 - (not (nth 3 (syntax-ppss (1+ (point))))) + (not (syntax-is-string-p (1+ (point)))) (forward-char -1)) (or (not (memq (char-after) '(?- ?+))) @@ -1982,7 +1982,7 @@ js--multi-line-declaration-indentation (when (looking-at js--indent-operator-re) (goto-char (match-end 0))) ;; The "operator" is probably a regexp literal opener. - (when (nth 3 (syntax-ppss)) + (when (syntax-is-string-p) (goto-char pt))) (while (and (not at-opening-bracket) (not (bobp)) diff --git a/lisp/progmodes/meta-mode.el b/lisp/progmodes/meta-mode.el index e207d22ff4..2475867adc 100644 --- a/lisp/progmodes/meta-mode.el +++ b/lisp/progmodes/meta-mode.el @@ -562,7 +562,7 @@ meta-indent-calculate (defun meta-indent-in-string-p () "Tell if the point is in a string." - (or (nth 3 (syntax-ppss)) + (or (syntax-is-string-p) (eq (get-text-property (point) 'face) font-lock-string-face))) (defun meta-indent-looking-at-code (regexp) @@ -636,7 +636,7 @@ meta-indent-current-nesting nil t) ;; If we aren't in a string or in a comment, we've found something. (unless (or (meta-indent-in-string-p) - (nth 4 (syntax-ppss))) + (syntax-is-comment-p)) (cond ((= (char-after) ?\() (setq to-add (+ to-add meta-indent-level))) ((= (char-after) ?\)) diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el index 984bb73c73..ec4eaa5fe5 100644 --- a/lisp/progmodes/octave.el +++ b/lisp/progmodes/octave.el @@ -995,13 +995,11 @@ inferior-octave-track-window-width-change ;;; Miscellaneous useful functions -(defun octave-in-comment-p () - "Return non-nil if point is inside an Octave comment." - (nth 4 (syntax-ppss))) +(defalias 'octave-in-comment-p 'syntax-is-comment-p + "Return non-nil if point is inside an Octave comment.") -(defun octave-in-string-p () - "Return non-nil if point is inside an Octave string." - (nth 3 (syntax-ppss))) +(defalias 'octave-in-string-p 'syntax-is-string-p + "Return non-nil if point is inside an Octave string.") (defun octave-in-string-or-comment-p () "Return non-nil if point is inside an Octave string or comment." diff --git a/lisp/progmodes/opascal.el b/lisp/progmodes/opascal.el index 4606621951..7f5f5f4dea 100644 --- a/lisp/progmodes/opascal.el +++ b/lisp/progmodes/opascal.el @@ -1705,7 +1705,7 @@ opascal--syntax-propertize ("(\\(\\/\\)" (1 (prog1 ". 1c" (forward-char -1) nil))) ;; Pascal uses '' and "" rather than \' and \" to escape quotes. ("''\\|\"\"" (0 (if (save-excursion - (nth 3 (syntax-ppss (match-beginning 0)))) + (syntax-is-string-p (match-beginning 0))) (string-to-syntax ".") ;; In case of 3 or more quotes in a row, only advance ;; one quote at a time. diff --git a/lisp/progmodes/pascal.el b/lisp/progmodes/pascal.el index 6d13d328c5..f196bcdeb4 100644 --- a/lisp/progmodes/pascal.el +++ b/lisp/progmodes/pascal.el @@ -190,7 +190,7 @@ pascal--syntax-propertize ("(\\(\\/\\)" (1 (prog1 ". 1c" (forward-char -1) nil))) ;; Pascal uses '' and "" rather than \' and \" to escape quotes. ("''\\|\"\"" (0 (if (save-excursion - (nth 3 (syntax-ppss (match-beginning 0)))) + (syntax-is-string-p (match-beginning 0))) (string-to-syntax ".") ;; In case of 3 or more quotes in a row, only advance ;; one quote at a time. diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el index b96aad7a6e..a217d4f85a 100644 --- a/lisp/progmodes/perl-mode.el +++ b/lisp/progmodes/perl-mode.el @@ -231,8 +231,8 @@ perl-syntax-propertize-function ;; check that it occurs inside a '..' string. ("\\(\\$\\)[{']" (1 (unless (and (eq ?\' (char-after (match-end 1))) (save-excursion - (not (nth 3 (syntax-ppss - (match-beginning 0)))))) + (not (syntax-is-string-p + (match-beginning 0))))) (string-to-syntax ". p")))) ;; Handle funny names like $DB'stop. ("\\$ ?{?^?[_[:alpha:]][_[:alnum:]]*\\('\\)[_[:alpha:]]" (1 "_")) diff --git a/lisp/progmodes/prolog.el b/lisp/progmodes/prolog.el index a895a77796..23aed9bafe 100644 --- a/lisp/progmodes/prolog.el +++ b/lisp/progmodes/prolog.el @@ -2291,7 +2291,7 @@ prolog-guess-fill-prefix ;; fill 'txt entities? (when (save-excursion (end-of-line) - (nth 4 (syntax-ppss))) + (syntax-is-comment-p)) (let* ((bounds (prolog-comment-limits)) (cbeg (car bounds)) (type (nth 2 bounds)) @@ -2755,7 +2755,7 @@ prolog-get-predspec (let ((state (prolog-clause-info)) (object (prolog-in-object))) (if (or (equal (nth 0 state) "") - (nth 4 (syntax-ppss))) + (syntax-is-comment-p)) nil (if (and (eq prolog-system 'sicstus) object) diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index fad7bc1fb8..abc66d3f85 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -1849,7 +1849,7 @@ ruby-syntax-propertize ;; ?' ?" ?` are character literals (one-char strings in 1.9+). ("\\([?$]\\)[#\"'`:?]" (1 (if (save-excursion - (nth 3 (syntax-ppss (match-beginning 0)))) + (syntax-is-string-p (match-beginning 0))) ;; Within a string, skip. (ignore (goto-char (match-end 1))) diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el index aaa86b5816..26c276504c 100644 --- a/lisp/progmodes/sh-script.el +++ b/lisp/progmodes/sh-script.el @@ -1882,7 +1882,7 @@ sh-smie-sh-forward-token (save-excursion (skip-chars-backward " \t") (not (bolp)))) - (if (and (match-end 1) (not (nth 3 (syntax-ppss)))) + (if (and (match-end 1) (not (syntax-is-string-p))) ;; Right before a here-doc. (let ((forward-sexp-function nil)) (forward-sexp 1) @@ -1931,7 +1931,7 @@ sh-smie-sh-backward-token (cond ((and (bolp) (not (bobp)) (equal (syntax-after (1- (point))) (string-to-syntax "|")) - (not (nth 3 (syntax-ppss)))) + (not (syntax-is-string-p))) ;; Right after a here-document. (let ((forward-sexp-function nil)) (forward-sexp -1) @@ -2169,7 +2169,7 @@ sh-smie-rc-forward-token (save-excursion (skip-chars-backward " \t") (not (bolp)))) - (if (and (match-end 1) (not (nth 3 (syntax-ppss)))) + (if (and (match-end 1) (not (syntax-is-string-p))) ;; Right before a here-doc. (let ((forward-sexp-function nil)) (forward-sexp 1) @@ -2211,7 +2211,7 @@ sh-smie-rc-backward-token (cond ((and (bolp) (not (bobp)) (equal (syntax-after (1- (point))) (string-to-syntax "|")) - (not (nth 3 (syntax-ppss)))) + (not (syntax-is-string-p))) ;; Right after a here-document. (let ((forward-sexp-function nil)) (forward-sexp -1) @@ -2827,7 +2827,7 @@ sh-get-indent-info ;; Note: setting result to t means we are done and will return nil. ;;(This function never returns just t.) (cond - ((or (nth 3 (syntax-ppss (point))) + ((or (syntax-is-string-p) (eq (get-text-property (point) 'face) 'sh-heredoc)) ;; String continuation -- don't indent (setq result t) diff --git a/lisp/simple.el b/lisp/simple.el index 0ccf2f1d22..fb44c4fac9 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -7264,7 +7264,7 @@ internal-auto-fill "The function called by `self-insert-command' to perform auto-filling." (when (or (not comment-start) (not comment-auto-fill-only-comments) - (nth 4 (syntax-ppss))) + (syntax-is-comment-p)) (funcall auto-fill-function))) (defvar normal-auto-fill-function 'do-auto-fill diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el index c223af4769..b6ebc1e3be 100644 --- a/lisp/textmodes/tex-mode.el +++ b/lisp/textmodes/tex-mode.el @@ -1328,7 +1328,7 @@ tex-insert-quote ;; (if (or arg (memq (char-syntax (preceding-char)) '(?/ ?\\)) (eq (get-text-property (point) 'face) 'tex-verbatim) - (nth 4 (syntax-ppss)) ; non-nil if point is in a TeX comment + (syntax-is-comment-p) ;; Discover if a preceding occurrence of `tex-open-quote' ;; should be morphed to a normal double quote. ;; @@ -1487,7 +1487,7 @@ tex-handle-newline unless prefix arg INHIBIT-VALIDATION is non-nil to inhibit the checking. Otherwise (in a comment), just insert a single continued comment line." (interactive "*P") - (if (nth 4 (syntax-ppss)) ; non-nil if point is in a TeX comment + (if (syntax-is-comment-p) (comment-indent-new-line) (tex-terminate-paragraph inhibit-validation))) diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el index 679401eef1..41185a778e 100644 --- a/lisp/thingatpt.el +++ b/lisp/thingatpt.el @@ -180,19 +180,13 @@ end-of-thing ;; Sexps -(defun in-string-p () - "Return non-nil if point is in a string." - (declare (obsolete "use (nth 3 (syntax-ppss)) instead." "25.1")) - (let ((orig (point))) - (save-excursion - (beginning-of-defun) - (nth 3 (parse-partial-sexp (point) orig))))) +(define-obsolete-function-alias 'in-string-p 'syntax-is-string-p "25.1") (defun thing-at-point--end-of-sexp () "Move point to the end of the current sexp." (let ((char-syntax (syntax-after (point)))) (if (or (eq char-syntax ?\)) - (and (eq char-syntax ?\") (nth 3 (syntax-ppss)))) + (and (eq char-syntax ?\") (syntax-is-string-p))) (forward-char 1) (forward-sexp 1)))) @@ -206,7 +200,7 @@ thing-at-point--beginning-of-sexp "Move point to the beginning of the current sexp." (let ((char-syntax (char-syntax (char-before)))) (if (or (eq char-syntax ?\() - (and (eq char-syntax ?\") (nth 3 (syntax-ppss)))) + (and (eq char-syntax ?\") (syntax-is-string-p))) (forward-char -1) (forward-sexp -1)))) diff --git a/lisp/vc/smerge-mode.el b/lisp/vc/smerge-mode.el index ff41473435..056bb4f46d 100644 --- a/lisp/vc/smerge-mode.el +++ b/lisp/vc/smerge-mode.el @@ -621,7 +621,7 @@ smerge-resolve ;; Idem, when the conflict is contained within a single comment. ((save-excursion (and m2e - (nth 4 (syntax-ppss m0b)) + (syntax-is-comment-p m0b) ;; If there's a conflict earlier in the file, ;; syntax-ppss is not reliable. (not (re-search-backward smerge-begin-re nil t)) -- 2.18.0 --=-=-=--