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

From: <[email-masked]>
Date: Fri, 25 Aug 2017 08:11:38 +0000

Hi Noam,

Thanks for the suggestions.

I don't know whether my Emacs uses smie for sh-mode but there's apparently no sh-use-smie variable set by default.

However, running smie-config-guess seems to have the same effect as sm-learn-buffer-indent so perhaps it does.  Unfortunately, I've still not managed to save the config.

Here's what I did:

1. I ran smie-config-guess on a correctly-indented bash script (see below) and confirmed that it now indents as I would expect when I hit tab on any line).

2. I then ran smie-save-config and it said it saved it to smie-config.

3. I ran customize-variable on smie-config and its value is now ((2 :elem basic 4)) which doesn't make any mention of indenting after "then" which is weird, because as I said, it does now indent correctly in this buffer.

4. I then clicked Apply and Save to add the setting to my ~/.emacs file.

5. I confirmed that it now appears in the (custom-set-variables ... ) section.

6. I restarted Emacs and loaded the bash script.

7. As feared, indentation is back to the way I don't like.

8. I then modified the smie-config entry in (custom-set-variables ... ) to correspond with your expression (that mentions "then").

9. I restarted Emacs and loaded the bash script.

10. Sadly, indentation is still unaffected.

The bash script I've used as a test here is:

#!/usr/bin/env bash

if [ "$1" ]
then
  echo "First argument is: $1"
else
  echo "No arguments"
fi

In case there's a problem with formatting by the time this email reaches you, only the two echo lines are indented, and each by two spaces.  Hitting tab on the first of these changes the indent to four spaces; on the second, indentation remains at two.

Regards,

Richard