unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Noam Postavsky <npostavs@gmail.com>
To: Alex Branham <alex.branham@gmail.com>
Cc: 32504@debbugs.gnu.org
Subject: bug#32504: [PATCH] syntax-is-{comment|string}-p
Date: Mon, 08 Jul 2019 20:05:15 -0400	[thread overview]
Message-ID: <87imsc2htw.fsf@gmail.com> (raw)
In-Reply-To: <87bm9js0zm.fsf@gmail.com> (Alex Branham's message of "Thu, 30 Aug 2018 21:50:37 -0500")

[-- Attachment #1: Type: text/plain, Size: 531 bytes --]

Alex Branham <alex.branham@gmail.com> writes:

> On Thu 30 Aug 2018 at 20:21, Noam Postavsky <npostavs@gmail.com> wrote:
>
>>> I'm not a big fan of the docstrings generated by this, is there a way to
>>> change them to be more helpful?
>>
>> Hmm, doesn't look like it.  Well, that's just a convenient way of
>> defining them all quickly for discussion, it wouldn't be that much
>> harder to write out defuns I guess.
>
> Fair enough.

The recent talk about accessors for decoded time reminded me of this.
Here's an initial patch.


[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 4457 bytes --]

From 0d09658a33aed36b0b647dc8dbfd08d8aa2dc535 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Mon, 8 Jul 2019 18:45:53 -0400
Subject: [PATCH] Add named accessors for syntax-ppss state (Bug#32504)

* lisp/emacs-lisp/syntax.el (syntax-ppss-depth, syntax-ppss-list-start)
(syntax-ppss-last-sexp-start, syntax-ppss-string-terminator)
(syntax-ppss-comment, syntax-ppss-quoted-p, syntax-ppss-min-depth)
(syntax-ppss-comment-style, syntax-ppss-context-start)
(syntax-ppss-open-parens, syntax-ppss-syntax-sequence): New functions.
(syntax-ppss-toplevel-pos, syntax-ppss-context): Use them.
---
 lisp/emacs-lisp/syntax.el | 62 ++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 58 insertions(+), 4 deletions(-)

diff --git a/lisp/emacs-lisp/syntax.el b/lisp/emacs-lisp/syntax.el
index 6464e2a52d..b7a5e585b7 100644
--- a/lisp/emacs-lisp/syntax.el
+++ b/lisp/emacs-lisp/syntax.el
@@ -358,7 +358,61 @@ internal--syntax-propertize
 ;;; Incrementally compute and memoize parser state.
 
 (defsubst syntax-ppss-depth (ppss)
+  "Depth in parens according to PPSS.
+PPSS is the return value `parse-partial-sexp' or `syntax-ppss'."
   (nth 0 ppss))
+(defsubst syntax-ppss-list-start (ppss)
+  "Start of innermost containing list according to PPSS; nil if none.
+PPSS is the return value `parse-partial-sexp' or `syntax-ppss'."
+  (nth 1 ppss))
+(defsubst syntax-ppss-last-sexp-start (ppss)
+  "Start of last complete sexp terminated according to PPSS.
+PPSS is the return value `parse-partial-sexp' or `syntax-ppss'."
+  (nth 2 ppss))
+(defsubst syntax-ppss-string-terminator (ppss)
+  "Terminating character of current string according to PPSS.
+Return t if the string should be terminated by generic string
+delimiter, or nil if not in a string.
+PPSS is the return value `parse-partial-sexp' or `syntax-ppss'."
+  (nth 3 ppss))
+(defsubst syntax-ppss-comment (ppss)
+  "Non-nil if inside a comment according to PPSS.
+Return t if inside a non-nestable comment, else an integer (the comment
+nesting depth).
+PPSS is the return value `parse-partial-sexp' or `syntax-ppss'."
+  (nth 4 ppss))
+(defsubst syntax-ppss-quoted-p (ppss)
+  "Non-nil if PPSS points to a position following a quote.
+PPSS is the return value `parse-partial-sexp' or `syntax-ppss'."
+  (nth 5 ppss))
+(defsubst syntax-ppss-min-depth (ppss)
+  "Minimum parenthesis depth of the scan according to PPSS.
+PPSS is the return value `parse-partial-sexp' or `syntax-ppss'."
+  (nth 6 ppss))
+(defsubst syntax-ppss-comment-style (ppss)
+  ;; FIXME: What is comment style exactly?
+  "Comment style according to PPSS.
+PPSS is the return value `parse-partial-sexp' or `syntax-ppss'."
+  (nth 7 ppss))
+(defsubst syntax-ppss-context-start (ppss)
+  "Start of comment or string according to PPSS.
+Return nil if not in one.
+PPSS is the return value `parse-partial-sexp' or `syntax-ppss'."
+  (nth 8 ppss))
+(defsubst syntax-ppss-open-parens (ppss)
+  "List of open parens according to PPSS.
+PPSS is the return value `parse-partial-sexp' or `syntax-ppss'."
+  (nth 9 ppss))
+(defsubst syntax-ppss-syntax-sequence (ppss)
+  "Syntax of the 1st of a two character sequence according to PPSS.
+When the last position scanned holds the first character of a
+\(potential) two character construct, the syntax of that
+position, otherwise nil.  That construct can be a two character
+comment delimiter or an Escaped or Char-quoted character.
+PPSS is the return value `parse-partial-sexp' or `syntax-ppss'."
+  (nth 10 ppss))
+
+
 
 (defun syntax-ppss-toplevel-pos (ppss)
   "Get the latest syntactically outermost position found in a syntactic scan.
@@ -367,8 +421,8 @@ syntax-ppss-toplevel-pos
 outside of any parentheses, comments, or strings encountered in the scan.
 If no such position is recorded in PPSS (because the end of the scan was
 itself at the outermost level), return nil."
-  (or (car (nth 9 ppss))
-      (nth 8 ppss)))
+  (or (car (syntax-ppss-open-parens ppss))
+      (syntax-ppss-context-start ppss)))
 
 (defsubst syntax-ppss-context (ppss)
   "Say whether PPSS is a string, a comment, or something else.
@@ -376,8 +430,8 @@ syntax-ppss-context
 comment, the symbol `comment' is returned.  If it's something
 else, nil is returned."
   (cond
-   ((nth 3 ppss) 'string)
-   ((nth 4 ppss) 'comment)
+   ((syntax-ppss-string-terminator ppss) 'string)
+   ((syntax-ppss-comment ppss) 'comment)
    (t nil)))
 
 (defvar syntax-ppss-max-span 20000
-- 
2.11.0


[-- Attachment #3: Type: text/plain, Size: 610 bytes --]


>>> CL-X defaults to point.
>>
>> And, my intention is to operate on the return value of syntax-ppss, not
>> give a point to call it with.
>
> Right, but whenever I want to call on these functions, 90% of the time
> the question I'm trying to answer is "Is point in a comment/string?" And
> the 3rd party ***-is-comment/string-p functions I've looked at usually
> (always?) look at positions.

Well, for me I just want to stop having to look up the docstring of
parse-partial-sexp every damn time I see (nth X PPSS).  But I wouldn't
be against having syntax-is-comment/string-p which take a position as
well.

  reply	other threads:[~2019-07-09  0:05 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-22 20:05 bug#32504: [PATCH] syntax-is-{comment|string}-p Alex Branham
2018-08-23  3:12 ` Noam Postavsky
2018-08-23 13:01   ` Alex Branham
2018-08-23 13:58     ` Eli Zaretskii
2018-08-24 16:11       ` Alex Branham
2018-08-24 19:28         ` Eli Zaretskii
2018-08-24 19:49           ` Alex Branham
2018-08-26  6:33             ` Andreas Röhler
2018-08-25  2:26         ` Noam Postavsky
2018-08-30 14:39           ` Alex Branham
2018-08-31  1:21             ` Noam Postavsky
2018-08-31  2:50               ` Alex Branham
2019-07-09  0:05                 ` Noam Postavsky [this message]
2019-07-11  5:11                   ` Leo Liu
2018-08-23 23:18     ` Phil Sainty
2019-06-23 22:05   ` Lars Ingebrigtsen

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=87imsc2htw.fsf@gmail.com \
    --to=npostavs@gmail.com \
    --cc=32504@debbugs.gnu.org \
    --cc=alex.branham@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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).