1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-19 23:57:59 +01:00

General cleanup related to last commit.

This commit is contained in:
Kris Maglione
2009-04-15 16:31:32 -04:00
parent df5b66d838
commit f3f70d5cb8
9 changed files with 129 additions and 119 deletions

View File

@@ -101,7 +101,7 @@ function Buffer() //{{{
if (win.scrollMaxX > 0 || win.scrollMaxY > 0) if (win.scrollMaxX > 0 || win.scrollMaxY > 0)
return win; return win;
for (let frame in util.Array.iterator(win.frames)) for (let frame in util.Array.itervalues(win.frames))
if (frame.scrollMaxX > 0 || frame.scrollMaxY > 0) if (frame.scrollMaxX > 0 || frame.scrollMaxY > 0)
return frame; return frame;
@@ -174,17 +174,7 @@ function Buffer() //{{{
} }
catch (e) { liberator.reportError(e) } catch (e) { liberator.reportError(e) }
}, },
completer: function(context) { completer: function(context) completion.charset(context)
context.anchored = false;
context.generate = function() {
let names = util.Array.uniq(
util.Array.flatten(
'more1 more2 more3 more4 more5 unicode'.split(' ').map(function(key)
options.getPref('intl.charsetmenu.browser.' + key).split(', '))));
let bundle = document.getElementById('liberator-charset-bundle');
return names.map(function(name) [name, bundle.getString(name.toLowerCase() + '.title')])
};
}
}); });
// FIXME: Most certainly belongs elsewhere. // FIXME: Most certainly belongs elsewhere.
@@ -803,7 +793,7 @@ function Buffer() //{{{
const ACCESS_READ = Ci.nsICache.ACCESS_READ; const ACCESS_READ = Ci.nsICache.ACCESS_READ;
let cacheKey = doc.location.toString().replace(/#.*$/, ""); let cacheKey = doc.location.toString().replace(/#.*$/, "");
for (let proto in util.Array.iterator(["HTTP", "FTP"])) for (let proto in util.Array.itervalues(["HTTP", "FTP"]))
{ {
try try
{ {

View File

@@ -324,7 +324,7 @@ function Commands() //{{{
__iterator__: function () __iterator__: function ()
{ {
let sorted = exCommands.sort(function (a, b) a.name > b.name); let sorted = exCommands.sort(function (a, b) a.name > b.name);
return util.Array.iterator(sorted); return util.Array.itervalues(sorted);
}, },
add: function (names, description, action, extra) add: function (names, description, action, extra)
@@ -480,7 +480,7 @@ function Commands() //{{{
argCount = "*"; argCount = "*";
var args = []; // parsed options var args = []; // parsed options
args.__iterator__ = function () util.Array.iterator2(this); args.__iterator__ = function () util.Array.iteritems(this);
args.string = str; // for access to the unparsed string args.string = str; // for access to the unparsed string
args.literalArg = ""; args.literalArg = "";
@@ -919,12 +919,10 @@ function Commands() //{{{
{ {
command: this.name, command: this.name,
bang: true, bang: true,
// Yeah, this is a bit scary. Perhaps I'll fix it when I'm options: util.Array.toObject(
// awake. [[v, typeof cmd[k] == "boolean" ? null : cmd[k]]
options: util.Array.assocToObj( for ([k, v] in Iterator({ argCount: "-nargs", bang: "-bang", count: "-count" }))
util.map({ argCount: "-nargs", bang: "-bang", count: "-count" }, if (k in cmd && cmd[k] != "0")]),
function ([k, v]) k in cmd && cmd[k] != "0" && [v, typeof cmd[k] == "boolean" ? null : cmd[k]])
.filter(util.identity)),
arguments: [cmd.name], arguments: [cmd.name],
literalArg: cmd.replacementText literalArg: cmd.replacementText
} }

View File

@@ -291,7 +291,7 @@ CompletionContext.prototype = {
set completions(items) set completions(items)
{ {
// Accept a generator // Accept a generator
if (!("length" in items)) if ({}.toString.call(items) != '[object Array]')
items = [x for (x in Iterator(items))]; items = [x for (x in Iterator(items))];
delete this.cache.filtered; delete this.cache.filtered;
delete this.cache.filter; delete this.cache.filter;
@@ -1454,6 +1454,18 @@ function Completion() //{{{
}); });
}, },
charset: function(context) {
context.anchored = false;
context.generate = function() {
let names = util.Array(
'more1 more2 more3 more4 more5 unicode'.split(' ').map(function(key)
options.getPref('intl.charsetmenu.browser.' + key).split(', ')))
.flatten().uniq();
let bundle = document.getElementById('liberator-charset-bundle');
return names.map(function(name) [name, bundle.getString(name.toLowerCase() + '.title')]);
};
},
colorScheme: function colorScheme(context) colorScheme: function colorScheme(context)
{ {
let colors = []; let colors = [];

View File

@@ -180,7 +180,7 @@ function AutoCommands() //{{{
return { return {
__iterator__: function () util.Array.iterator(store), __iterator__: function () util.Array.itervalues(store),
/** /**
* Adds a new autocommand. <b>cmd</b> will be executed when one of the * Adds a new autocommand. <b>cmd</b> will be executed when one of the

View File

@@ -129,7 +129,7 @@ const modes = (function () //{{{
NONE: 0, NONE: 0,
__iterator__: function () util.Array.iterator(this.all), __iterator__: function () util.Array.itervalues(this.all),
get all() mainModes.slice(), get all() mainModes.slice(),

View File

@@ -488,10 +488,10 @@ function Styles(name, store, serial)
return namespace + "@-moz-document " + selectors + "{\n" + css + "\n}\n"; return namespace + "@-moz-document " + selectors + "{\n" + css + "\n}\n";
} }
} }
let (array = util.Array) let (array = utiltte.Array)
{ {
Styles.prototype = { Styles.prototype = {
get sites() array.uniq(array.flatten([v.sites for ([k, v] in this.userSheets)])), get sites() array([v.sites for ([k, v] in this.userSheets)]).flatten().uniq(),
completeSite: function (context, content) completeSite: function (context, content)
{ {
let compl = []; let compl = [];

View File

@@ -15,7 +15,7 @@ const template = {
map: function map(iter, fn, sep, interruptable) map: function map(iter, fn, sep, interruptable)
{ {
if (iter.length) // FIXME: Kludge? if (iter.length) // FIXME: Kludge?
iter = util.Array.iterator(iter); iter = util.Array.itervalues(iter);
let ret = <></>; let ret = <></>;
let n = 0; let n = 0;
for each (let i in Iterator(iter)) for each (let i in Iterator(iter))

View File

@@ -1867,7 +1867,7 @@ function ItemList(id) //{{{
for (let [i, row] in Iterator(context.getRows(start, end, doc))) for (let [i, row] in Iterator(context.getRows(start, end, doc)))
nodes[i] = row; nodes[i] = row;
for (let [i, row] in util.Array.iterator2(nodes)) for (let [i, row] in util.Array.iteritems(nodes))
{ {
if (!row) if (!row)
continue; continue;
@@ -2197,7 +2197,7 @@ function StatusLine() //{{{
// tab numbers set // tab numbers set
if (options.get("guioptions").has("n", "N")) if (options.get("guioptions").has("n", "N"))
{ {
for (let [i, tab] in util.Array.iterator2(getBrowser().mTabs)) for (let [i, tab] in util.Array.iteritems(getBrowser().mTabs))
tab.setAttribute("ordinal", i + 1); tab.setAttribute("ordinal", i + 1);
} }

View File

@@ -33,96 +33,6 @@ const NS = Namespace("liberator", "http://vimperator.org/namespaces/liberator");
default xml namespace = XHTML; default xml namespace = XHTML;
const util = { //{{{ const util = { //{{{
/**
* Array utility methods.
* @singleton
*/
Array: {
/**
* Converts an array to an object. As in lisp, an assoc is an
* array of key-value pairs, which maps directly to an object,
* as such:
* [["a", "b"], ["c", "d"]] -> { a: "b", c: "d" }
*
* @param {Array[]} assoc
* @... {string} 0 - Key
* @... 1 - Value
*/
assocToObj: function assocToObj(assoc)
{
let obj = {};
assoc.forEach(function ([k, v]) { obj[k] = v });
return obj;
},
/**
* Flattens an array, such that all elements of the array are
* joined into a single array:
* [["foo", ["bar"]], ["baz"], "quux"] -> ["foo", ["bar"], "baz", "quux"]
*
* @param {Array} ary
* @returns {Array}
*/
flatten: function flatten(ary) Array.concat.apply([], ary),
/**
* Returns an Iterator for an array's values.
*
* @param {Array} ary
* @returns {Iterator(Object)}
*/
iterator: function iterator(ary)
{
let length = ary.length;
for (let i = 0; i < length; i++)
yield ary[i];
},
/**
* Returns an Iterator for an array's indices and values.
*
* @param {Array} ary
* @returns {Iterator([{number}, {Object}])}
*/
iterator2: function (ary)
{
let length = ary.length;
for (let i = 0; i < length; i++)
yield [i, ary[i]];
},
/**
* Filters out all duplicates from an array. If
* <b>unsorted</b> is false, the array is sorted before
* duplicates are removed.
*
* @param {Array} ary
* @param {boolean} unsorted
* @returns {Array}
*/
uniq: function uniq(ary, unsorted)
{
let ret = [];
if (unsorted)
{
for (let [,item] in Iterator(ary))
if (ret.indexOf(item) == -1)
ret.push(item);
}
else
{
for (let [,item] in Iterator(ary.sort()))
{
if (item != last || !ret.length)
ret.push(item);
var last = item;
}
}
return ret;
}
},
/** /**
* Returns a shallow copy of <b>obj</b>. * Returns a shallow copy of <b>obj</b>.
* *
@@ -730,6 +640,106 @@ const util = { //{{{
} }
}; //}}} }; //}}}
/**
* Array utility methods.
* @singleton
*/
util.Array = function Array(ary) {
var obj = {
__proto__: ary,
__iterator__: function() this.iteritems(),
__noSuchMethod__: function (meth, args) {
let res = util.Array(util.Array[meth].apply(null, [this.__proto__].concat(args)))
if (res instanceof Array)
return util.Array(res);
return res;
}
};
return obj;
}
/**
* Converts an array to an object. As in lisp, an assoc is an
* array of key-value pairs, which maps directly to an object,
* as such:
* [["a", "b"], ["c", "d"]] -> { a: "b", c: "d" }
*
* @param {Array[]} assoc
* @... {string} 0 - Key
* @... 1 - Value
*/
util.Array.toObject = function toObject(assoc)
{
let obj = {};
assoc.forEach(function ([k, v]) { obj[k] = v });
return obj;
};
/**
* Flattens an array, such that all elements of the array are
* joined into a single array:
* [["foo", ["bar"]], ["baz"], "quux"] -> ["foo", ["bar"], "baz", "quux"]
*
* @param {Array} ary
* @returns {Array}
*/
util.Array.flatten = function flatten(ary) Array.concat.apply([], ary),
/**
* Returns an Iterator for an array's values.
*
* @param {Array} ary
* @returns {Iterator(Object)}
*/
util.Array.itervalues = function itervalues(ary)
{
let length = ary.length;
for (let i = 0; i < length; i++)
yield ary[i];
};
/**
* Returns an Iterator for an array's indices and values.
*
* @param {Array} ary
* @returns {Iterator([{number}, {Object}])}
*/
util.Array.iteritems = function iteritems(ary)
{
let length = ary.length;
for (let i = 0; i < length; i++)
yield [i, ary[i]];
};
/**
* Filters out all duplicates from an array. If
* <b>unsorted</b> is false, the array is sorted before
* duplicates are removed.
*
* @param {Array} ary
* @param {boolean} unsorted
* @returns {Array}
*/
util.Array.uniq = function uniq(ary, unsorted)
{
let ret = [];
if (unsorted)
{
for (let [,item] in Iterator(ary))
if (ret.indexOf(item) == -1)
ret.push(item);
}
else
{
for (let [,item] in Iterator(ary.sort()))
{
if (item != last || !ret.length)
ret.push(item);
var last = item;
}
}
return ret;
};
function Struct() function Struct()
{ {
let self = this instanceof Struct ? this : new Struct(); let self = this instanceof Struct ? this : new Struct();