Skip to content

Adding an End keyword at the end of a function/loop/if. #12494

Open
@cyb3rkun

Description

@cyb3rkun

Describe the project you are working on

In this case this doesn't really matter as it's not a feature that would be tied to a specific project.

it's more just syntactic sugar that would make auto indentation easier (especially for external editors like vsCode, Neovim etc.)

first suggested here

and like I mention in that discussion I don't think that it should be enforced but an optional keyword for those who want better auto indentation and who just like having that type of syntax.

while at the same time those who don't want to use it would have no need to do so and should still be able to write gdscript the way they've always been.

Describe the problem or limitation you are having in your project

without an end keyword or some type of symbol denoting the end of a function, if/ loop or any other kind of block it makes auto indentation very difficult to do.

it's not a big issue but I'm very used to languages like c where that's never an issue and an editor can very easily auto indent code because the start and end of any block is clearly denoted with brackets.

I'm a neovim user and when I press enter at the end of a function then I have to first erase the tabs at the beginning of a line since it would continue at the previous indentation level.

so for instance if I had the following:

func foo():
      if this:
            dosomething()
      else:
            dosomethingelse() |< # imagine cursor here at end of line

and I then press enter:

func foo():
      if this:
            dosomething()
      else:
            dosomethingelse() 
            |< #  cursor now here

when in actuallity I intended for it to be at the first level of indentation to start writing another function.

this becomes a very tedious thing to deal with and while one could use and
at the end of a function/if, it's not really intended for that purpose and their indentation level won't match the function definition's indentation level:

func foo():
      if this:
            dosomething()
            pass
      else:
            dosomethingelse() 
            return
      pass
|< #  cursor now here after entering

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

simply add an optional end keyword to denote the end of a block:

func foo():
      if foo:
            print("this is foo!")
      else
            print("where is foo?")
      end
end

and since the end would literally be syntactic sugar with no real meaning you could even do this:

func foo():
      if foo:
            print("this is foo!")
      end
      else
            print("where is foo?")
      end
end

and it would be the exact same thing. (although I probably wouldn't use it like that.)

and like I said I don't think this should be an enforced syntax, just like using pass is mostly optional (unless you have empty functions?)

some people might use this as they prefer that type of syntax, others might use it for better auto indentation.

and others might decide not to use it at all.
it should be up to them.

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

I have no Idea how writing a scripting language works so unfortunately I can't provide any psuedo code for it's implementation.

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

Definitely not.
I don't believe one can make changes to gdscript inside of gdscript.

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

because it would add a core feature to the gdscript syntax. it can't be implemented as an addon. (at least not to my knowledge)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions