From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Noam Postavsky Newsgroups: gmane.emacs.bugs Subject: bug#32504: [PATCH] syntax-is-{comment|string}-p Date: Mon, 08 Jul 2019 20:05:15 -0400 Message-ID: <87imsc2htw.fsf@gmail.com> References: <87o9dup3ow.fsf@gmail.com> <871sapwzbp.fsf@gmail.com> <87lg8xtexb.fsf@gmail.com> <83a7pdb2x4.fsf@gnu.org> <87d0u7n3r0.fsf@gmail.com> <87bm9ruqok.fsf@gmail.com> <87efefgbpj.fsf@gmail.com> <87bm9js53h.fsf@gmail.com> <87bm9js0zm.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="84704"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2.90 (gnu/linux) Cc: 32504@debbugs.gnu.org To: Alex Branham Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jul 09 02:07:00 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hkdet-000LtD-Jc for geb-bug-gnu-emacs@m.gmane.org; Tue, 09 Jul 2019 02:06:59 +0200 Original-Received: from localhost ([::1]:45778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkdes-00054Z-K1 for geb-bug-gnu-emacs@m.gmane.org; Mon, 08 Jul 2019 20:06:58 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44091) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkde1-00051U-6f for bug-gnu-emacs@gnu.org; Mon, 08 Jul 2019 20:06:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hkddz-00005R-IG for bug-gnu-emacs@gnu.org; Mon, 08 Jul 2019 20:06:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51186) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hkddy-00004q-Av for bug-gnu-emacs@gnu.org; Mon, 08 Jul 2019 20:06:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hkddy-0000ME-3Q for bug-gnu-emacs@gnu.org; Mon, 08 Jul 2019 20:06:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Noam Postavsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 09 Jul 2019 00:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32504 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: fixed patch Original-Received: via spool by 32504-submit@debbugs.gnu.org id=B32504.15626307251327 (code B ref 32504); Tue, 09 Jul 2019 00:06:02 +0000 Original-Received: (at 32504) by debbugs.gnu.org; 9 Jul 2019 00:05:25 +0000 Original-Received: from localhost ([127.0.0.1]:60007 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hkddM-0000LK-Rp for submit@debbugs.gnu.org; Mon, 08 Jul 2019 20:05:25 -0400 Original-Received: from mail-io1-f47.google.com ([209.85.166.47]:34364) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hkddK-0000L7-PD for 32504@debbugs.gnu.org; Mon, 08 Jul 2019 20:05:23 -0400 Original-Received: by mail-io1-f47.google.com with SMTP id k8so39402729iot.1 for <32504@debbugs.gnu.org>; Mon, 08 Jul 2019 17:05:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=MexDXb54Px03kThy6wkn8wA4LC8y7Hh5f+gHkcnCUH0=; b=HBfYMPdJDLYhPPufC9IptfPmpnvnqhG1W2WsXB09Gaq7Wx5LyOncELaNTlraOJtm+7 um9xXvR125JyAwnjJcMF0+uFpIlwSPtT/QtK54RYGs39UPVu/AKjIygj7jngpTw36m8R WzfN1E+rISC60spaROC5+id/ziybqA/KKA3RL/4gBYiwF1YdRb8B3h1Q7LE+KdJd9aOH +qx6XEX+Kal2IvNn299ltzwkzRGbryxJ4S4jGL3tycnst6yZqlWBhT6vOTPtkVogFV3m lZIHKDtPLwSNN2XZJdP9ldX3fDtTvIAwoXBpm219zJSZavIdHnJhGqNnSUxie8UOBPP4 Wl4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=MexDXb54Px03kThy6wkn8wA4LC8y7Hh5f+gHkcnCUH0=; b=cF5YI/qmO8vCpzOmd6AVkXT9nH1IgNh0ZuQ6LcgoUvNcpuvdfdreIsgOapQpM8W/zS kdB95mO+ulzxXiZxoTjI183fxQgwVcBeV0HDKZ5XXA+OPClNNsmHFZWeF6sM4rKTMz7r IZdf3mgVm32meFwWu4XNpiEeOvXy/TlK91UMg4aqHNO6L0JC4+Uys9PXIZtfR3DFY4dB WOGePNOnzFz4E+G/+gw1ee9QYtw5V1IQhs4WwLm9vfZYlneT5MjOE92yJyXkVbH8/f5Q +54bFNnpMbpEn3xi9WkkoC1gAhS5EAUsuqVJ4Ji1EodaBlXNgpSWtteSVttHLbBIRCxi xHlQ== X-Gm-Message-State: APjAAAUaYNchnwHIGQkN7odmpI/fR5DJB0WEPZ75rxUXPyLj8AbMBsEs gNFU4RljMPzEarK0utD0iRn5YvYR X-Google-Smtp-Source: APXvYqxDvj50tpzjNWYAaoBgb2baG9zPzeSuingLCaNFjMKVHkJvjetenbU4uWS1eA72/29+SEYZRQ== X-Received: by 2002:a5d:9e49:: with SMTP id i9mr22318957ioi.290.1562630716857; Mon, 08 Jul 2019 17:05:16 -0700 (PDT) Original-Received: from minid (cbl-45-2-119-34.yyz.frontiernetworks.ca. [45.2.119.34]) by smtp.gmail.com with ESMTPSA id s10sm10276299iod.46.2019.07.08.17.05.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Jul 2019 17:05:16 -0700 (PDT) In-Reply-To: <87bm9js0zm.fsf@gmail.com> (Alex Branham's message of "Thu, 30 Aug 2018 21:50:37 -0500") 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: 209.51.188.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:162411 Archived-At: --=-=-= Content-Type: text/plain Alex Branham writes: > On Thu 30 Aug 2018 at 20:21, Noam Postavsky 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. --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=0001-Add-named-accessors-for-syntax-ppss-state-Bug-32504.patch Content-Description: patch >From 0d09658a33aed36b0b647dc8dbfd08d8aa2dc535 Mon Sep 17 00:00:00 2001 From: Noam Postavsky 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 --=-=-= Content-Type: text/plain >>> 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. --=-=-=--