kopia lustrzana https://github.com/c9/core
fix custom formatter for the case when formatOnSave is disabled
rodzic
2795ef0379
commit
82b9de1239
|
@ -17,30 +17,13 @@ define(function(require, exports, module) {
|
||||||
|
|
||||||
var ERROR_NOT_FOUND = 127;
|
var ERROR_NOT_FOUND = 127;
|
||||||
|
|
||||||
function load() {
|
var fromFormatCommand;
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
function beforeSave(e) {
|
function load() {
|
||||||
|
collab.on("beforeSave", function(e) {
|
||||||
var mode = getMode(e.docId);
|
var mode = getMode(e.docId);
|
||||||
var enabled = settings.getBool("project/" + mode + "/@formatOnSave");
|
var enabled = settings.getBool("project/" + mode + "/@formatOnSave");
|
||||||
if (!enabled)
|
if (!enabled && !fromFormatCommand)
|
||||||
return;
|
return;
|
||||||
if (mode === "javascript" && settings.getBool("project/javascript/@use_jsbeautify"))
|
if (mode === "javascript" && settings.getBool("project/javascript/@use_jsbeautify"))
|
||||||
return; // use built-in JS Beautify instead
|
return; // use built-in JS Beautify instead
|
||||||
|
@ -51,6 +34,25 @@ define(function(require, exports, module) {
|
||||||
command: "bash",
|
command: "bash",
|
||||||
args: ["-c", formatter]
|
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) {
|
function getMode(docId) {
|
||||||
|
@ -64,7 +66,7 @@ define(function(require, exports, module) {
|
||||||
load();
|
load();
|
||||||
});
|
});
|
||||||
plugin.on("unload", function() {
|
plugin.on("unload", function() {
|
||||||
|
fromFormatCommand = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Ładowanie…
Reference in New Issue