all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#60832: [PATCH] sh-script.el: Use sh-indent-for-continuation to indent line continuations.
@ 2023-01-15 11:55 Philippe Altherr
       [not found] ` <handler.60832.B.16737920185787.ack@debbugs.gnu.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Philippe Altherr @ 2023-01-15 11:55 UTC (permalink / raw)
  To: 60832


[-- Attachment #1.1: Type: text/plain, Size: 2779 bytes --]

The variable sh-indent-for-continuation
<https://github.com/emacs-mirror/emacs/blob/77ca6aa56e3425c87861cab8abce52bee3697cf4/lisp/progmodes/sh-script.el#L1300>
is defined in sh-script.el as "How much to indent for a continuation
statement." but it is never used. In particular, the function
sh-smie--indent-continuation
<https://github.com/emacs-mirror/emacs/blob/77ca6aa56e3425c87861cab8abce52bee3697cf4/lisp/progmodes/sh-script.el#L2000>,
which indents line continuations, doesn't use it and instead uses
sh-basic-offset. The attached patch modifies
sh-smie--indent-continuation to use sh-indent-for-continuation instead of
sh-basic-offset.

I have tested the patch by adding the patched function
sh-smie--indent-continuation to my .emacs (in a (with-eval-after-load
'sh-script ...) statement).

Here are details of what changes on the example used in the description of
sh-indent-after-continuation
<https://github.com/emacs-mirror/emacs/blob/77ca6aa56e3425c87861cab8abce52bee3697cf4/lisp/progmodes/sh-script.el#L1965>.
In all cases I have used the following settings:

(setq sh-basic-offset 4)
(setq sh-indent-for-continuation '++)


   - With (setq sh-indent-after-continuation 'always), I get the following
   result with the unpatched function:

   for f \
       in a; do \
       toto; \
       done

   This looks wrong to me because it doesn't take into account my setting
   (setq sh-indent-for-continuation '++) for line continuations. With the
   patched function I get the expected result:

   for f \
           in a; do \
           toto; \
           done

   - With (setq sh-indent-after-continuation nil), I get the following
   result with the unpatched and the patched function:

   for f \
   in a; do \
       toto; \
   done

   This looks correct to me. My understanding is that with (setq
   sh-indent-after-continuation nil), line continuations are kind of ignored
   and thus the setting (setq sh-indent-for-continuation '++) should never
   intervene, which is also the case.

   - With (setq sh-indent-after-continuation t), I get the following result
   with the unpatched function:

   for f \
       in a; do \
       toto; \
       done

   With the patched function, I get the following result:

   for f \
           in a; do \
       toto; \
       done

   I think that's also what's expected with (setq
   sh-indent-for-continuation '++) but I'm not entirely sure as I don't fully
   understand how (setq sh-indent-after-continuation t) is supposed to work.

Overall, I'm pretty confident that the first change in my patch should be
done. It's what affects the setting (setq sh-indent-after-continuation
'always). I'm a bit less confident about the second change, which affects
the setting (setq sh-indent-after-continuation t).

Philippe

[-- Attachment #1.2: Type: text/html, Size: 3153 bytes --]

[-- Attachment #2: 0001-For-line-continuations-use-sh-indent-for-continuatio.patch --]
[-- Type: application/x-patch, Size: 1538 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#60832: Acknowledgement ([PATCH] sh-script.el: Use sh-indent-for-continuation to indent line continuations.)
       [not found] ` <handler.60832.B.16737920185787.ack@debbugs.gnu.org>
@ 2023-01-23  4:18   ` Philippe Altherr
  2023-02-17 15:21     ` Philippe Altherr
  0 siblings, 1 reply; 4+ messages in thread
From: Philippe Altherr @ 2023-01-23  4:18 UTC (permalink / raw)
  To: 60832


