Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect current indentation style before converting indentation in the script editor #6250

Open
HolonProduction opened this issue Feb 7, 2023 · 4 comments

Comments

@HolonProduction
Copy link
Member

Describe the project you are working on

A python tool that analyzes GDScript and uses a yaml file for configuration.

Describe the problem or limitation you are having in your project

The configuration file beeing a yaml file means it cannot be changed from the godot editor. This is the case because yaml will not accept tabs as indentation. When saving the file godot will convert the space based indents into tabs (with the default editor settings). When disabeling the Convert Indent on Save option the yaml file can be saved, but this functionality can be usefull when copying GDScript code.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

The Convert Indent on Save option should only effect GDScript files. When editing a text file the conversion should not happen. I consider it out of scope for the Godot code editor to provide the best edditing experience for files other than GDScript therefore implementing file type based settings is too complex.

To improve editing of text files further it would also be good to make the Auto Indent option use some heuristic to determine the indent type of the current file instead of using the Indent option. This would allow for broad use of the auto indent function.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Possible heuristic for determineing the indent type:

  • go through all lines of the files
  • if the line has trailing whitespace (tabs or spaces):
    • if the line starts with a tab:
      • use tab indentation (prioritizing tabs makes sure that it will never fail when editing gdscript with recommended settings)
      • return
    • count the amount of trailing spaces
      • save the amount into A if it is samller then the current value
  • if the file had no lines with trailing white space:
    • use tab indentation (prioritizing tabs makes sure that it will never fail when editing gdscript with recommended settings)
    • return
  • use space indentation with the size stored in the A

If this enhancement will not be used often, can it be worked around with a few lines of script?

I don't think so.

Is there a reason why this should be core and not an add-on in the asset library?

There is no way for an addon to implement this. (As far as i know.)

@HolonProduction
Copy link
Member Author

I would give the implementation a try but I think there should be some sort of consent on this before I invest the time.

@Calinou Calinou changed the title Improve indent handling for non GDScript files. Detect current indentation style before converting indentation in the script editor Feb 7, 2023
@AngelOnFira
Copy link

I want to add a +1 for this, Godot formatting (some) of a yaml file with tabs instead of spaces can make it quite difficult to track down why a config suddenly isn't working 👍

@tlaine

This comment was marked as off-topic.

@Calinou
Copy link
Member

Calinou commented Mar 4, 2024

@tlaine Please don't bump issues without contributing significant new information. Use the 👍 reaction button on the first post instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants