unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Philippe Altherr <philippe.altherr@gmail.com>
To: 60832@debbugs.gnu.org
Subject: bug#60832: [PATCH] sh-script.el: Use sh-indent-for-continuation to indent line continuations.
Date: Sun, 15 Jan 2023 12:55:43 +0100	[thread overview]
Message-ID: <CAGdYchs=BFmJ0a-ypxt_u9N0pUPco+KDsPWv34JH=qKamE91ag@mail.gmail.com> (raw)


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

             reply	other threads:[~2023-01-15 11:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-15 11:55 Philippe Altherr [this message]
     [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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAGdYchs=BFmJ0a-ypxt_u9N0pUPco+KDsPWv34JH=qKamE91ag@mail.gmail.com' \
    --to=philippe.altherr@gmail.com \
    --cc=60832@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).