1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 20:32:25 +01:00

better argument processing for :source, :mkvimperatorc, and :saveas

This commit is contained in:
Doug Kearns
2008-10-19 14:13:31 +00:00
parent 337f956323
commit 86460fd8c5
3 changed files with 42 additions and 34 deletions

View File

@@ -797,18 +797,33 @@ function Buffer() //{{{
argCount: "0" argCount: "0"
}); });
// TODO: we're prompted if download.useDownloadDir isn't set and no arg specified - intentional?
commands.add(["sav[eas]", "w[rite]"], commands.add(["sav[eas]", "w[rite]"],
"Save current document to disk", "Save current document to disk",
function (args, special) function (args, special)
{ {
args = args.string;
let doc = window.content.document; let doc = window.content.document;
let file = io.getFile(args || ""); let chosenData = null;
if (args && file.exists() && !special) let filename = args.arguments[0];
return liberator.echoerr("E13: File exists (add ! to override)");
if (filename)
{
let file = io.getFile(filename);
if (file.exists() && !special)
{
liberator.echoerr("E13: File exists (add ! to override)");
return;
}
chosenData = { file: file, uri: makeURI(doc.location.href, doc.characterSet) };
}
// if browser.download.useDownloadDir = false then the "Save As"
// dialog is used with this as the default directory
// TODO: if we're going to do this shouldn't it be done in setCWD or the value restored?
options.setPref("browser.download.lastDir", io.getCurrentDirectory()); options.setPref("browser.download.lastDir", io.getCurrentDirectory());
try try
{ {
var contentDisposition = window.content var contentDisposition = window.content
@@ -818,12 +833,11 @@ function Buffer() //{{{
} catch (e) {} } catch (e) {}
internalSave(doc.location.href, doc, null, contentDisposition, internalSave(doc.location.href, doc, null, contentDisposition,
doc.contentType, false, null, doc.contentType, false, null, chosenData, doc.referrer ?
args && { file: file, uri: makeURI(doc.location.href, doc.characterSet) }, makeURI(doc.referrer) : null, true);
doc.referrer ? makeURI(doc.referrer) : null,
true);
}, },
{ {
argCount: "?",
bang: true, bang: true,
completer: function (filter) completion.file(filter) completer: function (filter) completion.file(filter)
}); });

View File

@@ -897,28 +897,32 @@ function Completion() //{{{
// if "tail" is true, only return names without any directory components // if "tail" is true, only return names without any directory components
file: function file(filter, tail) file: function file(filter, tail)
{ {
let [matches, dir, compl] = filter.match(/^((?:.*[\/\\])?)(.*?)$/); let [, dir, compl] = filter.match(/^((?:.*[\/\\])?)(.*?)$/);
// dir == "" is expanded inside readDirectory to the current dir // dir == "" is expanded inside readDirectory to the current dir
let generate = function () let generate = function ()
{ {
var files = [], mapped = []; let files = [], mapped = [];
try try
{ {
dir = dir.replace("\\ ", " ", "g");
files = io.readDirectory(dir, true); files = io.readDirectory(dir, true);
if (options["wildignore"]) if (options["wildignore"])
{ {
var wigRegexp = new RegExp("(^" + options["wildignore"].replace(",", "|", "g") + ")$"); let wigRegexp = RegExp("(^" + options["wildignore"].replace(",", "|", "g") + ")$");
files = files.filter(function (f) f.isDirectory() || !wigRegexp.test(f.leafName)) files = files.filter(function (f) f.isDirectory() || !wigRegexp.test(f.leafName))
} }
mapped = files.map(function (file) [tail ? file.leafName : (dir + file.leafName), mapped = files.map(
file.isDirectory() ? "Directory" : "File"]); function (file) [(tail ? file.leafName : dir + file.leafName).replace(" ", "\\ ", "g"),
file.isDirectory() ? "Directory" : "File"]
);
} }
catch (e) {} catch (e) {}
return mapped; return mapped;
}; };

View File

@@ -218,23 +218,17 @@ function IO() //{{{
"Write current key mappings and changed options to the config file", "Write current key mappings and changed options to the config file",
function (args, special) function (args, special)
{ {
args = args.string;
// TODO: "E172: Only one file name allowed" // TODO: "E172: Only one file name allowed"
var filename; let filename = args.arguments[0] || "~/" + (WINDOWS ? "_" : ".") + EXTENSION_NAME + "rc";
if (args) let file = io.getFile(filename);
filename = args;
else
filename = "~/" + (WINDOWS ? "_" : ".") + EXTENSION_NAME + "rc";
var file = io.getFile(filename);
if (file.exists() && !special) if (file.exists() && !special)
{ {
liberator.echoerr("E189: \"" + filename + "\" exists (add ! to override)"); liberator.echoerr("E189: \"" + filename + "\" exists (add ! to override)");
return; return;
} }
var line = "\" " + liberator.version + "\n"; let line = "\" " + liberator.version + "\n";
line += "\" Mappings\n"; line += "\" Mappings\n";
[[[modes.NORMAL], ""], [[[modes.NORMAL], ""],
@@ -286,6 +280,7 @@ function IO() //{{{
} }
}, },
{ {
argCount: "?",
bang: true, bang: true,
completer: function (filter) completion.file(filter, true) completer: function (filter) completion.file(filter, true)
}); });
@@ -348,18 +343,11 @@ function IO() //{{{
"Read Ex commands from a file", "Read Ex commands from a file",
function (args, special) function (args, special)
{ {
args = args.string; // FIXME: "E172: Only one file name allowed"
io.source(args.arguments[0], special);
// FIXME: implement proper filename quoting - "E172: Only one file name allowed"
if (!args)
{
liberator.echoerr("E471: Argument required");
return;
}
io.source(args, special);
}, },
{ {
argCount: "1",
bang: true, bang: true,
completer: function (filter) completion.file(filter, true) completer: function (filter) completion.file(filter, true)
}); });
@@ -414,7 +402,7 @@ function IO() //{{{
// expand "~" to VIMPERATOR_HOME or HOME (USERPROFILE or HOMEDRIVE\HOMEPATH on Windows if HOME is not set) // expand "~" to VIMPERATOR_HOME or HOME (USERPROFILE or HOMEDRIVE\HOMEPATH on Windows if HOME is not set)
if (/^~/.test(path)) if (/^~/.test(path))
{ {
var home = environmentService.get("VIMPERATOR_HOME"); let home = environmentService.get("VIMPERATOR_HOME");
if (!home) if (!home)
home = environmentService.get("HOME"); home = environmentService.get("HOME");
@@ -434,6 +422,8 @@ function IO() //{{{
function (m, n1, n2, i, s) environmentService.get((n1 || n2), "$1") function (m, n1, n2, i, s) environmentService.get((n1 || n2), "$1")
); );
path = path.replace("\\ ", " ", "g");
return path; return path;
}, },