emacs-gdscript-mode icon indicating copy to clipboard operation
emacs-gdscript-mode copied to clipboard

Add code snippets

Open NathanLovato opened this issue 5 years ago • 10 comments

Add code snippets or skeletons for GDScript.

I use yasnippet, that's really powerful, but should snippets for this package be included here? Split to another package?

Should I use the emacs skeletons? Abbreviations? Both? As these features are included in Emacs itself.

Feedback is welcome!

NathanLovato avatar Jan 15 '20 14:01 NathanLovato

The reason I like to use yas is that you can use code and conditions in the snippets. This way, if the user wants to code with type hints, the snippets could have optional type hints.

Also, you can easily have things like creating a setter and/or a getter function along with a variable.

NathanLovato avatar Jan 15 '20 14:01 NathanLovato

Some snippet ideas:

  • variables: simple, constant, onready, exported
  • var with setter
  • var with getter
  • var with setter and getter
  • void function
  • static function
  • yield on an on-the-fly timer: yield(get_tree().create_timer(1.0), "timeout")
  • function call with yield, waiting for function to complete: yield(some_func(), "completed")

NathanLovato avatar Jul 01 '20 14:07 NathanLovato

and also estructures like an if, if-else, if-elif-else, while, for etc... That would be great!

PinyaColada avatar Oct 13 '20 23:10 PinyaColada

@PinyaColada An if or a while statement only has minimal boilerplate (a keyword and a punctuation sign). Is a snippet really useful at this point?

Calinou avatar Oct 14 '20 13:10 Calinou

The simpler statements aren't too useful, yes. Maybe they can be there for the sake of providing a consistent experience. The if template is a little too basic but as you can autocomplete all snippets as you type with yas, if you know you have all basic keywords supported, you can type quite a bit of code using the same keyboard shortcuts.

Although I don't know how you'd make if/else and if/elif/else work efficiently as one snippet. I'd rather have one for each, so you insert if, elif, or else lines as needed.

NathanLovato avatar Oct 28 '20 13:10 NathanLovato

The simpler statements aren't too useful, yes. Maybe they can be there for the sake of providing a consistent experience. The if template is a little too basic but as you can autocomplete all snippets as you type with yas, if you know you have all basic keywords supported, you can type quite a bit of code using the same keyboard shortcuts.

Although I don't know how you'd make if/else and if/elif/else work efficiently as one snippet. I'd rather have one for each, so you insert if, elif, or else lines as needed.

NathanLovato avatar Oct 28 '20 13:10 NathanLovato

Also I'd prefer yasnippet after spending some time with it, because it supports much more stuff than alternatives. For instance, we can optionally include type hints in snippets.

NathanLovato avatar Oct 28 '20 13:10 NathanLovato

I thought maybe use the yasnippet-snippets package and submit spnippet in gdscript-mode.

xiliuya avatar Apr 24 '23 10:04 xiliuya

That'd probably be the way to go! Feel free to close this.

NathanLovato avatar Apr 24 '23 15:04 NathanLovato

Currently, the requirements listed above are not fully supported, so they will not be closed . :heart:

xiliuya avatar Apr 24 '23 16:04 xiliuya