From: Philippe Altherr Date: Sat, 14 Jan 2023 04:22:26 +0000 (+0100) Subject: Use 'sh-indent-for-continuation' for continued lines in 'sh-script-mode' X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=30e2a85717c4189994c7ae759888e257225f0a21;p=emacs.git Use 'sh-indent-for-continuation' for continued lines in 'sh-script-mode' * 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. --- diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el index 17c22ff4751..741803a5175 100644 --- a/lisp/progmodes/sh-script.el +++ b/lisp/progmodes/sh-script.el @@ -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)))))) diff --git a/test/lisp/progmodes/sh-script-tests.el b/test/lisp/progmodes/sh-script-tests.el index c850a5d8af7..52c1303c414 100644 --- a/test/lisp/progmodes/sh-script-tests.el +++ b/test/lisp/progmodes/sh-script-tests.el @@ -52,6 +52,24 @@ (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)