jetbrains-plugin-st4 icon indicating copy to clipboard operation
jetbrains-plugin-st4 copied to clipboard

Auto-closing paired symbols

Open Clashsoft opened this issue 6 years ago • 13 comments

When typing new templates, it would be very useful if certain opening/closing constructs were autocompleted. This applies to:

  • the closing parenthesis after the argument list: foo( )
  • the template delimiters: << >>, <% %>, " "
  • placeholders < > (also for custom delimiters?)
  • ifs: <if( )> <endif>
  • anonymous templates: <foo:{ }>
  • ...?

Clashsoft avatar Dec 18 '19 10:12 Clashsoft

Current status:

  • [x] the closing parenthesis after the argument list: foo( )
  • [x] the template delimiters: << >>, <% %>, " "
  • [x] placeholders < >
  • [x] (also for custom delimiters?)
  • [ ] ifs: <if( )> <endif>
  • [x] quotes in attributes: <foo format=" ">
  • [x] anonymous templates: <foo:{ }>

bjansen avatar Sep 14 '20 12:09 bjansen

Keep up the great work, @bjansen !

parrt avatar Sep 14 '20 16:09 parrt

@bjansen

~~I just realized that format="" is not really special, the quotes are just template syntax. If "" and anonymous templates already work, then shouldn't this be covered too?~~

Remembering what I originally had in mind when I wrote the issue, it's about offering the option names format, wrap, separator, etc. as an autocomplete dropdown. The same case can be made for functions like strip, reverse, trim, ….

Re. <endif>, do you have an idea at what point of typing <if(...)> the <endif> should be inserted? Because I'm not sure what's most intuitive. After <if may be a little to early, in case they want to type <iframe> or whatever. Maybe after the parenthesis?

Clashsoft avatar Sep 14 '20 22:09 Clashsoft

Remembering what I originally had in mind when I wrote the issue, it's about offering the option names format, wrap, separator, etc. as an autocomplete dropdown. The same case can be made for functions like strip, reverse, trim, ….

OK, so this is actual code completion (the other items were more "auto closing" than code completion per se).

do you have an idea at what point of typing <if(...)> the should be inserted?

To be consistent with XML/HTML files, I suppose <endif> should be inserted when you type the closing >, but at the moment it's automatically inserted.

bjansen avatar Sep 15 '20 08:09 bjansen

I've created #33 to separate the autoclosing of symbol pairs and actual autocompletion for identifiers and keywords.

For <endif> I think it makes sense to be consistent with HTML. Maybe it doesn't need to be autocompleted at all, I imagine it could be annoying when encasing existing template text within an if/endif. Adding <endif> when typing the closing > could be a nice way to make it opt-in.

Clashsoft avatar Sep 15 '20 13:09 Clashsoft

If we make it opt-in, I think there's a good chance that users won't even know that the option exists, and thus it will never be used.

bjansen avatar Sep 15 '20 13:09 bjansen

when encasing existing template text within an if/endif.

This is probably an opportunity to implement "Surround With..." :)

bjansen avatar Sep 15 '20 13:09 bjansen

I agree, Surround With is a good idea. A similar feature is Live Templates, which could make the endif problem obsolete. Here's how it looks in a shell script:

recording

Clashsoft avatar Sep 15 '20 13:09 Clashsoft

You can already define your own live templates, but sure it would be better to ship them in the plugin directly.

bjansen avatar Sep 15 '20 13:09 bjansen

Here's a preview of what I did so far. Most of what's listed in your request should work, except for <endif>s. I haven't figured out how to deal with that yet. Maybe "surround with" is enough?

jetbrains-plugin-st4-0.9-SNAPSHOT.zip

bjansen avatar Sep 15 '20 19:09 bjansen

Thanks, I tested the snapshot and found the following:

  • foo() ::= " did not insert the closing "
  • delimiters " dito
  • myDict ::= [ " dito
  • <foo:{ did not insert }
  • when manually typing closing parentheses, it correctly replaces the automatically inserted one. This does not work for delimiters, however. I.e., if I press < and then >, it produces <>>, while I would have expected <>.

Clashsoft avatar Sep 15 '20 23:09 Clashsoft

Weird, it all works fine on my machine and in unit tests. How did you install the plugin?

bjansen avatar Sep 16 '20 07:09 bjansen

I used "Install plugin from disk" and selected your zip file.

But I found the problem. I was testing at the top of an existing stg file. The templates had } and " scattered across. When testing at the bottom or in a blank file, it works indeed. My last point always happens though.

Clashsoft avatar Sep 16 '20 09:09 Clashsoft