mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-16 15:05:46 +01:00
Move iteration utility functions to the iter namespace.
This commit is contained in:
@@ -13,12 +13,13 @@ var Bookmarks = Module("bookmarks", {
|
||||
init: function () {
|
||||
storage.addObserver("bookmark-cache", function (key, event, arg) {
|
||||
if (["add", "change", "remove"].indexOf(event) >= 0)
|
||||
autocommands.trigger("Bookmark" + event[0].toUpperCase() + event.substr(1), iterAll({
|
||||
bookmark: {
|
||||
toString: function () "bookmarkcache.bookmarks[" + arg.id + "]",
|
||||
valueOf: function () arg
|
||||
}
|
||||
}, arg));
|
||||
autocommands.trigger("Bookmark" + event[0].toUpperCase() + event.substr(1),
|
||||
iter({
|
||||
bookmark: {
|
||||
toString: function () "bookmarkcache.bookmarks[" + arg.id + "]",
|
||||
valueOf: function () arg
|
||||
}
|
||||
}, arg));
|
||||
statusline.updateUrl();
|
||||
}, window);
|
||||
},
|
||||
@@ -195,7 +196,7 @@ var Bookmarks = Module("bookmarks", {
|
||||
get searchEngines() {
|
||||
let searchEngines = [];
|
||||
let aliases = {};
|
||||
return array.toObject(services.browserSearch.getVisibleEngines({}).map(function (engine) {
|
||||
return array(services.browserSearch.getVisibleEngines({})).map(function (engine) {
|
||||
let alias = engine.alias;
|
||||
if (!alias || !/^[a-z_-]+$/.test(alias))
|
||||
alias = engine.name.replace(/^\W*([a-zA-Z_-]+).*/, "$1").toLowerCase();
|
||||
@@ -208,7 +209,7 @@ var Bookmarks = Module("bookmarks", {
|
||||
aliases[alias] = 0;
|
||||
|
||||
return [alias, { keyword: alias, __proto__: engine, title: engine.description, icon: engine.iconURI && engine.iconURI.spec }];
|
||||
}));
|
||||
}).toObject();
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -579,7 +580,7 @@ var Bookmarks = Module("bookmarks", {
|
||||
completion.bookmark = function bookmark(context, tags, extra) {
|
||||
context.title = ["Bookmark", "Title"];
|
||||
context.format = bookmarks.format;
|
||||
forEach(iter(extra || {}), function ([k, v]) {
|
||||
iter(extra || {}).forEach(function ([k, v]) {
|
||||
if (v != null)
|
||||
context.filters.push(function (item) item.item[k] != null && this.matchString(v, item.item[k]));
|
||||
});
|
||||
@@ -593,7 +594,7 @@ var Bookmarks = Module("bookmarks", {
|
||||
let engines = bookmarks.searchEngines;
|
||||
|
||||
context.title = ["Search Keywords"];
|
||||
context.completions = iterAll(values(keywords), values(engines));
|
||||
context.completions = iter(values(keywords), values(engines));
|
||||
context.keys = { text: "keyword", description: "title", icon: "icon" };
|
||||
|
||||
if (!space || noSuggest)
|
||||
|
||||
@@ -1440,7 +1440,7 @@ var Buffer = Module("buffer", {
|
||||
context.title = ["Stylesheet", "Location"];
|
||||
|
||||
// unify split style sheets
|
||||
let styles = array.toObject([[s.title, []] for (s in values(buffer.alternateStyleSheets))]);
|
||||
let styles = iter([s.title, []] for (s in values(buffer.alternateStyleSheets))).toObject();
|
||||
|
||||
buffer.alternateStyleSheets.forEach(function (style) {
|
||||
styles[style.title].push(style.href || "inline");
|
||||
@@ -1477,7 +1477,7 @@ var Buffer = Module("buffer", {
|
||||
context.fork(id, 0, this, function (context, [name, browsers]) {
|
||||
context.title = [name || "Buffers"];
|
||||
context.generate = function ()
|
||||
util.map(array.iterValues(browsers), function ([i, browser]) {
|
||||
Array.map(browsers, function ([i, browser]) {
|
||||
let indicator = " ";
|
||||
if (i == tabs.index())
|
||||
indicator = "%";
|
||||
|
||||
@@ -114,7 +114,7 @@ var Command = Class("Command", {
|
||||
let parsedSpecs = Command.parseSpecs(specs);
|
||||
|
||||
this.specs = specs;
|
||||
this.shortNames = array(parsedSpecs).map(function (n) n[1]).compact();
|
||||
this.shortNames = array.compact(parsedSpecs.map(function (n) n[1]));
|
||||
this.longNames = parsedSpecs.map(function (n) n[0]);
|
||||
this.name = this.longNames[0];
|
||||
this.names = array(parsedSpecs).flatten();
|
||||
@@ -321,12 +321,12 @@ var Command = Class("Command", {
|
||||
|
||||
if (callable(params))
|
||||
function makeParams(self, args)
|
||||
array.toObject([[k, process(v)]
|
||||
for ([k, v] in iter(params.apply(self, args)))])
|
||||
iter.toObject([k, process(v)]
|
||||
for ([k, v] in iter(params.apply(self, args))))
|
||||
else if (params)
|
||||
function makeParams(self, args)
|
||||
array.toObject([[name, process(args[i])]
|
||||
for ([i, name] in Iterator(params))]);
|
||||
iter.toObject([name, process(args[i])]
|
||||
for ([i, name] in Iterator(params)));
|
||||
|
||||
let rhs = args.literalArg;
|
||||
let type = ["-builtin", "-ex", "-javascript", "-keys"].reduce(function (a, b) args[b] ? b : a, default_);
|
||||
@@ -551,8 +551,8 @@ var Commands = Module("commands", {
|
||||
let str = args.literalArg;
|
||||
if (str)
|
||||
res.push(!/\n/.test(str) ? str :
|
||||
this.hereDoc ? "<<EOF\n" + String.replace(str, /\n$/, "") + "\nEOF"
|
||||
: String.replace(str, /\n/, "\n" + res[0].replace(/./g, " ").replace(/.$/, "\\")));
|
||||
this.hereDoc && false ? "<<EOF\n" + String.replace(str, /\n$/, "") + "\nEOF"
|
||||
: String.replace(str, /\n/, "\n" + res[0].replace(/./g, " ").replace(/.$/, "\\")));
|
||||
return res.join(" ");
|
||||
},
|
||||
|
||||
@@ -1397,11 +1397,15 @@ var Commands = Module("commands", {
|
||||
serialize: function () [ {
|
||||
command: this.name,
|
||||
bang: true,
|
||||
options: array.toObject(
|
||||
[[v, typeof cmd[k] == "boolean" ? null : cmd[k]]
|
||||
// FIXME: this map is expressed multiple times
|
||||
for ([k, v] in Iterator({ argCount: "-nargs", bang: "-bang", count: "-count", description: "-description" }))
|
||||
if (cmd[k])]),
|
||||
options: iter([v, typeof cmd[k] == "boolean" ? null : cmd[k]]
|
||||
// FIXME: this map is expressed multiple times
|
||||
for ([k, v] in Iterator({
|
||||
argCount: "-nargs",
|
||||
bang: "-bang",
|
||||
count: "-count",
|
||||
description: "-description"
|
||||
}))
|
||||
if (cmd[k])).toObject(),
|
||||
arguments: [cmd.name],
|
||||
literalArg: cmd.action,
|
||||
ignoreDefaults: true
|
||||
|
||||
@@ -333,7 +333,7 @@ var CompletionContext = Class("CompletionContext", {
|
||||
yield ["result", quote ? function () quote[0] + quote[1](this.text) + quote[2]
|
||||
: function () this.text];
|
||||
};
|
||||
for (let i in iterAll(this.keys, result(this.quote))) {
|
||||
for (let i in iter(this.keys, result(this.quote))) {
|
||||
let [k, v] = i;
|
||||
if (typeof v == "string" && /^[.[]/.test(v))
|
||||
// This is only allowed to be a simple accessor, and shouldn't
|
||||
@@ -609,7 +609,7 @@ var CompletionContext = Class("CompletionContext", {
|
||||
let step = start > end ? -1 : 1;
|
||||
start = Math.max(0, start || 0);
|
||||
end = Math.min(items.length, end ? end : items.length);
|
||||
return util.map(util.range(start, end, step), function (i) items[i]);
|
||||
return iter.map(util.range(start, end, step), function (i) items[i]);
|
||||
},
|
||||
|
||||
getRows: function getRows(start, end, doc) {
|
||||
|
||||
@@ -577,7 +577,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
||||
// Find the tags in the document.
|
||||
function addTags(file, doc) {
|
||||
for (let elem in util.evaluateXPath("//@tag|//dactyl:tags/text()|//dactyl:tag/text()", doc))
|
||||
for (let tag in array((elem.value || elem.textContent).split(/\s+/)).compact().iterValues())
|
||||
for (let tag in values((elem.value || elem.textContent).split(/\s+/)))
|
||||
tagMap[tag] = file;
|
||||
}
|
||||
|
||||
@@ -1285,14 +1285,6 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
||||
let items = [];
|
||||
addChildren(document.getElementById(config.guioptions["m"][1]), "");
|
||||
return items;
|
||||
},
|
||||
|
||||
// show a usage index either in the MOW or as a full help page
|
||||
showHelpIndex: function (tag, items, inMow) {
|
||||
if (inMow)
|
||||
commandline.commandOutput(template.usage(array(items).sort(function (a, b) String.localeCompare(a.name, b.name))));
|
||||
else
|
||||
dactyl.help(tag);
|
||||
}
|
||||
}, {
|
||||
// Only general options are added here, which are valid for all Dactyl extensions
|
||||
|
||||
@@ -36,14 +36,14 @@ var History = Module("history", {
|
||||
// execute the query
|
||||
let root = services.history.executeQuery(query, options).root;
|
||||
root.containerOpen = true;
|
||||
let items = util.map(util.range(0, root.childCount), function (i) {
|
||||
let items = iter(util.range(0, root.childCount)).map(function (i) {
|
||||
let node = root.getChild(i);
|
||||
return {
|
||||
url: node.uri,
|
||||
title: node.title,
|
||||
icon: node.icon ? node.icon.spec : DEFAULT_FAVICON
|
||||
};
|
||||
});
|
||||
}).toArray();
|
||||
root.containerOpen = false; // close a container after using it!
|
||||
|
||||
return items;
|
||||
|
||||
@@ -466,7 +466,7 @@ var IO = Module("io", {
|
||||
* otherwise, the return value of *func*.
|
||||
*/
|
||||
withTempFiles: function (func, self, checked) {
|
||||
let args = util.map(util.range(0, func.length), this.createTempFile);
|
||||
let args = array(util.range(0, func.length)).map(this.createTempFile);
|
||||
try {
|
||||
if (!args.every(util.identity))
|
||||
return false;
|
||||
@@ -688,7 +688,7 @@ unlet s:cpo_save
|
||||
let lines = [];
|
||||
lines.__defineGetter__("last", function () this[this.length - 1]);
|
||||
|
||||
for (let item in (isArray(items) ? array.iterValues : iter)(items)) {
|
||||
for (let item in values(items.array || items)) {
|
||||
if (item.length > width && (!lines.length || lines.last.length > 1)) {
|
||||
lines.push([prefix]);
|
||||
width = WIDTH - prefix.length;
|
||||
|
||||
@@ -34,13 +34,13 @@ var JavaScript = Module("javascript", {
|
||||
return undefined;
|
||||
},
|
||||
|
||||
iter: function iter(obj, toplevel) {
|
||||
iter: function iter_(obj, toplevel) {
|
||||
if (obj == null)
|
||||
return;
|
||||
|
||||
let seen = isinstance(obj, ["Sandbox"]) ? set(JavaScript.magicalNames) : {};
|
||||
let globals = values(toplevel && window === obj ? JavaScript.globalNames : []);
|
||||
for (let key in iterAll(globals, properties(obj, !toplevel, true)))
|
||||
for (let key in iter(globals, properties(obj, !toplevel, true)))
|
||||
if (!set.add(seen, key))
|
||||
yield key;
|
||||
|
||||
|
||||
@@ -37,13 +37,17 @@ var Map = Class("Map", {
|
||||
|
||||
this.id = ++Map.id;
|
||||
this.modes = modes;
|
||||
this.names = keys.map(events.canonicalKeys);
|
||||
this.names = keys.map(events.closure.canonicalKeys);
|
||||
this._keys = keys;
|
||||
this.name = this.names[0];
|
||||
this.action = action;
|
||||
this.description = description;
|
||||
if (Object.freeze)
|
||||
Object.freeze(this.modes);
|
||||
|
||||
if (extraInfo)
|
||||
update(this, extraInfo);
|
||||
util.dump("\n\n\n", this.name, extraInfo);
|
||||
},
|
||||
|
||||
/** @property {number[]} All of the modes for which this mapping applies. */
|
||||
@@ -160,13 +164,12 @@ var Mappings = Module("mappings", {
|
||||
let names;
|
||||
|
||||
for (let [i, map] in Iterator(maps)) {
|
||||
for (let [j, name] in Iterator(map.names)) {
|
||||
if (name == cmd) {
|
||||
map.names.splice(j, 1);
|
||||
if (map.names.length == 0)
|
||||
maps.splice(i, 1);
|
||||
return;
|
||||
}
|
||||
let j = map.names.indexOf(cmd);
|
||||
if (j >= 0) {
|
||||
map.names.splice(j, 1);
|
||||
if (map.names.length == 0)
|
||||
maps.splice(i, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -183,7 +186,7 @@ var Mappings = Module("mappings", {
|
||||
|
||||
iterate: function (mode) {
|
||||
let seen = {};
|
||||
for (let map in iterAll(values(this._user[mode]), values(this._main[mode])))
|
||||
for (let map in iter(values(this._user[mode]), values(this._main[mode])))
|
||||
if (!set.add(seen, map.name))
|
||||
yield map;
|
||||
},
|
||||
@@ -448,6 +451,7 @@ var Mappings = Module("mappings", {
|
||||
] : [];
|
||||
}
|
||||
};
|
||||
window.userMappings = userMappings;
|
||||
function userMappings() {
|
||||
let seen = {};
|
||||
for (let [, stack] in Iterator(mappings._user))
|
||||
@@ -579,7 +583,7 @@ var Mappings = Module("mappings", {
|
||||
]
|
||||
});
|
||||
|
||||
forEach(modes.mainModes, function (mode) {
|
||||
iter.forEach(modes.mainModes, function (mode) {
|
||||
if (mode.char && !commands.get(mode.char + "listkeys", true))
|
||||
dactyl.addUsageCommand({
|
||||
__proto__: args,
|
||||
|
||||
@@ -29,12 +29,9 @@ var Marks = Module("marks", {
|
||||
* @property {Array} Returns all marks, both local and URL, in a sorted
|
||||
* array.
|
||||
*/
|
||||
get all() {
|
||||
let lmarks = array(Iterator(this._localMarks.get(this.localURI) || {}));
|
||||
let umarks = array(Iterator(this._urlMarks)).array;
|
||||
|
||||
return lmarks.concat(umarks).sort(function (a, b) String.localeCompare(a[0], b[0]));
|
||||
},
|
||||
get all() iter(this._localMarks.get(this.localURI) || {},
|
||||
this._urlMarks
|
||||
).sort(function (a, b) String.localeCompare(a[0], b[0])),
|
||||
|
||||
get localURI() buffer.focusedFrame.document.documentURI,
|
||||
|
||||
|
||||
@@ -459,7 +459,7 @@ var Option = Class("Option", {
|
||||
testValues: {
|
||||
regexpmap: function (vals, validator) vals.every(function (re) validator(re.result)),
|
||||
stringlist: function (vals, validator) vals.every(validator, this),
|
||||
stringmap: function (vals, validator) array(values(vals)).every(validator, this)
|
||||
stringmap: function (vals, validator) values(vals).every(validator, this)
|
||||
},
|
||||
|
||||
dequote: function (value) {
|
||||
|
||||
Reference in New Issue
Block a user