]> code.delx.au - gnu-emacs/commitdiff
(js--continued-expression-p): Special-case unary plus and minus
authorDmitry Gutov <dgutov@yandex.ru>
Sat, 2 Apr 2016 00:02:03 +0000 (03:02 +0300)
committerDmitry Gutov <dgutov@yandex.ru>
Sat, 2 Apr 2016 00:07:09 +0000 (03:07 +0300)
* lisp/progmodes/js.el (js--continued-expression-p): Make an
effort to recognize unary plus and minus, in the contexts where
they make sense (https://github.com/mooz/js2-mode/issues/322).

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

index 15a52ba8cdc9a0b1a2f2c3e9e1c8981454a0a044..8c93ffa87310bd844ad830bea3a288ae11e975d6 100644 (file)
@@ -1770,16 +1770,20 @@ This performs fontification according to `js--class-styles'."
   "Return non-nil if the current line continues an expression."
   (save-excursion
     (back-to-indentation)
-    (or (js--looking-at-operator-p)
-        (and (js--re-search-backward "\n" nil t)
-            (progn
-              (skip-chars-backward " \t")
-              (or (bobp) (backward-char))
-              (and (> (point) (point-min))
-                    (save-excursion (backward-char) (not (looking-at "[/*]/")))
-                    (js--looking-at-operator-p)
-                   (and (progn (backward-char)
-                               (not (looking-at "+\\+\\|--\\|/[/*]"))))))))))
+    (if (js--looking-at-operator-p)
+        (or (not (memq (char-after) '(?- ?+)))
+            (progn
+              (forward-comment (- (point)))
+              (not (memq (char-before) '(?, ?\[ ?\()))))
+      (and (js--re-search-backward "\n" nil t)
+           (progn
+             (skip-chars-backward " \t")
+             (or (bobp) (backward-char))
+             (and (> (point) (point-min))
+                  (save-excursion (backward-char) (not (looking-at "[/*]/")))
+                  (js--looking-at-operator-p)
+                  (and (progn (backward-char)
+                              (not (looking-at "+\\+\\|--\\|/[/*]"))))))))))
 
 
 (defun js--end-of-do-while-loop-p ()
index d843f615fd8ec313d8ea70922c83e70c849c71f0..61c7b440ea3025b6427eef40e457fefd4605a07f 100644 (file)
@@ -95,6 +95,12 @@ Foobar
     console.log(num);
   });
 
+var arr = [
+  -1, 2,
+  -3, 4 +
+    -5
+];
+
 // Local Variables:
 // indent-tabs-mode: nil
 // js-indent-level: 2