From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#22983: syntax-ppss returns wrong result. Date: Sat, 19 Mar 2016 12:27:59 +0000 Message-ID: <20160319122759.GA2644@acm.fritz.box> References: <20160311151512.GD2888@acm.fritz.box> <44b4fa9e-ec8e-98a4-d8ad-e799fffa7959@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1458390384 5269 80.91.229.3 (19 Mar 2016 12:26:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 19 Mar 2016 12:26:24 +0000 (UTC) Cc: 22983@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Mar 19 13:26:13 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ahFxN-0005db-56 for geb-bug-gnu-emacs@m.gmane.org; Sat, 19 Mar 2016 13:26:13 +0100 Original-Received: from localhost ([::1]:48663 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahFxJ-0003bE-9K for geb-bug-gnu-emacs@m.gmane.org; Sat, 19 Mar 2016 08:26:09 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57887) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahFxG-0003b9-2m for bug-gnu-emacs@gnu.org; Sat, 19 Mar 2016 08:26:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ahFxC-0003J5-2D for bug-gnu-emacs@gnu.org; Sat, 19 Mar 2016 08:26:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:56112) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahFxB-0003Iy-UN for bug-gnu-emacs@gnu.org; Sat, 19 Mar 2016 08:26:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ahFxB-0001jz-OH for bug-gnu-emacs@gnu.org; Sat, 19 Mar 2016 08:26:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 19 Mar 2016 12:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22983 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 22983-submit@debbugs.gnu.org id=B22983.14583903186641 (code B ref 22983); Sat, 19 Mar 2016 12:26:01 +0000 Original-Received: (at 22983) by debbugs.gnu.org; 19 Mar 2016 12:25:18 +0000 Original-Received: from localhost ([127.0.0.1]:53239 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ahFwT-0001j3-OF for submit@debbugs.gnu.org; Sat, 19 Mar 2016 08:25:17 -0400 Original-Received: from mail.muc.de ([193.149.48.3]:16365) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ahFwR-0001iu-Mo for 22983@debbugs.gnu.org; Sat, 19 Mar 2016 08:25:16 -0400 Original-Received: (qmail 38936 invoked by uid 3782); 19 Mar 2016 12:25:14 -0000 Original-Received: from acm.muc.de (p548A5545.dip0.t-ipconnect.de [84.138.85.69]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sat, 19 Mar 2016 13:25:13 +0100 Original-Received: (qmail 3783 invoked by uid 1000); 19 Mar 2016 12:27:59 -0000 Content-Disposition: inline In-Reply-To: <44b4fa9e-ec8e-98a4-d8ad-e799fffa7959@yandex.ru> User-Agent: Mutt/1.5.24 (2015-08-30) X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de 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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:115077 Archived-At: Hello, Dmitry. On Fri, Mar 18, 2016 at 02:49:34AM +0200, Dmitry Gutov wrote: > On 03/11/2016 05:15 PM, Alan Mackenzie wrote: > This patch should make ppss-0 and ppss-1 match: OK, no bad thing! But seeing that the function is a new function (its specification has changed), it will need new test cases, fresh new attempts to break it. > diff --git a/lisp/emacs-lisp/syntax.el b/lisp/emacs-lisp/syntax.el > index e20a210..c1b9d84 100644 > --- a/lisp/emacs-lisp/syntax.el > +++ b/lisp/emacs-lisp/syntax.el > @@ -371,6 +371,11 @@ syntax-ppss-max-span > We try to make sure that cache entries are at least this far apart > from each other, to avoid keeping too much useless info.") > +(defvar syntax-ppss-dont-widen nil > + "If non-nil, `syntax-ppss' will work on the non-widened buffer. > +The code that uses this should create local bindings for > +`syntax-ppss-cache' and `syntax-ppss-last' too.") > + I'm against this bit. If syntax-ppss-dont-widen is non-nil, the buffer is narrowed, and the local cache variables are correctly bound and filled, then something at a low level is going to widen the buffer (and call back_comment) without knowing to restore the global bindings for those cache variables. This could easily give the wrong result and corrupt the locally bound cache. I think the only sensible functionality for syntax-ppss is to be equivalent to (parse-partial-sexp 1 pos). Then everybody knows where they stand. Those pieces of code which actually need a ppss cache with origin other than 1 could then use a more appropriate specialized function whose cache wouldn't get mixed up with syntax-ppss's. (It could share a lot of code with syntax-ppss). > (defvar syntax-begin-function nil > "Function to move back outside of any comment/string/paren. > This function should move the cursor back to some syntactically safe > @@ -423,12 +428,21 @@ syntax-ppss > in the returned list (counting from 0) cannot be relied upon. > Point is at POS when this function returns. > +IF `syntax-ppss-dont-widen' is nil, the buffer is temporarily > +widened. > + > It is necessary to call `syntax-ppss-flush-cache' explicitly if > this function is called while `before-change-functions' is > temporarily let-bound, or if the buffer is modified without > running the hook." > ;; Default values. > (unless pos (setq pos (point))) > + (save-restriction > + (unless syntax-ppss-dont-widen > + (widen)) > + (syntax-pps--at pos))) > + > +(defun syntax-ppss--at (pos) > (syntax-propertize pos) > ;; > (let ((old-ppss (cdr syntax-ppss-last)) -- Alan Mackenzie (Nuremberg, Germany).