atom / snippets

Atom snippets package
MIT License
205 stars 101 forks source link

Feature request: Convert Case #170

Closed idleberg closed 5 years ago

idleberg commented 9 years ago

There's one feature I miss compared to Sublime Text: controlling case used in snippets. Here's an example from the NSIS package:

!insertmacro MUI_LANGUAGE "${1:English}"
LangString DESC_SECTION_INDEX \${LANG_${1/(.*)/\U\1/}} "${2:section_description}"

The result would look like this:

!insertmacro MUI_LANGUAGE "English"
LangString DESC_SECTION_INDEX ${LANG_ENGLISH} "section_description"

Notice the /\U\1/ part which converts the string (in this case the word “English”) to uppercase letters. There's also a /\L\1/ counterpart to convert the string to lowercase. (I'm not sure what the number 1 does in there!)

Edit: If I'm not mistaken, the number sets the amount of times the preceding string is inserted (once in the example)

felixakiragreen commented 8 years ago

:+1:

This would be huge

deedubs commented 8 years ago

Yeah I can see using this like

import $1 from '{$1:toLowerCase};

jeremiahrhall commented 8 years ago

I use a feature like this in IntelliJ's live templates regularly. It would be cool to use this in Atom as well. :+1:

pvorona commented 8 years ago

+1

crwh05 commented 8 years ago

+1

gurdilou commented 8 years ago

+1 !

hnordt commented 8 years ago

This would be great :+1:

Demetri0 commented 8 years ago

maybe better like this: ${1:Word | upper}

aysner commented 6 years ago

260

shuntaroy commented 5 years ago

As @aysner referred to, the following kinds of regex syntax have already worked: ${1/(.)/\\U$1/}, which will be converted to upper-cased $1.

260 says:

There's one extra feature that I brought over from TextMate format strings: the ability to control case through the \u, \l, \U, \L, and \E flags: \u and \l will force the next character to uppercase or lowercase, respectively. \U and \L will force the rest of the string to uppercase or lowercase, respectively (or until we encounter a different case directive or \E). \E stops the effects of \U and \L.

Besides, README.md says:

This package supports a subset of the features of TextMate snippets, documented here. The following features are not yet supported:

  • Variables
  • Interpolated shell code
  • Conditional insertions in transformations

I wonder this issue may be closed.

savetheclocktower commented 5 years ago

Yeah, missed this one. Fixed in #260. Thanks!