aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2014-12-23 11:17:55 -0500
committerStefan Monnier2014-12-23 11:17:55 -0500
commit29c5e2cea22f909af7d33b290ca0eb23c5ad6c00 (patch)
treea2e38d5bc89e31cd19beef7ac39750f7d962e4d8
parent46d40398fc0bebd8584636eddadb138a62bf32af (diff)
downloademacs-29c5e2cea22f909af7d33b290ca0eb23c5ad6c00.tar.gz
emacs-29c5e2cea22f909af7d33b290ca0eb23c5ad6c00.zip
(js-syntax-propertize-regexp): Recognize "slash in a character class"
Fixes: debbugs:19397 * lisp/progmodes/js.el (js--syntax-propertize-regexp-syntax-table): New var. (js-syntax-propertize-regexp): Use it to recognize "slash in a character class".
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/progmodes/js.el27
-rw-r--r--test/indent/js.js5
3 files changed, 33 insertions, 5 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index d8bb1c89f1f..12430b69fb7 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12014-12-23 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * progmodes/js.el (js--syntax-propertize-regexp-syntax-table): New var.
4 (js-syntax-propertize-regexp): Use it to recognize "slash in
5 a character class" (bug#19397).
6
12014-12-22 Stefan Monnier <monnier@iro.umontreal.ca> 72014-12-22 Stefan Monnier <monnier@iro.umontreal.ca>
2 8
3 * completion.el: Use post-self-insert-hook (bug#19400). 9 * completion.el: Use post-self-insert-hook (bug#19400).
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index c2c45aa4ef8..45074d338d3 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -1637,12 +1637,29 @@ This performs fontification according to `js--class-styles'."
1637 js--font-lock-keywords-3) 1637 js--font-lock-keywords-3)
1638 "Font lock keywords for `js-mode'. See `font-lock-keywords'.") 1638 "Font lock keywords for `js-mode'. See `font-lock-keywords'.")
1639 1639
1640(defconst js--syntax-propertize-regexp-syntax-table
1641 (let ((st (make-char-table 'syntax-table (string-to-syntax "."))))
1642 (modify-syntax-entry ?\[ "(]" st)
1643 (modify-syntax-entry ?\] ")[" st)
1644 (modify-syntax-entry ?\\ "\\" st)
1645 st))
1646
1640(defun js-syntax-propertize-regexp (end) 1647(defun js-syntax-propertize-regexp (end)
1641 (when (eq (nth 3 (syntax-ppss)) ?/) 1648 (let ((ppss (syntax-ppss)))
1642 ;; A /.../ regexp. 1649 (when (eq (nth 3 ppss) ?/)
1643 (when (re-search-forward "\\(?:\\=\\|[^\\]\\)\\(?:\\\\\\\\\\)*/" end 'move) 1650 ;; A /.../ regexp.
1644 (put-text-property (1- (point)) (point) 1651 (while
1645 'syntax-table (string-to-syntax "\"/"))))) 1652 (when (re-search-forward "\\(?:\\=\\|[^\\]\\)\\(?:\\\\\\\\\\)*/"
1653 end 'move)
1654 (if (nth 1 (with-syntax-table
1655 js--syntax-propertize-regexp-syntax-table
1656 (let ((parse-sexp-lookup-properties nil))
1657 (parse-partial-sexp (nth 8 ppss) (point)))))
1658 ;; A / within a character class is not the end of a regexp.
1659 t
1660 (put-text-property (1- (point)) (point)
1661 'syntax-table (string-to-syntax "\"/"))
1662 nil))))))
1646 1663
1647(defun js-syntax-propertize (start end) 1664(defun js-syntax-propertize (start end)
1648 ;; Javascript allows immediate regular expression objects, written /.../. 1665 ;; Javascript allows immediate regular expression objects, written /.../.
diff --git a/test/indent/js.js b/test/indent/js.js
index 1924094e9d8..2d458e1b769 100644
--- a/test/indent/js.js
+++ b/test/indent/js.js
@@ -7,6 +7,11 @@ let c = 1,
7var e = 100500, 7var e = 100500,
8 + 1; 8 + 1;
9 9
10function test ()
11{
12 return /[/]/.test ('/') // (bug#19397)
13}
14
10var f = bar('/protocols/') 15var f = bar('/protocols/')
11baz(); 16baz();
12 17