[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master ee4a202 18/22: Merge pull request #195 from jacksonrayhami
From: |
Dmitry Gutov |
Subject: |
[elpa] master ee4a202 18/22: Merge pull request #195 from jacksonrayhamilton/pretty-multiline-declarations |
Date: |
Fri, 24 Apr 2015 02:57:16 +0000 |
branch: master
commit ee4a202e063d271f0d98452c2976347dd6f66f52
Merge: 4de6f03 d4d9c54
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>
Merge pull request #195 from
jacksonrayhamilton/pretty-multiline-declarations
js2-pretty-multiline-declarations: Add 'dynamic option
---
js2-mode.el | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++----
tests/indent.el | 27 ++++++++++++++++++++++
2 files changed, 87 insertions(+), 5 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index c8f47e6..3df192e 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -263,14 +263,37 @@ js2-mode also binds `js2-bounce-indent-backwards' to
Shift-Tab."
b = 20,
c = 30;
-If the value is not `all', and the first assigned value in
+If the value is t, and the first assigned value in the
declaration is a function/array/object literal spanning several
lines, it won't be indented additionally:
var o = { var bar = 2,
foo: 3 vs. o = {
}, foo: 3
- bar = 2; };"
+ bar = 2; };
+
+If the value is `all', it will always be indented additionally:
+
+ var o = {
+ foo: 3
+ };
+
+ var o = {
+ foo: 3
+ },
+ bar = 2;
+
+If the value is `dynamic', it will be indented additionally only
+if the declaration contains more than one variable:
+
+ var o = {
+ foo: 3
+ };
+
+ var o = {
+ foo: 3
+ },
+ bar = 2;"
:group 'js2-mode
:type 'symbol)
(js2-mark-safe-local 'js2-pretty-multiline-declarations 'symbolp)
@@ -10780,6 +10803,40 @@ In particular, return the buffer position of the first
`for' kwd."
(goto-char for-kwd)
(current-column))))
+(defun js2-maybe-goto-declaration-keyword-end (bracket)
+ "Helper function for `js2-proper-indentation'.
+Depending on the value of `js2-pretty-multiline-declarations',
+move point to the end of a variable declaration keyword so that
+indentation is aligned to that column."
+ (cond
+ ((eq js2-pretty-multiline-declarations 'all)
+ (when (looking-at js2-declaration-keyword-re)
+ (goto-char (1+ (match-end 0)))))
+ ((eq js2-pretty-multiline-declarations 'dynamic)
+ (let (declaration-keyword-end
+ at-closing-bracket-p
+ comma-p)
+ (when (looking-at js2-declaration-keyword-re)
+ ;; Preserve the match data lest it somehow be overridden.
+ (setq declaration-keyword-end (match-end 0))
+ (save-excursion
+ (goto-char bracket)
+ (setq at-closing-bracket-p
+ ;; Handle scan errors gracefully.
+ (condition-case nil
+ (progn
+ ;; Use the regular `forward-sexp-function' because the
+ ;; normal one for this mode uses the AST.
+ (let (forward-sexp-function)
+ (forward-sexp))
+ t)
+ (error nil)))
+ (when at-closing-bracket-p
+ (js2-forward-sws)
+ (setq comma-p (looking-at-p ","))))
+ (when comma-p
+ (goto-char (1+ declaration-keyword-end))))))))
+
(defun js2-proper-indentation (parse-status)
"Return the proper indentation for the current line."
(save-excursion
@@ -10823,9 +10880,7 @@ In particular, return the buffer position of the first
`for' kwd."
(looking-at ")"))
(backward-list))
(back-to-indentation)
- (and (eq js2-pretty-multiline-declarations 'all)
- (looking-at js2-declaration-keyword-re)
- (goto-char (1+ (match-end 0))))
+ (js2-maybe-goto-declaration-keyword-end bracket)
(setq indent
(cond (same-indent-p
(current-column))
diff --git a/tests/indent.el b/tests/indent.el
index b720984..df69202 100644
--- a/tests/indent.el
+++ b/tests/indent.el
@@ -112,3 +112,30 @@
| are kept
| unchanged!`"
:keep-indent t)
+
+(js2-deftest-indent no-multiline-decl-first-arg-function-dynamic
+ "var foo = function() {
+ | return 7;
+ |};"
+ :bind ((js2-pretty-multiline-declarations 'dynamic)))
+
+(js2-deftest-indent multiline-decl-first-arg-function-indent-dynamic
+ "var foo = function() {
+ | return 7;
+ | },
+ | bar = 8;"
+ :bind ((js2-pretty-multiline-declarations 'dynamic)))
+
+(js2-deftest-indent multiline-decl-first-arg-function-indent-dynamic-comment
+ "var foo = function() {
+ | return 7;
+ | }/* MUAHAHAHA, ah ha! */,
+ | bar = 8;"
+ :bind ((js2-pretty-multiline-declarations 'dynamic)))
+
+(js2-deftest-indent multiline-decl-first-arg-function-indent-dynamic-scan-error
+ "var foo = function() {
+ | return 7;
+ | ,
+ | bar = 8;"
+ :bind ((js2-pretty-multiline-declarations 'dynamic)))
- [elpa] master 7bf479a 08/22: Fix js2-paren-node length, (continued)
- [elpa] master 7bf479a 08/22: Fix js2-paren-node length, Dmitry Gutov, 2015/04/23
- [elpa] master 4d8ec67 07/22: Rely on bogus scopes less, Dmitry Gutov, 2015/04/23
- [elpa] master 4a1b4e8 09/22: Parse without error first method in a class with keyword name, Dmitry Gutov, 2015/04/23
- [elpa] master 90a9056 10/22: ...or any following one, Dmitry Gutov, 2015/04/23
- [elpa] master bc61ce0 11/22: Fix off-by-one error for comment node length, Dmitry Gutov, 2015/04/23
- [elpa] master 3b76567 12/22: Fix js2-node-get-enclosing-scope, Dmitry Gutov, 2015/04/23
- [elpa] master 458d3fe 14/22: Merge pull request #221 from jacksonrayhamilton/enclosing-scope, Dmitry Gutov, 2015/04/23
- [elpa] master a184642 13/22: Merge pull request #220 from jacksonrayhamilton/comment-length, Dmitry Gutov, 2015/04/23
- [elpa] master 2bb4db0 15/22: Assign quote syntax to backquotes, Dmitry Gutov, 2015/04/23
- [elpa] master 4de6f03 16/22: Don't indent in multiline strings, Dmitry Gutov, 2015/04/23
- [elpa] master ee4a202 18/22: Merge pull request #195 from jacksonrayhamilton/pretty-multiline-declarations,
Dmitry Gutov <=
- [elpa] master d4d9c54 17/22: js2-pretty-multiline-declarations: Add 'dynamic option, Dmitry Gutov, 2015/04/23
- [elpa] master 9790b97 19/22: * js2-mode.el (js2-mode): Use cursor-sensor-mode if available., Dmitry Gutov, 2015/04/23
- [elpa] master ac93b9e 21/22: Address two FIXMEs; fix a regression flagged by tests, Dmitry Gutov, 2015/04/23
- [elpa] master 022ef95 20/22: Merge commit '9790b9781aa8ca1d4bdf94d06d4e8ff2e68d37e8' into js2-mode-master, Dmitry Gutov, 2015/04/23
- [elpa] master 54df259 22/22: Merge commit 'ac93b9eef9b6ac44d187b9688d68a7a5f205b3fe' from js2-mode, Dmitry Gutov, 2015/04/23