Permalink
Browse files

pretty print the active config to the Sublime console

  • Loading branch information...
1 parent 79b466e commit cf51245f45626959217032f546a0cd0c14f2c3da @sindresorhus committed Aug 17, 2014
Showing with 46 additions and 8 deletions.
  1. +17 −5 EditorConfig.py
  2. +21 −0 license
  3. +8 −3 readme.md
View
@@ -1,5 +1,11 @@
+import pprint
import sublime_plugin
+def unexpanduser(path):
+ import re
+ from os.path import expanduser
+ return re.sub(r'^%s' % expanduser('~'), '~', path)
+
try:
import os, sys
# stupid python module system
@@ -28,16 +34,16 @@ class EditorConfig(sublime_plugin.EventListener):
def on_activated(self, view):
if not view.settings().has(self.MARKER):
- self.init(view, False)
+ self.init(view, 'activated')
def on_pre_save(self, view):
- self.init(view, True)
+ self.init(view, 'pre_save')
def on_post_save(self, view):
if not view.settings().has(self.MARKER):
- self.init(view, False)
+ self.init(view, 'post_save')
- def init(self, view, pre_save):
+ def init(self, view, event):
path = view.file_name()
if not path:
return
@@ -48,7 +54,13 @@ def init(self, view, pre_save):
print('Error occurred while getting EditorConfig properties')
else:
if config:
- if pre_save:
+ if event == 'activated':
+ print('\nEditorConfig')
+ path = unexpanduser(path)
+ print(path)
+ pprint.pprint(config)
+ print('')
+ if event == 'pre_save':
self.apply_pre_save(view, config)
else:
self.apply_config(view, config)
View
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
@@ -40,25 +40,30 @@ end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
+
+[*.md]
+trim_trailing_whitespace = false
```
## Tips
+### View active config
+
+The active config is printed in the Sublime console.
+
### Trailing whitespace
Even though there is a `trim_trailing_whitespace` property. I would still recommend you set `"draw_white_space": "all"` and/or `"trim_trailing_white_space_on_save": true` in your Sublime preferences to prevent you from accidentally committing whitespace garbage whenever a project is missing a .editorconfig file.
-
### Show changes
This plugin does its changes transparently in the background. I would recommend the excellent [Modific](https://github.com/gornostal/Modific) plugin if you would like to see what changed.
## License
-[MIT](http://opensource.org/licenses/MIT) © [Sindre Sorhus](http://sindresorhus.com)
-
+MIT © [Sindre Sorhus](http://sindresorhus.com)
[EditorConfig site]: http://editorconfig.org

0 comments on commit cf51245

Please sign in to comment.