1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 15:27:58 +01:00

Rename 'array' class 'Ary'.

This commit is contained in:
Kris Maglione
2015-03-04 17:27:32 -08:00
parent 313fa1c333
commit d6543c6510
36 changed files with 239 additions and 232 deletions

View File

@@ -56,7 +56,7 @@ var Abbreviation = Class("Abbreviation", {
* @param {[Mode]} modes The modes to test.
* @returns {boolean} The result of the comparison.
*/
modesEqual: function (modes) array.equals(this.modes, modes),
modesEqual: function (modes) Ary.equals(this.modes, modes),
/**
* Returns true if this abbreviation is defined for *mode*.
@@ -91,7 +91,7 @@ var Abbreviation = Class("Abbreviation", {
get modeChar() Abbreviation.modeChar(this.modes)
}, {
modeChar: function (_modes) {
let result = array.uniq(_modes.map(m => m.char)).join("");
let result = Ary.uniq(_modes.map(m => m.char)).join("");
if (result == "ci")
result = "!";
return result;
@@ -352,7 +352,7 @@ var Abbreviations = Module("abbreviations", {
description: "Expand this abbreviation by evaluating its right-hand-side as JavaScript"
}
],
serialize: function () array(abbreviations.userHives)
serialize: function () Ary(abbreviations.userHives)
.filter(h => h.persist)
.map(hive => [
{

View File

@@ -23,7 +23,7 @@ var AutoCmdHive = Class("AutoCmdHive", Contexts.Hive, {
this._store = [];
},
"@@iterator": function () array.iterValues(this._store),
"@@iterator": function () this._store[Symbol.iterator](),
/**
* Adds a new autocommand. *cmd* will be executed when one of the specified

View File

@@ -437,9 +437,9 @@ var Bookmarks = Module("bookmarks", {
names: ["-tags", "-T"],
description: "A comma-separated list of tags",
completer: function tags(context, args) {
context.generate = function () array(b.tags
for (b in bookmarkcache)
if (b.tags))
context.generate = function () Ary(b.tags
for (b in bookmarkcache)
if (b.tags))
.flatten().uniq().array;
context.keys = { text: util.identity, description: util.identity };
},
@@ -593,7 +593,7 @@ var Bookmarks = Module("bookmarks", {
bang: true,
completer: function completer(context, args)
completion.bookmark(context, args["-tags"], { keyword: args["-keyword"], title: args["-title"] }),
domains: function (args) array.compact(args.map(util.getHost)),
domains: function (args) Ary.compact(args.map(util.getHost)),
literal: 0,
options: [tags, title, keyword],
privateData: true
@@ -758,8 +758,8 @@ var Bookmarks = Module("bookmarks", {
ctxt.cache.request = bookmarks.getSuggestions(name, ctxt.filter);
ctxt.cache.request.then(function (compl) {
ctxt.incomplete = false;
ctxt.completions = array.uniq(ctxt.completions.filter(c => ~compl.indexOf(c))
.concat(compl), true);
ctxt.completions = Ary.uniq(ctxt.completions.filter(c => ~compl.indexOf(c))
.concat(compl), true);
}).catch(function (e) {
ctxt.incomplete = false;
ctxt.completions = [];

View File

@@ -211,8 +211,8 @@ var Browser = Module("browser", XPCOM(Ci.nsISupportsWeakReference, ModuleBase),
function (args) { dactyl.open(args[0] || "about:blank"); },
{
completer: function (context) completion.url(context),
domains: function (args) array.compact(dactyl.parseURLs(args[0] || "")
.map(url => util.getHost(url))),
domains: function (args) Ary.compact(dactyl.parseURLs(args[0] || "")
.map(url => util.getHost(url))),
literal: 0,
privateData: true
});
@@ -229,7 +229,7 @@ var Browser = Module("browser", XPCOM(Ci.nsISupportsWeakReference, ModuleBase),
{ argCount: "0" });
},
mappings: function initMappings(dactyl, modules, window) {
let openModes = array.toObject([
let openModes = Ary.toObject([
[dactyl.CURRENT_TAB, ""],
[dactyl.NEW_TAB, "tab"],
[dactyl.NEW_BACKGROUND_TAB, "background tab"],

View File

@@ -1219,8 +1219,8 @@ var CommandLine = Module("commandline", {
get selected() this.itemList.selected,
set selected(tuple) {
if (!array.equals(tuple || [],
this.itemList.selected || []))
if (!Ary.equals(tuple || [],
this.itemList.selected || []))
this.itemList.select(tuple);
if (!tuple)

View File

@@ -235,7 +235,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
let name = commands.add(params.name, params.description,
function (args) {
let results = array(params.iterate(args))
let results = Ary(params.iterate(args))
.sort((a, b) => String.localeCompare(a.name, b.name));
let filters = args.map(arg => {
@@ -256,8 +256,8 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
context.keys.description = function () seen[this.text] + /*L*/" matching items";
context.ignoreCase = true;
let seen = {};
context.completions = array(keys(item).join(" ").toLowerCase().split(/[()\s]+/)
for (item of params.iterate(args)))
context.completions = Ary(keys(item).join(" ").toLowerCase().split(/[()\s]+/)
for (item of params.iterate(args)))
.flatten()
.map(function (k) {
seen[k] = (seen[k] || 0) + 1;
@@ -269,7 +269,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
if (params.index)
this.indices[params.index] = function* () {
let results = array((params.iterateIndex || params.iterate).call(params, commands.get(name).newArgs()))
let results = Ary((params.iterateIndex || params.iterate).call(params, commands.get(name).newArgs()))
.array.sort((a, b) => String.localeCompare(a.name, b.name));
for (let obj of values(results)) {
@@ -1403,8 +1403,8 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
"rb" + [k for ([k, v] of iter(groups[1].opts))
if (!Dactyl.toolbarHidden(document.getElementById(v[1][0])))].join(""),
values: array(groups).map(g => [[k, v[0]] for ([k, v] of iter(g.opts))])
.flatten(),
values: Ary(groups).map(g => [[k, v[0]] for ([k, v] of iter(g.opts))])
.flatten(),
setter: function (value) {
for (let group of values(groups))

View File

@@ -24,7 +24,7 @@ var EventHive = Class("EventHive", Contexts.Hive, {
_events: function _events(event, callback) {
if (!isObject(event))
var [self, events] = [null, array.toObject([[event, callback]])];
var [self, events] = [null, Ary.toObject([[event, callback]])];
else
[self, events] = [event, event[callback || "events"]];
@@ -1148,7 +1148,7 @@ var Events = Module("events", {
"sitemap", "", {
flush: function flush() {
memoize(this, "filters", function () this.value.filter(function (f) f(buffer.documentURI)));
memoize(this, "pass", function () new RealSet(array.flatten(this.filters.map(function (f) f.keys))));
memoize(this, "pass", function () new RealSet(Ary.flatten(this.filters.map(function (f) f.keys))));
memoize(this, "commandHive", function hive() Hive(this.filters, "command"));
memoize(this, "inputHive", function hive() Hive(this.filters, "input"));
},

View File

@@ -286,7 +286,7 @@ var HintSession = Class("HintSession", CommandMode, {
memoize(doc, "dactylLabels", () =>
iter([l.getAttribute("for"), l]
for (l of array.iterValues(doc.querySelectorAll("label[for]"))))
for (l of doc.querySelectorAll("label[for]")))
.toObject());
let [offsetX, offsetY] = this.getContainerOffsets(doc);
@@ -1362,7 +1362,7 @@ var Hints = Module("hints", {
},
validator: function (value) {
let values = DOM.Event.parse(value).map(DOM.Event.bound.stringify);
return Option.validIf(array.uniq(values).length === values.length && values.length > 1,
return Option.validIf(Ary.uniq(values).length === values.length && values.length > 1,
_("option.hintkeys.duplicate"));
}
});

View File

@@ -65,7 +65,7 @@ var History = Module("history", {
let obj = [];
obj.__defineGetter__("index", () => sh.index);
obj.__defineSetter__("index", function (val) { webNav.gotoIndex(val); });
obj[Symbol.iterator] = function () array.iterItems(this);
obj[Symbol.iterator] = function () this.entries();
for (let item of iter(sh.SHistoryEnumerator, Ci.nsISHEntry))
obj.push(update(Object.create(item), {
@@ -276,7 +276,7 @@ var History = Module("history", {
description: "The sort order of the results",
completer: function (context, args) {
context.compare = CompletionContext.Sort.unsorted;
return array.flatten([
return Ary.flatten([
"annotation",
"date",
"date added",

View File

@@ -17,7 +17,7 @@ var ProcessorStack = Class("ProcessorStack", {
events.dbg("STACK " + mode);
let main = { __proto__: mode.main, params: mode.params };
this.modes = array([mode.params.keyModes, main, mode.main.allBases.slice(1)]).flatten().compact();
this.modes = Ary([mode.params.keyModes, main, mode.main.allBases.slice(1)]).flatten().compact();
if (builtin)
hives = hives.filter(h => h.name === "builtin");

View File

@@ -1,6 +1,6 @@
// Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
// Copyright (c) 2008-2014 Kris Maglione <maglione.k at Gmail>
// Copyright (c) 2008-2015 Kris Maglione <maglione.k at Gmail>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
@@ -107,7 +107,7 @@ var Map = Class("Map", {
*/
hasName: function (name) this.keys.indexOf(name) >= 0,
get keys() array.flatten(this.names.map(mappings.bound.expand)),
get keys() Ary.flatten(this.names.map(mappings.bound.expand)),
/**
* Execute the action for this mapping.
@@ -284,7 +284,7 @@ var MapHive = Class("MapHive", Contexts.Hive, {
return self;
},
"@@iterator": function () array.iterValues(this),
"@@iterator": function () Ary.iterValues(this),
get candidates() this.states.candidates,
get mappings() this.states.mappings,
@@ -367,12 +367,16 @@ var Mappings = Module("mappings", {
expand: function expand(keys) {
if (!/<\*-/.test(keys))
var res = keys;
else
res = util.debrace(DOM.Event.iterKeys(keys).map(function (key) {
else {
let globbed = DOM.Event.iterKeys(keys)
.map(key => {
if (/^<\*-/.test(key))
return ["<", this.prefixes, key.slice(3)];
return key;
}, this).flatten().array).map(k => DOM.Event.canonicalKeys(k));
}).flatten().array;
res = util.debrace(globbed).map(k => DOM.Event.canonicalKeys(k));
}
if (keys != arguments[0])
return [arguments[0]].concat(keys);
@@ -382,7 +386,7 @@ var Mappings = Module("mappings", {
iterate: function* (mode) {
let seen = new RealSet;
for (let hive of this.hives.iterValues())
for (let map of array(hive.getStack(mode)).iterValues())
for (let map of Ary.iterValues(hive.getStack(mode)))
if (!seen.add(map.name))
yield map;
},
@@ -521,7 +525,7 @@ var Mappings = Module("mappings", {
commands: function initCommands(dactyl, modules, window) {
function addMapCommands(ch, mapmodes, modeDescription) {
function map(args, noremap) {
let mapmodes = array.uniq(args["-modes"].map(findMode));
let mapmodes = Ary.uniq(args["-modes"].map(findMode));
let hives = args.explicitOpts["-group"] ? [args["-group"]] : null;
if (!args.length) {
@@ -561,7 +565,7 @@ var Mappings = Module("mappings", {
const opts = {
identifier: "map",
completer: function (context, args) {
let mapmodes = array.uniq(args["-modes"].map(findMode));
let mapmodes = Ary.uniq(args["-modes"].map(findMode));
if (args.length == 1)
return completion.userMapping(context, mapmodes, args["-group"]);
if (args.length == 2) {
@@ -618,7 +622,7 @@ var Mappings = Module("mappings", {
],
serialize: function () {
return this.name != "map" ? [] :
array(mappings.userHives)
Ary(mappings.userHives)
.filter(h => h.persist)
.map(hive => [
{
@@ -643,7 +647,7 @@ var Mappings = Module("mappings", {
function* userMappings(hive) {
let seen = new RealSet;
for (let stack of values(hive.stacks))
for (let map of array.iterValues(stack))
for (let map of Ary.iterValues(stack))
if (!seen.add(map.id))
yield map;
}
@@ -666,7 +670,7 @@ var Mappings = Module("mappings", {
util.assert(args.bang ^ !!args[0], _("error.argumentOrBang"));
let mapmodes = array.uniq(args["-modes"].map(findMode));
let mapmodes = Ary.uniq(args["-modes"].map(findMode));
let found = 0;
for (let mode of values(mapmodes))
@@ -701,7 +705,7 @@ var Mappings = Module("mappings", {
names: ["-mode", "-m"],
type: CommandOption.STRING,
validator: function (value) Array.concat(value).every(findMode),
completer: function () [[array.compact([mode.name.toLowerCase().replace(/_/g, "-"), mode.char]), mode.description]
completer: function () [[Ary.compact([mode.name.toLowerCase().replace(/_/g, "-"), mode.char]), mode.description]
for (mode of values(modes.all))
if (!mode.hidden)]
};
@@ -718,9 +722,9 @@ var Mappings = Module("mappings", {
let chars = [k for ([k, v] of iter(modules.modes.modeChars))
if (v.every(mode => modes.indexOf(mode) >= 0))];
return array.uniq(modes.filter(m => chars.indexOf(m.char) < 0)
.map(m => m.name.toLowerCase())
.concat(chars));
return Ary.uniq(modes.filter(m => chars.indexOf(m.char) < 0)
.map(m => m.name.toLowerCase())
.concat(chars));
}
commands.add(["feedkeys", "fk"],
@@ -756,7 +760,7 @@ var Mappings = Module("mappings", {
// Bloody hell. --Kris
for (let [i, mode] of iter(modes))
for (let hive of mappings.hives.iterValues())
for (let map of array.iterValues(hive.getStack(mode)))
for (let map of Ary.iterValues(hive.getStack(mode)))
for (let name of values(map.names))
if (!seen.add(name))
yield {
@@ -779,7 +783,7 @@ var Mappings = Module("mappings", {
template.linkifyHelp(map.description + (map.rhs ? ": " + map.rhs : ""))
],
help: function (map) {
let char = array.compact(map.modes.map(m => m.char))[0];
let char = Ary.compact(map.modes.map(m => m.char))[0];
return char === "n" ? map.name : char ? char + "_" + map.name : "";
},
headings: ["Command", "Mode", "Group", "Description"]

View File

@@ -198,12 +198,12 @@ var Marks = Module("marks", {
this._pendingJumps.push(mark);
let sh = tab.linkedBrowser.sessionHistory;
let items = array(util.range(0, sh.count));
let items = Ary(util.range(0, sh.count));
let a = items.slice(0, sh.index).reverse();
let b = items.slice(sh.index);
a.length = b.length = Math.max(a.length, b.length);
items = array(a).zip(b).flatten().compact();
items = Ary(a).zip(b).flatten().compact();
for (let i of items.iterValues()) {
let entry = sh.getEntryAtIndex(i, false);

View File

@@ -194,7 +194,7 @@ var Modes = Module("modes", {
NONE: 0,
"@@iterator": function __iterator__() array.iterValues(this.all),
"@@iterator": function __iterator__() Ary.iterValues(this.all),
get all() this._modes.slice(),
@@ -238,7 +238,7 @@ var Modes = Module("modes", {
dumpStack: function dumpStack() {
util.dump("Mode stack:");
for (let [i, mode] of array.iterItems(this._modeStack))
for (let [i, mode] of Ary.iterItems(this._modeStack))
util.dump(" " + i + ": " + mode);
},
@@ -285,7 +285,7 @@ var Modes = Module("modes", {
save: function save(id, obj, prop, test) {
if (!(id in this.boundProperties))
for (let elem of array.iterValues(this._modeStack))
for (let elem of Ary.iterValues(this._modeStack))
elem.saved[id] = { obj: obj, prop: prop, value: obj[prop], test: test };
this.boundProperties[id] = { obj: util.weakReference(obj), prop: prop, test: test };
},
@@ -447,7 +447,7 @@ var Modes = Module("modes", {
let seen = new RealSet,
res = [],
queue = [this].concat(this.bases);
for (let mode of array.iterValues(queue))
for (let mode of queue)
if (!seen.add(mode)) {
res.push(mode);
apply(queue, "push", mode.bases);
@@ -633,8 +633,8 @@ var Modes = Module("modes", {
validator: function validator(vals) vals.map(v => v.replace(/^!/, ""))
.every(k => hasOwnProperty(this.values, k)),
get values() array.toObject([[m.name.toLowerCase(), m.description]
for (m of values(modes._modes)) if (!m.hidden)])
get values() Ary.toObject([[m.name.toLowerCase(), m.description]
for (m of values(modes._modes)) if (!m.hidden)])
};
options.add(["passunknown", "pu"],

View File

@@ -201,7 +201,7 @@ var MOW = Module("mow", {
selection: !window.document.commandDispatcher.focusedWindow.getSelection().isCollapsed
};
for (let node of array.iterValues(menu.children)) {
for (let node of menu.children) {
let group = node.getAttributeNS(NS, "group");
node.hidden = group && !group.split(/\s+/).every(g => enabled[g]);
}