Sublime Forum

Bash indent to sensitive, and lacking

#1

This probbably should be a bug report, but since the issue have been aroud forever perhaps it could be concidered a feature.

Bash indenting is very sensitive to characters. For example a space behind “do” in while/for loops will throw it of.

Indenting whithout a space trailing “do”

When you have nested loops this is very ugly, and makes it hard to follow the code. I who now know about this oddity can probably live with it. But how many users will not take the time do search the cause of this behaviuor, and just silently suffer? Or go back to editors who handles this (emacs).

And while I’m at it, bash indenting for case is also faulty and have been since at least 2012. Why not give bash indenting some much needed love?

0 Likes

#2

you can get it to indent do with a trailing space by modifying the tmPreferences file:

just stick a [ ]* after the do)\b

0 Likes

#3

Thanks for the tip @kingkeith, but the idea here is to get this as a sane default. Not that every user should have to annoy themselvs over this issue. Search the forums, then perhaps find this tip, and implementing it. It should “just work” in my opinion.

0 Likes

#4

so submit a PR to that repo, and once it is merged, it will be the default in the next build of ST, and you will be the one that made it happen and improved the experience for others :slight_smile:

0 Likes

#5

Any chance you will do a real for-dummies on this one? I thought I had the idea, but whatever I do to the file, no behaviour is changed. I copied the content of the githib link and started altering line 13 to be more acceping (adding a \s after the \b). I put this file into /Users/eriktar/Library/Application Support/Sublime Text 3/Packages/User and named it Miscellaneous.tmPreferences. This file seems to be disregarded, no changes I do affect the behaviuor of indenting. I’m quiting and restarting sublime at every iteration to try and force reload of the .tmPreferences file.

I also tried to create the directory /Users/eriktar/Library/Application Support/Sublime Text 3/Packages/User/ShellScript and put the file there.

0 Likes

#6

you shouldn’t need to restart ST each time, though it can’t hurt - if ST detects the changes it should show generating meta info summary in it’s console.

For the do indentation, probably the best thing to do is make sure you override the existing tmPreferences file. The easiest way to do this is to:

  1. Install PackageResourceViewer if it isn’t already installed
  2. Open Command Palette
  3. Type PRV: O and select PackageResourceViewer: Open Resource
  4. Select ShellScript
  5. Select Miscellaneous.tmPreferences
  6. Make your changes
  7. Save it

You’ll find that this creates a file in Packages/ShellScript/ as opposed to Packages/User/ShellScript.

0 Likes

#7

Thanks! Now I’m getting the expected and wanted bahaviour.

So you don’t have to teach med GIT as well, this is the changed line:
<string>^\s*(if|elif|else|case)\b|^.*(\{|\b(do)\b\s?)$</string>
where \s? is the needed magic.

0 Likes