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

Make further use of default parameters.

--HG--
extra : rebase_source : ab666bce7ed7e47c8f1e2bc4145f553da990d319
This commit is contained in:
Doug Kearns
2013-10-06 22:33:59 +11:00
parent cf7e0c479d
commit 4872666ef5
18 changed files with 49 additions and 85 deletions

View File

@@ -628,10 +628,10 @@ var Bookmarks = Module("bookmarks", {
},
completion: function initCompletion() {
completion.bookmark = function bookmark(context, tags, extra) {
completion.bookmark = function bookmark(context, tags, extra = {}) {
context.title = ["Bookmark", "Title"];
context.format = bookmarks.format;
iter(extra || {}).forEach(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]));
});

View File

@@ -866,9 +866,7 @@ var CommandLine = Module("commandline", {
* @... {string} default - The initial value that will be returned
* if the user presses <CR> straightaway. @default ""
*/
input: function _input(prompt, callback, extra) {
extra = extra || {};
input: function _input(prompt, callback, extra = {}) {
CommandPromptMode(prompt, update({ onSubmit: callback }, extra)).open();
},
@@ -1396,10 +1394,8 @@ var CommandLine = Module("commandline", {
* @default {@link #selected}
* @returns {object}
*/
getItem: function getItem(tuple) {
tuple = tuple || this.selected;
return tuple && tuple[0] && tuple[0].items[tuple[1]];
},
getItem: function getItem(tuple = this.selected)
tuple && tuple[0] && tuple[0].items[tuple[1]],
/**
* Returns a tuple representing the next item, at the given
@@ -1510,11 +1506,10 @@ var CommandLine = Module("commandline", {
* @default 1
* @param {boolean} fromTab If true, this function was
* called by {@link #tab}.
* @default false
* @private
*/
select: function select(idx, count, fromTab) {
count = count || 1;
select: function select(idx, count = 1, fromTab = false) {
switch (idx) {
case this.UP:
case this.DOWN:

View File

@@ -538,13 +538,11 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
* @param {boolean} silent Whether the command should be echoed on the
* command line.
*/
execute: function execute(str, modifiers, silent) {
execute: function execute(str, modifiers = {}, silent = false) {
// skip comments and blank lines
if (/^\s*("|$)/.test(str))
return;
modifiers = modifiers || {};
if (!silent)
commands.lastCommand = str.replace(/^\s*:\s*/, "");
let res = true;
@@ -892,7 +890,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
* tabs.
* @returns {boolean}
*/
open: function open(urls, params, force) {
open: function open(urls, params = {}, force = false) {
if (typeof urls == "string")
urls = dactyl.parseURLs(urls);
@@ -903,7 +901,6 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
dactyl.open(urls, params, true);
});
params = params || {};
if (isString(params))
params = { where: params };
@@ -1187,8 +1184,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
return [];
}
},
wrapCallback: function wrapCallback(callback, self) {
self = self || this;
wrapCallback: function wrapCallback(callback, self = this) {
let save = ["forceOpen"];
let saved = save.map(p => dactyl[p]);
return function wrappedCallback() {

View File

@@ -212,8 +212,7 @@ var Events = Module("events", {
/**
* Wraps an event listener to ensure that errors are reported.
*/
wrapListener: function wrapListener(method, self) {
self = self || this;
wrapListener: function wrapListener(method, self = this) {
method.wrapper = wrappedListener;
wrappedListener.wrapped = method;
function wrappedListener(event) {

View File

@@ -12,11 +12,9 @@
var HintSession = Class("HintSession", CommandMode, {
get extendedMode() modes.HINTS,
init: function init(mode, opts) {
init: function init(mode, opts = {}) {
init.supercall(this);
opts = opts || {};
if (!opts.window)
opts.window = modes.getStack(0).params.window;
@@ -1056,11 +1054,9 @@ var Hints = Module("hints", {
return null;
}, //}}}
open: function open(mode, opts) {
open: function open(mode, opts = {}) {
this._extendedhintCount = opts.count;
opts = opts || {};
mappings.pushCommand();
commandline.input(["Normal", mode], null, {
autocomplete: false,

View File

@@ -13,9 +13,7 @@ var History = Module("history", {
get service() services.history,
get: function get(filter, maxItems, sort) {
sort = sort || this.SORT_DEFAULT;
get: function get(filter, maxItems, sort = this.SORT_DEFAULT) {
if (isString(filter))
filter = { searchTerms: filter };

View File

@@ -187,9 +187,7 @@ var MapHive = Class("MapHive", Contexts.Hive, {
* @param {Object} extra An optional extra configuration hash.
* @optional
*/
add: function (modes, keys, description, action, extra) {
extra = extra || {};
add: function (modes, keys, description, action, extra = {}) {
modes = Array.concat(modes);
if (!modes.every(util.identity))
throw TypeError(/*L*/"Invalid modes: " + modes);
@@ -814,9 +812,7 @@ var Mappings = Module("mappings", {
});
},
completion: function initCompletion(dactyl, modules, window) {
completion.userMapping = function userMapping(context, modes_, hive) {
hive = hive || mappings.user;
modes_ = modes_ || [modes.NORMAL];
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.completions = hive.iterate(modes_);

View File

@@ -34,12 +34,10 @@ var Marks = Module("marks", {
get localURI() buffer.focusedFrame.document.documentURI.replace(/#.*/, ""),
Mark: function Mark(params) {
Mark: function Mark(params = {}) {
let win = buffer.focusedFrame;
let doc = win.document;
params = params || {};
params.location = doc.documentURI.replace(/#.*/, ""),
params.offset = buffer.scrollPosition;
params.path = DOM(buffer.findScrollable(0, false)).xpath;

View File

@@ -502,11 +502,10 @@ var Modes = Module("modes", {
return StackElement;
})(),
cacheId: 0,
boundProperty: function BoundProperty(desc) {
boundProperty: function BoundProperty(desc = {}) {
let id = this.cacheId++;
let value;
desc = desc || {};
return Class.Property(update({
configurable: true,
enumerable: true,

View File

@@ -408,8 +408,7 @@ var Tabs = Module("tabs", {
* @param {number} count How many tabs to remove.
* @param {boolean} focusLeftTab Focus the tab to the left of the removed tab.
*/
remove: function remove(tab, count, focusLeftTab) {
count = count || 1;
remove: function remove(tab, count = 1, focusLeftTab = false) {
let res = this.count > count;
let tabs = this.visibleTabs;

View File

@@ -1094,8 +1094,7 @@ let stub = Class.Property({
*/
var ErrorBase = Class("ErrorBase", Error, {
level: 2,
init: function EB_init(message, level) {
level = level || 0;
init: function EB_init(message, level = 0) {
let error = Error(message);
update(this, error);
this.stack = error.stack;
@@ -1269,10 +1268,10 @@ var StructBase = Class("StructBase", Array, {
});
var Timer = Class("Timer", {
init: function init(minInterval, maxInterval, callback, self) {
init: function init(minInterval, maxInterval, callback, self = this) {
this._timer = services.Timer();
this.callback = callback;
this.self = self || this;
this.self = self;
this.minInterval = minInterval;
this.maxInterval = maxInterval;
this.doneAt = 0;

View File

@@ -784,11 +784,10 @@ var Buffer = Module("Buffer", {
* @param {number} count The multiple of 'scroll' lines to scroll.
* @optional
*/
scrollByScrollSize: function scrollByScrollSize(direction, count) {
scrollByScrollSize: function scrollByScrollSize(direction, count = 1) {
let { options } = this.modules;
direction = direction ? 1 : -1;
count = count || 1;
if (options["scroll"] > 0)
this.scrollVertical("lines", options["scroll"] * direction);

View File

@@ -155,15 +155,13 @@ var Command = Class("Command", {
* @param {Args} args The Args object passed to {@link #action}.
* @param {Object} modifiers Any modifiers to be passed to {@link #action}.
*/
execute: function execute(args, modifiers) {
execute: function execute(args, modifiers = {}) {
const { dactyl } = this.modules;
let context = args.context;
if (this.deprecated)
this.warn(context, "deprecated", _("warn.deprecated", ":" + this.name, this.deprecated));
modifiers = modifiers || {};
if (args.count != null && !this.count)
throw FailedAssertion(_("command.noCount"));
if (args.bang && !this.bang)
@@ -543,21 +541,21 @@ var CommandHive = Class("CommandHive", Contexts.Hive, {
repeat: null,
/**
* Adds a new command to the builtin hive. Accessible only to core
* dactyl code. Plugins should use group.commands.add instead.
* Adds a new command to the builtin hive. Accessible only to core dactyl
* code. Plugins should use group.commands.add instead.
*
* @param {[string]} specs The names by which this command can be
* invoked. The first name specified is the command's canonical
* name.
* @param {[string]} specs The names by which this command can be invoked.
* The first name specified is the command's canonical name.
* @param {string} description A description of the command.
* @param {function} action The action invoked by this command.
* @param {Object} extra An optional extra configuration hash.
* @optional
* @param {boolean} replace Replace an existing command of the same name.
* @optional
*/
add: function add(specs, description, action, extra, replace) {
add: function add(specs, description, action, extra = {}, replace = false) {
const { commands, contexts } = this.modules;
extra = extra || {};
if (!extra.definedAt)
extra.definedAt = contexts.getCaller(Components.stack.caller);
if (!extra.sourceModule)
@@ -594,10 +592,8 @@ var CommandHive = Class("CommandHive", Contexts.Hive, {
return name;
},
_add: function _add(names, description, action, extra, replace) {
_add: function _add(names, description, action, extra = {}, replace = false) {
const { contexts } = this.modules;
extra = extra || {};
extra.definedAt = contexts.getCaller(Components.stack.caller.caller);
return this.add.apply(this, arguments);
},
@@ -968,7 +964,7 @@ var Commands = Module("commands", {
* Args object.
* @returns {Args}
*/
parseArgs: function parseArgs(str, params) {
parseArgs: function parseArgs(str, params = {}) {
const self = this;
function getNextArg(str, _keepQuotes=keepQuotes) {
@@ -990,7 +986,7 @@ var Commands = Module("commands", {
try {
var { allowUnknownOptions, argCount, complete, extra, hereDoc, literal, options, keepQuotes } = params || {};
var { allowUnknownOptions, argCount, complete, extra, hereDoc, literal, options, keepQuotes } = params;
if (!options)
options = [];
@@ -1776,8 +1772,7 @@ var Commands = Module("commands", {
}
});
let quote = function quote(q, list, map) {
map = map || Commands.quoteMap;
let quote = function quote(q, list, map = Commands.quoteMap) {
let re = RegExp("[" + list + "]", "g");
function quote(str) (q + String.replace(str, re, $0 => ($0 in map ? map[$0] : ("\\" + $0)))
+ q);

View File

@@ -33,10 +33,7 @@ lazyRequire("template", ["template"]);
* @constructor
*/
var CompletionContext = Class("CompletionContext", {
init: function cc_init(editor, name, offset) {
if (!name)
name = "";
init: function cc_init(editor, name = "", offset = 0) {
let self = this;
if (editor instanceof this.constructor) {
let parent = editor;
@@ -68,7 +65,7 @@ var CompletionContext = Class("CompletionContext", {
self.__defineGetter__("value", function get_value() this.top.value);
self.offset = parent.offset;
self.advance(offset || 0);
self.advance(offset);
/**
* @property {boolean} Specifies that this context is not finished
@@ -156,7 +153,7 @@ var CompletionContext = Class("CompletionContext", {
* @property {number} This context's offset from the beginning of
* {@link #editor}'s value.
*/
this.offset = offset || 0;
this.offset = offset;
/**
* @property {function} A function which is called when any subcontext
* changes its completion list. Only called when

View File

@@ -241,11 +241,13 @@ var IO = Module("io", {
/**
* Sets the current working directory.
*
* @param {string} newDir The new CWD. This may be a relative or
* @param {File|string} newDir The new CWD. This may be a relative or
* absolute path and is expanded by {@link #expandPath}.
* @optional
* @default = "~"
*/
set cwd(newDir) {
newDir = newDir && newDir.path || newDir || "~";
set cwd(newDir = "~") {
newDir = newDir.path || newDir;
if (newDir == "-") {
util.assert(this._oldcwd != null, _("io.noPrevDir"));

View File

@@ -11,9 +11,9 @@ defineModule("messages", {
var Messages = Module("messages", {
init: function init(name) {
init: function init(name = "messages") {
let self = this;
this.name = name || "messages";
this.name = name;
this._ = Class("_", String, {
init: function _(message) {
@@ -97,10 +97,9 @@ var Messages = Module("messages", {
let { Buffer, commands, hints, io, mappings, modes, options, sanitizer } = overlay.activeModules;
file = io.File(file);
function properties(base, iter_, prop) iter(function _properties() {
function properties(base, iter_, prop = "description") iter(function _properties() {
function key(...args) [base, obj.identifier || obj.name].concat(args).join(".").replace(/[\\:=]/g, "\\$&");
prop = prop || "description";
for (var obj in iter_) {
if (!obj.hive || obj.hive.name !== "user") {
yield key(prop) + " = " + obj[prop];

View File

@@ -382,8 +382,7 @@ var Styles = Module("Styles", {
return val;
},
completeSite: function (context, content, group) {
group = group || styles.user;
completeSite: function (context, content, group = styles.user) {
context.anchored = false;
try {
context.fork("current", 0, this, function (context) {

View File

@@ -467,9 +467,7 @@ var Template = Module("Template", {
["td", { style: style[i] || "" }, d])])];
},
usage: function usage(iter, format) {
format = format || {};
usage: function usage(iter, format = {}) {
let desc = format.description || (item => this.linkifyHelp(item.description));
let help = format.help || (item => item.name);
let sourceLink = (frame) => {