1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 10:47:58 +01:00

Complete :bmarkgit diff properly

This commit is contained in:
Kris Maglione
2008-12-05 08:45:43 -05:00
parent d81fdddb7b
commit d5439d0bdc
3 changed files with 54 additions and 9 deletions

View File

@@ -143,7 +143,7 @@ Command.prototype = {
return false;
},
parseArgs: function (args, complete) commands.parseArgs(args, this.options, this.argCount, false, this.literal, complete)
parseArgs: function (args, complete, extra) commands.parseArgs(args, this.options, this.argCount, false, this.literal, complete, extra)
}; //}}}
@@ -319,7 +319,7 @@ function Commands() //{{{
// @param allowUnknownOptions: -foo won't result in an error, if -foo isn't
// specified in "options"
// TODO: should it handle comments?
parseArgs: function (str, options, argCount, allowUnknownOptions, literal, complete)
parseArgs: function (str, options, argCount, allowUnknownOptions, literal, complete, extra)
{
// returns [count, parsed_argument]
function getNextArg(str)
@@ -421,6 +421,10 @@ function Commands() //{{{
args.string = str; // for access to the unparsed string
args.literalArg = "";
// FIXME!
for (let [k, v] in Iterator(extra || []))
args[k] = v;
var invalid = false;
// FIXME: best way to specify these requirements?
var onlyArgumentsRemaining = allowUnknownOptions || options.length == 0 || false; // after a -- has been found

View File

@@ -452,9 +452,9 @@ CompletionContext.prototype = {
catch (e) {}
},
match: function match(str)
// FIXME
_match: function _match(filter, str)
{
let filter = this.filter;
if (this.ignoreCase)
{
filter = filter.toLowerCase();
@@ -465,6 +465,11 @@ CompletionContext.prototype = {
return str.indexOf(filter) > -1;
},
match: function match(str)
{
return this._match(this.filter, str);
},
reset: function reset()
{
let self = this;
@@ -1172,10 +1177,16 @@ function Completion() //{{{
context.completions = config.autocommands;
},
bookmark: function bookmark(context, tags)
bookmark: function bookmark(context, tags, extra)
{
context.title = ["Bookmark", "Title"];
context.format = bookmarks.format;
for (let val in Iterator(extra || []))
{
let [k, v] = val; // Need let block here for closure.
if (v)
context.filters.push(function (item) this._match(v, this.getKey(item, k)));
}
// Need to make a copy because set completions() checks instanceof Array,
// and this may be an Array from another window.
context.completions = Array.slice(storage["bookmark-cache"].bookmarks);
@@ -1279,7 +1290,7 @@ function Completion() //{{{
[prefix] = context.filter.match(/^(?:\w*[\s!]|!)\s*/);
let cmdContext = context.fork(cmd, prefix.length);
let argContext = context.fork("args", prefix.length);
args = command.parseArgs(cmdContext.filter, argContext);
args = command.parseArgs(cmdContext.filter, argContext, { count: count, bang: bang });
if (args)
{
// FIXME: Move to parseCommand

View File

@@ -278,16 +278,37 @@ function Bookmarks() //{{{
},
{ argCount: "0" });
// TODO: Clean this up.
function tags(context, args)
{
let filter = context.filter;
let have = filter.split(",");
args.completeFilter = have.pop();
let prefix = filter.substr(0, filter.length - args.completeFilter.length);
let tags = util.Array.uniq(util.Array.flatten([b.tags for ([k, b] in Iterator(cache.bookmarks))]));
return [[prefix + tag, tag] for ([i, tag] in Iterator(tags)) if (have.indexOf(tag) < 0)];
}
function title(context, args)
{
if (!args.bang)
return [[content.document.title, "Current Page Title"]];
context.keys.text = "title";
context.keys.description = "url";
return bookmarks.get(args.join(" "), args["-tags"], null, { keyword: args["-keyword"], title: context.filter });
}
function keyword(context, args)
{
if (!args.bang)
return [];
context.keys.text = "keyword";
return bookmarks.get(args.join(" "), args["-tags"], null, { keyword: context.filter, title: args["-title"] });
}
commands.add(["bma[rk]"],
"Add a bookmark",
function (args)
@@ -308,7 +329,16 @@ function Bookmarks() //{{{
{
argCount: "?",
bang: true,
options: [[["-title", "-t"], commands.OPTION_STRING, null, function () [[content.document.title, "Current Page Title"]]],
completer: function (context, args)
{
if (!args.bang)
{
context.completions = [[content.document.documentURI, "Current Location"]];
return
}
completion.bookmark(context, args["-tags"], { keyword: args["-keyword"], title: args["-title"] });
},
options: [[["-title", "-t"], commands.OPTION_STRING, null, title],
[["-tags", "-T"], commands.OPTION_LIST, null, tags],
[["-keyword", "-k"], commands.OPTION_STRING, function (arg) /\w/.test(arg)]]
});
@@ -361,9 +391,9 @@ function Bookmarks() //{{{
// if "bypassCache" is true, it will force a reload of the bookmarks database
// on my PC, it takes about 1ms for each bookmark to load, so loading 1000 bookmarks
// takes about 1 sec
get: function get(filter, tags, maxItems)
get: function get(filter, tags, maxItems, extra)
{
return completion.runCompleter("bookmark", filter, maxItems, tags);
return completion.runCompleter("bookmark", filter, maxItems, tags, extra);
},
// if starOnly = true it is saved in the unfiledBookmarksFolder, otherwise in the bookmarksMenuFolder