mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 10:37:59 +01:00
better argument processing for :source, :mkvimperatorc, and :saveas
This commit is contained in:
@@ -797,18 +797,33 @@ function Buffer() //{{{
|
||||
argCount: "0"
|
||||
});
|
||||
|
||||
// TODO: we're prompted if download.useDownloadDir isn't set and no arg specified - intentional?
|
||||
commands.add(["sav[eas]", "w[rite]"],
|
||||
"Save current document to disk",
|
||||
function (args, special)
|
||||
{
|
||||
args = args.string;
|
||||
|
||||
let doc = window.content.document;
|
||||
let file = io.getFile(args || "");
|
||||
if (args && file.exists() && !special)
|
||||
return liberator.echoerr("E13: File exists (add ! to override)");
|
||||
let chosenData = null;
|
||||
let filename = args.arguments[0];
|
||||
|
||||
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());
|
||||
|
||||
try
|
||||
{
|
||||
var contentDisposition = window.content
|
||||
@@ -818,12 +833,11 @@ function Buffer() //{{{
|
||||
} catch (e) {}
|
||||
|
||||
internalSave(doc.location.href, doc, null, contentDisposition,
|
||||
doc.contentType, false, null,
|
||||
args && { file: file, uri: makeURI(doc.location.href, doc.characterSet) },
|
||||
doc.referrer ? makeURI(doc.referrer) : null,
|
||||
true);
|
||||
doc.contentType, false, null, chosenData, doc.referrer ?
|
||||
makeURI(doc.referrer) : null, true);
|
||||
},
|
||||
{
|
||||
argCount: "?",
|
||||
bang: true,
|
||||
completer: function (filter) completion.file(filter)
|
||||
});
|
||||
|
||||
@@ -897,28 +897,32 @@ function Completion() //{{{
|
||||
// if "tail" is true, only return names without any directory components
|
||||
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
|
||||
|
||||
let generate = function ()
|
||||
{
|
||||
var files = [], mapped = [];
|
||||
let files = [], mapped = [];
|
||||
|
||||
try
|
||||
{
|
||||
dir = dir.replace("\\ ", " ", "g");
|
||||
files = io.readDirectory(dir, true);
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
mapped = files.map(function (file) [tail ? file.leafName : (dir + file.leafName),
|
||||
file.isDirectory() ? "Directory" : "File"]);
|
||||
mapped = files.map(
|
||||
function (file) [(tail ? file.leafName : dir + file.leafName).replace(" ", "\\ ", "g"),
|
||||
file.isDirectory() ? "Directory" : "File"]
|
||||
);
|
||||
}
|
||||
catch (e) {}
|
||||
|
||||
return mapped;
|
||||
};
|
||||
|
||||
|
||||
@@ -218,23 +218,17 @@ function IO() //{{{
|
||||
"Write current key mappings and changed options to the config file",
|
||||
function (args, special)
|
||||
{
|
||||
args = args.string;
|
||||
|
||||
// TODO: "E172: Only one file name allowed"
|
||||
var filename;
|
||||
if (args)
|
||||
filename = args;
|
||||
else
|
||||
filename = "~/" + (WINDOWS ? "_" : ".") + EXTENSION_NAME + "rc";
|
||||
let filename = args.arguments[0] || "~/" + (WINDOWS ? "_" : ".") + EXTENSION_NAME + "rc";
|
||||
let file = io.getFile(filename);
|
||||
|
||||
var file = io.getFile(filename);
|
||||
if (file.exists() && !special)
|
||||
{
|
||||
liberator.echoerr("E189: \"" + filename + "\" exists (add ! to override)");
|
||||
return;
|
||||
}
|
||||
|
||||
var line = "\" " + liberator.version + "\n";
|
||||
let line = "\" " + liberator.version + "\n";
|
||||
line += "\" Mappings\n";
|
||||
|
||||
[[[modes.NORMAL], ""],
|
||||
@@ -286,6 +280,7 @@ function IO() //{{{
|
||||
}
|
||||
},
|
||||
{
|
||||
argCount: "?",
|
||||
bang: true,
|
||||
completer: function (filter) completion.file(filter, true)
|
||||
});
|
||||
@@ -348,18 +343,11 @@ function IO() //{{{
|
||||
"Read Ex commands from a file",
|
||||
function (args, special)
|
||||
{
|
||||
args = args.string;
|
||||
|
||||
// FIXME: implement proper filename quoting - "E172: Only one file name allowed"
|
||||
if (!args)
|
||||
{
|
||||
liberator.echoerr("E471: Argument required");
|
||||
return;
|
||||
}
|
||||
|
||||
io.source(args, special);
|
||||
// FIXME: "E172: Only one file name allowed"
|
||||
io.source(args.arguments[0], special);
|
||||
},
|
||||
{
|
||||
argCount: "1",
|
||||
bang: 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)
|
||||
if (/^~/.test(path))
|
||||
{
|
||||
var home = environmentService.get("VIMPERATOR_HOME");
|
||||
let home = environmentService.get("VIMPERATOR_HOME");
|
||||
|
||||
if (!home)
|
||||
home = environmentService.get("HOME");
|
||||
@@ -434,6 +422,8 @@ function IO() //{{{
|
||||
function (m, n1, n2, i, s) environmentService.get((n1 || n2), "$1")
|
||||
);
|
||||
|
||||
path = path.replace("\\ ", " ", "g");
|
||||
|
||||
return path;
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user