[-- Attachment #1.1: Type: text/plain, Size: 991 bytes --]

Here is an updated patch that includes a test case. I was able to test it
in my *scratch* buffer. Please double-check that it works as intended.


On Sun, Jan 15, 2023 at 3:14 PM GNU bug Tracking System <
help-debbugs@gnu.org> wrote:

> Thank you for filing a new bug report with debbugs.gnu.org.
>
> This is an automatically generated reply to let you know your message
> has been received.
>
> Your message is being forwarded to the package maintainers and other
> interested parties for their attention; they will reply in due course.
>
> Your message has been sent to the package maintainer(s):
>  bug-gnu-emacs@gnu.org
>
> If you wish to submit further information on this problem, please
> send it to 60832@debbugs.gnu.org.
>
> Please do not send mail to help-debbugs@gnu.org unless you wish
> to report a problem with the Bug-tracking system.
>
> --
> 60832: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=60832
> GNU Bug Tracking System
> Contact help-debbugs@gnu.org with problems
>

[-- Attachment #1.2: Type: text/html, Size: 1756 bytes --]

[-- Attachment #2: 0001-For-line-continuations-use-sh-indent-for-continuatio.patch --]
[-- Type: application/octet-stream, Size: 2842 bytes --]

From 2cea437f1f35772e660031d1bcc0ed7ec25b8803 Mon Sep 17 00:00:00 2001
From: Philippe Altherr <philippe.altherr@gmail.com>
Date: Sat, 14 Jan 2023 05:22:26 +0100
Subject: [PATCH] For line continuations, use sh-indent-for-continuation
 instead of sh-basic-offset.

---
 lisp/progmodes/sh-script.el            |  7 +++++--
 test/lisp/progmodes/sh-script-tests.el | 18 ++++++++++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index 17c22ff475..741803a517 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -2010,7 +2010,7 @@ sh-smie--indent-continuation
       (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 @@ sh-smie--indent-continuation
                        ;; 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 c850a5d8af..52c1303c41 100644
--- a/test/lisp/progmodes/sh-script-tests.el
+++ b/test/lisp/progmodes/sh-script-tests.el
@@ -52,6 +52,24 @@ test-basic-sh-indentation
 (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)
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#60832: Acknowledgement ([PATCH] sh-script.el: Use sh-indent-for-continuation to indent line continuations.)
  2023-01-23  4:18   ` bug#60832: Acknowledgement ([PATCH] sh-script.el: Use sh-indent-for-continuation to indent line continuations.) Philippe Altherr
@ 2023-02-17 15:21     ` Philippe Altherr
  2023-03-02 10:42       ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Philippe Altherr @ 2023-02-17 15:21 UTC (permalink / raw)
  To: 60832


[-- Attachment #1.1: Type: text/plain, Size: 1174 bytes --]

Here is an updated patch against the current master branch.


On Mon, Jan 23, 2023 at 5:18 AM Philippe Altherr <philippe.altherr@gmail.com>
wrote:

> Here is an updated patch that includes a test case. I was able to test it
> in my *scratch* buffer. Please double-check that it works as intended.
>
>
> On Sun, Jan 15, 2023 at 3:14 PM GNU bug Tracking System <
> help-debbugs@gnu.org> wrote:
>
>> Thank you for filing a new bug report with debbugs.gnu.org.
>>
>> This is an automatically generated reply to let you know your message
>> has been received.
>>
>> Your message is being forwarded to the package maintainers and other
>> interested parties for their attention; they will reply in due course.
>>
>> Your message has been sent to the package maintainer(s):
>>  bug-gnu-emacs@gnu.org
>>
>> If you wish to submit further information on this problem, please
>> send it to 60832@debbugs.gnu.org.
>>
>> Please do not send mail to help-debbugs@gnu.org unless you wish
>> to report a problem with the Bug-tracking system.
>>
>> --
>> 60832: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=60832
>> GNU Bug Tracking System
>> Contact help-debbugs@gnu.org with problems
>>
>

[-- Attachment #1.2: Type: text/html, Size: 2225 bytes --]

[-- Attachment #2: 0001-For-line-continuations-use-sh-indent-for-continuatio.patch --]
[-- Type: application/octet-stream, Size: 2846 bytes --]

From 36bce0c7a03bd96687cfb885cfe2fb431d2824ff Mon Sep 17 00:00:00 2001
From: Philippe Altherr <philippe.altherr@gmail.com>
Date: Sat, 14 Jan 2023 05:22:26 +0100
Subject: [PATCH] For line continuations, use sh-indent-for-continuation
 instead of sh-basic-offset.

---
 lisp/progmodes/sh-script.el            |  7 +++++--
 test/lisp/progmodes/sh-script-tests.el | 18 ++++++++++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

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 @@ sh-smie--indent-continuation
       (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 @@ sh-smie--indent-continuation
                        ;; 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 @@ test-basic-sh-indentation
 (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)
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#60832: Acknowledgement ([PATCH] sh-script.el: Use sh-indent-for-continuation to indent line continuations.)
  2023-02-17 15:21     ` Philippe Altherr
@ 2023-03-02 10:42       ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2023-03-02 10:42 UTC (permalink / raw)
  To: Philippe Altherr; +Cc: 60832-done

> From: Philippe Altherr <philippe.altherr@gmail.com>
> Date: Fri, 17 Feb 2023 16:21:36 +0100
> 
> Here is an updated patch against the current master branch.

Thanks, installed on master.

Please in the future accompany the changes with a ChangeLog-style
commit log messages (see CONTRIBUTE for details).  Also, the summary
in the Subject line cannot be longer than 78 characters (again
mentioned in CONTRIBUTE), otherwise our Git commit hooks reject the
patch, and I need to apply it by hand.





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-03-02 10:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-15 11:55 bug#60832: [PATCH] sh-script.el: Use sh-indent-for-continuation to indent line continuations Philippe Altherr
     [not found] ` <handler.60832.B.16737920185787.ack@debbugs.gnu.org>
2023-01-23  4:18   ` bug#60832: Acknowledgement ([PATCH] sh-script.el: Use sh-indent-for-continuation to indent line continuations.) Philippe Altherr
2023-02-17 15:21     ` Philippe Altherr
2023-03-02 10:42       ` Eli Zaretskii

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.