diff --git a/content/bookmarks.js b/content/bookmarks.js index 0334eca4..5b7a929e 100644 --- a/content/bookmarks.js +++ b/content/bookmarks.js @@ -233,8 +233,8 @@ function Bookmarks() //{{{ "Set the default search engine", "string", "google", { - completer: function completer(filter) completion.runCompleter("search", filter, true), - validator: function validator(value) completion.runCompleter("search", "", true).some(function ([s]) s == value) + completer: function completer(context) completion.search(context, true), + validator: function validator(value) completion.runCompleter("search", "", true).some(function ([s]) s == value) }); options.add(["preload"], diff --git a/content/buffer.js b/content/buffer.js index 3c494bb1..84c374ad 100644 --- a/content/buffer.js +++ b/content/buffer.js @@ -162,7 +162,7 @@ function Buffer() //{{{ ["1", "Show the link in the status line"], ["2", "Show the link in the command line"] ], - validator: function (value) value >= 0 && value <= 2 + validator: options.validateCompleter }); options.add(["usermode", "um"], diff --git a/content/completion.js b/content/completion.js index 2998d86e..7d9fc5ba 100644 --- a/content/completion.js +++ b/content/completion.js @@ -952,7 +952,9 @@ function Completion() //{{{ _runCompleter: function _runCompleter(name, filter) { let context = CompletionContext(filter); - context.fork.apply(context, ["run", 0, this, name].concat(Array.slice(arguments, 2))); + let res = context.fork.apply(context, ["run", 0, this, name].concat(Array.slice(arguments, 2))); + if (res) // FIXME + return { items: res.map(function (i) ({ item: i })) }; while (context.incomplete) liberator.threadYield(true, true); return context.allItems; diff --git a/content/events.js b/content/events.js index de4116d7..e27682eb 100644 --- a/content/events.js +++ b/content/events.js @@ -48,16 +48,8 @@ function AutoCommands() //{{{ "List of autocommand event names which should be ignored", "stringlist", "", { - completer: function (value) config.autocommands.concat([["all", "All events"]]), - validator: function (value) - { - let values = value.split(","); - let events = config.autocommands.map(function (event) event[0]); - - events.push("all"); - - return values.every(function (event) events.indexOf(event) >= 0); - } + completer: function () config.autocommands.concat([["all", "All events"]]), + validator: options.validateCompleter }); options.add(["focuscontent", "fc"], diff --git a/content/hints.js b/content/hints.js index 2503b43f..99896d03 100644 --- a/content/hints.js +++ b/content/hints.js @@ -568,7 +568,7 @@ function Hints() //{{{ { return [[m, ""] for each (m in ["contains", "wordstartswith", "firstletters", "custom"])]; }, - validator: function (value) /^(contains|wordstartswith|firstletters|custom)$/.test(value) + validator: options.validateCompleter }); options.add(["wordseparators", "wsp"], diff --git a/content/liberator.js b/content/liberator.js index 05d18ca8..1e3d9ccd 100644 --- a/content/liberator.js +++ b/content/liberator.js @@ -128,7 +128,7 @@ const liberator = (function () //{{{ ["b", "Bookmark bar"] ].concat(!liberator.has("tabs") ? [] : tabopts); }, - validator: function (value) Array.every(value, function (c) c in config.guioptions || tabopts.some(function (a) a[0] == c)) + validator: options.validateCompleter }); options.add(["helpfile", "hf"], diff --git a/content/mail.js b/content/mail.js index 34167960..44ae50a9 100644 --- a/content/mail.js +++ b/content/mail.js @@ -218,7 +218,7 @@ function Mail() //{{{ return value; }, - validator: function (value) /^(classic|wide|vertical|inherit)$/.test(value) + validator: options.validateCompleter }); /*options.add(["threads"], diff --git a/content/options.js b/content/options.js index ae1ca578..5ffd6bb2 100644 --- a/content/options.js +++ b/content/options.js @@ -170,10 +170,10 @@ Option.prototype = { hasName: function (name) this.names.indexOf(name) >= 0, - isValidValue: function (value) + isValidValue: function (values) { if (this.validator) - return this.validator(value); + return this.validator(values); else return true; }, @@ -277,10 +277,9 @@ Option.prototype = { if (newValue == null) return "Operator " + operator + " not supported for option type " + this.type; - newValue = this.joinValues(newValue); if (!this.isValidValue(newValue)) return "E474: Invalid argument: " + values; - this.set(newValue, scope); + this.setValues(newValue, scope); } }; //}}} @@ -744,9 +743,13 @@ function Options() //{{{ if (!opt.value) completions = [[option.value, "Current value"], [option.defaultValue, "Default value"]].filter(function (f) f[0]); + context.title = ["Option Value"]; if (completer) { - completions = completions.concat(completer(filter)); + let res = completer(context); + if (!res) + return; + completions = completions.concat(res); if (/list$/.test(option.type)) { completions = completions.filter(function (val) opt.values.indexOf(val[0]) == -1); @@ -762,7 +765,6 @@ function Options() //{{{ } } context.compare = function (a, b) 0; - context.title = ["Option Value"]; context.completions = completions; }, literal: true, @@ -989,6 +991,15 @@ function Options() //{{{ return ret; }, + // TODO: Run this by default? + validateCompleter: function (values) + { + let self = this; + let completions = completion.runCompleter(function (context) self.completer(context), ""); + return Array.concat(values).every( + function (value) completions.some(function (item) item[0] == value)); + }, + get store() storage.options, getPref: function (name, forcedDefault) diff --git a/content/tabs.js b/content/tabs.js index 5f770f2a..8b2886da 100644 --- a/content/tabs.js +++ b/content/tabs.js @@ -151,7 +151,7 @@ function Tabs() //{{{ ["2", "Always show tab bar"] ]; }, - validator: function (value) value >= 0 && value <= 2 + validator: options.validateCompleter }); if (config.name == "Vimperator") @@ -169,12 +169,7 @@ function Tabs() //{{{ ["paste", "P and gP mappings"] ]; }, - validator: function (value) - { - return value.split(",").every( - function (item) /^(homepage|quickmark|tabopen|paste|)$/.test(item) - ); - } + validator: options.validateCompleter }); options.add(["newtab"], @@ -192,12 +187,7 @@ function Tabs() //{{{ ["prefs", ":pref[erences]! or :prefs! command"] ]; }, - validator: function (value) - { - return value == "all" || value.split(",").every( - function (item) /^(addons|downloads|help|javascript|prefs|)$/.test(item) - ); - } + validator: options.validateCompleter }); options.add(["popups", "pps"], @@ -227,7 +217,7 @@ function Tabs() //{{{ ["4", "Open in the same tab unless it has a specific requested size"] ]; }, - validator: function (value) value >= 0 && value <= 4 + validator: options.validateCompleter }); // TODO: Add option, or only apply when go~=[nN] styles.addSheet("tab-binding", "chrome://*", diff --git a/content/ui.js b/content/ui.js index 0b0d0d18..8dff6fce 100644 --- a/content/ui.js +++ b/content/ui.js @@ -441,7 +441,7 @@ function CommandLine() //{{{ "charlist", "sfl", { completer: function completer(filter) [k for each (k in completion.urlCompleters)], - validator: function validator(value) Array.every(value, function (v) v in completion.urlCompleters) + validator: options.validateCompleter }); options.add(["history", "hi"], @@ -475,28 +475,19 @@ function CommandLine() //{{{ return engines.map(function (engine) [engine.alias, engine.description]); }, - validator: function validator(value) - { - let ss = Components.classes["@mozilla.org/browser/search-service;1"] - .getService(Components.interfaces.nsIBrowserSearchService); - - return value.split(",").every(function (alias) { - let engine = ss.getEngineByAlias(alias); - return engine && engine.supportsResponseType("application/x-suggestions+json"); - }); - } + validator: options.validateCompleter }); options.add(["wildignore", "wig"], "List of file patterns to ignore when completing files", "stringlist", "", { - validator: function validator(value) + validator: function validator(values) { // TODO: allow for escaping the "," try { - new RegExp("^(" + value.replace(",", "|", "g") + ")$"); + new RegExp("^(" + value.join("|") + ")$"); return true; } catch (e) @@ -521,12 +512,7 @@ function CommandLine() //{{{ ["list:longest", "List all and complete common string"] ]; }, - validator: function validator(value) - { - let self = this; - return value.split(",").every(function (opt) - self.completer().some(function ([key]) key == opt)) - }, + validator: options.validateCompleter, checkHas: function (value, val) { let [first, second] = value.split(":", 2); @@ -545,10 +531,7 @@ function CommandLine() //{{{ ["sort", "Always sort the completion list"] ]; }, - validator: function validator(value) - { - return value.split(",").every(function (item) /^(sort|auto|)$/.test(item)); - } + validator: options.validateCompleter }); /////////////////////////////////////////////////////////////////////////////}}} @@ -1571,7 +1554,7 @@ function StatusLine() //{{{ ["2", "Always display status line"] ]; }, - validator: function validator(value) value >= 0 && value <= 2 + validator: options.validateCompleter }); /////////////////////////////////////////////////////////////////////////////}}}