aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Tromey2017-01-09 22:15:57 -0700
committerTom Tromey2017-01-13 12:38:36 -0700
commitb47f97218efb8d9966e084bdfd8a86e8c47cf81d (patch)
tree34f8f08d35699b9ce9d08cfaab1e1998735cec56
parentcab7a385881b29df45338acd07dbc39ec703fa80 (diff)
downloademacs-b47f97218efb8d9966e084bdfd8a86e8c47cf81d.tar.gz
emacs-b47f97218efb8d9966e084bdfd8a86e8c47cf81d.zip
Fix js-mode indentation bug
Bug#15582: * lisp/progmodes/js.el (js--find-newline-backward): New function. (js--continued-expression-p): Use it. * test/manual/indent/js.js: Add new test.
-rw-r--r--lisp/progmodes/js.el20
-rw-r--r--test/manual/indent/js.js6
2 files changed, 25 insertions, 1 deletions
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 1484b79739f..e84215d4301 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -1771,6 +1771,24 @@ This performs fontification according to `js--class-styles'."
1771 ;; return NaN anyway. Shouldn't be a problem. 1771 ;; return NaN anyway. Shouldn't be a problem.
1772 (memq (char-before) '(?, ?} ?{)))))))) 1772 (memq (char-before) '(?, ?} ?{))))))))
1773 1773
1774(defun js--find-newline-backward ()
1775 "Move backward to the nearest newline that is not in a block comment."
1776 (let ((continue t)
1777 (result t))
1778 (while continue
1779 (setq continue nil)
1780 (if (search-backward "\n" nil t)
1781 (let ((parse (syntax-ppss)))
1782 ;; We match the end of a // comment but not a newline in a
1783 ;; block comment.
1784 (when (nth 4 parse)
1785 (goto-char (nth 8 parse))
1786 ;; If we saw a block comment, keep trying.
1787 (unless (nth 7 parse)
1788 (setq continue t))))
1789 (setq result nil)))
1790 result))
1791
1774(defun js--continued-expression-p () 1792(defun js--continued-expression-p ()
1775 "Return non-nil if the current line continues an expression." 1793 "Return non-nil if the current line continues an expression."
1776 (save-excursion 1794 (save-excursion
@@ -1780,7 +1798,7 @@ This performs fontification according to `js--class-styles'."
1780 (progn 1798 (progn
1781 (forward-comment (- (point))) 1799 (forward-comment (- (point)))
1782 (not (memq (char-before) '(?, ?\[ ?\())))) 1800 (not (memq (char-before) '(?, ?\[ ?\()))))
1783 (and (js--re-search-backward "\n" nil t) 1801 (and (js--find-newline-backward)
1784 (progn 1802 (progn
1785 (skip-chars-backward " \t") 1803 (skip-chars-backward " \t")
1786 (or (bobp) (backward-char)) 1804 (or (bobp) (backward-char))
diff --git a/test/manual/indent/js.js b/test/manual/indent/js.js
index 806e9497ad5..d004b82f8bc 100644
--- a/test/manual/indent/js.js
+++ b/test/manual/indent/js.js
@@ -118,6 +118,12 @@ var arr = [
118 -5 118 -5
119]; 119];
120 120
121// Regression test for bug#15582.
122if (x > 72 &&
123 y < 85) { // found
124 do_something();
125}
126
121// Local Variables: 127// Local Variables:
122// indent-tabs-mode: nil 128// indent-tabs-mode: nil
123// js-indent-level: 2 129// js-indent-level: 2