[Conkeror] [PATCH] merge_completers function to combine completion results
Nelson Elhage
nelhage at MIT.EDU
Sun Mar 23 12:46:32 PDT 2008
First of a series to clean up url_completer().
commit c82353b3e0aee151349107db4e694ade39b7cc4b
Author: Nelson Elhage <nelhage at mit.edu>
Date: Tue Mar 18 13:49:50 2008 -0400
Implement a generic function to combine the results of multiple
minibuffer completion functions
diff --git a/modules/minibuffer-completion.js b/modules/minibuffer-completion.js
index 82cef54..b9ebe98 100644
--- a/modules/minibuffer-completion.js
+++ b/modules/minibuffer-completion.js
@@ -241,3 +241,43 @@ function javascript_completer(buffer) {
};
}
}
+
+
+function merge_completers(completers) {
+ if(completers.length == 0)
+ return null;
+ return function (input, pos, conservative) {
+ var results = [];
+ var count = 0;
+ var results = completers.map(function(c) {
+ var r = c(input, pos, conservative);
+ if(r != null) {
+ count += r.count;
+ }
+ return r;
+ });
+
+ function forward(name) {
+ return function() {
+ var args = Array.prototype.slice.call(arguments);
+ var i = args.shift();
+ for(var j=0; j < results.length; j++) {
+ var r = results[j];
+ if(r == null) continue;
+ if(i < r.count) {
+ args.unshift(i);
+ return r[name].apply(this, args);
+ }
+ i -= r.count;
+ }
+ return null;
+ }
+ }
+ return {count: count,
+ get_string: forward('get_string'),
+ get_description: forward('get_description'),
+ apply: forward('apply'),
+ destroy: forward('destroy')
+ };
+ };
+}
More information about the Conkeror
mailing list