[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 4de6f03 16/22: Don't indent in multiline strings
From: |
Dmitry Gutov |
Subject: |
[elpa] master 4de6f03 16/22: Don't indent in multiline strings |
Date: |
Fri, 24 Apr 2015 02:57:15 +0000 |
branch: master
commit 4de6f035be0fdf76034917e526d7ae8fd06bc76b
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>
Don't indent in multiline strings
Fixes #227
---
js2-mode.el | 34 ++++++++++++++++++----------------
tests/indent.el | 18 ++++++++++++++----
2 files changed, 32 insertions(+), 20 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index 35f24ba..c8f47e6 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -11114,22 +11114,24 @@ If so, we don't ever want to use bounce-indent."
offset (- (point) (save-excursion
(back-to-indentation)
(point))))
- (js2-with-underscore-as-word-syntax
- (if (nth 4 parse-status)
- (js2-lineup-comment parse-status)
- (setq indent-col (js2-proper-indentation parse-status))
- ;; See comments below about `js2-mode-last-indented-line'.
- (cond
- ;; bounce-indenting is disabled during electric-key indent.
- ;; It doesn't work well on first line of buffer.
- ((and js2-bounce-indent-p
- (not (js2-same-line (point-min)))
- (not (js2-1-line-comment-continuation-p)))
- (js2-bounce-indent indent-col parse-status bounce-backwards))
- ;; just indent to the guesser's likely spot
- (t (indent-line-to indent-col))))
- (when (cl-plusp offset)
- (forward-char offset)))))
+ ;; Don't touch multiline strings.
+ (unless (nth 3 parse-status)
+ (js2-with-underscore-as-word-syntax
+ (if (nth 4 parse-status)
+ (js2-lineup-comment parse-status)
+ (setq indent-col (js2-proper-indentation parse-status))
+ ;; See comments below about `js2-mode-last-indented-line'.
+ (cond
+ ;; bounce-indenting is disabled during electric-key indent.
+ ;; It doesn't work well on first line of buffer.
+ ((and js2-bounce-indent-p
+ (not (js2-same-line (point-min)))
+ (not (js2-1-line-comment-continuation-p)))
+ (js2-bounce-indent indent-col parse-status bounce-backwards))
+ ;; just indent to the guesser's likely spot
+ (t (indent-line-to indent-col))))
+ (when (cl-plusp offset)
+ (forward-char offset))))))
(defun js2-indent-region (start end)
"Indent the region, but don't use bounce indenting."
diff --git a/tests/indent.el b/tests/indent.el
index affbd58..b720984 100644
--- a/tests/indent.el
+++ b/tests/indent.el
@@ -23,22 +23,25 @@
(require 'js2-mode)
(require 'cl-lib)
-(defun js2-test-indent (content)
+(defun js2-test-indent (content keep-indent)
(let ((s (replace-regexp-in-string "^ *|" "" content)))
(with-temp-buffer
- (insert (replace-regexp-in-string "^ *" "" s))
+ (insert
+ (if keep-indent
+ s
+ (replace-regexp-in-string "^ *" "" s)))
(js2-mode)
(indent-region (point-min) (point-max))
(should (string= s (buffer-substring-no-properties
(point-min) (point)))))))
-(cl-defmacro js2-deftest-indent (name content &key bind)
+(cl-defmacro js2-deftest-indent (name content &key bind keep-indent)
`(ert-deftest ,(intern (format "js2-%s" name)) ()
(let ,(append '((js2-basic-offset 2)
(js2-pretty-multiline-declarations t)
(inhibit-point-motion-hooks t))
bind)
- (js2-test-indent ,content))))
+ (js2-test-indent ,content ,keep-indent))))
(put 'js2-deftest-indent 'lisp-indent-function 'defun)
@@ -102,3 +105,10 @@
| default: 'donkey',
| tee: 'ornery'
|};")
+
+(js2-deftest-indent multiline-string-noop
+ "`multiline string
+ | contents
+ | are kept
+ | unchanged!`"
+ :keep-indent t)
- [elpa] master bf454ef 05/22: Fix typos in comments and docstrings, (continued)
- [elpa] master bf454ef 05/22: Fix typos in comments and docstrings, Dmitry Gutov, 2015/04/23
- [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 <=
- [elpa] master ee4a202 18/22: Merge pull request #195 from jacksonrayhamilton/pretty-multiline-declarations, Dmitry Gutov, 2015/04/23
- [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