application.js: fix matching of module load error messages to work with Firefox 36
[conkeror.git] / modules / commands.js
blob16509e261ab3480935cbab85e7863c44809999b7
1 /**
2  * (C) Copyright 2004-2007 Shawn Betts
3  * (C) Copyright 2007-2010 John J. Foerch
4  * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
5  *
6  * Use, modification, and distribution are subject to the terms specified in the
7  * COPYING file.
8 **/
10 define_coroutine_hook("before_quit_hook", RUN_HOOK_UNTIL_FAILURE);
11 define_hook("quit_hook");
13 function quit () {
14     var res = yield before_quit_hook.run();
15     if (res) {
16         quit_hook.run();
17         var appStartup = Cc["@mozilla.org/toolkit/app-startup;1"]
18             .getService(Ci.nsIAppStartup);
19         appStartup.quit(appStartup.eAttemptQuit);
20     }
22 interactive("quit", "Quit Conkeror", quit);
25 function show_conkeror_version (window) {
26     var xulrunner_version = Cc['@mozilla.org/xre/app-info;1']
27         .getService(Ci.nsIXULAppInfo)
28         .platformVersion;
29     window.minibuffer.message("Conkeror "+conkeror.version+
30                               " (XULRunner "+xulrunner_version+
31                               ", "+get_os()+")");
33 interactive("conkeror-version",
34     "Show version information for Conkeror.",
35     function (I) { show_conkeror_version(I.window); });
36 interactive("version",
37     "Show version information for Conkeror.",
38     "conkeror-version");
40 /* FIXME: maybe this should be supported for non-browser buffers */
41 function scroll_horiz_complete (buffer, n) {
42     var w = buffer.focused_frame;
43     w.scrollTo (n > 0 ? w.scrollMaxX : 0, w.scrollY);
45 interactive("scroll-beginning-of-line",
46     "Scroll the current frame all the way to the left.",
47     function (I) { scroll_horiz_complete(I.buffer, -1); });
49 interactive("scroll-end-of-line",
50     "Scroll the current frame all the way to the right.",
51     function (I) { scroll_horiz_complete(I.buffer, 1); });
53 interactive("scroll-top-left",
54     "Scroll the current frame all the way to the top left",
55     function (I) {
56         scroll_horiz_complete(I.buffer, -1);
57         I.buffer.do_command("cmd_scrollTop");
58     });
61 function delete_window (window) {
62     window.window.close();
64 interactive("delete-window",
65     "Delete the current window.",
66     function (I) { delete_window(I.window); });
68 interactive("jsconsole",
69     "Open the JavaScript console.",
70     "find-url-new-buffer",
71     $browser_object = "chrome://global/content/console.xul");
74 function paste_x_primary_selection (field) {
75     modify_region(field, function (str) read_from_x_primary_selection());
77 interactive("paste-x-primary-selection",
78     "Insert the contents of the X primary selection into the selected field or "+
79     "minibuffer. Deactivates the region if it is active, and leaves the point "+
80     "after the inserted text.",
81     function (I) call_on_focused_field(I, paste_x_primary_selection, true));
84 function open_line (field) {
85     modify_region(field, function() ["\n", 0]);
87 interactive("open-line",
88     "If there is an active region, replace is with a newline, otherwise just "+
89     "insert a newline. In both cases leave point before the inserted newline.",
90     function (I) call_on_focused_field(I, open_line, true));
93 interactive("insert-parentheses",
94     "Insert a pair of parentheses, or surround the currently selected text "+
95     "with a pair of parentheses.",
96     function (I) {
97         call_on_focused_field(I, function (field) {
98             modify_region(field,
99                           function (str) {
100                               return ["("+str+")", (str ? str.length+2 : 1)];
101                           });
102         }, true);
103     });
106 function transpose_chars (field) {
107     var value = field.value;
108     var caret = field.selectionStart; // Caret position.
109     var length = value.length;
111     // If we have less than two character in the field or if we are at the
112     // beginning of the field, do nothing.
113     if (length < 2 || caret == 0)
114         return;
116     // If we are at the end of the field, switch places on the two last
117     // characters. TODO: This should happen at the end of every line, not only
118     // at the end of the field.
119     if (caret == length)
120         caret--;
122     // Do the transposing.
123     field.value = switch_subarrays(value, caret - 1, caret, caret, caret + 1);
125     // Increment the caret position. If this is not done, the caret is left at
126     // the end of the field as a result of the replacing of contents.
127     field.selectionStart = caret + 1;
128     field.selectionEnd = caret + 1;
130 interactive("transpose-chars",
131     "Interchange characters around point, moving forward one character.",
132     function (I) call_on_focused_field(I, transpose_chars, true));
135 interactive("execute-extended-command",
136     "Call a command specified in the minibuffer.",
137     function (I) {
138         var prefix = I.P;
139         var boc = I.browser_object;
140         var prompt = "M-x";
141         if (I.key_sequence)
142             prompt = I.key_sequence.join(" ");
143         if (boc)
144             prompt += ' ['+boc.name+']';
145         if (prefix !== null && prefix !== undefined) {
146             if (typeof prefix == "object")
147                 prompt += prefix[0] == 4 ? " C-u" : " "+prefix[0];
148             else
149                 prompt += " "+prefix;
150         }
151         var command = yield I.minibuffer.read_command($prompt = prompt);
152         call_after_timeout(function () {
153             input_handle_command.call(I.window, new command_event(command));
154         }, 0);
155     },
156     $prefix = true);
159 /// built in commands
160 // see: http://www.xulplanet.com/tutorials/xultu/commandupdate.html
162 // Performs a command on a browser buffer content area
165 define_builtin_commands("",
166     function (I, command) {
167         call_builtin_command(I.window, command);
168     },
169     false);
171 define_builtin_commands("caret-",
172     function (I, command) {
173         var buffer = I.buffer;
174         try {
175             buffer.do_command(command);
176         } catch (e) {
177             /* Ignore exceptions */
178         }
179     },
180     'caret');
182 function get_link_text () {
183     var e = document.commandDispatcher.focusedElement;
184     if (e && e.getAttribute("href")) {
185         return e.getAttribute("href");
186     }
187     return null;
192 function copy_email_address (loc)
194     // Copy the comma-separated list of email addresses only.
195     // There are other ways of embedding email addresses in a mailto:
196     // link, but such complex parsing is beyond us.
197     var qmark = loc.indexOf( "?" );
198     var addresses;
200     if ( qmark > 7 ) {                   // 7 == length of "mailto:"
201         addresses = loc.substring( 7, qmark );
202     } else {
203         addresses = loc.substr( 7 );
204     }
206     //XXX: the original code, which we got from firefox, unescapes the string
207     //     using the current character set.  To do this in conkeror, we
208     //     *should* use an interactive method that gives us the character set,
209     //     rather than fetching it by side-effect.
211     //     // Let's try to unescape it using a character set
212     //     // in case the address is not ASCII.
213     //     try {
214     //         var characterSet = this.target.ownerDocument.characterSet;
215     //         const textToSubURI = Components.classes["@mozilla.org/intl/texttosuburi;1"]
216     //             .getService(Components.interfaces.nsITextToSubURI);
217     //         addresses = textToSubURI.unEscapeURIForUI(characterSet, addresses);
218     //     }
219     //     catch(ex) {
220     //         // Do nothing.
221     //     }
223     writeToClipboard(addresses);
224     message("Copied '" + addresses + "'");
226 interactive("copy-email-address", copy_email_address, ['focused_link_url']);
229 /* FIXME: fix this command */
231 interactive("source",
232             "Load a JavaScript file.",
233             function (fo) { load_rc (fo.path); }, [['f', function (a) { return "Source File: "; }, null, "source"]]);
235 function reinit (window) {
236     try {
237         var obs = Cc["@mozilla.org/observer-service;1"]
238             .getService(Ci.nsIObserverService);
239         obs.notifyObservers(null, "startupcache-invalidate", null);
240         var path = load_rc();
241         window.minibuffer.message("Loaded: " + path);
242     } catch (e) {
243         window.minibuffer.message("Failed to load: "+path);
244     }
247 interactive("reinit",
248     "Reload the Conkeror rc file.",
249     function (I) { reinit(I.window); });
251 interactive("help-page",
252     "Open the Conkeror help page.",
253     "find-url-new-buffer",
254     $browser_object = "chrome://conkeror-help/content/help.html");
256 interactive("tutorial",
257     "Open the Conkeror tutorial.",
258     "find-url-new-buffer",
259     $browser_object = "chrome://conkeror-help/content/tutorial.html");
261 function univ_arg_to_number (prefix, default_value) {
262     if (prefix == null) {
263         if (default_value == null)
264             return 1;
265         else
266             return default_value;
267     }
268     if (typeof prefix == "object")
269         return prefix[0];
270     return prefix;
274 interactive("eval-expression",
275     "Evaluate JavaScript statements.",
276     function (I) {
277         var s = yield I.minibuffer.read(
278             $prompt = "Eval:",
279             $history = "eval-expression",
280             $completer = new javascript_completer(conkeror));
281         var result = evaluate(s);
282         if (result !== undefined)
283             I.window.minibuffer.message(String(result));
284     });
287 function show_extension_manager () {
288     return conkeror.window_watcher.openWindow(
289         null,
290         "chrome://mozapps/content/extensions/extensions.xul?type=extensions",
291         "ExtensionsWindow",
292         "resizable=yes,dialog=no",
293         null);
295 interactive("extensions",
296     "Open the extensions manager in a new window.",
297     show_extension_manager);
299 function print_buffer (buffer) {
300     buffer.top_frame.print();
303 interactive("print-buffer",
304     "Print the currently loaded page.",
305     function (I) { print_buffer(I.buffer); });
307 function view_partial_source (window, charset, selection) {
308     if (charset)
309         charset = "charset=" + charset;
310     window.window.openDialog("chrome://global/content/viewPartialSource.xul",
311                              "_blank", "scrollbars,resizable,chrome,dialog=no",
312                              null, charset, selection, 'selection');
314 //interactive ('view-partial-source', view_partial_source, I.current_window, I.content_charset, I.content_selection);
317 function view_mathml_source (window, charset, target) {
318     if (charset)
319         charset = "charset=" + charset;
320     window.window.openDialog("chrome://global/content/viewPartialSource.xul",
321                              "_blank", "scrollbars,resizable,chrome,dialog=no",
322                              null, charset, target, 'mathml');
326 function send_key_as_event (window, element, combo) {
327     var split = unformat_key_combo(combo);
328     var event = window.document.createEvent("KeyboardEvent");
329     event.initKeyEvent(
330         "keypress",
331         true,
332         true,
333         null,
334         split.ctrlKey,
335         split.altKey,
336         split.shiftKey,
337         split.metaKey,
338         split.keyCode,
339         split.charCode);
340     if (element)
341         return element.dispatchEvent(event);
342     else
343         return window.dispatchEvent(event);
347 function ensure_content_focused (buffer) {
348     var foc = buffer.focused_frame_or_null;
349     if (!foc)
350         buffer.top_frame.focus();
352 interactive("ensure-content-focused", "Ensure that the content document has focus.",
353     function (I) { ensure_content_focused(I.buffer); });
356 function network_set_online_status (status) {
357     const io_service = Cc["@mozilla.org/network/io-service;1"]
358         .getService(Ci.nsIIOService2);
359     status = !status;
360     io_service.manageOfflineStatus = false;
361     io_service.offline = status;
363 interactive("network-go-online", "Work online.",
364     function (I) { network_set_online_status(true); });
366 interactive("network-go-offline", "Work offline.",
367     function (I) { network_set_online_status(false); });
370 interactive("submit-form",
371     "Submit the form to which the focused element belongs.",
372     function (I) {
373         var el = I.buffer.focused_element.parentNode;
374         while (el && el.tagName != "FORM")
375             el = el.parentNode;
376         if (el) {
377             var inputs = el.getElementsByTagName("input");
378             for (var i = 0, ilen = inputs.length; i < ilen; i++) {
379                 if (inputs[i].getAttribute("type") == "submit")
380                     return browser_object_follow(I.buffer, FOLLOW_DEFAULT,
381                                                  inputs[i]);
382             }
383             el.submit();
384         }
385     });
389  * Browser Object Commands
390  */
391 interactive("follow", null,
392     alternates(follow, follow_new_buffer, follow_new_window),
393     $browser_object = browser_object_links);
395 interactive("follow-top", null,
396     alternates(follow_current_buffer, follow_current_frame),
397     $browser_object = browser_object_frames,
398     $prompt = "Follow");
400 interactive("follow-new-buffer",
401     "Follow a link in a new buffer",
402     alternates(follow_new_buffer, follow_new_window),
403     $browser_object = browser_object_links,
404     $prompt = "Follow");
406 interactive("follow-new-buffer-background",
407     "Follow a link in a new buffer in the background",
408     alternates(follow_new_buffer_background, follow_new_window),
409     $browser_object = browser_object_links,
410     $prompt = "Follow");
412 interactive("follow-new-window",
413     "Follow a link in a new window",
414     follow_new_window,
415     $browser_object = browser_object_links,
416     $prompt = "Follow");
418 interactive("find-url", "Open a URL in the current buffer",
419     alternates(follow_current_buffer, follow_new_buffer, follow_new_window),
420     $browser_object = browser_object_url);
422 interactive("find-url-new-buffer",
423     "Open a URL in a new buffer",
424     alternates(follow_new_buffer, follow_new_window),
425     $browser_object = browser_object_url,
426     $prompt = "Find url");
428 interactive("find-url-new-window", "Open a URL in a new window",
429     follow_new_window,
430     $browser_object = browser_object_url,
431     $prompt = "Find url");
433 interactive("find-alternate-url", "Edit the current URL in the minibuffer",
434     "find-url",
435     $browser_object =
436         define_browser_object_class("alternate-url", null,
437             function (I, prompt) {
438                 check_buffer(I.buffer, content_buffer);
439                 var result = yield I.buffer.window.minibuffer.read_url(
440                     $prompt = prompt,
441                     $initial_value = I.buffer.display_uri_string);
442                 yield co_return(result);
443             }),
444     $prompt = "Find url");
447 interactive("up", "Go to the parent directory of the current URL",
448     "find-url",
449     $browser_object = browser_object_up_url);
451 interactive("home",
452     "Go to the homepage in the current buffer.", "follow",
453     $browser_object = function () { return homepage; });
455 interactive("make-window",
456     "Make a new window with the homepage.",
457     follow_new_window,
458     $browser_object = function () { return homepage; });
460 interactive("focus", null,
461     function (I) {
462         var element = yield read_browser_object(I);
463         browser_element_focus(I.buffer, element);
464     },
465     $browser_object = browser_object_frames);
467 interactive("save",
468     "Save a browser object.",
469     function (I) {
470         var element = yield read_browser_object(I);
471         var spec = load_spec(element);
472         var panel;
473         panel = create_info_panel(I.window, "download-panel",
474                                   [["downloading",
475                                     element_get_operation_label(element, "Saving"),
476                                     load_spec_uri_string(spec)],
477                                    ["mime-type", "Mime type:", load_spec_mime_type(spec)]]);
478         try {
479             var file = yield I.minibuffer.read_file_check_overwrite(
480                 $prompt = "Save as:",
481                 $initial_value = suggest_save_path_from_file_name(suggest_file_name(spec), I.buffer),
482                 $history = "save");
483         } finally {
484             panel.destroy();
485         }
486         save_uri(spec, file,
487                  $buffer = I.buffer,
488                  $use_cache = false);
489     },
490     $browser_object = browser_object_links);
493 interactive("copy", null,
494     alternates(copy_text, copy_text_append),
495     $browser_object = browser_object_links);
497 interactive("paste-url", "Open a URL from the clipboard in the current buffer.",
498     alternates(follow_current_buffer, follow_new_buffer, follow_new_window),
499     $browser_object = browser_object_paste_url);
501 interactive("paste-url-new-buffer", "Open a URL from the clipboard in a new buffer.",
502     alternates(follow_new_buffer, follow_new_window),
503     $browser_object = browser_object_paste_url);
505 interactive("paste-url-new-window", "Open a URL from the clipboard in a new window.",
506     follow_new_window,
507     $browser_object = browser_object_paste_url);
509 interactive("view-source",
510     "Toggle between source and rendered views of a URL.",
511     alternates(view_source, view_source_new_buffer, view_source_new_window),
512     $browser_object = browser_object_frames);
515 interactive("shell-command-on-url",
516     "Run a shell command on the url of a browser object.\n\n"+
517     "If the given shell command contains the string '{}', the "+
518     "url will be substituted in its place, otherwise the url "+
519     "will be added to the end of the command.",
520     function (I) {
521         var cwd = I.local.cwd;
522         var element = yield read_browser_object(I);
523         var spec = load_spec(element);
524         var uri = load_spec_uri_string(spec);
525         var panel = create_info_panel(I.window, "download-panel",
526                                       [["downloading",
527                                         element_get_operation_label(element, "Running on", "URI"),
528                                         load_spec_uri_string(spec)],
529                                        ["mime-type", "Mime type:", load_spec_mime_type(spec)]]);
530         try {
531             var cmd = yield I.minibuffer.read_shell_command(
532                 $cwd = cwd,
533                 $initial_value = load_spec_default_shell_command(spec));
534         } finally {
535             panel.destroy();
536         }
537         shell_command_with_argument_blind(cmd, uri, $cwd = cwd);
538     },
539     $browser_object = browser_object_url,
540     $prompt = "Shell command");
543 interactive("shell-command-on-file",
544     "Download a document to a temporary file and run a shell command on it.",
545     function (I) {
546         var cwd = I.local.cwd;
547         var element = yield read_browser_object(I);
548         var spec = load_spec(element);
549         var uri = load_spec_uri_string(spec);
550         var panel = create_info_panel(I.window, "download-panel",
551                                       [["downloading",
552                                         element_get_operation_label(element, "Running on"),
553                                         load_spec_uri_string(spec)],
554                                        ["mime-type", "Mime type:", load_spec_mime_type(spec)]]);
555         try {
556             var cmd = yield I.minibuffer.read_shell_command(
557                 $cwd = cwd,
558                 $initial_value = load_spec_default_shell_command(spec));
559         } finally {
560             panel.destroy();
561         }
562         yield browser_element_shell_command(I.buffer, element, cmd, cwd);
563     },
564     $browser_object = browser_object_links,
565     $prompt = "Shell command");
568 interactive("bookmark",
569     "Create a bookmark.",
570     function (I) {
571         var element = yield read_browser_object(I);
572         var spec = load_spec(element);
573         var uri_string = load_spec_uri_string(spec);
574         var panel = create_info_panel(I.window, "bookmark-panel",
575                                       [["bookmarking",
576                                         element_get_operation_label(element, "Bookmarking"),
577                                         uri_string]]);
578         try {
579             var title = yield I.minibuffer.read($prompt = "Bookmark with title:", $initial_value = load_spec_title(spec) || "");
580         } finally {
581             panel.destroy();
582         }
583         add_bookmark(uri_string, title);
584         I.minibuffer.message("Added bookmark: " + uri_string + " - " + title);
585     },
586     $browser_object = browser_object_frames);
589 interactive("save-page",
590     "Save a document, not including any embedded documents such as images "+
591     "and css.",
592     function (I) {
593         check_buffer(I.buffer, content_buffer);
594         var element = yield read_browser_object(I);
595         var spec = load_spec(element);
596         if (!load_spec_document(spec))
597             throw interactive_error("Element is not associated with a document.");
598         var suggested_path = suggest_save_path_from_file_name(suggest_file_name(spec), I.buffer);
599         var panel = create_info_panel(I.window, "download-panel",
600                                       [["downloading",
601                                         element_get_operation_label(element, "Saving"),
602                                         load_spec_uri_string(spec)],
603                                        ["mime-type", "Mime type:", load_spec_mime_type(spec)]]);
604         try {
605             var file = yield I.minibuffer.read_file_check_overwrite(
606                 $prompt = "Save page as:",
607                 $history = "save",
608                 $initial_value = suggested_path);
609         } finally {
610             panel.destroy();
611         }
612         save_uri(spec, file, $buffer = I.buffer);
613     },
614     $browser_object = browser_object_frames);
617 interactive("save-page-as-text",
618     "Save a page as plain text.",
619     function (I) {
620         check_buffer(I.buffer, content_buffer);
621         var element = yield read_browser_object(I);
622         var spec = load_spec(element);
623         var doc;
624         if (!(doc = load_spec_document(spec)))
625             throw interactive_error("Element is not associated with a document.");
626         var suggested_path = suggest_save_path_from_file_name(suggest_file_name(spec, "txt"), I.buffer);
627         var panel = create_info_panel(I.window, "download-panel",
628                                       [["downloading",
629                                         element_get_operation_label(element, "Saving", "as text"),
630                                         load_spec_uri_string(spec)],
631                                        ["mime-type", "Mime type:", load_spec_mime_type(spec)]]);
632         try {
633             var file = yield I.minibuffer.read_file_check_overwrite(
634                 $prompt = "Save page as text:",
635                 $history = "save",
636                 $initial_value = suggested_path);
637         } finally {
638             panel.destroy();
639         }
640         save_document_as_text(doc, file, $buffer = I.buffer);
641     },
642     $browser_object = browser_object_frames);
645 interactive("save-page-complete",
646     "Save a page and all supporting documents, including images, css, "+
647     "and child frame documents.",
648     function (I) {
649         check_buffer(I.buffer, content_buffer);
650         var element = yield read_browser_object(I);
651         var spec = load_spec(element);
652         var doc;
653         if (!(doc = load_spec_document(spec)))
654             throw interactive_error("Element is not associated with a document.");
655         var suggested_path = suggest_save_path_from_file_name(suggest_file_name(spec), I.buffer);
656         var panel = create_info_panel(I.window, "download-panel",
657                                       [["downloading",
658                                         element_get_operation_label(element, "Saving complete"),
659                                         load_spec_uri_string(spec)],
660                                        ["mime-type", "Mime type:", load_spec_mime_type(spec)]]);
661         try {
662             var file = yield I.minibuffer.read_file_check_overwrite(
663                 $prompt = "Save page complete:",
664                 $history = "save",
665                 $initial_value = suggested_path);
666             // FIXME: use proper read function
667             var dir = yield I.minibuffer.read_file(
668                 $prompt = "Data Directory:",
669                 $history = "save",
670                 $initial_value = file.path + ".support");
671         } finally {
672             panel.destroy();
673         }
674         save_document_complete(doc, file, dir, $buffer = I.buffer);
675     },
676     $browser_object = browser_object_frames);
679 function view_as_mime_type (I, target) {
680     I.target = target;
681     var element = yield read_browser_object(I);
682     var spec = load_spec(element);
684     if (target == null)
685         target = FOLLOW_CURRENT_FRAME;
687     if (!can_override_mime_type_for_uri(load_spec_uri(spec)))
688         throw interactive_error("Overriding the MIME type is not currently supported for non-HTTP URLs.");
690     var mime_type = load_spec_mime_type(spec);
691     var panel = create_info_panel(I.window, "download-panel",
692                                   [["downloading",
693                                     element_get_operation_label(element, "View in browser"),
694                                     load_spec_uri_string(spec)],
695                                    ["mime-type", "Mime type:", load_spec_mime_type(spec)]]);
696     try {
697         let suggested_type = mime_type;
698         if (viewable_mime_type_list.indexOf(suggested_type) == -1)
699             suggested_type = "text/plain";
700         mime_type = yield I.minibuffer.read_viewable_mime_type(
701             $prompt = "View internally as",
702             $initial_value = suggested_type,
703             $select);
704         yield override_mime_type_for_next_load(load_spec_uri(spec), mime_type);
705         browser_object_follow(I.buffer, target, spec);
706     } finally {
707         panel.destroy();
708     }
711 function view_as_mime_type_new_buffer (I) {
712     yield view_as_mime_type(I, OPEN_NEW_BUFFER);
715 function view_as_mime_type_new_window (I) {
716     yield view_as_mime_type(I, OPEN_NEW_WINDOW);
719 interactive("view-as-mime-type",
720     "Display a browser object in the browser using the specified MIME type.",
721     alternates(view_as_mime_type,
722                view_as_mime_type_new_buffer,
723                view_as_mime_type_new_window),
724     $browser_object = browser_object_frames);
727 interactive("delete",
728     "Delete a DOM node, given as a browser object.",
729     function (I) {
730         var elem = yield read_browser_object(I);
731         if (! (elem instanceof Ci.nsIDOMNode))
732             throw interactive_error("Cannot delete item");
733         elem.parentNode.removeChild(elem);
734     },
735     $browser_object = browser_object_dom_node);
738 interactive("charset-prefix",
739     "A prefix command that prompts for a charset to use in a "+
740     "subsequent navigation command.",
741     function (I) {
742         var ccman = Cc["@mozilla.org/charset-converter-manager;1"]
743             .getService(Ci.nsICharsetConverterManager);
744         var decoders = ccman.getDecoderList()
745         var charsets = [];
746         while (decoders.hasMore())
747             charsets.push(decoders.getNext());
748         I.forced_charset = yield I.minibuffer.read(
749             $prompt = "Charset:",
750             $completer = new prefix_completer(
751                 $completions = charsets,
752                 $get_string = function (x) x.toLowerCase()),
753             $require_match,
754             $space_completes);
755     },
756     $prefix);
759 interactive("reload-with-charset",
760     "Prompt for a charset, and reload the current page, forcing use "+
761     "of that charset.",
762     function (I) {
763         var ccman = Cc["@mozilla.org/charset-converter-manager;1"]
764             .getService(Ci.nsICharsetConverterManager);
765         var decoders = ccman.getDecoderList()
766         var charsets = [];
767         while (decoders.hasMore())
768             charsets.push(decoders.getNext());
769         var forced_charset = yield I.minibuffer.read(
770             $prompt = "Charset:",
771             $completer = new prefix_completer(
772                 $completions = charsets,
773                 $get_string = function (x) x.toLowerCase()),
774             $require_match,
775             $space_completes);
776         reload(I.buffer, false, null, forced_charset);
777     });
780 interactive("yank",
781     "Paste the contents of the clipboard",
782     function (I) {
783         call_builtin_command(I.window, "cmd_paste", true);
784     });
786 interactive("kill-region",
787     "Kill (\"cut\") the selected text.",
788     function (I) {
789         call_builtin_command(I.window, "cmd_cut", true);
790     });
792 interactive("kill-ring-save",
793     "Save the region as if killed, but don't kill it.",
794     function (I) {
795         call_builtin_command(I.window, "cmd_copy", true);
796     });
798 interactive("password-manager",
799     "Open the password manager.",
800     "find-url-new-buffer",
801     $browser_object = "chrome://passwordmgr/content/passwordManager.xul");
804 interactive("toggle-full-screen",
805     "Toggle full screen mode for the current window.",
806     function (I) {
807         window_set_full_screen(I.window);
808         if (I.window.fullScreen)
809             I.minibuffer.message("Fullscreen mode on");
810         else
811             I.minibuffer.message("Fullscreen mode off");
812     });
815 interactive("image-toggle-zoom-to-fit",
816     "Toggle zoom-to-fit (viewport) on an image document.",
817     function (I) {
818         try {
819             var doc = I.buffer.document
820                 .QueryInterface(Ci.nsIImageDocument);
821             doc.toggleImageSize();
822             zoom_hook.run(I.buffer);
823         } catch (e) {
824             I.minibuffer.message("Not an image document");
825         }
826     });
829 provide("commands");