godot icon indicating copy to clipboard operation
godot copied to clipboard

.gd files changed unexpectedly on running a project

Open velteyn opened this issue 3 years ago • 5 comments

Godot version

3.4.2

System information

Windows 10 GLES3

Issue description

I'm learning Godot and I downloaded an example project from GitHub https://github.com/CadanoX/Godot-Slot-Machine

After I run it it gives me the error: "mixed tabs and spacing in indentation." And it does not start. I see that the original files from GitHub are indented using spaces only. When I RUN the project it seems that Godot adds some tabs under the ifs autonomously. I think that a program don't have the rights to change files autonomously but only to give errors if the file is not correct..

Steps to reproduce

1)Download the Github project as a zip https://github.com/CadanoX/Godot-Slot-Machine 2)Open SlotMachine.gd with notepad++ and enable "display Spaces and tabulations" As you can see the file is paced indented only, leave it opened 3) Import the project in godot 4) Run it 5) Project don't start but gives "Mixed tabs and spacing in indentation" error 6) Notepad++ states that the files have been modified and ask to reload it 7) Reload the file and you can see that Godot modified the file..

According to me Godot should only tell the User that something is wrong but should not touch the files on loading. I tried fixing the files but Godot keeps changing them. It only likes tabs indentation and in that case it leaves them untouched..

Minimal reproduction project

https://github.com/CadanoX/Godot-Slot-Machine

velteyn avatar Jan 05 '22 10:01 velteyn

This happens because Godot's default Editor Settings are:

  • text_editor/indent/convert_indent_on_save: enabled
  • text_editor/indent/type: Tabs
  • text_editor/indent/size: 4

So it automatically converts 4 spaces to one tab.

You can solve it by disabling convert_indent_on_save, or by changing the indent type to 2 Spaces to match that project's convention.

akien-mga avatar Jan 05 '22 10:01 akien-mga

@Paulb23 Do you think we could make Convert Indent on Save cleverer in such cases to avoid breakage?

Or should we disable it by default (and maybe add a "Strip Trailing Whitespace" instead that could be enabled by default).

Also related: https://github.com/godotengine/godot-proposals/issues/3525, which would make Convert Indent on Save mostly irrelevant (never got to finish my implementation)

akien-mga avatar Jan 05 '22 10:01 akien-mga

Or should we disable it by default (and maybe add a "Strip Trailing Whitespace" instead that could be enabled by default).

This option already exists, but it's disabled by default. Enabling it by default makes sense, but it can reduce productivity due to it always trimming whitespace on the line the cursor is currently on. See also https://github.com/godotengine/godot-proposals/issues/3229.

Calinou avatar Jan 05 '22 16:01 Calinou

Just got bitten by this after upgrading to 3.5 from 3.4.5... I'm at a loss here: shouldn't it convert ALL spaces to tabs, or ALL tabs to spaces? Why some tabs (default) are apparently randomly added/replaced but only on some lines, if the setting is called convert_indent_on_save?

RobertoMaurizzi avatar Aug 07 '22 07:08 RobertoMaurizzi