Subject: Re: bug#24848: [sh-script] How to save "Local rules set" result from sh-learn-buffer-indent?

From: <[email-masked]>
Date: Thu, 24 Aug 2017 13:44:17 +0000

Hi Noam,

Thanks for such a quick response!

I've had a try with the commands in the comment.  Here's what I did:

1. Load a correctly-formatted bash script.

2. Move to a line that I know will be problematic -- it always wants to indent 4 characters after a "then" -- and press tab.  Sure enough, the indentation changes to how I don't like.

3. Undo that to restore the correctly-formatted bash script.

4. Run sh-learn-buffer-indent.

5. Press tab on that problematic line; this time, correctly, the indentation doesn't change.

6. Run sh-name-style and call it "bash".

7. Run sh-save-styles-to-buffer and let it use *scratch*.

8. Copy the output in *scratch* into my .emacs file.

9. Quit emacs.

10. Start emacs.

11. Load the same bash script.

12. Load the style, "bash".

13. Press tab on that problematic line.  It still indents incorrectly, so although sh-save-styles-to-buffer saved styles (see below), it evidently didn't include the modification. :-(

Sadly, even the following doesn't work:

1. Load a correctly-formatted bash script.

2. Move to a line that I know will be problematic -- it always wants to indent 4 characters after a "then" -- and press tab.  Sure enough, the indentation changes to how I don't like.

3. Undo that to restore the correctly-formatted bash script.

4. Run sh-learn-buffer-indent.

5. Press tab on that problematic line; this time, correctly, the indentation doesn't change.

6. Run sh-name-style and call it "bash".

7. Load a different bash script without quitting emacs first.

8. Run sh-load-style and press tab so it auto-completes to "bash".

9. Press tab on a problematic line -- indentation is still incorrect.

So the above seem to demonstrate that sh-name-buffer and sh-save-styles-to-buffer don't save all indentation information.

Here's what sh-save-styles-to-buffer puts in my *scratch* buffer:

(setq sh-styles-alist
      '(("bash"
         (sh-basic-offset . 2)
         (sh-first-lines-indent . 0)
         (sh-indent-after-case . +)
         (sh-indent-after-do . +)
         (sh-indent-after-done . 0)
         (sh-indent-after-else . +)
         (sh-indent-after-if . +)
         (sh-indent-after-loop-construct . +)
         (sh-indent-after-open . +)
         (sh-indent-comment . t)
         (sh-indent-for-case-alt . ++)
         (sh-indent-for-case-label . +)
         (sh-indent-for-continuation . +)
         (sh-indent-for-do . 0)
         (sh-indent-for-done . 0)
         (sh-indent-for-else . 0)
         (sh-indent-for-fi . 0)
         (sh-indent-for-then . 0))))

Please let me know if you'd like any further information.

Thanks again for the message,

Richard

PS - I guess (add-hook 'sh-set-shell-hook 'sh-learn-buffer-indent) will help me if my file is already properly formatted, but I would like to know how to save ALL the indent rules established by sh-learn-buffer-indent if at all possible!