fix custom formatter for the case when formatOnSave is disabled

pull/125/merge
nightwing 2017-04-30 21:48:56 +04:00
rodzic 2795ef0379
commit 82b9de1239
1 zmienionych plików z 22 dodań i 20 usunięć

Wyświetl plik

@ -17,30 +17,13 @@ define(function(require, exports, module) {
var ERROR_NOT_FOUND = 127;
function load() {
collab.on("beforeSave", beforeSave, plugin);
collab.on("postProcessorError", function(e) {
var mode = getMode(e.docId) || "language";
if (e.code !== ERROR_NOT_FOUND)
return console.error("Error running formatter for " + mode + ": " + (e.stderr || e.code));
var formatter = (settings.get("project/" + mode + "/@formatter") || "formatter").replace(/(.*?) .*/, "$1");
showError("Error running code formatter for " + mode + ": "
+ formatter + " not found, please check your project settings");
});
format.on("format", function(e) {
if (!settings.get("project/" + e.mode + "/@formatOnSave"))
return;
if (e.mode === "javascript" && settings.getBool("project/javascript/@use_jsbeautify"))
return; // use built-in JS Beautify instead
save.save(tabs.currentTab);
return true;
}, plugin);
}
var fromFormatCommand;
function beforeSave(e) {
function load() {
collab.on("beforeSave", function(e) {
var mode = getMode(e.docId);
var enabled = settings.getBool("project/" + mode + "/@formatOnSave");
if (!enabled)
if (!enabled && !fromFormatCommand)
return;
if (mode === "javascript" && settings.getBool("project/javascript/@use_jsbeautify"))
return; // use built-in JS Beautify instead
@ -51,6 +34,25 @@ define(function(require, exports, module) {
command: "bash",
args: ["-c", formatter]
};
}, plugin);
collab.on("postProcessorError", function(e) {
var mode = getMode(e.docId) || "language";
if (e.code !== ERROR_NOT_FOUND)
return console.error("Error running formatter for " + mode + ": " + (e.stderr || e.code));
var formatter = (settings.get("project/" + mode + "/@formatter") || "formatter").replace(/(.*?) .*/, "$1");
showError("Error running code formatter for " + mode + ": "
+ formatter + " not found, please check your project settings");
});
format.on("format", function(e) {
if (!settings.get("project/" + e.mode + "/@formatter"))
return;
if (e.mode === "javascript" && settings.getBool("project/javascript/@use_jsbeautify"))
return; // use built-in JS Beautify instead
fromFormatCommand = true;
save.save(tabs.focussedTab);
fromFormatCommand = false;
return true;
}, plugin);
}
function getMode(docId) {
@ -64,7 +66,7 @@ define(function(require, exports, module) {
load();
});
plugin.on("unload", function() {
fromFormatCommand = false;
});
/**