diff options
| author | Nathan Weizenbaum | 2010-08-26 16:09:31 -0400 |
|---|---|---|
| committer | Chong Yidong | 2010-08-26 16:09:31 -0400 |
| commit | 4142607e2fb5acacc8d087fa581422df3459fc81 (patch) | |
| tree | bdb04393ccebaff9089a01a2a5eb831551feb2bb | |
| parent | 88a36e604acbcb7093cb271ebf7b3ebed4d750ef (diff) | |
| download | emacs-4142607e2fb5acacc8d087fa581422df3459fc81.tar.gz emacs-4142607e2fb5acacc8d087fa581422df3459fc81.zip | |
* progmodes/js.el: Make indentation more customizable (Bug#6914).
(js-paren-indent-offset, js-square-indent-offset)
(js-curly-indent-offset): New options.
(js--proper-indentation): Use them.
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/progmodes/js.el | 41 |
2 files changed, 43 insertions, 5 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index dd96803195f..a220bc38f95 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2010-08-26 Nathan Weizenbaum <nweiz@cressida.sea.corp.google.com> (tiny change) | ||
| 2 | |||
| 3 | * progmodes/js.el: Make indentation more customizable (Bug#6914). | ||
| 4 | (js-paren-indent-offset, js-square-indent-offset) | ||
| 5 | (js-curly-indent-offset): New options. | ||
| 6 | (js--proper-indentation): Use them. | ||
| 7 | |||
| 1 | 2010-08-26 Daniel Colascione <dan.colascione@gmail.com> | 8 | 2010-08-26 Daniel Colascione <dan.colascione@gmail.com> |
| 2 | 9 | ||
| 3 | * progmodes/sh-script.el (sh-get-indent-info): Use syntax-ppss | 10 | * progmodes/sh-script.el (sh-get-indent-info): Use syntax-ppss |
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index d6feca4d8a0..9fb4822436a 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el | |||
| @@ -431,11 +431,32 @@ Match group 1 is the name of the macro.") | |||
| 431 | :group 'js) | 431 | :group 'js) |
| 432 | 432 | ||
| 433 | (defcustom js-expr-indent-offset 0 | 433 | (defcustom js-expr-indent-offset 0 |
| 434 | "Number of additional spaces used for indentation of continued expressions. | 434 | "Number of additional spaces for indenting continued expressions. |
| 435 | The value must be no less than minus `js-indent-level'." | 435 | The value must be no less than minus `js-indent-level'." |
| 436 | :type 'integer | 436 | :type 'integer |
| 437 | :group 'js) | 437 | :group 'js) |
| 438 | 438 | ||
| 439 | (defcustom js-paren-indent-offset 0 | ||
| 440 | "Number of additional spaces for indenting expressions in parentheses. | ||
| 441 | The value must be no less than minus `js-indent-level'." | ||
| 442 | :type 'integer | ||
| 443 | :group 'js | ||
| 444 | :version "24.1") | ||
| 445 | |||
| 446 | (defcustom js-square-indent-offset 0 | ||
| 447 | "Number of additional spaces for indenting expressions in square braces. | ||
| 448 | The value must be no less than minus `js-indent-level'." | ||
| 449 | :type 'integer | ||
| 450 | :group 'js | ||
| 451 | :version "24.1") | ||
| 452 | |||
| 453 | (defcustom js-curly-indent-offset 0 | ||
| 454 | "Number of additional spaces for indenting expressions in curly braces. | ||
| 455 | The value must be no less than minus `js-indent-level'." | ||
| 456 | :type 'integer | ||
| 457 | :group 'js | ||
| 458 | :version "24.1") | ||
| 459 | |||
| 439 | (defcustom js-auto-indent-flag t | 460 | (defcustom js-auto-indent-flag t |
| 440 | "Whether to automatically indent when typing punctuation characters. | 461 | "Whether to automatically indent when typing punctuation characters. |
| 441 | If non-nil, the characters {}();,: also indent the current line | 462 | If non-nil, the characters {}();,: also indent the current line |
| @@ -1769,14 +1790,17 @@ nil." | |||
| 1769 | ((eq (char-after) ?#) 0) | 1790 | ((eq (char-after) ?#) 0) |
| 1770 | ((save-excursion (js--beginning-of-macro)) 4) | 1791 | ((save-excursion (js--beginning-of-macro)) 4) |
| 1771 | ((nth 1 parse-status) | 1792 | ((nth 1 parse-status) |
| 1793 | ;; A single closing paren/bracket should be indented at the | ||
| 1794 | ;; same level as the opening statement. Same goes for | ||
| 1795 | ;; "case" and "default". | ||
| 1772 | (let ((same-indent-p (looking-at | 1796 | (let ((same-indent-p (looking-at |
| 1773 | "[]})]\\|\\_<case\\_>\\|\\_<default\\_>")) | 1797 | "[]})]\\|\\_<case\\_>\\|\\_<default\\_>")) |
| 1774 | (continued-expr-p (js--continued-expression-p))) | 1798 | (continued-expr-p (js--continued-expression-p))) |
| 1775 | (goto-char (nth 1 parse-status)) | 1799 | (goto-char (nth 1 parse-status)) ; go to the opening char |
| 1776 | (if (looking-at "[({[]\\s-*\\(/[/*]\\|$\\)") | 1800 | (if (looking-at "[({[]\\s-*\\(/[/*]\\|$\\)") |
| 1777 | (progn | 1801 | (progn ; nothing following the opening paren/bracket |
| 1778 | (skip-syntax-backward " ") | 1802 | (skip-syntax-backward " ") |
| 1779 | (when (eq (char-before) ?\)) (backward-list)) | 1803 | (when (eq (char-before) ?\)) (backward-list)) |
| 1780 | (back-to-indentation) | 1804 | (back-to-indentation) |
| 1781 | (cond (same-indent-p | 1805 | (cond (same-indent-p |
| 1782 | (current-column)) | 1806 | (current-column)) |
| @@ -1784,7 +1808,14 @@ nil." | |||
| 1784 | (+ (current-column) (* 2 js-indent-level) | 1808 | (+ (current-column) (* 2 js-indent-level) |
| 1785 | js-expr-indent-offset)) | 1809 | js-expr-indent-offset)) |
| 1786 | (t | 1810 | (t |
| 1787 | (+ (current-column) js-indent-level)))) | 1811 | (+ (current-column) js-indent-level |
| 1812 | (case (char-after (nth 1 parse-status)) | ||
| 1813 | (?\( js-paren-indent-offset) | ||
| 1814 | (?\[ js-square-indent-offset) | ||
| 1815 | (?\{ js-curly-indent-offset)))))) | ||
| 1816 | ;; If there is something following the opening | ||
| 1817 | ;; paren/bracket, everything else should be indented at | ||
| 1818 | ;; the same level. | ||
| 1788 | (unless same-indent-p | 1819 | (unless same-indent-p |
| 1789 | (forward-char) | 1820 | (forward-char) |
| 1790 | (skip-chars-forward " \t")) | 1821 | (skip-chars-forward " \t")) |