diff --git a/common/content/abbreviations.js b/common/content/abbreviations.js index 0dac5c3c..0ca49cba 100644 --- a/common/content/abbreviations.js +++ b/common/content/abbreviations.js @@ -215,12 +215,9 @@ const Abbreviations = Module("abbreviations", { }, { }, { completion: function () { - // TODO: shouldn't all of these have a standard signature (context, args, ...)? --djk - completion.abbreviation = function abbreviation(context, args, modes) { - if (args.completeArg == 0) { - let abbrevs = abbreviations.merged.filter(function (abbr) abbr.inModes(modes)); - context.completions = [[abbr.lhs, abbr.rhs] for ([, abbr] in Iterator(abbrevs))]; - } + completion.abbreviation = function abbreviation(context, modes) { + let abbrevs = abbreviations.merged.filter(function (abbr) abbr.inModes(modes)); + context.completions = [[abbr.lhs, abbr.rhs] for ([, abbr] in Iterator(abbrevs))]; }; }, @@ -252,7 +249,7 @@ const Abbreviations = Module("abbreviations", { ], completer: function (context, args) { if (args.length == 1) - return completion.abbreviation(context, args, modes); + return completion.abbreviation(context, modes); else if (args["-javascript"]) return completion.javascript(context); }, @@ -279,7 +276,7 @@ const Abbreviations = Module("abbreviations", { return dactyl.echoerr("E24: No such abbreviation"); }, { argCount: "1", - completer: function (context, args) completion.abbreviation(context, args, modes), + completer: function (context) completion.abbreviation(context, modes), literal: 0 }); diff --git a/common/content/buffer.js b/common/content/buffer.js index ab728a36..e44a97ee 100644 --- a/common/content/buffer.js +++ b/common/content/buffer.js @@ -1205,7 +1205,7 @@ const Buffer = Module("buffer", { elem.value = file.path; }, { - completer: completion.file, + completer: function (context) completion.file(context), default: elem.value }); } diff --git a/common/content/commands.js b/common/content/commands.js index 91311f8a..3a856393 100644 --- a/common/content/commands.js +++ b/common/content/commands.js @@ -1252,7 +1252,7 @@ const Commands = Module("commands", { argCount: args["-nargs"], bang: args["-bang"], count: args["-count"], - completer: completeFunc, + completer: function (context) completeFunc(context), persist: !args["-nopersist"], replacementText: args.literalArg, sourcing: io.sourcing && update({}, io.sourcing) diff --git a/common/content/completion.js b/common/content/completion.js index 87d1680c..ddd8f1a2 100644 --- a/common/content/completion.js +++ b/common/content/completion.js @@ -851,7 +851,7 @@ const Completion = Module("completion", { }, { argCount: "*", - completer: function (context, args) { + completer: function (context) { let PREFIX = "/ex/contexts"; context.fork("ex", 0, completion, "ex"); completion.contextList = [[k.substr(PREFIX.length), v.title[0]] for ([k, v] in iter(context.contexts)) if (k.substr(0, PREFIX.length) == PREFIX)]; diff --git a/common/content/mappings.js b/common/content/mappings.js index 057fc24e..b596dd4c 100644 --- a/common/content/mappings.js +++ b/common/content/mappings.js @@ -406,7 +406,7 @@ const Mappings = Module("mappings", { const opts = { completer: function (context, args) { if (args.length == 1) - return completion.userMapping(context, args, mapmodes); + return completion.userMapping(context, mapmodes); if (args.length == 2) { if (args["-javascript"]) return completion.javascript(context); @@ -515,7 +515,7 @@ const Mappings = Module("mappings", { }, { argCount: "1", - completer: function (context, args) completion.userMapping(context, args, mapmodes) + completer: function (context) completion.userMapping(context, mapmodes) }); } @@ -528,14 +528,11 @@ const Mappings = Module("mappings", { [mode.disp.toLowerCase()]); }, completion: function () { - completion.userMapping = function userMapping(context, args, modes) { + completion.userMapping = function userMapping(context, modes) { // FIXME: have we decided on a 'standard' way to handle this clash? --djk modes = modes || [modules.modes.NORMAL]; - - if (args.completeArg == 0) { - let maps = [[m.names[0], ""] for (m in mappings.getUserIterator(modes))]; - context.completions = maps; - } + let maps = [[m.names[0], ""] for (m in mappings.getUserIterator(modes))]; + context.completions = maps; }; }, javascript: function () { diff --git a/common/modules/sanitizer.jsm b/common/modules/sanitizer.jsm index c57cba26..24422504 100644 --- a/common/modules/sanitizer.jsm +++ b/common/modules/sanitizer.jsm @@ -408,7 +408,7 @@ const Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakR { names: ["-host", "-h"], description: "Only sanitize items referring to listed host or hosts", - completer: function (context, args) { + completer: function (context) { let hosts = context.filter.split(","); context.advance(context.filter.length - hosts.pop().length); context.filters.push(function (item) diff --git a/melodactyl/content/player.js b/melodactyl/content/player.js index 23096d06..6875f61c 100644 --- a/melodactyl/content/player.js +++ b/melodactyl/content/player.js @@ -487,7 +487,7 @@ const Player = Module("player", { }, { argCount: "?", - completer: function (context, args) completion.playlist(context, args), + completer: function (context, args) completion.playlist(context), literal: 0 }); @@ -617,7 +617,14 @@ const Player = Module("player", { }, { argCount: "+", - completer: function (context, args) completion.song(context, args) + completer: function (context, args) { + if (args.completeArg == 0) + completion.artist(context); + else if (args.completeArg == 1) + completion.album(context, args[0]); + else if (args.completeArg == 2) + completion.song(context, args[0], args[1]); + } }); // TODO: maybe :vol! could toggle mute on/off? --djk @@ -639,26 +646,17 @@ const Player = Module("player", { { argCount: "1" }); }, completion: function () { - completion.song = function song(context, args) { - // TODO: useful descriptions? - function map(list) list.map(function (i) [i, ""]); - let [artist, album] = [args[0], args[1]]; - - if (args.completeArg == 0) { - context.title = ["Artists"]; - context.completions = map(library.getArtists()); - } - else if (args.completeArg == 1) { - context.title = ["Albums by " + artist]; - context.completions = map(library.getAlbums(artist)); - } - else if (args.completeArg == 2) { - context.title = ["Tracks from " + album + " by " + artist]; - context.completions = map(library.getTracks(artist, album)); - } + completion.album = function album(context, artist) { + context.title = ["Album"]; + context.completions = [[v, ""] for ([, v] in Iterator(library.getAlbums(artist)))]; }; - completion.playlist = function playlist(context, args) { + completion.artist = function artist(context) { + context.title = ["Artist"]; + context.completions = [[v, ""] for ([, v] in Iterator(library.getArtists()))]; + }; + + completion.playlist = function playlist(context) { context.title = ["Playlist", "Type"]; context.keys = { text: "name", description: "type" }; context.completions = player.getPlaylists(); @@ -677,6 +675,11 @@ const Player = Module("player", { context.completions = [["title", "Track name"], ["time", "Duration"], ["artist", "Artist name"], ["album", "Album name"], ["genre", "Genre"], ["rating", "Rating"]]; // FIXME: generate this list dynamically - see #sortBy }; + + completion.song = function album(context, artist, album) { + context.title = ["Song"]; + context.completions = [[v, ""] for ([, v] in Iterator(library.getTracks(artist, album)))]; + }; }, mappings: function () { mappings.add([modes.PLAYER],