Skip to content

Instantly share code, notes, and snippets.

@jordonbiondo
Created May 20, 2014 20:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jordonbiondo/3174df4b718695ebaf5e to your computer and use it in GitHub Desktop.
Save jordonbiondo/3174df4b718695ebaf5e to your computer and use it in GitHub Desktop.
/**
* Read a command from the minibuffer fuzzily
*/
minibuffer.prototype.read_command_fuzzy = function () {
keywords(
arguments,
$prompt = "Command", $history = "command",
$completer = all_word_completer (
$completions = function (visitor) {
for (let [k,v] in Iterator(interactive_commands)) {
visitor(v);
}
},
$get_string = function (x) x.name,
//$get_description = function (x) x.shortdoc || "",
$get_value = function (x) x.name),
$match_required,
$select,
//$space_completes,
$auto_complete_initial,
$auto_complete = true,
$auto_complete_delay = 50
);
var result = yield this.read(forward_keywords(arguments));
yield co_return(result);
};
/**
* Read and call command with fuzzy matching
* > searching for entering 'f char' will match forward-char
*/
interactive("smex",
"Call a command specified in the minibuffer.",
function (I) {
var prefix = I.P;
var boc = I.browser_object;
var prompt = ">>> ";
if (boc)
prompt += ' ['+boc.name+']';
if (prefix !== null && prefix !== undefined) {
if (typeof prefix == "object")
prompt += prefix[0] == 4 ? " C-u" : " "+prefix[0];
else
prompt += " "+prefix;
}
var command = yield I.minibuffer.read_command_fuzzy($prompt = prompt);
call_after_timeout(function () {
input_handle_command.call(I.window, new command_event(command));
}, 0);
},
$prefix = true);
define_key(content_buffer_normal_keymap, "o", "smex");
provide("smex");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment