1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-24 13:35:47 +01:00

Replace expression closures (methods).

Expression closures are to be axed. See https://bugzil.la/1083458.
This commit is contained in:
Doug Kearns
2015-07-23 01:55:32 +10:00
parent c035aa936b
commit 77d59cdfd1
45 changed files with 1595 additions and 1045 deletions

View File

@@ -39,7 +39,9 @@ var Abbreviation = Class("Abbreviation", {
* @param {Abbreviation} other The abbreviation to test.
* @returns {boolean} The result of the comparison.
*/
equals: function (other) this.lhs == other.lhs && this.rhs == other.rhs,
equals: function (other) {
return this.lhs == other.lhs && this.rhs == other.rhs;
},
/**
* Returns the abbreviation's expansion text.
@@ -48,7 +50,9 @@ var Abbreviation = Class("Abbreviation", {
* occurring.
* @returns {string}
*/
expand: function (editor) String(callable(this.rhs) ? this.rhs(editor) : this.rhs),
expand: function (editor) {
return String(callable(this.rhs) ? this.rhs(editor) : this.rhs);
},
/**
* Returns true if this abbreviation is defined for all *modes*.
@@ -56,7 +60,9 @@ var Abbreviation = Class("Abbreviation", {
* @param {[Mode]} modes The modes to test.
* @returns {boolean} The result of the comparison.
*/
modesEqual: function (modes) Ary.equals(this.modes, modes),
modesEqual: function (modes) {
return Ary.equals(this.modes, modes);
},
/**
* Returns true if this abbreviation is defined for *mode*.
@@ -64,7 +70,9 @@ var Abbreviation = Class("Abbreviation", {
* @param {Mode} mode The mode to test.
* @returns {boolean} The result of the comparison.
*/
inMode: function (mode) this.modes.some(m => m == mode),
inMode: function (mode) {
return this.modes.some(m => m == mode);
},
/**
* Returns true if this abbreviation is defined in any of *modes*.
@@ -72,7 +80,9 @@ var Abbreviation = Class("Abbreviation", {
* @param {[Modes]} modes The modes to test.
* @returns {boolean} The result of the comparison.
*/
inModes: function (modes) modes.some(mode => this.inMode(mode)),
inModes: function (modes) {
return modes.some(mode => this.inMode(mode));
},
/**
* Remove *mode* from the list of supported modes for this abbreviation.

View File

@@ -26,7 +26,9 @@ var AutoCmdHive = Class("AutoCmdHive", Contexts.Hive, {
this._store = [];
},
"@@iterator": function () this._store[Symbol.iterator](),
"@@iterator": function () {
return this._store[Symbol.iterator]();
},
/**
* Adds a new autocommand. *cmd* will be executed when one of the specified
@@ -171,7 +173,9 @@ var AutoCommands = Module("autocommands", {
hives: contexts.Hives("autocmd", AutoCmdHive),
user: contexts.hives.autocmd.user,
allHives: contexts.allGroups.autocmd,
matchingHives: function matchingHives(uri, doc) contexts.matchingGroups(uri, doc).autocmd
matchingHives: function matchingHives(uri, doc) {
return contexts.matchingGroups(uri, doc).autocmd;
}
});
},
commands: function initCommands() {

View File

@@ -18,8 +18,10 @@ var Bookmarks = Module("bookmarks", {
autocommands.trigger("Bookmark" + util.capitalize(event),
update({
bookmark: {
toString: function () "bookmarkcache.bookmarks[" + arg.id + "]",
valueOf: function () arg
toString: function () {
return "bookmarkcache.bookmarks[" + arg.id + "]";
},
valueOf: function () { return arg; }
}
}, arg.toObject()));
bookmarks.timer.tell();
@@ -37,7 +39,7 @@ var Bookmarks = Module("bookmarks", {
return {
anchored: false,
title: ["URL", "Info"],
keys: { text: "url", description: "title", icon: "icon", extra: "extra", tags: "tags", isURI: function () true },
keys: { text: "url", description: "title", icon: "icon", extra: "extra", tags: "tags", isURI: function () { return true; }},
process: [template.icon, template.bookmarkDescription]
};
},
@@ -752,7 +754,10 @@ var Bookmarks = Module("bookmarks", {
let ctxt = context.fork(name, 0);
ctxt.title = [/*L*/desc + " Suggestions"];
ctxt.keys = { text: identity, description: function () "" };
ctxt.keys = {
text: identity,
description: function () { return ""; }
};
ctxt.compare = CompletionContext.Sort.unsorted;
ctxt.filterFunc = null;

View File

@@ -51,7 +51,10 @@ var Browser = Module("browser", XPCOM(Ci.nsISupportsWeakReference, ModuleBase),
uri = isObject(uri) ? uri : util.newURI(uri || doc.location.href);
let args = {
url: { toString: function () uri.spec, valueOf: function () uri },
url: {
toString: function () { return uri.spec; },
valueOf: function () { return uri; }
},
title: doc.title
};
@@ -60,12 +63,16 @@ var Browser = Module("browser", XPCOM(Ci.nsISupportsWeakReference, ModuleBase),
else {
args.tab = tabs.getContentIndex(doc) + 1;
args.doc = {
valueOf: function () doc,
toString: function () "tabs.getTab(" + (args.tab - 1) + ").linkedBrowser.contentDocument"
valueOf: function () { return doc; },
toString: function () {
return "tabs.getTab(" + (args.tab - 1) + ").linkedBrowser.contentDocument";
}
};
args.win = {
valueOf: function () doc.defaultView,
toString: function () "tabs.getTab(" + (args.tab - 1) + ").linkedBrowser.contentWindow"
valueOf: function () { return doc.defaultView; },
toString: function () {
return "tabs.getTab(" + (args.tab - 1) + ").linkedBrowser.contentWindow";
}
};
}

View File

@@ -66,20 +66,29 @@ var CommandWidgets = Class("CommandWidgets", {
this.addElement({
name: "commandline",
getGroup: function () options.get("guioptions").has("C") ? this.commandbar : this.statusbar,
getValue: function () this.command
getGroup: function () {
return options.get("guioptions").has("C") ? this.commandbar
: this.statusbar;
},
getValue: function () {
return this.command;
}
});
this.addElement({
name: "strut",
defaultGroup: "Normal",
getGroup: function () this.commandbar,
getValue: function () options.get("guioptions").has("c")
getGroup: function () { return this.commandbar; },
getValue: function () {
return options.get("guioptions").has("c");
}
});
this.addElement({
name: "command",
test: function test(stack, prev) stack.pop && !isinstance(prev.main, modes.COMMAND_LINE),
test: function test(stack, prev) {
return stack.pop && !isinstance(prev.main, modes.COMMAND_LINE);
},
id: "commandline-command",
get: function command_get(elem) {
// The long path is because of complications with the
@@ -92,7 +101,9 @@ var CommandWidgets = Class("CommandWidgets", {
}
},
getElement: CommandWidgets.getEditor,
getGroup: function (value) this.activeGroup.commandline,
getGroup: function (value) {
return this.activeGroup.commandline;
},
onChange: function command_onChange(elem, value) {
if (elem.inputField != dactyl.focusedElement)
try {
@@ -114,7 +125,7 @@ var CommandWidgets = Class("CommandWidgets", {
name: "prompt",
id: "commandline-prompt",
defaultGroup: "CmdPrompt",
getGroup: function () this.activeGroup.commandline
getGroup: function () { return this.activeGroup.commandline; }
});
this.addElement({
@@ -136,14 +147,14 @@ var CommandWidgets = Class("CommandWidgets", {
this.addElement({
name: "message-pre",
defaultGroup: "WarningMsg",
getGroup: function () this.activeGroup.message
getGroup: function () { return this.activeGroup.message; }
});
this.addElement({
name: "message-box",
defaultGroup: "Normal",
getGroup: function () this.activeGroup.message,
getValue: function () this.message
getGroup: function () { return this.activeGroup.message; },
getValue: function () { return this.message; }
});
this.addElement({
@@ -1393,8 +1404,9 @@ var CommandLine = Module("commandline", {
* Returns true if the currently selected 'wildmode' index
* has the given completion type.
*/
haveType: function haveType(type)
this.wildmode.checkHas(this.wildtype, type == "first" ? "" : type),
haveType: function haveType(type) {
return this.wildmode.checkHas(this.wildtype, type == "first" ? "" : type);
},
/**
* Returns the completion item for the given selection
@@ -1405,8 +1417,9 @@ var CommandLine = Module("commandline", {
* @default {@link #selected}
* @returns {object}
*/
getItem: function getItem(tuple=this.selected)
tuple && tuple[0] && tuple[0].items[tuple[1]],
getItem: function getItem(tuple=this.selected) {
return tuple && tuple[0] && tuple[0].items[tuple[1]];
},
/**
* Returns a tuple representing the next item, at the given
@@ -1779,7 +1792,9 @@ var CommandLine = Module("commandline", {
return Events.PASS;
});
let bind = function bind(...args) apply(mappings, "add", [[modes.COMMAND_LINE]].concat(args));
let bind = function bind(...args) {
apply(mappings, "add", [[modes.COMMAND_LINE]].concat(args));
};
bind(["<Esc>", "<C-[>"], "Stop waiting for completions or exit Command Line mode",
function ({ self }) {
@@ -2305,12 +2320,17 @@ var ItemList = Class("ItemList", {
* @param {CompletionContext} context
* @returns {ItemList.Group}
*/
getGroup: function getGroup(context)
context instanceof ItemList.Group ? context
: context && context.getCache("itemlist-group",
() => ItemList.Group(this, context)),
getGroup: function getGroup(context) {
if (context instanceof ItemList.Group)
return context;
else
return context && context.getCache("itemlist-group",
() => ItemList.Group(this, context));
},
getOffset: function getOffset(tuple) tuple && this.getGroup(tuple[0]).getOffset(tuple[1])
getOffset: function getOffset(tuple) {
return tuple && this.getGroup(tuple[0]).getOffset(tuple[1]);
}
}, {
RESIZE_BRIEF: 1 << 0,
@@ -2454,9 +2474,13 @@ var ItemList = Class("ItemList", {
}
},
getRow: function getRow(idx) this.context.getRow(idx, this.doc),
getRow: function getRow(idx) {
return this.context.getRow(idx, this.doc);
},
getOffset: function getOffset(idx) this.offsets.start + (idx || 0),
getOffset: function getOffset(idx) {
return this.offsets.start + (idx || 0);
},
get selectedRow() { return this.getRow(this._selectedIdx); },
@@ -2475,10 +2499,13 @@ var ItemList = Class("ItemList", {
Range: Class.Memoize(function () {
let Range = Struct("ItemList.Range", "start", "end");
update(Range.prototype, {
contains: function contains(idx)
typeof idx == "number" ? idx >= this.start && idx < this.end
: this.contains(idx.start) &&
idx.end >= this.start && idx.end <= this.end
contains: function contains(idx) {
if (typeof idx == "number")
return idx >= this.start && idx < this.end;
else
return this.contains(idx.start) &&
idx.end >= this.start && idx.end <= this.end;
}
});
return Range;
})

View File

@@ -203,7 +203,8 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
registerObserver: function registerObserver(type, callback, weak) {
if (!(type in this._observers))
this._observers[type] = [];
this._observers[type].push(weak ? util.weakReference(callback) : { get: function () callback });
this._observers[type].push(weak ? util.weakReference(callback)
: { get: function () { return callback; } });
},
registerObservers: function registerObservers(obj, prop) {
@@ -620,7 +621,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
* @param {string} feature The feature name.
* @returns {boolean}
*/
has: function has(feature) config.has(feature),
has: function has(feature) { return config.has(feature); },
/**
* @private
@@ -1083,11 +1084,12 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
node.collapsed = !visible;
},
confirmQuit: function confirmQuit()
prefs.withContext(function () {
confirmQuit: function confirmQuit() {
return prefs.withContext(function () {
prefs.set("browser.warnOnQuit", false);
return window.canQuitApplication();
}),
});
},
/**
* Quit the host application, no matter how many tabs/windows are open.

View File

@@ -718,7 +718,9 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
modes.addMode("VISUAL", {
char: "v",
description: "Active when text is selected",
display: function () "VISUAL" + (this._extended & modes.LINE ? " LINE" : ""),
display: function () {
return "VISUAL" + (this._extended & modes.LINE ? " LINE" : "");
},
bases: [modes.COMMAND],
ownsFocus: true
}, {
@@ -762,7 +764,9 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
});
modes.addMode("AUTOCOMPLETE", {
description: "Active when an input autocomplete pop-up is active",
display: function () "AUTOCOMPLETE (insert)",
display: function () {
return "AUTOCOMPLETE (insert)";
},
bases: [modes.INSERT]
});
},
@@ -924,26 +928,29 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
editor.selectionController.repaintSelection(editor.selectionController.SELECTION_NORMAL);
}
function clear(forward, re)
function _clear(editor) {
function clear(forward, re) {
return function _clear(editor) {
updateRange(editor, forward, re, range => {});
dactyl.assert(!editor.selection.isCollapsed);
editor.selection.deleteFromDocument();
let parent = DOM(editor.rootElement.parentNode);
if (parent.isInput)
parent.input();
}
};
}
function move(forward, re, sameWord)
function _move(editor) {
function move(forward, re, sameWord) {
return function _move(editor) {
updateRange(editor, forward, re,
range => { range.collapse(!forward); },
sameWord);
}
function select(forward, re)
function _select(editor) {
};
}
function select(forward, re) {
return function _select(editor) {
updateRange(editor, forward, re, range => {});
}
};
}
function beginLine(editor_) {
editor.executeCommand("cmd_beginLine");
move(true, /\s/, true)(editor_);
@@ -1083,9 +1090,10 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
},
{ count: true, type: "operator" });
let bind = function bind(names, description, action, params)
let bind = function bind(names, description, action, params) {
mappings.add([modes.INPUT], names, description,
action, update({ type: "editor" }, params));
};
bind(["<C-w>"], "Delete previous word",
function () {
@@ -1166,9 +1174,10 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
["<C-]>", "<C-5>"], "Expand Insert mode abbreviation",
function () { editor.expandAbbreviation(modes.INSERT); });
bind = function bind(names, description, action, params)
bind = function bind(names, description, action, params) {
mappings.add([modes.TEXT_EDIT], names, description,
action, update({ type: "editor" }, params));
};
bind(["<C-a>"], "Increment the next number",
function ({ count }) { editor.modifyNumber(count || 1); },
@@ -1279,10 +1288,11 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
},
{ arg: true });
bind = function bind(names, description, action, params)
bind = function bind(names, description, action, params) {
mappings.add([modes.TEXT_EDIT, modes.OPERATOR, modes.VISUAL],
names, description,
action, update({ type: "editor" }, params));
};
// finding characters
function offset(backward, before, pos) {
@@ -1347,7 +1357,9 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
},
{ count: true });
bind = function bind(...args) apply(mappings, "add", [[modes.AUTOCOMPLETE]].concat(args));
bind = function bind(...args) {
apply(mappings, "add", [[modes.AUTOCOMPLETE]].concat(args));
};
bind(["<Esc>"], "Return to Insert mode",
() => Events.PASS_THROUGH);

View File

@@ -113,7 +113,7 @@ var Events = Module("events", {
});
this._fullscreen = window.fullScreen;
this._lastFocus = { get: function () null };
this._lastFocus = { get: function () { return null; } };
this._macroKeys = [];
this._lastMacro = "";
@@ -472,8 +472,8 @@ var Events = Module("events", {
let accel = config.OS.isMacOSX ? "metaKey" : "ctrlKey";
let access = iter({ 1: "shiftKey", 2: "ctrlKey", 4: "altKey", 8: "metaKey" })
.filter(function ([k, v]) this & k,
prefs.get("ui.key.chromeAccess"))
.filter(function ([k, v]) { return this & k; },
prefs.get("ui.key.chromeAccess")) // XXX
.map(([k, v]) => [v, true])
.toObject();
@@ -514,7 +514,9 @@ var Events = Module("events", {
* @param {string} key The key code to test.
* @returns {boolean}
*/
isAcceptKey: function (key) key == "<Return>" || key == "<C-j>" || key == "<C-m>",
isAcceptKey: function (key) {
return key == "<Return>" || key == "<C-j>" || key == "<C-m>";
},
/**
* Returns true if *key* is a key code defined to reject/cancel input on
@@ -523,7 +525,9 @@ var Events = Module("events", {
* @param {string} key The key code to test.
* @returns {boolean}
*/
isCancelKey: function (key) key == "<Esc>" || key == "<C-[>" || key == "<C-c>",
isCancelKey: function (key) {
return key == "<Esc>" || key == "<C-[>" || key == "<C-c>";
},
/**
* Returns true if *node* belongs to the current content document or any
@@ -969,9 +973,10 @@ var Events = Module("events", {
}
},
shouldPass: function shouldPass(event)
!event.noremap && (!dactyl.focusedElement || events.isContentNode(dactyl.focusedElement)) &&
options.get("passkeys").has(DOM.Event.stringify(event))
shouldPass: function shouldPass(event) {
return !event.noremap && (!dactyl.focusedElement || events.isContentNode(dactyl.focusedElement)) &&
options.get("passkeys").has(DOM.Event.stringify(event));
}
}, {
ABORT: {},
KILL: true,
@@ -1140,7 +1145,7 @@ var Events = Module("events", {
this.stack = MapHive.Stack(values.map(v => Map(v[map + "Keys"])));
function Map(keys) {
return {
execute: function () Events.PASS_THROUGH,
execute: function () { return Events.PASS_THROUGH; },
keys: keys
};
}
@@ -1148,9 +1153,13 @@ var Events = Module("events", {
get active() { return this.stack.length; },
get: function get(mode, key) this.stack.mappings[key],
get: function get(mode, key) {
return this.stack.mappings[key];
},
getCandidates: function getCandidates(mode, key) this.stack.candidates[key]
getCandidates: function getCandidates(mode, key) {
return this.stack.candidates[key];
}
});
options.add(["passkeys", "pk"],
"Pass certain keys through directly for the given URLs",

View File

@@ -194,7 +194,9 @@ var HintSession = Class("HintSession", CommandMode, {
* @param {string} key The key to test.
* @returns {boolean} Whether the key represents a hint number.
*/
isHintKey: function isHintKey(key) this.hintKeys.indexOf(key) >= 0,
isHintKey: function isHintKey(key) {
return this.hintKeys.indexOf(key) >= 0;
},
/**
* Gets the actual offset of an imagemap area.
@@ -1266,9 +1268,10 @@ var Hints = Module("hints", {
});
},
mappings: function () {
let bind = function bind(names, description, action, params)
let bind = function bind(names, description, action, params) {
mappings.add(config.browserModes, names, description,
action, params);
};
bind(["f"],
"Start Hints mode",
@@ -1288,9 +1291,10 @@ var Hints = Module("hints", {
function ({ count }) { hints.open("g;", { continue: true, count: count }); },
{ count: true });
bind = function bind(names, description, action, params)
bind = function bind(names, description, action, params) {
mappings.add([modes.HINTS], names, description,
action, params);
};
bind(["<Return>"],
"Follow the selected hint",
@@ -1306,7 +1310,7 @@ var Hints = Module("hints", {
bind(["<BS>", "<C-h>"],
"Delete the previous character",
function ({ self }) self.backspace());
function ({ self }) { self.backspace(); });
bind(["\\"],
"Toggle hint filtering",
@@ -1343,7 +1347,9 @@ var Hints = Module("hints", {
return vals;
},
testValues: function testValues(vals, validator) vals.every(re => Option.splitList(re).every(validator)),
testValues: function testValues(vals, validator) {
return vals.every(re => Option.splitList(re).every(validator));
},
validator: DOM.validateMatcher
});

View File

@@ -341,8 +341,13 @@ var History = Module("history", {
completion.domain = context => {
context.anchored = false;
context.compare = (a, b) => String.localeCompare(a.key, b.key);
context.keys = { text: identity, description: identity,
key: function (host) host.split(".").reverse().join(".") };
context.keys = {
text: identity,
description: identity,
key: function (host) {
return host.split(".").reverse().join(".");
}
};
// FIXME: Schema-specific
context.generate = () => [

View File

@@ -60,11 +60,13 @@ var ProcessorStack = Class("ProcessorStack", {
}
},
_result: function (result) (result === Events.KILL ? "KILL" :
result === Events.PASS ? "PASS" :
result === Events.PASS_THROUGH ? "PASS_THROUGH" :
result === Events.ABORT ? "ABORT" :
callable(result) ? result.toSource().substr(0, 50) : result),
_result: function (result) {
return (result === Events.KILL ? "KILL" :
result === Events.PASS ? "PASS" :
result === Events.PASS_THROUGH ? "PASS_THROUGH" :
result === Events.ABORT ? "ABORT" :
callable(result) ? result.toSource().substr(0, 50) : result);
},
execute: function execute(result, force) {
events.dbg("EXECUTE(" + this._result(result) + ", " + force + ") events:" + this.events.length
@@ -255,8 +257,8 @@ var KeyProcessor = Class("KeyProcessor", {
return this.onKeyPress(event);
},
execute: function execute(map, args)
() => {
execute: function execute(map, args) {
return () => {
if (this.preExecute)
apply(this, "preExecute", args);
@@ -266,7 +268,8 @@ var KeyProcessor = Class("KeyProcessor", {
if (this.postExecute)
apply(this, "postExecute", args);
return res;
},
};
},
onKeyPress: function onKeyPress(event) {
if (event.skipmap)

View File

@@ -112,7 +112,9 @@ var Map = Class("Map", {
* @param {string} name The name to query.
* @returns {boolean}
*/
hasName: function (name) this.keys.indexOf(name) >= 0,
hasName: function (name) {
return this.keys.indexOf(name) >= 0;
},
get keys() { return Ary.flatten(this.names.map(mappings.bound.expand)); },
@@ -232,7 +234,9 @@ var MapHive = Class("MapHive", Contexts.Hive, {
* @param {string} cmd The map name to match.
* @returns {Map|null}
*/
get: function (mode, cmd) this.getStack(mode).mappings[cmd],
get: function (mode, cmd) {
return this.getStack(mode).mappings[cmd];
},
/**
* Returns a count of maps with names starting with but not equal to
@@ -242,7 +246,9 @@ var MapHive = Class("MapHive", Contexts.Hive, {
* @param {string} prefix The map prefix string to match.
* @returns {number)
*/
getCandidates: function (mode, prefix) this.getStack(mode).candidates[prefix] || 0,
getCandidates: function (mode, prefix) {
return this.getStack(mode).candidates[prefix] || 0;
},
/**
* Returns whether there is a user-defined mapping *cmd* for the specified
@@ -252,7 +258,9 @@ var MapHive = Class("MapHive", Contexts.Hive, {
* @param {string} cmd The candidate key mapping.
* @returns {boolean}
*/
has: function (mode, cmd) this.getStack(mode).mappings[cmd] != null,
has: function (mode, cmd) {
return this.getStack(mode).mappings[cmd] != null;
},
/**
* Remove the mapping named *cmd* for *mode*.
@@ -291,7 +299,9 @@ var MapHive = Class("MapHive", Contexts.Hive, {
return self;
},
"@@iterator": function () Ary.iterValues(this),
"@@iterator": function () {
return Ary.iterValues(this);
},
get candidates() { return this.states.candidates; },
get mappings() { return this.states.mappings; },
@@ -401,7 +411,9 @@ var Mappings = Module("mappings", {
// NOTE: just normal mode for now
/** @property {Iterator(Map)} */
"@@iterator": function () this.iterate(modes.NORMAL),
"@@iterator": function () {
return this.iterate(modes.NORMAL);
},
getDefault: deprecated("mappings.builtin.get", function getDefault(mode, cmd) this.builtin.get(mode, cmd)),
getUserIterator: deprecated("mappings.user.iterator", function getUserIterator(modes) this.user.iterator(modes)),
@@ -455,8 +467,9 @@ var Mappings = Module("mappings", {
* @param {string} cmd The map name to match.
* @returns {Map}
*/
get: function get(mode, cmd) this.hives.map(h => h.get(mode, cmd))
.compact()[0] || null,
get: function get(mode, cmd) {
return this.hives.map(h => h.get(mode, cmd)).compact()[0] || null;
},
/**
* Returns a count of maps with names starting with but not equal to
@@ -466,9 +479,10 @@ var Mappings = Module("mappings", {
* @param {string} prefix The map prefix string to match.
* @returns {[Map]}
*/
getCandidates: function (mode, prefix)
this.hives.map(h => h.getCandidates(mode, prefix))
.reduce((a, b) => (a + b), 0),
getCandidates: function (mode, prefix) {
return this.hives.map(h => h.getCandidates(mode, prefix))
.reduce((a, b) => (a + b), 0);
},
/**
* Lists all user-defined mappings matching *filter* for the specified
@@ -763,7 +777,7 @@ var Mappings = Module("mappings", {
mode.displayName);
let args = {
getMode: function (args) findMode(args["-mode"]),
getMode: function (args) { return findMode(args["-mode"]); },
iterate: function* (args, mainOnly) {
let modes = [this.getMode(args)];
if (!mainOnly)
@@ -788,13 +802,15 @@ var Mappings = Module("mappings", {
};
},
format: {
description: function (map) [
description: function (map) {
return [
options.get("passkeys").has(map.name)
? ["span", { highlight: "URLExtra" },
"(", template.linkifyHelp(_("option.passkeys.passedBy")), ")"]
: [],
template.linkifyHelp(map.description + (map.rhs ? ": " + map.rhs : ""))
],
];
},
help: function (map) {
let char = Ary.compact(map.modes.map(m => m.char))[0];
return char === "n" ? map.name : char ? char + "_" + map.name : "";
@@ -831,15 +847,21 @@ var Mappings = Module("mappings", {
},
description: "List all " + mode.displayName + " mode mappings along with their short descriptions",
index: mode.char + "-map",
getMode: function (args) mode,
getMode: function (args) { return mode; },
options: []
});
});
},
completion: function initCompletion(dactyl, modules, window) {
completion.userMapping = function userMapping(context, modes_=[modes.NORMAL], hive=mappings.user) {
context.keys = { text: function (m) m.names[0],
description: function (m) m.description + ": " + m.action };
context.keys = {
text: function (m) {
return m.names[0];
},
description: function (m) {
return m.description + ": " + m.action;
}
};
context.completions = hive.iterate(modes_);
};
},
@@ -847,8 +869,10 @@ var Mappings = Module("mappings", {
JavaScript.setCompleter([Mappings.prototype.get, MapHive.prototype.get],
[
null,
function (context, obj, args) [[m.names, m.description]
for (m of this.iterate(args[0]))]
function (context, obj, args) {
return [[m.names, m.description]
for (m of this.iterate(args[0]))];
}
]);
},
mappings: function initMappings(dactyl, modules, window) {

View File

@@ -106,10 +106,11 @@ var Modes = Module("modes", {
bases: [this.BASE],
hidden: true,
passthrough: true,
display: function ()
(modes.getStack(1).main == modes.PASS_THROUGH
? (modes.getStack(2).main.display() || modes.getStack(2).main.name)
: "PASS THROUGH") + " (next)"
display: function () {
return (modes.getStack(1).main == modes.PASS_THROUGH
? (modes.getStack(2).main.display() || modes.getStack(2).main.name)
: "PASS THROUGH") + " (next)";
}
}, {
// Fix me.
preExecute: function (map) { if (modes.main == modes.QUOTE && map.name !== "<C-v>") modes.pop(); },
@@ -198,7 +199,9 @@ var Modes = Module("modes", {
NONE: 0,
"@@iterator": function __iterator__() Ary.iterValues(this.all),
"@@iterator": function __iterator__() {
return Ary.iterValues(this.all);
},
get all() { return this._modes.slice(); },
@@ -251,19 +254,28 @@ var Modes = Module("modes", {
util.dump(" " + i + ": " + mode);
},
getMode: function getMode(name) this._modeMap[name],
getMode: function getMode(name) {
return this._modeMap[name];
},
getStack: function getStack(idx) this._modeStack[this._modeStack.length - idx - 1] || this._modeStack[0],
getStack: function getStack(idx) {
return this._modeStack[this._modeStack.length - idx - 1] ||
this._modeStack[0];
},
get stack() { return this._modeStack.slice(); },
getCharModes: function getCharModes(chr) (this.modeChars[chr] || []).slice(),
getCharModes: function getCharModes(chr) {
return (this.modeChars[chr] || []).slice();
},
have: function have(mode) this._modeStack.some(m => isinstance(m.main, mode)),
have: function have(mode) {
return this._modeStack.some(m => isinstance(m.main, mode));
},
matchModes: function matchModes(obj)
this._modes.filter(mode => Object.keys(obj)
.every(k => obj[k] == (mode[k] || false))),
matchModes: function matchModes(obj) {
return this._modes.filter(mode => Object.keys(obj).every(k => obj[k] == (mode[k] || false)));
},
// show the current mode string in the command line
show: function show() {
@@ -451,8 +463,10 @@ var Modes = Module("modes", {
return this.name.split("_").map(util.capitalize).join(" ");
}),
isinstance: function isinstance(obj)
this.allBases.indexOf(obj) >= 0 || callable(obj) && this instanceof obj,
isinstance: function isinstance(obj) {
return this.allBases.indexOf(obj) >= 0 ||
callable(obj) && this instanceof obj;
},
allBases: Class.Memoize(function () {
let seen = new RealSet,
@@ -474,7 +488,7 @@ var Modes = Module("modes", {
return this.name.replace(/_/g, " ");
}),
display: function display() this._display,
display: function display() { return this._display; },
extended: false,
@@ -506,18 +520,19 @@ var Modes = Module("modes", {
get toStringParams() { return [this.name]; },
valueOf: function valueOf() this.id
valueOf: function valueOf() { return this.id; }
}, {
_id: 0
}),
ModeStack: function ModeStack(array)
update(array, {
ModeStack: function ModeStack(array) {
return update(array, {
pop: function pop() {
if (this.length <= 1)
throw Error("Trying to pop last element in mode stack");
return pop.superapply(this, arguments);
}
}),
});
},
StackElement: (function () {
const StackElement = Struct("main", "extended", "params", "saved");
StackElement.className = "Modes.StackElement";
@@ -546,19 +561,21 @@ var Modes = Module("modes", {
return Class.Property(update({
configurable: true,
enumerable: true,
init: function bound_init(prop) update(this, {
get: function bound_get() {
if (desc.get)
var val = desc.get.call(this, value);
return val === undefined ? value : val;
},
set: function bound_set(val) {
modes.save(id, this, prop, desc.test);
if (desc.set)
value = desc.set.call(this, val);
value = !desc.set || value === undefined ? val : value;
}
})
init: function bound_init(prop) {
return update(this, {
get: function bound_get() {
if (desc.get)
var val = desc.get.call(this, value);
return val === undefined ? value : val;
},
set: function bound_set(val) {
modes.save(id, this, prop, desc.test);
if (desc.set)
value = desc.set.call(this, val);
value = !desc.set || value === undefined ? val : value;
}
});
}
}, desc));
}
}, {

View File

@@ -66,7 +66,9 @@ var MOW = Module("mow", {
});
},
__noSuchMethod__: function (meth, args) apply(Buffer, meth, [this.body].concat(args)),
__noSuchMethod__: function (meth, args) {
return apply(Buffer, meth, [this.body].concat(args));
},
get widget() { return this.widgets.multilineOutput; },
@@ -288,7 +290,9 @@ var MOW = Module("mow", {
},
visible: Modes.boundProperty({
get: function get_mowVisible() !this.widgets.mowContainer.collapsed,
get: function get_mowVisible() {
return !this.widgets.mowContainer.collapsed;
},
set: function set_mowVisible(value) {
this.widgets.mowContainer.collapsed = !value;

View File

@@ -51,7 +51,9 @@ var QuickMarks = Module("quickmarks", {
* @param {string} mark The mark to find.
* @returns {string} The mark's URL.
*/
get: function (mark) this._qmarks.get(mark) || null,
get: function (mark) {
return this._qmarks.get(mark) || null;
},
/**
* Deletes the specified quickmarks. The *filter* is a list of quickmarks

View File

@@ -329,7 +329,9 @@ var StatusLine = Module("statusline", {
* Any other number - The progress is cleared.
*/
progress: Modes.boundProperty({
get: function progress() this._progress,
get: function progress() {
return this._progress;
},
set: function progress(progress) {
this._progress = progress || "";

View File

@@ -1058,7 +1058,7 @@ var Tabs = Module("tabs", {
let filter = context.filter.toLowerCase();
let defItem = { parent: { getTitle: function () "" } };
let defItem = { parent: { getTitle: function () { return ""; } } };
let tabGroups = {};
tabs.getGroups();
@@ -1071,22 +1071,28 @@ var Tabs = Module("tabs", {
group[1].push([i, tab.linkedBrowser]);
});
context.pushProcessor(0, function (item, text, next) [
["span", { highlight: "Indicator", style: "display: inline-block;" },
item.indicator],
next.call(this, item, text)
]);
context.process[1] = function (item, text) template.bookmarkDescription(item, template.highlightFilter(text, this.filter));
context.pushProcessor(0, function (item, text, next) {
return [
["span", { highlight: "Indicator", style: "display: inline-block;" },
item.indicator],
next.call(this, item, text)
];
});
context.process[1] = function (item, text) {
return template.bookmarkDescription(item, template.highlightFilter(text, this.filter));
};
context.anchored = false;
context.keys = {
text: "text",
description: "url",
indicator: function (item) item.tab === tabs.getTab() ? "%" :
item.tab === tabs.alternate ? "#" : " ",
indicator: function (item) {
return item.tab === tabs.getTab() ? "%" :
item.tab === tabs.alternate ? "#" : " ";
},
icon: "icon",
id: "id",
command: function () "tabs.select"
command: function () { return "tabs.select"; }
};
context.compare = CompletionContext.Sort.number;
context.filters[0] = CompletionContext.Filter.textDescription;
@@ -1121,8 +1127,11 @@ var Tabs = Module("tabs", {
context.title = ["Tab Groups"];
context.keys = {
text: "id",
description: function (group) group.getTitle() ||
group.getChildren().map(t => t.tab.label).join(", ")
description: function (group) {
return group.getTitle() ||
group.getChildren().map(t => t.tab.label)
.join(", ");
}
};
context.generate = () => {
context.incomplete = true;