diff options
| author | Tom Tromey <tom@tromey.com> | 2017-01-09 22:15:57 -0700 |
|---|---|---|
| committer | Tom Tromey <tom@tromey.com> | 2017-01-13 12:38:36 -0700 |
| commit | b47f97218efb8d9966e084bdfd8a86e8c47cf81d (patch) | |
| tree | 34f8f08d35699b9ce9d08cfaab1e1998735cec56 /lisp | |
| parent | cab7a385881b29df45338acd07dbc39ec703fa80 (diff) | |
| download | emacs-b47f97218efb8d9966e084bdfd8a86e8c47cf81d.tar.gz | |
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.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/progmodes/js.el | 20 |
1 files changed, 19 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'." ;; 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)) |
