From 28ef2ec54aa5db1e9d187ac66371ecff50a3669d Mon Sep 17 00:00:00 2001 From: John Foerch Date: Wed, 1 Feb 2012 01:45:10 -0500 Subject: [PATCH] interactive_commands: use js object instead of string_hashmap --- modules/help.js | 12 ++++++------ modules/input.js | 4 ++-- modules/interactive.js | 13 ++++++------- modules/minibuffer-read.js | 6 +++++- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/modules/help.js b/modules/help.js index c1ec1bd..d704716 100644 --- a/modules/help.js +++ b/modules/help.js @@ -215,7 +215,7 @@ describe_bindings_buffer.prototype = { if (typeof(bind.command) == "function") { g.text("[function]", command_td); } else { - let cmd = interactive_commands.get(bind.command); + let cmd = interactive_commands[bind.command]; if (cmd != null) { g.command_reference(cmd.name, command_td); help_str = cmd.shortdoc; @@ -374,12 +374,12 @@ apropos_command_buffer.prototype = { /* TODO: support regexps/etc. */ function apropos_command (buffer, substring, target) { var list = []; - interactive_commands.for_each(function (name, cmd) { + for (let [name, cmd] in Iterator(interactive_commands)) { if (name.indexOf(substring) != -1) { var binding = {name: name, cmd: cmd}; list.push(binding); } - }); + } list.sort(function (a,b) { if (a.name < b.name) return -1; @@ -421,7 +421,7 @@ function describe_command_buffer (window) { special_buffer.call(this, window, forward_keywords(arguments)); this.bindings = arguments.$bindings; this.command = arguments.$command; - this.cmd = interactive_commands.get(this.command); + this.cmd = interactive_commands[this.command]; this.source_code_reference = this.cmd.source_code_reference; this.modalities.push(help_buffer_modality); this.constructor_end(); @@ -446,7 +446,7 @@ describe_command_buffer.prototype = { p = g.element("p", d.body); g.command_reference(this.command, p); - var cmd = interactive_commands.get(this.command); + var cmd = interactive_commands[this.command]; if (cmd.source_code_reference) { g.text(" is an interactive command in ", p); g.source_code_reference(cmd.source_code_reference, p); @@ -569,7 +569,7 @@ describe_key_buffer.prototype = { if (command != null) { p = g.element("p", d.body); g.command_reference(command, p); - var cmd = interactive_commands.get(command); + var cmd = interactive_commands[command]; if (cmd.source_code_reference) { g.text(" is an interactive command in ", p); g.source_code_reference(cmd.source_code_reference, p); diff --git a/modules/input.js b/modules/input.js index e48d33c..0fe3f6a 100644 --- a/modules/input.js +++ b/modules/input.js @@ -233,7 +233,7 @@ sequence: command = binding.repeat; yield call_interactively(I, command); if (typeof command == "string" && - interactive_commands.get(command).prefix) + interactive_commands[command].prefix) { keymaps = get_current_keymaps(window); //back to top keymap input_show_partial_sequence(window, I); @@ -256,7 +256,7 @@ sequence: input_help_timer_clear(window); window.minibuffer.clear(); yield call_interactively(I, command); - if (! interactive_commands.get(command).prefix) + if (! interactive_commands[command].prefix) break sequence; } break; diff --git a/modules/interactive.js b/modules/interactive.js index 0d5afb2..9c22261 100644 --- a/modules/interactive.js +++ b/modules/interactive.js @@ -8,7 +8,7 @@ require("utils.js"); -var interactive_commands = new string_hashmap(); +var interactive_commands = {}; /** * name: string name of the command. @@ -32,8 +32,7 @@ function interactive (name, doc, handler) { shortdoc: get_shortdoc_string(doc), prompt: arguments.$prompt, source_code_reference: get_caller_source_code_reference() }; - - interactive_commands.put(name, cmd); + interactive_commands[name] = cmd; return name; } @@ -93,7 +92,7 @@ function call_interactively (I, command) { yield co_return(); } - var cmd = interactive_commands.get(command); + var cmd = interactive_commands[command]; if (!cmd) { handle_interactive_error( window, @@ -106,7 +105,7 @@ function call_interactively (I, command) { try { while (typeof handler == "string") { - let parent = interactive_commands.get(handler); + let parent = interactive_commands[handler]; handler = parent.handler; if (handler == command) { throw (interactive_error("circular command alias, "+command)); @@ -145,12 +144,12 @@ function alternates () { * of interactive commands. */ function set_handler (name, handler) { - var cmd = interactive_commands.get(name); + var cmd = interactive_commands[name]; cmd.handler = handler; } function set_default_browser_object (name, browser_object) { - var cmd = interactive_commands.get(name); + var cmd = interactive_commands[name]; cmd.browser_object = browser_object; } diff --git a/modules/minibuffer-read.js b/modules/minibuffer-read.js index 431f13a..d559ba2 100644 --- a/modules/minibuffer-read.js +++ b/modules/minibuffer-read.js @@ -517,7 +517,11 @@ minibuffer.prototype.read_command = function () { arguments, $prompt = "Command", $history = "command", $completer = prefix_completer( - $completions = function (visitor) interactive_commands.for_each_value(visitor), + $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), -- 2.11.4.GIT