Is it possible in a yasnippet snippet to create an arbitrary number of fields following a template, stopping only once the user indicates they are done entering fields?


One use case is to generate a Dart data class with an arbitrary number of member variables:

class MyDataClass {
  final Type1 field1;
  final Type2 field2;
  final Type3 field3;

    required this.field1,
    required this.field2,
    required this.field3,

Ideally this would work by yasnippet continuing to prompt for additional fields until I hit a key to stop the field entry loop.

Is this possible in yasnippet?


The closest question I could find is generating a template from strings, but this is more or less custom elisp that happens to piggyback on yasnippet, rather than using facilities of yasnippet itself. Creating custom elisp for every snippet with aribitrary numbers of fields (something I would use often in many languages and contexts) seems to largely defeat the purpose of yasnippet, which is to make creating snippets almost as easy as writing code.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.