Add a snippet for EditorConfig file content #50

Closed
wants to merge 9 commits into
from

Projects

None yet

3 participants

@kipit
Collaborator
kipit commented Dec 18, 2015

Event if the scope of EditorConfig files is very limited, this snippet ease the creation of EditorConfig files. All parameters except tab_size are used, as this one has a default based on indent_size.

@sindresorhus sindresorhus and 1 other commented on an outdated diff Dec 19, 2015
editorconfig.sublime-snippet
@@ -0,0 +1,14 @@
+<snippet>
+ <content><![CDATA[
+root = ${1:true}
+
+[*]
+charset = ${2:utf-8}
+end_of_line = ${3:lf}
+indent_size = ${4:4}
+indent_style = ${5:space}
+insert_final_newline = ${6:true}
+trim_trailing_whitespace = ${7:true}
@kipit
kipit Dec 21, 2015 Collaborator

I can get all your default recommend settings. Can I add the indent_size as a comment?

@sindresorhus
Owner

Good idea :) Can you add something to the readme that it's included and how to use it?

@kipit
Collaborator
kipit commented Dec 21, 2015

No sure the tips section is the suitable place for the snippet how-to, I've oriented the text in a tips way.

@kipit
Collaborator
kipit commented Dec 21, 2015

I've added a small precision for user with conflicting snippet.

@sindresorhus sindresorhus and 1 other commented on an outdated diff Dec 24, 2015
editorconfig.sublime-snippet
@@ -0,0 +1,18 @@
+<snippet>
+ <content><![CDATA[
+# EditorConfig is awesome: http://EditorConfig.org
@sindresorhus
sindresorhus Dec 24, 2015 Owner

Drop this line

@kipit
kipit Dec 24, 2015 Collaborator

Done

@sindresorhus sindresorhus and 1 other commented on an outdated diff Dec 24, 2015
editorconfig.sublime-snippet
@@ -0,0 +1,18 @@
+<snippet>
+ <content><![CDATA[
+# EditorConfig is awesome: http://EditorConfig.org
+root = ${1:true}
+
+[*]
+indent_style = ${2:tab}
+#indent_size = ${3:4}
+end_of_line = ${4:lf}
+charset = ${5:utf-8}
+trim_trailing_whitespace = ${6:true}
+insert_final_newline = ${7:true}
+
+[*.md]
+trim_trailing_whitespace = ${8:false}
@sindresorhus
sindresorhus Dec 24, 2015 Owner

This no point in having an option here as you'll never want to trim trailing whitespace in markdown as trailing whitespace has semantic value of being a linebreak.

@kipit
kipit Dec 24, 2015 Collaborator

Oh! Sure! Done.

@sindresorhus sindresorhus and 1 other commented on an outdated diff Dec 24, 2015
editorconfig.sublime-snippet
@@ -0,0 +1,18 @@
+<snippet>
+ <content><![CDATA[
+# EditorConfig is awesome: http://EditorConfig.org
+root = ${1:true}
@sindresorhus
sindresorhus Dec 24, 2015 Owner

Remove the configurability here. 99% of people would set it to true.

@kipit
kipit Dec 24, 2015 Collaborator

Done

@sindresorhus sindresorhus and 1 other commented on an outdated diff Dec 24, 2015
editorconfig.sublime-snippet
@@ -0,0 +1,18 @@
+<snippet>
+ <content><![CDATA[
+# EditorConfig is awesome: http://EditorConfig.org
+root = ${1:true}
+
+[*]
+indent_style = ${2:tab}
@sindresorhus
sindresorhus Dec 24, 2015 Owner

Is there any way to do a list of choices? Like tab or space?

@kipit
kipit Dec 24, 2015 Collaborator

Not to my knowledge, the snippet feature is fairly simple. When can add leave choices as a comment or using a default placeholder like tab|space (but this makes a default generated editorconfig - ie untouch - invalid, bad idear IMO)

@sindresorhus sindresorhus and 1 other commented on an outdated diff Dec 24, 2015
editorconfig.sublime-snippet
@@ -0,0 +1,18 @@
+<snippet>
+ <content><![CDATA[
+# EditorConfig is awesome: http://EditorConfig.org
+root = ${1:true}
+
+[*]
+indent_style = ${2:tab}
+#indent_size = ${3:4}
@sindresorhus
sindresorhus Dec 24, 2015 Owner

Does Sublime support snippet conditionals, so this is only added if the users selects tab in the above?

@kipit
kipit Dec 24, 2015 Collaborator

No. Anyway, the indent_sizemakes sense for tab or space indent style.

@sindresorhus sindresorhus and 1 other commented on an outdated diff Dec 24, 2015
@@ -48,6 +48,14 @@ trim_trailing_whitespace = false
## Tips
+### EditorConfig snippet
+
+If you can't remember all settings managed by the EditorConfig file, you'll love the `editorconfig` snippet.
+
+Just type `editorconfig` + `tab`, and your editor will focus on the first setting's value (root = *true*). You can change the value, if you want, and jump to the next setting's value by hitting `tab` and so on.
@sindresorhus
sindresorhus Dec 24, 2015 Owner

tab => <kbd>tab</kbd>

@kipit
kipit Dec 24, 2015 Collaborator

Done, for other keyboard strokes also.

@kipit

Another option would be to use a default value with all the possible values, something like tab|space but this would make an invalid EditorConfig by default. @sindresorhus What do you think?

@kipit
Collaborator
kipit commented Jan 13, 2016

Any advice on this ?

@kevva
Collaborator
kevva commented Jan 13, 2016

👍 lgtm

Another option would be to use a default value with all the possible values, something like tab|space but this would make an invalid EditorConfig by default.

I'm not against keeping it as is.

@sindresorhus sindresorhus and 1 other commented on an outdated diff Jan 16, 2016
editorconfig.sublime-snippet
+<snippet>
+ <content><![CDATA[
+root = true
+
+[*]
+${1/(^$)|.*/?1:# tab | space\n/i}indent_style = ${1:tab}${1/(t$)|(s$)|(ta$)|(sp$)|.*/?1:ab:?2:pace:?3:b:?4:ace/i}
+#indent_size = ${2:4}
+${3/(^$)|.*/?1:# lf | cr\n/i}end_of_line = ${3:lf}${3/(l$)|(c$)|.*/?1:f:?2:r/i}
+${4/(^$)|.*/?1:# latin1 | utf-8 | utf-8-bom | utf-16be | utf-16le\n/i}charset = ${4:utf-8}${4/(l$)|(u$)|(la$)|(ut$)|.*/(?1:atin1:)(?2:tf-8:)(?3:tin1:)(?4:f-8)/i}
+${5/(^$)|.*/?1:# true | false\n/i}trim_trailing_whitespace = ${5:true}${5/(t$)|(f$)|(tr$)|(fa$)|.*/?1:rue:?2:alse:?3:ue:?4:lse/i}
+${6/(^$)|.*/?1:# true | false\n/i}insert_final_newline = ${6:true}${6/(t$)|(f$)|(tr$)|(fa$)|.*/?1:rue:?2:alse:?3:ue:?4:lse/i}
+
+[*.md]
+trim_trailing_whitespace = false
+]]></content>
+ <tabTrigger>editorconfig</tabTrigger>
@sindresorhus
sindresorhus Jan 16, 2016 Owner

Should probably set scope to source.ini.editorconfig.

@kipit
kipit Jan 16, 2016 Collaborator

Well, in fact I dropped the scope to ease fast creation of editorconfig. The scenario I was thinking was :

  1. "Hey! I should add the EditorConfig file"
  2. Create a new file (here, ST open a Plain Text file)
  3. Call the snippet
  4. Adjust rules
  5. Save

I don't know if the initial scope of ST can parameterized by user, that's why I didn't specified the scope.
Maybe we can use source.ini.editorconfig,text.plain. No?

@sindresorhus
sindresorhus Jan 16, 2016 Owner

Maybe we can use source.ini.editorconfig,text.plain. No?

👍

@kipit
kipit Jan 16, 2016 Collaborator

Done!

@sindresorhus sindresorhus and 1 other commented on an outdated diff Jan 16, 2016
editorconfig.sublime-snippet
@@ -0,0 +1,17 @@
+<snippet>
+ <content><![CDATA[
+root = true
+
+[*]
+${1/(^$)|.*/?1:# tab | space\n/i}indent_style = ${1:tab}${1/(t$)|(s$)|(ta$)|(sp$)|.*/?1:ab:?2:pace:?3:b:?4:ace/i}
+#indent_size = ${2:4}
+${3/(^$)|.*/?1:# lf | cr\n/i}end_of_line = ${3:lf}${3/(l$)|(c$)|.*/?1:f:?2:r/i}
@sindresorhus
sindresorhus Jan 16, 2016 Owner

Currently if I write c here it autocompletes to cr. Instead it should autocomplete to crlf. cr is archaic and not used anymore.

@kipit
kipit Jan 16, 2016 Collaborator

For sure!

@sindresorhus sindresorhus and 1 other commented on an outdated diff Jan 16, 2016
editorconfig.sublime-snippet
@@ -0,0 +1,17 @@
+<snippet>
+ <content><![CDATA[
+root = true
+
+[*]
+${1/(^$)|.*/?1:# tab | space\n/i}indent_style = ${1:tab}${1/(t$)|(s$)|(ta$)|(sp$)|.*/?1:ab:?2:pace:?3:b:?4:ace/i}
+#indent_size = ${2:4}
+${3/(^$)|.*/?1:# lf | cr\n/i}end_of_line = ${3:lf}${3/(l$)|(c$)|.*/?1:f:?2:r/i}
+${4/(^$)|.*/?1:# latin1 | utf-8 | utf-8-bom | utf-16be | utf-16le\n/i}charset = ${4:utf-8}${4/(l$)|(u$)|(la$)|(ut$)|.*/(?1:atin1:)(?2:tf-8:)(?3:tin1:)(?4:f-8)/i}
+${5/(^$)|.*/?1:# true | false\n/i}trim_trailing_whitespace = ${5:true}${5/(t$)|(f$)|(tr$)|(fa$)|.*/?1:rue:?2:alse:?3:ue:?4:lse/i}
+${6/(^$)|.*/?1:# true | false\n/i}insert_final_newline = ${6:true}${6/(t$)|(f$)|(tr$)|(fa$)|.*/?1:rue:?2:alse:?3:ue:?4:lse/i}
+
+[*.md]
+trim_trailing_whitespace = false
@sindresorhus
sindresorhus Jan 16, 2016 Owner

Let's remove this one. It's too opinionated.

@kipit
kipit Jan 16, 2016 Collaborator

Done!

@sindresorhus sindresorhus and 1 other commented on an outdated diff Jan 16, 2016
editorconfig.sublime-snippet
@@ -0,0 +1,17 @@
+<snippet>
+ <content><![CDATA[
+root = true
+
+[*]
+${1/(^$)|.*/?1:# tab | space\n/i}indent_style = ${1:tab}${1/(t$)|(s$)|(ta$)|(sp$)|.*/?1:ab:?2:pace:?3:b:?4:ace/i}
+#indent_size = ${2:4}
@sindresorhus
sindresorhus Jan 16, 2016 Owner

Wonder if it's possible to uncomment this if it changes from the default value. Seems you can do some transformation on substitution: http://sublimetext.info/docs/en/extensibility/snippets.html#substitutions We could then leave it without a value and if a value is typed it's uncommented.

@kipit
kipit Jan 16, 2016 Collaborator

For sure, done! I've used substitutions all the way since you pointed me to this direction earlier, in december ;-).

@sindresorhus
Owner

Sorry about the delay @kipit. I got too busy in real life. I added some inline comments, but generally looks really good :)

@kipit
Collaborator
kipit commented Jan 16, 2016

No problem for the delay. Your comments have been integrated, except the scope one where I need feedbacks.

@sindresorhus
Owner

Awesome! Landed at last. Thanks for persevering through this :)

@kipit kipit deleted the kipit:add_editorconfig_snippet branch Jan 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment