Atom-beautify: beautifying should follow Atom's indentation preferences

Created on 15 Jun 2015  路  22Comments  路  Source: Glavin001/atom-beautify

Despite having set the indent tab length to 4 in the preferences, atom-beautify will "beautify" the indentation only to 2 spaces.

published question

Most helpful comment

Good question!

From https://github.com/Glavin001/atom-beautify/issues/341#issuecomment-104231483:

Like CSS, Atom Beautify's options are prioritized by specificity: the options set closer to the file itself, or for that specific language, take precedence.

For instance, you could have Atom Beautify package settings setup for your personal configuration, however when working on a project with others your settings may be different. The .jsbeautifyrc file takes precedence over the package settings and Atom editor settings, etc. Furthermore, you could have multiple .jsbeautifyrc files, potentially in the same directory as your current file and all the way up to root directory. All of these would be applied, with priority going to the closest file to your currently beautified file.

Given that Atom's editor preferences are global, not language specific, and therefore lowest priority for Atom Beautify, this makes sense why you are experiencing this. You should create either .editorconfig or .jsbeautifyrc file in your project's directory, or edit Atom Beautify's package settings on a per-language basis for personal / user specific settings. See https://github.com/Glavin001/atom-beautify#configuration for more details. List of available options here: https://github.com/Glavin001/atom-beautify/blob/master/docs/options.md

All 22 comments

Good question!

From https://github.com/Glavin001/atom-beautify/issues/341#issuecomment-104231483:

Like CSS, Atom Beautify's options are prioritized by specificity: the options set closer to the file itself, or for that specific language, take precedence.

For instance, you could have Atom Beautify package settings setup for your personal configuration, however when working on a project with others your settings may be different. The .jsbeautifyrc file takes precedence over the package settings and Atom editor settings, etc. Furthermore, you could have multiple .jsbeautifyrc files, potentially in the same directory as your current file and all the way up to root directory. All of these would be applied, with priority going to the closest file to your currently beautified file.

Given that Atom's editor preferences are global, not language specific, and therefore lowest priority for Atom Beautify, this makes sense why you are experiencing this. You should create either .editorconfig or .jsbeautifyrc file in your project's directory, or edit Atom Beautify's package settings on a per-language basis for personal / user specific settings. See https://github.com/Glavin001/atom-beautify#configuration for more details. List of available options here: https://github.com/Glavin001/atom-beautify/blob/master/docs/options.md

I am experiencing this same issue after setting per language basis personal / user specific settings in Beautify's package settings. No matter what I set, it beautifies with two spaces ... which is really difficult reading for heavily nested scss ... am I missing something?

Solved by turning off soft tab options in Atom main prefs~

This is the recent related issue: https://github.com/Glavin001/atom-beautify/issues/894
There has been a change in v0.29.x. See https://github.com/Glavin001/atom-beautify/issues/894#issuecomment-205889555
For someone interested in fixing the current behaviour see https://github.com/Glavin001/atom-beautify/issues/894#issuecomment-209458518
Thanks.

@Glavin001 thanks. Maybe because of the mixing of one configuration with another. I think the configuration panel should be designed more friendly if possible. One tab for one language only.

@calidion please feel free to create an issue outlining what you recommend the configuration should look like. With v0.29.x there were a lot of configuration UI improvements, however there is always room for improvement. I am open to Pull Requests as well. If you don't like something, please work with us to change it and make it better 馃槃 .

@Glavin001 Thanks. I will when I am ready:)

What is the easiest way to globally set my indent character to tab and 1 indent size?

happening with me as well.

screen shot 2017-03-30 at 9 06 10 am

Why the the python files are being saved with 2 spaces instead of 4?

The easiest way to set universal settings is to modify the src/.jsbeautifyrc file.

I don't want to modify it universally, I want it only for python and I would like to understand why it doesn't work.

@prettydiff I've also opened an issue with more details here: https://github.com/Glavin001/atom-beautify/issues/1574

Ok my issue is exactly the opposite of what the question is, I have set everywhere as 2 but atom-beautify does 4 spaces. I have also checked .jsbeautifyrc , that also has 2 only. Does anybody have solution? This is frustrating.

@emailprashanthvg I ended up using python-ident instead, it's much faster and it works!

This has been an issue for a long time. Between two projects on the same machine I get different outcomes, and all settings are the same. There's definitely something wrong here. I'd provide my configs, etc., but they are the same on both projects so I can't imagine how it would help.

@DLiblik if you could provide both debug.md files we could investigate. It does not make sense they would perform differently if there is no difference in configuration, however often the issue is some configuration which you did not think of which causes unexpected behaviours. For example, if I recall correctly there have been a few users who had a .editorconfig file or similar in their user home directory and it was causing conflicts. Once we have your debugging info we can narrow it down.

For this main issue, I will be investigating ways to improve configuration of Atom-Beautify over the next couple weeks. Thank you for your interest and patience!

I do want to universally use tabs unless the language absolutely requires it, and would like to be able to do this programmatically via script. (See https://github.com/zamicol/dotfiles/blob/master/install.sh)

This is where I am with accomplishing it. (See https://gist.github.com/zamicol/c5c926500ddde49006122f9e4e52e48f)

In Edit -> Preferences -> "editor" tab

  1. Uncheck "Soft Tabs".
  2. Change "Tab Length" to 2.
  3. "Tab Type" to hard.

Put the following at $atom/config.cson

"atom-beautify":
  general:
      _default:
          indent_char: "\t"
          indent_size: 1
          indent_with_tabs: true
      indent_char: "\t"
      indent_size: 1
      indent_with_tabs: true
      css:
          indent_char: "\t"
          indent_size: 1
      html:
          indent_char: "\t"
          indent_size: 1
      js:
          indent_char: "\t"
          indent_size: 1
      json:
          indent_char: "\t"
          indent_size: 1
      xml:
          indent_char: "\t"
          indent_size: 1

Put this at $ATOMPATH/packages/atom-beautify/.jsbeautifyrc AND $ATOMPATH/packages/atom-beautify/src/.jsbeautifyrc.

{
  "indent_char": "    ", //Tab here. Make sure editor doesn't change it. 
  "indent_size": 1,
  "indent_with_tabs": true
}

@zamicol why do you need to edit $ATOMPATH/packages/atom-beautify/.jsbeautifyrc and $ATOMPATH/packages/atom-beautify/src/.jsbeautifyrc?

See https://github.com/Glavin001/atom-beautify#configuration for configuration details.

Configure options for all languages

An example .jsbeautifyrc file using _default key meaning "apply to all languages":

{
  "_default": {
    "indent_char": "\t",
    "indent_size": 1,
    "indent_with_tabs": true
  }
}

Then languages can be specifically configured on top of this on a per-project basis.

Configure options for all projects

Place the .jsbeautifyrc file in your user's home directory.

馃挜 Profit! 馃巻

Does that not work for you? If not, then please provide a link to a Gist with your debugging information. See https://github.com/Glavin001/atom-beautify/blob/master/docs/troubleshooting.md for details. Once we have your complete debugging information we can resolve the other issues in your way.

I've merged https://github.com/Glavin001/atom-beautify/pull/1598 which should resolve these issues.

Published to v0.29.21.

Thanks @Glavin001 !

solved my problem

@Glavin001 You are a fuckin master!!

I am doing a Angular App and I tried everything to indent my html files to 4 instead of 2 spaces.

The solution was to change .editorconfig file where it says "indentation" and then restart my atom editor.

Thanks!! By the way you have to work on your explaining.

Was this page helpful?
0 / 5 - 0 ratings