3 var interactive_commands = new string_hashmap();
6 * First argument is the command name.
8 * This is optionally followed by a documentation string.
10 * This is followed by the command function.
12 function interactive(name)
17 if (typeof(arguments[1]) == "string" || arguments[1] == null)
22 handler = arguments[offset++];
27 shortdoc: get_shortdoc_string(doc),
28 source_code_reference: get_caller_source_code_reference() };
30 interactive_commands.put(name, cmd);
33 function interactive_error(str) {
34 var e = new Error(str);
35 e.__proto__ = interactive_error.prototype;
38 interactive_error.prototype.__proto__ = Error;
40 function interactive_context() {}
41 interactive_context.prototype = {
43 get P () this.prefix_argument,
45 get p () univ_arg_to_number(this.prefix_argument),
47 set p (default_value) univ_arg_to_number(this.prefix_argument, default_value),
49 get minibuffer () this.window.minibuffer
52 function handle_interactive_error(window, e) {
53 if (e instanceof interactive_error)
54 window.minibuffer.message(e.message);
55 else if (e instanceof abort)
56 window.minibuffer.message("Quit");
59 window.minibuffer.message("call interactively: " + e);
63 // Any additional arguments specify "given" arguments to the function.
64 function call_interactively(I, command)
69 I.__proto__ = interactive_context.prototype;
72 I.buffer = I.window.buffers.current;
73 else if (I.window == null)
74 I.window = I.buffer.window;
76 var window = I.window;
78 var cmd = interactive_commands.get(command);
81 window.minibuffer.message("Invalid command: " + command);
87 var handler = cmd.handler;
90 var result = handler(I);
91 if (is_coroutine(result)) {
96 handle_interactive_error(window, e);
102 handle_interactive_error(window, e);
107 I.f = interactive_method(
108 $doc = "Existing file",
109 $async = function (ctx, cont) {
110 keywords(arguments, $prompt = "File:", $initial_value = default_directory.path,
112 ctx.window.minibuffer.read(
113 $prompt = arguments.$prompt,
114 $initial_value = arguments.$initial_value,
115 $history = arguments.$history,
116 $callback = function(s) {
117 var f = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
123 // FIXME: eventually they will differ, when completion for files is added