emacs-elpa-diffs
[Top][All Lists]
Advanced

[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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]