Sublime Forum

Commenting snippets

#1

Hi! I’ve been growing my snippet collection and they are becoming more complex and harder to read. I use a lot of substitutions and so my snippets are full of regex. I am aware that CDATA doesn’t allow for comments and that other solutions are being ‘noodled’ over. That being said, being able to comment in whatever snippet filetype would be great.

Here’s a snippet of a snippet:

Conclusie
${10/(1[3-5])|(9|1[0-2])|([3-8])|(\d+|)/(?1Minor:)(?2Matig ernstig:)(?3Ernstig:)/} ${14:__conclusie-trauma-capitis}

Being able to explain this to future me and/or others would be helpful.

Martien

0 Likes

#2

:+1:, normally one could use multiple cdata nodes with comments in between them, but ST just parses the first cdata node… though have you considered/tried the following:

  • undefined variables resolve to blank, so you could potentially include a comment as part of a snippet variable ${IGNORE_ME this is a comment, assuming spaces are allowed etc.}
  • comments can be used in regular expressions - iirc, ST doesn’t support the (?x) flag in snippet substitutions unfortunately, but one can presumably add comments like (?# I am a comment), though I guess it would not work in the actual substitution part of the regex?
0 Likes

#3

Very cool! I did not know the inline regex comment! @kingkeith, since we’re on the topic, would you know a way to insert newlines in snippets that would be ignored on insertion? Maybe that’s asking for too much :slight_smile:

Conclusie
${10/(1[3-5])|                              (?# GCS 13-15)
(9|1[0-2])|                                 (?# GCS 9-12)
([3-8])|                                    (?# GCS 3-8)
(\d+|)/                                     (?# any other number)
(?1Minor:)(?2Matig ernstig:)(?3Ernstig:)/}  (?# Trauma classification)
${14:__conclusie-trauma-capitis}
0 Likes