mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 19:32:27 +01:00
Allow completion of quoted function args.
This commit is contained in:
@@ -186,6 +186,11 @@ function Commands() //{{{
|
|||||||
let re = RegExp("[" + list + "]", "g");
|
let re = RegExp("[" + list + "]", "g");
|
||||||
return function (str) q + String.replace(str, re, function ($0, $1) $1 in quoteMap ? quoteMap[$1] : "\\" + $1) + q;
|
return function (str) q + String.replace(str, re, function ($0, $1) $1 in quoteMap ? quoteMap[$1] : "\\" + $1) + q;
|
||||||
}
|
}
|
||||||
|
const _quoteArg = { // FIXME
|
||||||
|
'"': ['"', quote("", '\n\t"\\\\'), '"'],
|
||||||
|
"'": ["'", quote("", "\\\\'"), "'"],
|
||||||
|
"": ["", quote("", "\\\\ "), ""]
|
||||||
|
};
|
||||||
const quoteArg = {
|
const quoteArg = {
|
||||||
'"': quote('"', '\n\t"\\\\'),
|
'"': quote('"', '\n\t"\\\\'),
|
||||||
"'": quote("'", "\\\\'"),
|
"'": quote("'", "\\\\'"),
|
||||||
@@ -474,7 +479,7 @@ function Commands() //{{{
|
|||||||
args.completeOpt = null;
|
args.completeOpt = null;
|
||||||
args.completeFilter = null;
|
args.completeFilter = null;
|
||||||
args.completeStart = i;
|
args.completeStart = i;
|
||||||
args.quote = quoteArg[""];
|
args.quote = _quoteArg[""];
|
||||||
}
|
}
|
||||||
if (complete)
|
if (complete)
|
||||||
{
|
{
|
||||||
@@ -549,7 +554,7 @@ function Commands() //{{{
|
|||||||
args.completeStart += optname.length + 1;
|
args.completeStart += optname.length + 1;
|
||||||
args.completeOpt = opt;
|
args.completeOpt = opt;
|
||||||
args.completeFilter = arg;
|
args.completeFilter = arg;
|
||||||
args.quote = quoteArg[quote] || quoteArg[""];
|
args.quote = _quoteArg[quote] || _quoteArg[""];
|
||||||
}
|
}
|
||||||
let type = argTypes[opt[1]];
|
let type = argTypes[opt[1]];
|
||||||
if (type)
|
if (type)
|
||||||
@@ -610,7 +615,10 @@ function Commands() //{{{
|
|||||||
// if not an option, treat this token as an argument
|
// if not an option, treat this token as an argument
|
||||||
var [count, arg, quote] = getNextArg(sub);
|
var [count, arg, quote] = getNextArg(sub);
|
||||||
if (complete)
|
if (complete)
|
||||||
args.quote = quoteArg[quote] || quoteArg[""];
|
{
|
||||||
|
args.quote = _quoteArg[quote] || _quoteArg[""];
|
||||||
|
args.completeFilter = arg || "";
|
||||||
|
}
|
||||||
else if (count == -1)
|
else if (count == -1)
|
||||||
{
|
{
|
||||||
liberator.echoerr("Error parsing arguments: " + arg);
|
liberator.echoerr("Error parsing arguments: " + arg);
|
||||||
@@ -644,14 +652,13 @@ function Commands() //{{{
|
|||||||
else
|
else
|
||||||
compl = opt[3] || [];
|
compl = opt[3] || [];
|
||||||
context.title = [opt[0][0]];
|
context.title = [opt[0][0]];
|
||||||
context.quote = ["", args.quote, ""]; // FIXME
|
context.quote = args.quote;
|
||||||
context.completions = compl;
|
context.completions = compl;
|
||||||
}
|
}
|
||||||
complete.advance(args.completeStart);
|
complete.advance(args.completeStart);
|
||||||
complete.title = ["Options"];
|
complete.title = ["Options"];
|
||||||
if (completeOpts)
|
if (completeOpts)
|
||||||
complete.completions = completeOpts;
|
complete.completions = completeOpts;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for correct number of arguments
|
// check for correct number of arguments
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ function CompletionContext(editor, name, offset)
|
|||||||
self.offset = parent.offset + (offset || 0);
|
self.offset = parent.offset + (offset || 0);
|
||||||
self.keys = util.cloneObject(parent.keys);
|
self.keys = util.cloneObject(parent.keys);
|
||||||
delete self._generate;
|
delete self._generate;
|
||||||
|
delete self._filter; // FIXME?
|
||||||
["anchored", "compare", "editor", "filterFunc", "keys", "_process", "quote", "title", "top"].forEach(function (key)
|
["anchored", "compare", "editor", "filterFunc", "keys", "_process", "quote", "title", "top"].forEach(function (key)
|
||||||
self[key] = parent[key]);
|
self[key] = parent[key]);
|
||||||
if (self != this)
|
if (self != this)
|
||||||
@@ -243,7 +244,9 @@ CompletionContext.prototype = {
|
|||||||
if (quote)
|
if (quote)
|
||||||
filtered.forEach(function (item) {
|
filtered.forEach(function (item) {
|
||||||
item.unquoted = item.text;
|
item.unquoted = item.text;
|
||||||
|
try {
|
||||||
item.text = quote[0] + quote[1](item.text) + quote[2];
|
item.text = quote[0] + quote[1](item.text) + quote[2];
|
||||||
|
} catch(e) { liberator.dump(quote.map(function (x) <>{util.objectToString(x)}</>)) }
|
||||||
})
|
})
|
||||||
if (options.get("wildoptions").has("sort"))
|
if (options.get("wildoptions").has("sort"))
|
||||||
filtered.sort(this.compare);
|
filtered.sort(this.compare);
|
||||||
@@ -309,6 +312,11 @@ CompletionContext.prototype = {
|
|||||||
advance: function advance(count)
|
advance: function advance(count)
|
||||||
{
|
{
|
||||||
this.offset += count;
|
this.offset += count;
|
||||||
|
if (this.quote)
|
||||||
|
{
|
||||||
|
this.quote[0] = "";
|
||||||
|
this.quote[2] = "";
|
||||||
|
}
|
||||||
// XXX
|
// XXX
|
||||||
if (this._filter)
|
if (this._filter)
|
||||||
this._filter = this._filter.substr(count);
|
this._filter = this._filter.substr(count);
|
||||||
@@ -1197,6 +1205,8 @@ function Completion() //{{{
|
|||||||
if (!args.completeOpt && command.completer)
|
if (!args.completeOpt && command.completer)
|
||||||
{
|
{
|
||||||
cmdContext.advance(args.completeStart);
|
cmdContext.advance(args.completeStart);
|
||||||
|
cmdContext.quote = args.quote;
|
||||||
|
cmdContext.filter = args.completeFilter;
|
||||||
compObject = command.completer.call(command, cmdContext, args, special, count);
|
compObject = command.completer.call(command, cmdContext, args, special, count);
|
||||||
if (compObject instanceof Array) // for now at least, let completion functions return arrays instead of objects
|
if (compObject instanceof Array) // for now at least, let completion functions return arrays instead of objects
|
||||||
compObject = { start: compObject[0], items: compObject[1] };
|
compObject = { start: compObject[0], items: compObject[1] };
|
||||||
|
|||||||
Reference in New Issue
Block a user