Fixes #1 beautify on save option
This commit is contained in:
parent
2e142a3fe1
commit
230f30d6aa
|
@ -6,6 +6,10 @@ var beautifyJS = require('js-beautify');
|
|||
var beautifyHTML = require('js-beautify').html;
|
||||
var beautifyCSS = require('js-beautify').css;
|
||||
|
||||
var Subscriber = require('emissary').Subscriber;
|
||||
var plugin = module.exports;
|
||||
Subscriber.extend(plugin);
|
||||
|
||||
function beautify() {
|
||||
var text;
|
||||
var editor = atom.workspace.getActiveEditor();
|
||||
|
@ -48,6 +52,24 @@ function beautify() {
|
|||
}
|
||||
}
|
||||
|
||||
exports.activate = function() {
|
||||
function handleSafeEvent() {
|
||||
atom.workspace.eachEditor(function(editor) {
|
||||
var buffer = editor.getBuffer();
|
||||
plugin.unsubscribe(buffer);
|
||||
|
||||
if (atom.config.get('beautify.beautifyOnSave')) {
|
||||
var events = 'will-be-saved';
|
||||
plugin.subscribe(buffer, events, beautify);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
plugin.configDefaults = {
|
||||
beautifyOnSave: false
|
||||
};
|
||||
|
||||
plugin.activate = function() {
|
||||
handleSafeEvent();
|
||||
plugin.subscribe(atom.config.observe('beautify.beautifyOnSave', handleSafeEvent));
|
||||
return atom.workspaceView.command('beautify', beautify);
|
||||
};
|
||||
|
|
|
@ -4,9 +4,6 @@
|
|||
"version": "0.2.0",
|
||||
"private": true,
|
||||
"description": "Beautify HTML, CSS and Javascript in Atom",
|
||||
"activationEvents": [
|
||||
"beautify"
|
||||
],
|
||||
"repository": "https://github.com/donaldpipowitch/atom-beautify",
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
|
@ -18,6 +15,7 @@
|
|||
"atom": ">0.50.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"js-beautify": "~1.4.2"
|
||||
"js-beautify": "~1.4.2",
|
||||
"emissary": "^1.0.0"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue