Subject: Re: 26.0.50; js-mode slash insertion bug

From: Tom Tromey <[email-masked]>
Date: Mon, 13 Mar 2017 14:50:56 +0100

Richard> I couldn't see what code is running, because C-g doesn't enter the
Richard> debugger in this situation even when debug-on-quit is true, but I
Richard> bisected it to this commit:

Thanks for finding this and bisecting it.

At first I thought the problem was that the regexp literal matching code
in js-syntax-propertize should leave point after the construct.
However, the call to js-syntax-propertize really ought to do that... but
this code is always requiring the trailing "/", which is what is going
wrong.

I think once js-syntax-propertize is called, the regexp should always
succeed, so this patch makes the trailing "/" optional.

Can you try this and let me know if it works for you?

Tom

diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 84c9111..fa865db 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -1714,7 +1714,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)
@@ -1724,8 +1724,8 @@ js-syntax-propertize-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)
+                 (or (not (match-end 1)) (<= (match-end 1) end)))
+        (put-text-property (match-beginning 1) (or (match-end 1) (match-end 0))
                            'syntax-table (string-to-syntax "\"/"))
         (goto-char (match-end 0))))))