]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix js-mode indentation bug
authorTom Tromey <tom@tromey.com>
Tue, 10 Jan 2017 05:15:57 +0000 (22:15 -0700)
committerTom Tromey <tom@tromey.com>
Fri, 13 Jan 2017 19:38:36 +0000 (12:38 -0700)
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.

lisp/progmodes/js.el
test/manual/indent/js.js

index 1484b79739f3236a79b56f62c9a8fc0efd1cbab6..e84215d4301174d2b21cba69abdab73a8525621e 100644 (file)
@@ -1771,6 +1771,24 @@ This performs fontification according to `js--class-styles'."
                  ;; return NaN anyway.  Shouldn't be a problem.
                  (memq (char-before) '(?, ?} ?{))))))))
 
+(defun js--find-newline-backward ()
+  "Move backward to the nearest newline that is not in a block comment."
+  (let ((continue t)
+        (result t))
+    (while continue
+      (setq continue nil)
+      (if (search-backward "\n" nil t)
+          (let ((parse (syntax-ppss)))
+            ;; We match the end of a // comment but not a newline in a
+            ;; block comment.
+            (when (nth 4 parse)
+              (goto-char (nth 8 parse))
+              ;; If we saw a block comment, keep trying.
+              (unless (nth 7 parse)
+                (setq continue t))))
+        (setq result nil)))
+    result))
+
 (defun js--continued-expression-p ()
   "Return non-nil if the current line continues an expression."
   (save-excursion
@@ -1780,7 +1798,7 @@ This performs fontification according to `js--class-styles'."
             (progn
               (forward-comment (- (point)))
               (not (memq (char-before) '(?, ?\[ ?\()))))
-      (and (js--re-search-backward "\n" nil t)
+      (and (js--find-newline-backward)
            (progn
              (skip-chars-backward " \t")
              (or (bobp) (backward-char))
index 806e9497ad5c8c8e5763d3218087787f625f0b27..d004b82f8bceacc0ee7695aa26d948f5142d5d20 100644 (file)
@@ -118,6 +118,12 @@ var arr = [
     -5
 ];
 
+// Regression test for bug#15582.
+if (x > 72 &&
+    y < 85) { // found
+  do_something();
+}
+
 // Local Variables:
 // indent-tabs-mode: nil
 // js-indent-level: 2