From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: Problems with syntax-ppss: Was [... Apply `comment-depth' text properties when calling `back_comment'.] Date: Fri, 11 Mar 2016 20:48:17 +0000 Message-ID: <20160311204817.GF2888@acm.fritz.box> References: <20160309193758.GH3948@acm.fritz.box> <20160310130156.GA4831@acm.fritz.box> <20160310152949.GB4831@acm.fritz.box> <20160310172539.GC4831@acm.fritz.box> <20160310190824.GD4831@acm.fritz.box> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1457729635 28027 80.91.229.3 (11 Mar 2016 20:53:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 11 Mar 2016 20:53:55 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Mar 11 21:53:47 2016 Return-path: Envelope-to: ged-emacs-devel@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 1aeU4A-0001xv-A8 for ged-emacs-devel@m.gmane.org; Fri, 11 Mar 2016 21:53:46 +0100 Original-Received: from localhost ([::1]:57630 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aeU49-0005xm-PF for ged-emacs-devel@m.gmane.org; Fri, 11 Mar 2016 15:53:45 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55885) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aeTwM-00033G-PE for emacs-devel@gnu.org; Fri, 11 Mar 2016 15:45:43 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aeTwJ-0001Sh-IQ for emacs-devel@gnu.org; Fri, 11 Mar 2016 15:45:42 -0500 Original-Received: from mail.muc.de ([193.149.48.3]:45326) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aeTwJ-0001SO-8h for emacs-devel@gnu.org; Fri, 11 Mar 2016 15:45:39 -0500 Original-Received: (qmail 95816 invoked by uid 3782); 11 Mar 2016 20:45:37 -0000 Original-Received: from acm.muc.de (p579E8E6B.dip0.t-ipconnect.de [87.158.142.107]) by colin.muc.de (tmda-ofmipd) with ESMTP; Fri, 11 Mar 2016 21:45:36 +0100 Original-Received: (qmail 5891 invoked by uid 1000); 11 Mar 2016 20:48:17 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x X-Received-From: 193.149.48.3 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:201489 Archived-At: Hello, Stefan. On Thu, Mar 10, 2016 at 06:10:58PM -0500, Stefan Monnier wrote: [ .... ] > or replace my previous patch with this one below, which is almost > identical to the previous one, tho a bit cleaner and with a fix to make > comment-use-syntax-ppss override open-paren-in-column-0-is-defun-start, > as it should. OK. It wouldn't compile, so I had to correct it a little bit. Anyhow, what is going on at the indicated lines, where the input values of the end of comment are simply returned as the beginning of defun? Perhaps more seriously, the scheme won't work if point-min is inside a string. In that case, strings and non-strings get swapped. syntax-ppss will return what it thinks is the beginning of the string enclosing POS, but which in reality is the end " of the previous actual string. This could easily be inside an actual comment: ............" "...." /* "...." */ /* */ /* */ | | | point-min return value of syntax-ppss pos This is not a valid position to return as a safe place. > diff --git a/src/syntax.c b/src/syntax.c > index 249d0d5..f2268da 100644 > --- a/src/syntax.c > +++ b/src/syntax.c > @@ -597,6 +597,26 @@ find_defun_start (ptrdiff_t pos, ptrdiff_t pos_byte) > && MODIFF == find_start_modiff) > return find_start_value; > + if (!NILP (Vcomment_use_syntax_ppss)) > + { > + EMACS_INT modiffs = CHARS_MODIFF; > + Lisp_Object ppss = call1 (Qsyntax_ppss, make_number (pos)); > + if (modiffs != CHARS_MODIFF) > + error ("syntax-ppss modified the buffer!"); > + TEMP_SET_PT_BOTH (opoint, opoint_byte); > + Lisp_Object boc = Fnth (make_number (8), ppss); > + if (NUMBERP (boc)) > + { > + find_start_value = XINT (boc); > + find_start_value_byte = CHAR_TO_BYTE (find_start_value); > + } > + else > + { > + find_start_value = pos; <===================== > + find_start_value_byte = pos_byte; <===================== > + } > + goto found; > + } > if (!open_paren_in_column_0_is_defun_start) > { > find_start_value = BEGV; > @@ -864,6 +884,7 @@ back_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop, > case Sopen: > /* Assume a defun-start point is outside of strings. */ > if (open_paren_in_column_0_is_defun_start > + && NILP (Vcomment_use_syntax_ppss)) > && (from == stop > || (temp_byte = dec_bytepos (from_byte), > FETCH_CHAR (temp_byte) == '\n'))) > @@ -3647,6 +3668,11 @@ void > syms_of_syntax (void) > { > DEFSYM (Qsyntax_table_p, "syntax-table-p"); > + DEFSYM (Qsyntax_ppss, "syntax-ppss-for-syntax.c"); > + DEFVAR_LISP ("comment-use-syntax-ppss", > + Vcomment_use_syntax_ppss, > + doc: /* Non-nil means `forward-comment' can use `syntax-ppss' internally. */); > + Vcomment_use_syntax_ppss = Qt; > staticpro (&Vsyntax_code_object); > Stefan -- Alan Mackenzie (Nuremberg, Germany).