From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: forward-comment and syntax-ppss (was: Preview: portable dumper) Date: Sun, 04 Dec 2016 17:24:45 -0500 Message-ID: References: <878trydrbo.fsf@red-bean.com> <83a8cem1eq.fsf@gnu.org> <83zikdl7oo.fsf@gnu.org> <83y3zxkwms.fsf@gnu.org> <20161203143603.GA6921@acm.fritz.box> <43e8a279-3278-817b-7cd4-b669c5ae320b@yandex.ru> <20161204123434.GB2791@acm.fritz.box> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1480890350 7024 195.159.176.226 (4 Dec 2016 22:25:50 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 4 Dec 2016 22:25:50 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Dec 04 23:25:46 2016 Return-path: Envelope-to: ged-emacs-devel@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 1cDfE9-000189-Sx for ged-emacs-devel@m.gmane.org; Sun, 04 Dec 2016 23:25:46 +0100 Original-Received: from localhost ([::1]:35874 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cDfED-00066S-O7 for ged-emacs-devel@m.gmane.org; Sun, 04 Dec 2016 17:25:49 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45769) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cDfDP-0005we-VI for emacs-devel@gnu.org; Sun, 04 Dec 2016 17:25:01 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cDfDM-0005oz-Ow for emacs-devel@gnu.org; Sun, 04 Dec 2016 17:25:00 -0500 Original-Received: from [195.159.176.226] (port=40837 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cDfDM-0005oO-Hd for emacs-devel@gnu.org; Sun, 04 Dec 2016 17:24:56 -0500 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1cDfDG-0001KG-Dq for emacs-devel@gnu.org; Sun, 04 Dec 2016 23:24:50 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 102 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:Ttwkt3Q4hxqRpqzYV2FWUAyFfLE= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.devel:210037 Archived-At: >> Your patch was indeed simpler. Indeed, it was so simple as actually not >> to work in general, as well as being ~2 orders of magnitude slower than >> the current (forward-comment -1). > You make it sound like it barely ever works and it's always 100 > times slower. I think this qualifies as "gross misrepresentation". As a counter-point, I've been using the patch below since this discussion, without noticing any adverse effects. I don't doubt that it will occasionally mis-behave in cc-mode buffers, but I'm not sure it's an argument against this patch. After all, there are mostly 3 entities at play here: - this patch (i.e. the linkage between forward-commment and syntax-ppss). - syntax-ppss itself. - cc-mode. I think most of the problems that will show up with this patch can be attributed to the current syntax-ppss implementation (e.g. its inability to deal reliably with narrowing or with changes of the syntax-table). Maybe those problems will best be solved not just by changing syntax-ppss but by providing more info to syntax-ppss (e.g. requiring major modes who narrow the buffer or change the syntax-table to indicate to syntax-ppss how to handle it (since there are various possible choices and syntax-ppss usually can't know which is best or even which is right)). So I see this patch as an opportunity to improve syntax-ppss. Stefan diff --git a/src/syntax.c b/src/syntax.c index d463f7e..b56e808 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -297,6 +297,7 @@ SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object object, gl_state.b_property = 0; gl_state.e_property = PTRDIFF_MAX; gl_state.offset = 0; + return; /* There are no syntax-table properties here. */ } else { @@ -607,6 +634,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; @@ -874,6 +921,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'))) @@ -3453,10 +3493,7 @@ internalize_parse_state (Lisp_Object external, struct lisp_parse_state *state) else { tem = Fcar (external); - if (!NILP (tem)) - state->depth = XINT (tem); - else - state->depth = 0; + state->depth = INTEGERP (tem) ? XINT (tem) : 0; external = Fcdr (external); external = Fcdr (external); @@ -3680,6 +3717,11 @@ void syms_of_syntax (void) { DEFSYM (Qsyntax_table_p, "syntax-table-p"); + DEFSYM (Qsyntax_ppss, "syntax-ppss"); + 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);