duckduckgo_anchor_keymap: remove binding of duckduckgo-follow-current (return)
[conkeror.git] / modules / commands.js
blobdd132672e9c06d2b47d6c7d8857182363c772c34
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) { I.buffer.do_command("cmd_scrollTop");
56                     scroll_horiz_complete(I.buffer, -1); });
59 function delete_window (window) {
60     window.window.close();
62 interactive("delete-window",
63     "Delete the current window.",
64     function (I) { delete_window(I.window); });
66 interactive("jsconsole",
67     "Open the JavaScript console.",
68     "find-url-new-buffer",
69     $browser_object = "chrome://global/content/console.xul");
72 function paste_x_primary_selection (field) {
73     modify_region(field, function (str) read_from_x_primary_selection());
75 interactive("paste-x-primary-selection",
76     "Insert the contents of the X primary selection into the selected field or "+
77     "minibuffer. Deactivates the region if it is active, and leaves the point "+
78     "after the inserted text.",
79     function (I) call_on_focused_field(I, paste_x_primary_selection, true));
82 function open_line (field) {
83     modify_region(field, function() ["\n", 0]);
85 interactive("open-line",
86     "If there is an active region, replace is with a newline, otherwise just "+
87     "insert a newline. In both cases leave point before the inserted newline.",
88     function (I) call_on_focused_field(I, open_line, true));
91 interactive("insert-parentheses",
92     "Insert a pair of parentheses, or surround the currently selected text "+
93     "with a pair of parentheses.",
94     function (I) {
95         call_on_focused_field(I, function (field) {
96             modify_region(field,
97                           function (str) {
98                               return ["("+str+")", (str ? str.length+2 : 1)];
99                           });
100         }, true);
101     });
104 function transpose_chars (field) {
105     var value = field.value;
106     var caret = field.selectionStart; // Caret position.
107     var length = value.length;
109     // If we have less than two character in the field or if we are at the
110     // beginning of the field, do nothing.
111     if (length < 2 || caret == 0)
112         return;
114     // If we are at the end of the field, switch places on the two last
115     // characters. TODO: This should happen at the end of every line, not only
116     // at the end of the field.
117     if (caret == length)
118         caret--;
120     // Do the transposing.
121     field.value = switch_subarrays(value, caret - 1, caret, caret, caret + 1);
123     // Increment the caret position. If this is not done, the caret is left at
124     // the end of the field as a result of the replacing of contents.
125     field.selectionStart = caret + 1;
126     field.selectionEnd = caret + 1;
128 interactive("transpose-chars",
129     "Interchange characters around point, moving forward one character.",
130     function (I) call_on_focused_field(I, transpose_chars, true));
133 interactive("execute-extended-command",
134     "Call a command specified in the minibuffer.",
135     function (I) {
136         var prefix = I.P;
137         var boc = I.browser_object;
138         var prompt = "M-x";
139         if (I.key_sequence)
140             prompt = I.key_sequence.join(" ");
141         if (boc)
142             prompt += ' ['+boc.name+']';
143         if (prefix !== null && prefix !== undefined) {
144             if (typeof prefix == "object")
145                 prompt += prefix[0] == 4 ? " C-u" : " "+prefix[0];
146             else
147                 prompt += " "+prefix;
148         }
149         var command = yield I.minibuffer.read_command($prompt = prompt);
150         call_after_timeout(function () {
151             input_handle_command.call(I.window, new command_event(command));
152         }, 0);
153     },
154     $prefix = true);
157 /// built in commands
158 // see: http://www.xulplanet.com/tutorials/xultu/commandupdate.html
160 // Performs a command on a browser buffer content area
163 define_builtin_commands(
164     "",
165     function (I, command) {
166         call_builtin_command(I.window, command);
167     },
168     false
171 define_builtin_commands(
172     "caret-",
173     function (I, command) {
174         var buffer = I.buffer;
175         try {
176             buffer.do_command(command);
177         } catch (e) {
178             /* Ignore exceptions */
179         }
180     },
181     'caret');
183 function get_link_text () {
184     var e = document.commandDispatcher.focusedElement;
185     if (e && e.getAttribute("href")) {
186         return e.getAttribute("href");
187     }
188     return null;
193 function copy_email_address (loc)
195     // Copy the comma-separated list of email addresses only.
196     // There are other ways of embedding email addresses in a mailto:
197     // link, but such complex parsing is beyond us.
198     var qmark = loc.indexOf( "?" );
199     var addresses;
201     if ( qmark > 7 ) {                   // 7 == length of "mailto:"
202         addresses = loc.substring( 7, qmark );
203     } else {
204         addresses = loc.substr( 7 );
205     }
207     //XXX: the original code, which we got from firefox, unescapes the string
208     //     using the current character set.  To do this in conkeror, we
209     //     *should* use an interactive method that gives us the character set,
210     //     rather than fetching it by side-effect.
212     //     // Let's try to unescape it using a character set
213     //     // in case the address is not ASCII.
214     //     try {
215     //         var characterSet = this.target.ownerDocument.characterSet;
216     //         const textToSubURI = Components.classes["@mozilla.org/intl/texttosuburi;1"]
217     //             .getService(Components.interfaces.nsITextToSubURI);
218     //         addresses = textToSubURI.unEscapeURIForUI(characterSet, addresses);
219     //     }
220     //     catch(ex) {
221     //         // Do nothing.
222     //     }
224     writeToClipboard(addresses);
225     message("Copied '" + addresses + "'");
227 interactive("copy-email-address", copy_email_address, ['focused_link_url']);
230 /* FIXME: fix this command */
232 interactive("source",
233             "Load a JavaScript file.",
234             function (fo) { load_rc (fo.path); }, [['f', function (a) { return "Source File: "; }, null, "source"]]);
236 function reinit (window) {
237     try {
238         var obs = Cc["@mozilla.org/observer-service;1"]
239             .getService(Ci.nsIObserverService);
240         obs.notifyObservers(null, "startupcache-invalidate", null);
241         var path = load_rc();
242         window.minibuffer.message("Loaded: " + path);
243     } catch (e) {
244         window.minibuffer.message("Failed to load: "+path);
245     }
248 interactive("reinit",
249             "Reload the Conkeror rc file.",
250             function (I) { reinit(I.window); });
252 interactive("help-page", "Open the Conkeror help page.",
253             "find-url-new-buffer",
254             $browser_object = "chrome://conkeror-help/content/help.html");
256 interactive("tutorial", "Open the Conkeror tutorial.",
257             "find-url-new-buffer",
258             $browser_object = "chrome://conkeror-help/content/tutorial.html");
260 function univ_arg_to_number (prefix, default_value) {
261     if (prefix == null) {
262         if (default_value == null)
263             return 1;
264         else
265             return default_value;
266     }
267     if (typeof prefix == "object")
268         return prefix[0];
269     return prefix;
273 interactive("eval-expression",
274     "Evaluate JavaScript statements.",
275     function (I) {
276         var s = yield I.minibuffer.read(
277             $prompt = "Eval:",
278             $history = "eval-expression",
279             $completer = javascript_completer(I.buffer));
280         var result = evaluate(s);
281         if (result !== undefined)
282             I.window.minibuffer.message(String(result));
283     });
286 function show_extension_manager () {
287     return conkeror.window_watcher.openWindow(
288         null,
289         "chrome://mozapps/content/extensions/extensions.xul?type=extensions",
290         "ExtensionsWindow",
291         "resizable=yes,dialog=no",
292         null);
294 interactive("extensions",
295     "Open the extensions manager in a new window.",
296     show_extension_manager);
298 function print_buffer (buffer) {
299     buffer.top_frame.print();
302 interactive("print-buffer",
303     "Print the currently loaded page.",
304     function (I) { print_buffer(I.buffer); });
306 function view_partial_source (window, charset, selection) {
307     if (charset)
308         charset = "charset=" + charset;
309     window.window.openDialog("chrome://global/content/viewPartialSource.xul",
310                              "_blank", "scrollbars,resizable,chrome,dialog=no",
311                              null, charset, selection, 'selection');
313 //interactive ('view-partial-source', view_partial_source, I.current_window, I.content_charset, I.content_selection);
316 function  view_mathml_source (window, charset, target) {
317     if (charset)
318         charset = "charset=" + charset;
319     window.window.openDialog("chrome://global/content/viewPartialSource.xul",
320                              "_blank", "scrollbars,resizable,chrome,dialog=no",
321                              null, charset, target, 'mathml');
325 function send_key_as_event (window, element, combo) {
326     var split = unformat_key_combo(combo);
327     var event = window.document.createEvent("KeyboardEvent");
328     event.initKeyEvent(
329         "keypress",
330         true,
331         true,
332         null,
333         split.ctrlKey,
334         split.altKey,
335         split.shiftKey,
336         split.metaKey,
337         split.keyCode,
338         split.charCode);
339     if (element) {
340         return element.dispatchEvent(event);
341     } else {
342         return window.dispatchEvent(event);
343     }
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;
526         panel = create_info_panel(I.window, "download-panel",
527                                   [["downloading",
528                                     element_get_operation_label(element, "Running on", "URI"),
529                                     load_spec_uri_string(spec)],
530                                    ["mime-type", "Mime type:", load_spec_mime_type(spec)]]);
531         try {
532             var cmd = yield I.minibuffer.read_shell_command(
533                 $cwd = cwd,
534                 $initial_value = load_spec_default_shell_command(spec));
535         } finally {
536             panel.destroy();
537         }
538         shell_command_with_argument_blind(cmd, uri, $cwd = cwd);
539     },
540     $browser_object = browser_object_url,
541     $prompt = "Shell command");
544 interactive("shell-command-on-file",
545     "Download a document to a temporary file and run a shell command on it.",
546     function (I) {
547         var cwd = I.local.cwd;
548         var element = yield read_browser_object(I);
549         var spec = load_spec(element);
550         var uri = load_spec_uri_string(spec);
551         var panel;
552         panel = create_info_panel(I.window, "download-panel",
553                                   [["downloading",
554                                     element_get_operation_label(element, "Running on"),
555                                     load_spec_uri_string(spec)],
556                                    ["mime-type", "Mime type:", load_spec_mime_type(spec)]]);
557         try {
558             var cmd = yield I.minibuffer.read_shell_command(
559                 $cwd = cwd,
560                 $initial_value = load_spec_default_shell_command(spec));
561         } finally {
562             panel.destroy();
563         }
564         yield browser_element_shell_command(I.buffer, element, cmd, cwd);
565     },
566     $browser_object = browser_object_links,
567     $prompt = "Shell command");
570 interactive("bookmark",
571     "Create a bookmark.",
572     function (I) {
573         var element = yield read_browser_object(I);
574         var spec = load_spec(element);
575         var uri_string = load_spec_uri_string(spec);
576         var panel;
577         panel = create_info_panel(I.window, "bookmark-panel",
578                                   [["bookmarking",
579                                     element_get_operation_label(element, "Bookmarking"),
580                                     uri_string]]);
581         try {
582             var title = yield I.minibuffer.read($prompt = "Bookmark with title:", $initial_value = load_spec_title(spec) || "");
583         } finally {
584             panel.destroy();
585         }
586         add_bookmark(uri_string, title);
587         I.minibuffer.message("Added bookmark: " + uri_string + " - " + title);
588     },
589     $browser_object = browser_object_frames);
592 interactive("save-page",
593     "Save a document, not including any embedded documents such as images "+
594     "and css.",
595     function (I) {
596         check_buffer(I.buffer, content_buffer);
597         var element = yield read_browser_object(I);
598         var spec = load_spec(element);
599         if (!load_spec_document(spec))
600             throw interactive_error("Element is not associated with a document.");
601         var suggested_path = suggest_save_path_from_file_name(suggest_file_name(spec), I.buffer);
603         var panel;
604         panel = create_info_panel(I.window, "download-panel",
605                                   [["downloading",
606                                     element_get_operation_label(element, "Saving"),
607                                     load_spec_uri_string(spec)],
608                                    ["mime-type", "Mime type:", load_spec_mime_type(spec)]]);
610         try {
611             var file = yield I.minibuffer.read_file_check_overwrite(
612                 $prompt = "Save page as:",
613                 $history = "save",
614                 $initial_value = suggested_path);
615         } finally {
616             panel.destroy();
617         }
619         save_uri(spec, file, $buffer = I.buffer);
620     },
621     $browser_object = browser_object_frames);
624 interactive("save-page-as-text",
625     "Save a page as plain text.",
626     function (I) {
627         check_buffer(I.buffer, content_buffer);
628         var element = yield read_browser_object(I);
629         var spec = load_spec(element);
630         var doc;
631         if (!(doc = load_spec_document(spec)))
632             throw interactive_error("Element is not associated with a document.");
633         var suggested_path = suggest_save_path_from_file_name(suggest_file_name(spec, "txt"), I.buffer);
635         var panel;
636         panel = create_info_panel(I.window, "download-panel",
637                                   [["downloading",
638                                     element_get_operation_label(element, "Saving", "as text"),
639                                     load_spec_uri_string(spec)],
640                                    ["mime-type", "Mime type:", load_spec_mime_type(spec)]]);
642         try {
643             var file = yield I.minibuffer.read_file_check_overwrite(
644                 $prompt = "Save page as text:",
645                 $history = "save",
646                 $initial_value = suggested_path);
647         } finally {
648             panel.destroy();
649         }
651         save_document_as_text(doc, file, $buffer = I.buffer);
652     },
653     $browser_object = browser_object_frames);
656 interactive("save-page-complete",
657     "Save a page and all supporting documents, including images, css, "+
658     "and child frame documents.",
659     function (I) {
660         check_buffer(I.buffer, content_buffer);
661         var element = yield read_browser_object(I);
662         var spec = load_spec(element);
663         var doc;
664         if (!(doc = load_spec_document(spec)))
665             throw interactive_error("Element is not associated with a document.");
666         var suggested_path = suggest_save_path_from_file_name(suggest_file_name(spec), I.buffer);
668         var panel;
669         panel = create_info_panel(I.window, "download-panel",
670                                   [["downloading",
671                                     element_get_operation_label(element, "Saving complete"),
672                                     load_spec_uri_string(spec)],
673                                    ["mime-type", "Mime type:", load_spec_mime_type(spec)]]);
675         try {
676             var file = yield I.minibuffer.read_file_check_overwrite(
677                 $prompt = "Save page complete:",
678                 $history = "save",
679                 $initial_value = suggested_path);
680             // FIXME: use proper read function
681             var dir = yield I.minibuffer.read_file(
682                 $prompt = "Data Directory:",
683                 $history = "save",
684                 $initial_value = file.path + ".support");
685         } finally {
686             panel.destroy();
687         }
689         save_document_complete(doc, file, dir, $buffer = I.buffer);
690     },
691     $browser_object = browser_object_frames);
694 function view_as_mime_type (I, target) {
695     I.target = target;
696     var element = yield read_browser_object(I);
697     var spec = load_spec(element);
699     if (target == null)
700         target = FOLLOW_CURRENT_FRAME;
702     if (!can_override_mime_type_for_uri(load_spec_uri(spec)))
703         throw interactive_error("Overriding the MIME type is not currently supported for non-HTTP URLs.");
705     var panel;
707     var mime_type = load_spec_mime_type(spec);
708     panel = create_info_panel(I.window, "download-panel",
709                               [["downloading",
710                                 element_get_operation_label(element, "View in browser"),
711                                 load_spec_uri_string(spec)],
712                                ["mime-type", "Mime type:", load_spec_mime_type(spec)]]);
715     try {
716         let suggested_type = mime_type;
717         if (viewable_mime_type_list.indexOf(suggested_type) == -1)
718             suggested_type = "text/plain";
719         mime_type = yield I.minibuffer.read_viewable_mime_type(
720             $prompt = "View internally as",
721             $initial_value = suggested_type,
722             $select);
723         yield override_mime_type_for_next_load(load_spec_uri(spec), mime_type);
724         browser_object_follow(I.buffer, target, spec);
725     } finally {
726         panel.destroy();
727     }
730 function view_as_mime_type_new_buffer (I) {
731     yield view_as_mime_type(I, OPEN_NEW_BUFFER);
734 function view_as_mime_type_new_window (I) {
735     yield view_as_mime_type(I, OPEN_NEW_WINDOW);
738 interactive("view-as-mime-type",
739     "Display a browser object in the browser using the specified MIME type.",
740     alternates(view_as_mime_type,
741         view_as_mime_type_new_buffer,
742         view_as_mime_type_new_window),
743     $browser_object = browser_object_frames);
746 interactive("delete",
747     "Delete a DOM node, given as a browser object.",
748     function (I) {
749         var elem = yield read_browser_object(I);
750         if (! (elem instanceof Ci.nsIDOMNode))
751             throw interactive_error("Cannot delete item");
752         elem.parentNode.removeChild(elem);
753     },
754     $browser_object = browser_object_dom_node);
757 interactive("charset-prefix",
758     "A prefix command that prompts for a charset to use in a "+
759     "subsequent navigation command.",
760     function (I) {
761         var ccman = Cc["@mozilla.org/charset-converter-manager;1"]
762             .getService(Ci.nsICharsetConverterManager);
763         var decoders = ccman.getDecoderList()
764         var charsets = [];
765         while (decoders.hasMore())
766             charsets.push(decoders.getNext());
767         I.forced_charset = yield I.minibuffer.read(
768             $prompt = "Charset:",
769             $completer = prefix_completer(
770                 $completions = charsets,
771                 $get_string = function (x) x.toLowerCase()),
772             $match_required,
773             $space_completes);
774     },
775     $prefix);
778 interactive("reload-with-charset",
779     "Prompt for a charset, and reload the current page, forcing use "+
780     "of that charset.",
781     function (I) {
782         var ccman = Cc["@mozilla.org/charset-converter-manager;1"]
783             .getService(Ci.nsICharsetConverterManager);
784         var decoders = ccman.getDecoderList()
785         var charsets = [];
786         while (decoders.hasMore())
787             charsets.push(decoders.getNext());
788         var forced_charset = yield I.minibuffer.read(
789             $prompt = "Charset:",
790             $completer = prefix_completer(
791                 $completions = charsets,
792                 $get_string = function (x) x.toLowerCase()),
793             $match_required,
794             $space_completes);
795         reload(I.buffer, false, null, forced_charset);
796     });
799 interactive("yank",
800     "Paste the contents of the clipboard",
801     function (I) {
802         call_builtin_command(I.window, "cmd_paste", true);
803     });
805 interactive("kill-region",
806     "Kill (\"cut\") the selected text.",
807     function (I) {
808         call_builtin_command(I.window, "cmd_cut", true);
809     });
811 interactive("kill-ring-save",
812     "Save the region as if killed, but don't kill it.",
813     function (I) {
814         call_builtin_command(I.window, "cmd_copy", true);
815     });
817 interactive("password-manager",
818     "Open the password manager.",
819     "find-url-new-buffer",
820     $browser_object = "chrome://passwordmgr/content/passwordManager.xul");
823 interactive("toggle-full-screen",
824     "Toggle full screen mode for the current window.",
825     function (I) {
826         window_set_full_screen(I.window);
827         if (I.window.fullScreen)
828             I.minibuffer.message("Fullscreen mode on");
829         else
830             I.minibuffer.message("Fullscreen mode off");
831     });
834 interactive("image-toggle-zoom-to-fit",
835     "Toggle zoom-to-fit (viewport) on an image document.",
836     function (I) {
837         try {
838             var doc = I.buffer.document
839                 .QueryInterface(Ci.nsIImageDocument);
840             doc.toggleImageSize();
841             zoom_hook.run(I.buffer);
842         } catch (e) {
843             I.minibuffer.message("Not an image document");
844         }
845     });
848 provide("commands");