Subject: Re: bug#44592: In sh-script-mode, should the syntax of . and / be made symbol?

From: Kévin Le Gouguec <[email-masked]>
Date: Sat, 28 Aug 2021 11:44:59 +0200

Lars Ingebrigtsen <[email-masked]> writes:

> I've now applied Dario's change to Emacs 28 (and added a test case).

I wonder, would it make sense to also add ){ and (} to handle cases with
${braces}?  E.g. I'd like this indentation:

${path_to_root}/configure --prefix=$prefix\
                          --with-x

but right now (55e77a811) I am getting this:

${path_to_root}/configure --prefix=$prefix\
               --with-x

I'm don't know all that much about syntax classes and SMIE; still,
here's a "monkey see; monkey do" patch that works for me:

diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index 201d1fd164..2d095c2a13 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -1775,7 +1775,7 @@ sh-smie--default-backward-token
                      (goto-char p)
                      nil))))
         (while
-            (progn (skip-syntax-backward ".w_'")
+            (progn (skip-syntax-backward ".w_'){(}")
                    (or (not (zerop (skip-syntax-backward "\\")))
                        (when (eq ?\\ (char-before (1- (point))))
                          (let ((p (point)))
diff --git a/test/lisp/progmodes/sh-script-tests.el b/test/lisp/progmodes/sh-script-tests.el
index 5bdce6260a..82c2d5168c 100644
--- a/test/lisp/progmodes/sh-script-tests.el
+++ b/test/lisp/progmodes/sh-script-tests.el
@@ -35,6 +35,17 @@ test-sh-script-indentation
     (should (equal
              (buffer-substring-no-properties (point-min) (point-max))
              "relative-path/to/configure --prefix=$prefix\\
-			   --with-x"))))
+			   --with-x")))
+  (with-temp-buffer
+    (insert "${path_to_root}/configure --prefix=$prefix\\
+             --with-x")
+    (shell-script-mode)
+    (goto-char (point-min))
+    (forward-line 1)
+    (indent-for-tab-command)
+    (should (equal
+             (buffer-substring-no-properties (point-min) (point-max))
+             "${path_to_root}/configure --prefix=$prefix\\
+			  --with-x"))))
 
 ;;; sh-script-tests.el ends here