1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-03-08 12:35:45 +01:00

Allow things like :com! foo\n \ echo 1\n \ echo 2

This commit is contained in:
Kris Maglione
2010-10-11 02:47:07 -04:00
parent 5a670ebd7b
commit 4efc6a3972
6 changed files with 127 additions and 99 deletions

View File

@@ -319,99 +319,61 @@ lookup:
source: function (filename, silent) {
defineModule.loadLog.push("sourcing " + filename);
let time = Date.now();
this.withSavedValues(["readHeredoc", "sourcing"], function () {
try {
var file = io.File(filename);
this.sourcing = {
file: file.path,
line: 0
};
try {
var file = io.File(filename);
if (!file.exists() || !file.isReadable() || file.isDirectory()) {
if (!silent)
dactyl.echoerr("E484: Can't open file " + filename.quote());
return;
}
dactyl.echomsg("sourcing " + filename.quote(), 2);
let uri = services.get("io").newFileURI(file);
// handle pure JavaScript files specially
if (/\.js$/.test(filename)) {
try {
dactyl.loadScript(uri.spec, Script(file));
dactyl.helpInitialized = false;
}
catch (e) {
if (e.fileName)
try {
e.fileName = e.fileName.replace(/^(chrome|resource):.*? -> /, "");
if (e.fileName == uri.spec)
e.fileName = filename;
e.echoerr = <>{e.fileName}:{e.lineNumber}: {e}</>
}
catch (e) {}
throw e;
}
}
else if (/\.css$/.test(filename))
storage.styles.registerSheet(uri.spec, false, true);
else {
let lines = file.read().split(/\r\n|[\r\n]/);
this.readHeredoc = function (end) {
let res = [];
io.sourcing.line++;
while (++i < lines.length) {
if (lines[i] === end)
return res.join("\n");
res.push(lines[i]);
}
dactyl.assert(false, "Unexpected end of file waiting for " + end);
};
for (var i = 0; i < lines.length && !this.sourcing.finished; i++) {
// Deal with editors from Silly OSs.
let line = lines[i].replace(/\r$/, "");
this.sourcing.line = i + 1;
// Process escaped new lines
while (i < lines.length && /^\s*\\/.test(lines[i + 1]))
line += "\n" + lines[++i].replace(/^\s*\\/, "");
try {
dactyl.execute(line, { setFrom: file });
}
catch (e) {
if (!silent) {
dactyl.echoerr("Error detected while processing " + file.path);
dactyl.echomsg("line\t" + this.sourcing.line + ":");
dactyl.reportError(e, true);
}
}
}
}
if (this._scriptNames.indexOf(file.path) == -1)
this._scriptNames.push(file.path);
dactyl.echomsg("finished sourcing " + filename.quote(), 2);
dactyl.log("Sourced: " + filename, 3);
}
catch (e) {
if (!(e instanceof FailedAssertion))
dactyl.reportError(e);
let message = "Sourcing file: " + (e.echoerr || file.path + ": " + e);
if (!file.exists() || !file.isReadable() || file.isDirectory()) {
if (!silent)
dactyl.echoerr(message);
dactyl.echoerr("E484: Can't open file " + filename.quote());
return;
}
finally {
defineModule.loadLog.push("done sourcing " + filename + ": " + (Date.now() - time) + "ms");
dactyl.echomsg("sourcing " + filename.quote(), 2);
let uri = services.get("io").newFileURI(file);
// handle pure JavaScript files specially
if (/\.js$/.test(filename)) {
try {
dactyl.loadScript(uri.spec, Script(file));
dactyl.helpInitialized = false;
}
catch (e) {
if (e.fileName)
try {
e.fileName = e.fileName.replace(/^(chrome|resource):.*? -> /, "");
if (e.fileName == uri.spec)
e.fileName = filename;
e.echoerr = <>{e.fileName}:{e.lineNumber}: {e}</>
}
catch (e) {}
throw e;
}
}
});
else if (/\.css$/.test(filename))
storage.styles.registerSheet(uri.spec, false, true);
else {
commands.execute(file.read(), null, silent, null,
{ file: file.path, line: 1 });
}
if (this._scriptNames.indexOf(file.path) == -1)
this._scriptNames.push(file.path);
dactyl.echomsg("finished sourcing " + filename.quote(), 2);
dactyl.log("Sourced: " + filename, 3);
}
catch (e) {
if (!(e instanceof FailedAssertion))
dactyl.reportError(e);
let message = "Sourcing file: " + (e.echoerr || file.path + ": " + e);
if (!silent)
dactyl.echoerr(message);
}
finally {
defineModule.loadLog.push("done sourcing " + filename + ": " + (Date.now() - time) + "ms");
}
},
// TODO: when https://bugzilla.mozilla.org/show_bug.cgi?id=68702 is