diff options
| author | Felix H. Dahlke | 2013-01-11 18:24:52 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2013-01-11 18:24:52 -0500 |
| commit | f90ff90659871ee5df8408476a3e4b832a21b17c (patch) | |
| tree | cfe272437725baeba15a1da1643fdbff540c83fe /lisp/progmodes | |
| parent | 9fc9a531a5938e870339211de6c0ecfedaa1c86b (diff) | |
| download | emacs-f90ff90659871ee5df8408476a3e4b832a21b17c.tar.gz emacs-f90ff90659871ee5df8408476a3e4b832a21b17c.zip | |
* lisp/progmodes/js.el: Fix multiline declarations's indentation.
(js--declaration-keyword-re): New var.
(js--multi-line-declaration-indentation): New function.
(js--proper-indentation): Use it.
Fixes: debbugs:8576
Diffstat (limited to 'lisp/progmodes')
| -rw-r--r-- | lisp/progmodes/js.el | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index 683b3927ae3..96e6039a8c2 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el | |||
| @@ -1680,12 +1680,15 @@ This performs fontification according to `js--class-styles'." | |||
| 1680 | "each")) | 1680 | "each")) |
| 1681 | "Regexp matching keywords optionally followed by an opening brace.") | 1681 | "Regexp matching keywords optionally followed by an opening brace.") |
| 1682 | 1682 | ||
| 1683 | (defconst js--declaration-keyword-re | ||
| 1684 | (regexp-opt '("var" "let" "const") 'words) | ||
| 1685 | "Regular expression matching variable declaration keywords.") | ||
| 1686 | |||
| 1683 | (defconst js--indent-operator-re | 1687 | (defconst js--indent-operator-re |
| 1684 | (concat "[-+*/%<>=&^|?:.]\\([^-+*/]\\|$\\)\\|" | 1688 | (concat "[-+*/%<>=&^|?:.]\\([^-+*/]\\|$\\)\\|" |
| 1685 | (js--regexp-opt-symbol '("in" "instanceof"))) | 1689 | (js--regexp-opt-symbol '("in" "instanceof"))) |
| 1686 | "Regexp matching operators that affect indentation of continued expressions.") | 1690 | "Regexp matching operators that affect indentation of continued expressions.") |
| 1687 | 1691 | ||
| 1688 | |||
| 1689 | (defun js--looking-at-operator-p () | 1692 | (defun js--looking-at-operator-p () |
| 1690 | "Return non-nil if point is on a JavaScript operator, other than a comma." | 1693 | "Return non-nil if point is on a JavaScript operator, other than a comma." |
| 1691 | (save-match-data | 1694 | (save-match-data |
| @@ -1764,6 +1767,37 @@ nil." | |||
| 1764 | (list (cons 'c js-comment-lineup-func)))) | 1767 | (list (cons 'c js-comment-lineup-func)))) |
| 1765 | (c-get-syntactic-indentation (list (cons symbol anchor))))) | 1768 | (c-get-syntactic-indentation (list (cons symbol anchor))))) |
| 1766 | 1769 | ||
| 1770 | (defun js--multi-line-declaration-indentation () | ||
| 1771 | "Helper function for `js--proper-indentation'. | ||
| 1772 | Return the proper indentation of the current line if it belongs to a declaration | ||
| 1773 | statement spanning multiple lines; otherwise, return nil." | ||
| 1774 | (let (at-opening-bracket) | ||
| 1775 | (save-excursion | ||
| 1776 | (back-to-indentation) | ||
| 1777 | (when (not (looking-at js--declaration-keyword-re)) | ||
| 1778 | (when (looking-at js--indent-operator-re) | ||
| 1779 | (goto-char (match-end 0))) | ||
| 1780 | (while (and (not at-opening-bracket) | ||
| 1781 | (not (bobp)) | ||
| 1782 | (let ((pos (point))) | ||
| 1783 | (save-excursion | ||
| 1784 | (js--backward-syntactic-ws) | ||
| 1785 | (or (eq (char-before) ?,) | ||
| 1786 | (and (not (eq (char-before) ?\;)) | ||
| 1787 | (prog2 | ||
| 1788 | (skip-chars-backward "[[:punct:]]") | ||
| 1789 | (looking-at js--indent-operator-re) | ||
| 1790 | (js--backward-syntactic-ws)) | ||
| 1791 | (not (eq (char-before) ?\;))) | ||
| 1792 | (and (>= pos (point-at-bol)) | ||
| 1793 | (<= pos (point-at-eol))))))) | ||
| 1794 | (condition-case err | ||
| 1795 | (backward-sexp) | ||
| 1796 | (scan-error (setq at-opening-bracket t)))) | ||
| 1797 | (when (looking-at js--declaration-keyword-re) | ||
| 1798 | (goto-char (match-end 0)) | ||
| 1799 | (1+ (current-column))))))) | ||
| 1800 | |||
| 1767 | (defun js--proper-indentation (parse-status) | 1801 | (defun js--proper-indentation (parse-status) |
| 1768 | "Return the proper indentation for the current line." | 1802 | "Return the proper indentation for the current line." |
| 1769 | (save-excursion | 1803 | (save-excursion |
| @@ -1772,6 +1806,7 @@ nil." | |||
| 1772 | (js--get-c-offset 'c (nth 8 parse-status))) | 1806 | (js--get-c-offset 'c (nth 8 parse-status))) |
| 1773 | ((nth 8 parse-status) 0) ; inside string | 1807 | ((nth 8 parse-status) 0) ; inside string |
| 1774 | ((js--ctrl-statement-indentation)) | 1808 | ((js--ctrl-statement-indentation)) |
| 1809 | ((js--multi-line-declaration-indentation)) | ||
| 1775 | ((eq (char-after) ?#) 0) | 1810 | ((eq (char-after) ?#) 0) |
| 1776 | ((save-excursion (js--beginning-of-macro)) 4) | 1811 | ((save-excursion (js--beginning-of-macro)) 4) |
| 1777 | ((nth 1 parse-status) | 1812 | ((nth 1 parse-status) |