]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/js.el
Update docs for `customize-mode'
[gnu-emacs] / lisp / progmodes / js.el
index d59e7679b478cd69ee5a6902a8d98d5d79d38398..f024d397ffb5790bfcdadd6fc13a9c3f2d513c51 100644 (file)
@@ -1744,7 +1744,7 @@ This performs fontification according to `js--class-styles'."
   "Regular expression matching variable declaration keywords.")
 
 (defconst js--indent-operator-re
-  (concat "[-+*/%<>&^|?:.]\\([^-+*/]\\|$\\)\\|!?=\\|"
+  (concat "[-+*/%<>&^|?:.]\\([^-+*/.]\\|$\\)\\|!?=\\|"
           (js--regexp-opt-symbol '("in" "instanceof")))
   "Regexp matching operators that affect indentation of continued expressions.")
 
@@ -1758,27 +1758,32 @@ This performs fontification according to `js--class-styles'."
                     (eq (char-after) ??))))
          (not (and
                (eq (char-after) ?*)
-               (looking-at (concat "\\* *" js--name-re " *("))
+               ;; Generator method (possibly using computed property).
+               (looking-at (concat "\\* *\\(?:\\[\\|" js--name-re " *(\\)"))
                (save-excursion
-                 (goto-char (1- (match-end 0)))
-                 (let (forward-sexp-function) (forward-sexp))
-                 (js--forward-syntactic-ws)
-                 (eq (char-after) ?{)))))))
+                 (js--backward-syntactic-ws)
+                 ;; We might misindent some expressions that would
+                 ;; return NaN anyway.  Shouldn't be a problem.
+                 (memq (char-before) '(?, ?} ?{))))))))
 
 (defun js--continued-expression-p ()
   "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 ()
@@ -1887,9 +1892,11 @@ In particular, return the buffer position of the first `for' kwd."
           ;; To skip arbitrary expressions we need the parser,
           ;; so we'll just guess at it.
           (if (and (> end (point)) ; Not empty literal.
-                   (re-search-forward "[^,]]* \\(for\\" end t)
+                   (re-search-forward "[^,]]* \\(for\\_>\\)" end t)
                    ;; Not inside comment or string literal.
-                   (not (nth 8 (parse-partial-sexp bracket (point)))))
+                   (let ((status (parse-partial-sexp bracket (point))))
+                     (and (= 1 (car status))
+                          (not (nth 8 status)))))
               (match-beginning 1)))))))
 
 (defun js--array-comp-indentation (bracket for-kwd)