]> git.eshelyaron.com Git - emacs.git/commitdiff
Use 'sh-indent-for-continuation' for continued lines in 'sh-script-mode'
authorPhilippe Altherr <philippe.altherr@gmail.com>
Sat, 14 Jan 2023 04:22:26 +0000 (05:22 +0100)
committerEli Zaretskii <eliz@gnu.org>
Thu, 2 Mar 2023 10:37:58 +0000 (12:37 +0200)
* lisp/progmodes/sh-script.el (sh-smie--indent-continuation): Use
'sh-indent-for-continuation' instead of 'sh-basic-offset'.
(Bug#60832)

* test/lisp/progmodes/sh-script-tests.el
(test-indent-after-continuation): New test.

lisp/progmodes/sh-script.el
test/lisp/progmodes/sh-script-tests.el

index 17c22ff475157c461d0a5a69227a8d17419a5487..741803a5175828dd83bb13975d3212918def0887 100644 (file)
@@ -2010,7 +2010,7 @@ May return nil if the line should not be treated as continued."
       (forward-line -1)
       (if (sh-smie--looking-back-at-continuation-p)
           (current-indentation)
-        (+ (current-indentation) sh-basic-offset))))
+        (+ (current-indentation) (sh-var-value 'sh-indent-for-continuation)))))
    (t
     ;; Just make sure a line-continuation is indented deeper.
     (save-excursion
@@ -2031,7 +2031,10 @@ May return nil if the line should not be treated as continued."
                        ;; check the line before that one.
                        (> ci indent))
                       (t ;Previous line is the beginning of the continued line.
-                       (setq indent (min (+ ci sh-basic-offset) max))
+                       (setq
+                        indent
+                        (min
+                         (+ ci (sh-var-value 'sh-indent-for-continuation)) max))
                        nil)))))
           indent))))))
 
index c850a5d8af74a1d08efce76afc2a3344f084aa68..52c1303c41411736f234d80f0bd21b77f42c7821 100644 (file)
 (ert-deftest test-indentation ()
   (ert-test-erts-file (ert-resource-file "sh-indents.erts")))
 
+(ert-deftest test-indent-after-continuation ()
+  (with-temp-buffer
+    (insert "for f \\\nin a; do \\\ntoto; \\\ndone\n")
+    (shell-script-mode)
+    (let ((sh-indent-for-continuation '++))
+      (let ((sh-indent-after-continuation t))
+        (indent-region (point-min) (point-max))
+        (should (equal (buffer-string)
+                       "for f \\\n\tin a; do \\\n    toto; \\\n    done\n")))
+      (let ((sh-indent-after-continuation 'always))
+        (indent-region (point-min) (point-max))
+        (should (equal (buffer-string)
+                       "for f \\\n\tin a; do \\\n\ttoto; \\\n\tdone\n")))
+      (let ((sh-indent-after-continuation nil))
+        (indent-region (point-min) (point-max))
+        (should (equal (buffer-string)
+                       "for f \\\nin a; do \\\n    toto; \\\ndone\n"))))))
+
 (defun test-sh-back (string &optional pos)
   (with-temp-buffer
     (shell-script-mode)