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#26070: 26.0.50; js-mode slash insertion bug Date: Thu, 23 Mar 2017 21:53:11 -0600 Message-ID: <87d1d71gbc.fsf@tromey.com> References: <87wpbt8ev3.fsf@pokyo> <87fuig86ed.fsf@pokyo> <87lgrx0xch.fsf@tromey.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1490327666 3054 195.159.176.226 (24 Mar 2017 03:54:26 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 24 Mar 2017 03:54:26 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) Cc: 26070@debbugs.gnu.org, Tom Tromey , Dmitry Gutov To: Richard Copley Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Mar 24 04:54:21 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 1crGIl-0007HL-K2 for geb-bug-gnu-emacs@m.gmane.org; Fri, 24 Mar 2017 04:54:12 +0100 Original-Received: from localhost ([::1]:59723 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1crGIm-0002UI-6d for geb-bug-gnu-emacs@m.gmane.org; Thu, 23 Mar 2017 23:54:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43679) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1crGIg-0002UB-5b for bug-gnu-emacs@gnu.org; Thu, 23 Mar 2017 23:54:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1crGId-00069M-2O for bug-gnu-emacs@gnu.org; Thu, 23 Mar 2017 23:54:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:43415) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1crGIc-000699-Qq for bug-gnu-emacs@gnu.org; Thu, 23 Mar 2017 23:54:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1crGIc-0006Ot-FR for bug-gnu-emacs@gnu.org; Thu, 23 Mar 2017 23:54:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tom Tromey Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 24 Mar 2017 03:54:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 26070 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 26070-submit@debbugs.gnu.org id=B26070.149032761524565 (code B ref 26070); Fri, 24 Mar 2017 03:54:02 +0000 Original-Received: (at 26070) by debbugs.gnu.org; 24 Mar 2017 03:53:35 +0000 Original-Received: from localhost ([127.0.0.1]:41614 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1crGIB-0006O9-9r for submit@debbugs.gnu.org; Thu, 23 Mar 2017 23:53:35 -0400 Original-Received: from gproxy5-pub.mail.unifiedlayer.com ([67.222.38.55]:37049) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1crGI9-0006Nv-4g for 26070@debbugs.gnu.org; Thu, 23 Mar 2017 23:53:33 -0400 Original-Received: (qmail 20967 invoked by uid 0); 24 Mar 2017 03:53:19 -0000 Original-Received: from unknown (HELO cmgw4) (10.0.90.85) by gproxy5.mail.unifiedlayer.com with SMTP; 24 Mar 2017 03:53:19 -0000 Original-Received: from box522.bluehost.com ([74.220.219.122]) by cmgw4 with id zftC1u0062f2jeq01ftF4b; Thu, 23 Mar 2017 21:53:19 -0600 X-Authority-Analysis: v=2.1 cv=R4+QR7hX 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=6Iz7jQTuP9IA:10 a=WiVod9pSvdkA:10 a=zstS-IiYAAAA:8 a=GM1t2KiBM_GhJYaLIXUA:9 a=4G6NA9xxw8l3yy4pmD5M:22 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=Dryo2szjwOASZ8F88ckgZbj5ZjMn+belqyP119k3o9w=; b=vY1MgK5qSN1kuYbUfLMFsfokAW dX0EC7SHiOPw0R+lteGPxSNZkOso6QdQa1etrKR0p9RoTb34fLCO0FBcxRmbsddIq3Nr+KzGJo4hg psyAa9hreblG0kOibNY2fGrcj; Original-Received: from 75-166-14-202.hlrn.qwest.net ([75.166.14.202]:35822 helo=bapiya) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1crGHo-0006LI-DZ; Thu, 23 Mar 2017 21:53:12 -0600 X-Attribution: Tom In-Reply-To: (Richard Copley's message of "Thu, 23 Mar 2017 07:00:58 +0000") 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: 75.166.14.202 X-Exim-ID: 1crGHo-0006LI-DZ X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-14-202.hlrn.qwest.net (bapiya) [75.166.14.202]:35822 X-Source-Auth: tom+tromey.com X-Email-Count: 6 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:130862 Archived-At: Richard> Seems good, thanks very much. Thanks for giving it a try. Here's the latest version of these two patches, with test cases. Dmitry, please let me know what you think. Tom commit ff870ef0324a3e5c43cf2d183df5db72e824efca Author: Tom Tromey Date: Mon Mar 13 21:53:59 2017 +0100 fix two js-mode syntax propertization bugs Bug#26070: * lisp/progmodes/js.el (js--syntax-propertize-regexp-regexp): Add zero-or-one to regular expression. (js-syntax-propertize-regexp): Update. Propertize body of regexp literal up to END. * test/lisp/progmodes/js-tests.el (js-mode-propertize-bug-1) (js-mode-propertize-bug-2): New tests. diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index aed42a8..3c720c0 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -1713,7 +1713,7 @@ js--syntax-propertize-regexp-regexp (not (any ?\] ?\\)) (and "\\" not-newline))) "]"))) - (group "/")) + (group (zero-or-one "/"))) "Regular expression matching a JavaScript regexp literal.") (defun js-syntax-propertize-regexp (end) @@ -1721,12 +1721,13 @@ js-syntax-propertize-regexp (when (eq (nth 3 ppss) ?/) ;; A /.../ regexp. (goto-char (nth 8 ppss)) - (when (and (looking-at js--syntax-propertize-regexp-regexp) - ;; Don't touch text after END. - (<= (match-end 1) end)) - (put-text-property (match-beginning 1) (match-end 1) + (when (looking-at js--syntax-propertize-regexp-regexp) + ;; Don't touch text after END. + (when (> end (match-end 1)) + (setq end (match-end 1))) + (put-text-property (match-beginning 1) end 'syntax-table (string-to-syntax "\"/")) - (goto-char (match-end 0)))))) + (goto-char end))))) (defun js-syntax-propertize (start end) ;; JavaScript allows immediate regular expression objects, written /.../. diff --git a/test/lisp/progmodes/js-tests.el b/test/lisp/progmodes/js-tests.el index e030675..8e1bac1 100644 --- a/test/lisp/progmodes/js-tests.el +++ b/test/lisp/progmodes/js-tests.el @@ -140,6 +140,43 @@ (font-lock-ensure) (should (eq (get-text-property (point) 'face) (caddr test)))))) +(ert-deftest js-mode-propertize-bug-1 () + (with-temp-buffer + (js-mode) + (save-excursion (insert "x")) + (insert "/") + ;; The bug was a hang. + (should t))) + +(ert-deftest js-mode-propertize-bug-2 () + (with-temp-buffer + (js-mode) + (insert "function f() { + function g() + { + 1 / 2; + } + + function h() { +") + (save-excursion + (insert " + 00000000000000000000000000000000000000000000000000; + 00000000000000000000000000000000000000000000000000; + 00000000000000000000000000000000000000000000000000; + 00000000000000000000000000000000000000000000000000; + 00000000000000000000000000000000000000000000000000; + 00000000000000000000000000000000000000000000000000; + 00000000000000000000000000000000000000000000000000; + 00000000000000000000000000000000000000000000000000; + 00; + } +} +")) + (insert "/") + ;; The bug was a hang. + (should t))) + (provide 'js-tests) ;;; js-tests.el ends here