From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tom Tromey Newsgroups: gmane.emacs.bugs Subject: bug#25529: diagnosis and one approach to a fix Date: Sun, 05 Feb 2017 11:05:45 -0700 Message-ID: <87o9yg8qdi.fsf@tromey.com> References: <87wpd58ag6.fsf@tromey.com> <87shnt89be.fsf@tromey.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1486318036 17060 195.159.176.226 (5 Feb 2017 18:07:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 5 Feb 2017 18:07:16 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.91 (gnu/linux) Cc: 25529@debbugs.gnu.org To: Tom Tromey Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Feb 05 19:07:13 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1caRDU-00043Q-3X for geb-bug-gnu-emacs@m.gmane.org; Sun, 05 Feb 2017 19:07:12 +0100 Original-Received: from localhost ([::1]:44049 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caRDT-0005zi-Hp for geb-bug-gnu-emacs@m.gmane.org; Sun, 05 Feb 2017 13:07:11 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50024) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1caRDN-0005za-9O for bug-gnu-emacs@gnu.org; Sun, 05 Feb 2017 13:07:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1caRDK-0002fz-4s for bug-gnu-emacs@gnu.org; Sun, 05 Feb 2017 13:07:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:58647) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1caRDJ-0002fr-Tw for bug-gnu-emacs@gnu.org; Sun, 05 Feb 2017 13:07:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1caRDJ-000810-NI for bug-gnu-emacs@gnu.org; Sun, 05 Feb 2017 13:07:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Tom Tromey Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 05 Feb 2017 18:07:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25529 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 25529-submit@debbugs.gnu.org id=B25529.148631796730736 (code B ref 25529); Sun, 05 Feb 2017 18:07:01 +0000 Original-Received: (at 25529) by debbugs.gnu.org; 5 Feb 2017 18:06:07 +0000 Original-Received: from localhost ([127.0.0.1]:56846 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1caRCR-0007zf-Lh for submit@debbugs.gnu.org; Sun, 05 Feb 2017 13:06:07 -0500 Original-Received: from gproxy5-pub.mail.unifiedlayer.com ([67.222.38.55]:35251) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1caRCP-0007z8-5G for 25529@debbugs.gnu.org; Sun, 05 Feb 2017 13:06:05 -0500 Original-Received: (qmail 30036 invoked by uid 0); 5 Feb 2017 18:05:55 -0000 Original-Received: from unknown (HELO cmgw4) (10.0.90.85) by gproxy5.mail.unifiedlayer.com with SMTP; 5 Feb 2017 18:05:55 -0000 Original-Received: from box522.bluehost.com ([74.220.219.122]) by cmgw4 with id h65m1u01w2f2jeq0165pVa; Sun, 05 Feb 2017 11:05:55 -0700 X-Authority-Analysis: v=2.1 cv=Pets2ERd c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=n2v9WMKugxEA:10 a=-DvV8ZXa530hOBIlvD4A:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=7f3zXANd0+6TBN1bcMrXfsGH1AAvmx3tzy+aWTVIIxw=; b=aZ/7GUOePPTXUtkmK/p77SvMMS HZ5LYdcJlrxJ9SGk5ozLmyi+WMUIZZkQzPhqr3SW3MDK/aUDSJSyGE3Wxd+tqTr3F4LDIkx5JHIjB EL3p4mRnFXmAkyL1eEa1H4QRt; Original-Received: from 174-16-146-181.hlrn.qwest.net ([174.16.146.181]:57686 helo=bapiya) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1caRC6-0006o2-PR; Sun, 05 Feb 2017 11:05:46 -0700 X-Attribution: Tom In-Reply-To: <87shnt89be.fsf@tromey.com> (Tom Tromey's message of "Sat, 04 Feb 2017 23:01:57 -0700") X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box522.bluehost.com X-AntiAbuse: Original Domain - debbugs.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 174.16.146.181 X-Exim-ID: 1caRC6-0006o2-PR X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 174-16-146-181.hlrn.qwest.net (bapiya) [174.16.146.181]:57686 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== 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" Xref: news.gmane.org gmane.emacs.bugs:128989 Archived-At: Tom> I've appended a patch implementing this idea. Another way is to use a regexp, see appended. I'll try to write a test for this soon. Tom diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index e42e014..2b4ae8e 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -1694,22 +1694,32 @@ js--syntax-propertize-regexp-syntax-table (modify-syntax-entry ?\\ "\\" st) st)) +(defconst js--syntax-propertize-regexp-regexp + (rx + ;; Start of regexp. + "/" + (0+ (or + ;; Match characters outside of a character class. + (not (any ?\[ ?/ ?\\)) + ;; Match backslash quoted characters. + (and "\\" not-newline) + ;; Match character class. + (and + "[" + (0+ (or + (not (any ?\] ?\\)) + (and "\\" not-newline))) + "]"))) + (group "/"))) + (defun js-syntax-propertize-regexp (end) (let ((ppss (syntax-ppss))) (when (eq (nth 3 ppss) ?/) ;; A /.../ regexp. - (while - (when (re-search-forward "\\(?:\\=\\|[^\\]\\)\\(?:\\\\\\\\\\)*/" - end 'move) - (if (nth 1 (with-syntax-table - js--syntax-propertize-regexp-syntax-table - (let ((parse-sexp-lookup-properties nil)) - (parse-partial-sexp (nth 8 ppss) (point))))) - ;; A / within a character class is not the end of a regexp. - t - (put-text-property (1- (point)) (point) - 'syntax-table (string-to-syntax "\"/")) - nil)))))) + (goto-char (nth 8 ppss)) + (when (looking-at js--syntax-propertize-regexp-regexp) + (put-text-property (match-beginning 1) (match-end 1) + 'syntax-table (string-to-syntax "\"/")))))) (defun js-syntax-propertize (start end) ;; JavaScript allows immediate regular expression objects, written /.../.