Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a snippet for EditorConfig file content #50

Closed
wants to merge 9 commits into from
17 changes: 17 additions & 0 deletions 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}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

${3/(^$)|.*/?1:# lf | cr\n/i}end_of_line = ${3:lf}${3/(l$)|(c$)|.*/?1:f:?2:r/i}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure!

${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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

]]></content>
<tabTrigger>editorconfig</tabTrigger>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably set scope to source.ini.editorconfig.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

</snippet>
8 changes: 8 additions & 0 deletions readme.md
Expand Up @@ -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` + <kbd>tab</kbd>, and your editor will focus on the first setting's value (indent_style = *lf*). You can change the value, if you want, and jump to the next setting's value by hitting <kbd>tab</kbd> and so on. Settings are somewhat autocompleted, and if you don't remember all possible values, simply remove the setting value to see them all as a comment.

You can be in a context where `editorconfig` + <kbd>tab</kbd> trigger another snippet. In that case, simply use `Goto anywhere` (<kbd>Ctrl</kbd> + <kbd>P</kbd> on Linux/Windows or <kbd>⌘</kbd> + <kbd>P</kbd> on OSX), type `editorconfig`, select `Snippet: editorconfig` and hit <kbd>Enter</kbd>.

### View active config

The active config is printed in the Sublime console.
Expand Down