]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/modules/contexts.jsm
Import r6976 from upstream hg supporting Firefox up to 25.*
[dactyl.git] / common / modules / contexts.jsm
index ffada2b7635446021f543c06cdc5c2a6e8165f7b..3c0ca3a94c39ea4ee79ae07addef934043fe1862 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (c) 2010-2012 Kris Maglione <maglione.k@gmail.com>
+// Copyright (c) 2010-2013 Kris Maglione <maglione.k@gmail.com>
 //
 // This work is licensed for reuse under an MIT license. Details are
 // given in the LICENSE.txt file included with this file.
@@ -65,12 +65,9 @@ var Group = Class("Group", {
     get builtin() this.modules.contexts.builtinGroups.indexOf(this) >= 0,
 
 }, {
-    compileFilter: function (patterns, default_ = false) {
-        if (arguments.length < 2)
-            default_ = false;
-
+    compileFilter: function (patterns, default_=false) {
         function siteFilter(uri)
-            let (match = array.nth(siteFilter.filters, function (f) f(uri), 0))
+            let (match = array.nth(siteFilter.filters, f => f(uri), 0))
                 match ? match.result : default_;
 
         return update(siteFilter, {
@@ -78,8 +75,9 @@ var Group = Class("Group", {
 
             toJSONXML: function (modules) let (uri = modules && modules.buffer.uri)
                 template.map(this.filters,
-                             function (f) ["span", { highlight: uri && f(uri) ? "Filter" : "" },
-                                               "toJSONXML" in f ? f.toJSONXML() : String(f)],
+                             f => ["span", { highlight: uri && f(uri) ? "Filter" : "" },
+                                       ("toJSONXML" in f ? f.toJSONXML()
+                                                         : String(f))],
                              ","),
 
             filters: Option.parse.sitelist(patterns)
@@ -140,8 +138,8 @@ var Contexts = Module("contexts", {
                 completer: function (context) modules.completion.group(context)
             });
 
-            memoize(modules, "userContext",  function () contexts.Context(modules.io.getRCFile("~", true), contexts.user, [modules, true]));
-            memoize(modules, "_userContext", function () contexts.Context(modules.io.getRCFile("~", true), contexts.user, [modules.userContext]));
+            memoize(modules, "userContext",  () => contexts.Context(modules.io.getRCFile("~", true), contexts.user, [modules, true]));
+            memoize(modules, "_userContext", () => contexts.Context(modules.io.getRCFile("~", true), contexts.user, [modules.userContext]));
         },
 
         cleanup: function () {
@@ -187,8 +185,8 @@ var Contexts = Module("contexts", {
                 });
 
                 memoize(contexts.hives, name,
-                        function () Object.create(Object.create(contexts.hiveProto,
-                                                                { _hive: { value: name } })));
+                        () => Object.create(Object.create(contexts.hiveProto,
+                                                          { _hive: { value: name } })));
 
                 memoize(contexts.groupsProto, name,
                         function () [group[name] for (group in values(this.groups)) if (Set.has(group, name))]);
@@ -201,11 +199,11 @@ var Contexts = Module("contexts", {
     Context: function Context(file, group, args) {
         const { contexts, io, newContext, plugins, userContext } = this.modules;
 
-        let isPlugin = array.nth(io.getRuntimeDirectories("plugins"),
-                                 function (dir) dir.contains(file, true),
-                                 0);
+        let isPlugin  = array.nth(io.getRuntimeDirectories("plugins"),
+                                  dir => dir.contains(file, true),
+                                  0);
         let isRuntime = array.nth(io.getRuntimeDirectories(""),
-                                  function (dir) dir.contains(file, true),
+                                  dir => dir.contains(file, true),
                                   0);
 
         let name = isPlugin ? file.getRelativeDescriptor(isPlugin).replace(File.PATH_SEP, "-")
@@ -305,7 +303,7 @@ var Contexts = Module("contexts", {
             var file = File(uri.file);
 
         let isPlugin = array.nth(io.getRuntimeDirectories("plugins"),
-                                 function (dir) dir.contains(file, true),
+                                 dir => dir.contains(file, true),
                                  0);
 
         let name = isPlugin && file && file.getRelativeDescriptor(isPlugin)
@@ -413,7 +411,7 @@ var Contexts = Module("contexts", {
 
     initializedGroups: function (hive)
         let (need = hive ? [hive] : Object.keys(this.hives))
-            this.groupList.filter(function (group) need.some(Set.has(group))),
+            this.groupList.filter(group => need.some(Set.has(group))),
 
     addGroup: function addGroup(name, description, filter, persist, replace) {
         let group = this.getGroup(name);
@@ -515,7 +513,7 @@ var Contexts = Module("contexts", {
                               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_);
+        let type = ["-builtin", "-ex", "-javascript", "-keys"].reduce((a, b) => args[b] ? b : a, default_);
 
         switch (type) {
         case "-builtin":
@@ -544,7 +542,7 @@ var Contexts = Module("contexts", {
                 action = dactyl.userEval("(function action() { with (action.makeParams(this, arguments)) {" + args.literalArg + "} })");
             else
                 action = dactyl.userFunc.apply(dactyl, params.concat(args.literalArg));
-            process = function (param) isObject(param) && param.valueOf ? param.valueOf() : param;
+            process = param => isObject(param) && param.valueOf ? param.valueOf() : param;
             action.params = params;
             action.makeParams = makeParams;
             break;
@@ -707,7 +705,7 @@ var Contexts = Module("contexts", {
                 util.assert(args.bang ^ !!args[0], _("error.argumentOrBang"));
 
                 if (args.bang)
-                    contexts.groupList = contexts.groupList.filter(function (g) g.builtin);
+                    contexts.groupList = contexts.groupList.filter(g => g.builtin);
                 else {
                     util.assert(contexts.getGroup(args[0]), _("group.noSuch", args[0]));
                     contexts.removeGroup(args[0]);
@@ -719,7 +717,7 @@ var Contexts = Module("contexts", {
                 completer: function (context, args) {
                     if (args.bang)
                         return;
-                    context.filters.push(function ({ item }) !item.builtin);
+                    context.filters.push(({ item }) => !item.builtin);
                     modules.completion.group(context);
                 }
             });
@@ -795,7 +793,7 @@ var Contexts = Module("contexts", {
             context.title = ["Group"];
             let uri = modules.buffer.uri;
             context.keys = {
-                active: function (group) group.filter(uri),
+                active: group => group.filter(uri),
                 text: "name",
                 description: function (g) ["", g.filter.toJSONXML ? g.filter.toJSONXML(modules).concat("\u00a0") : "", g.description || ""]
             };
@@ -805,7 +803,7 @@ var Contexts = Module("contexts", {
             iter({ Active: true, Inactive: false }).forEach(function ([name, active]) {
                 context.split(name, null, function (context) {
                     context.title[0] = name + " Groups";
-                    context.filters.push(function ({ item }) !!item.filter(modules.buffer.uri) == active);
+                    context.filters.push(({ item }) => !!item.filter(modules.buffer.uri) == active);
                 });
             });
         };