Prepare new Debian package
[conkeror.git] / modules / commands.js
blob0f82e3600b802b68ce50995edb5a3475ab983127
1 /**
2  * (C) Copyright 2004-2007 Shawn Betts
3  * (C) Copyright 2007-2009 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_hook("quit_hook");
12 function quit () {
13     quit_hook.run();
14     var appStartup = Cc["@mozilla.org/toolkit/app-startup;1"]
15         .getService(Ci.nsIAppStartup);
16     appStartup.quit(appStartup.eAttemptQuit);
18 interactive("quit",
19             "Quit Conkeror",
20             quit);
22 interactive("confirm-quit",
23             "Quit Conkeror with confirmation",
24             function (I) {
25                 let result = yield I.window.minibuffer.read_single_character_option(
26                     $prompt = "Quit Conkeror? (y/n)",
27                     $options = ["y", "n"]);
28                 if (result == "y")
29                     quit();
30             });
32 function show_conkeror_version (window) {
33     var xulrunner_version = Cc['@mozilla.org/xre/app-info;1']
34         .getService(Ci.nsIXULAppInfo)
35         .platformVersion;
36     window.minibuffer.message("Conkeror "+conkeror.version+
37                               " (XULRunner "+xulrunner_version+
38                               ", "+get_os()+")");
40 interactive("conkeror-version",
41             "Show version information for Conkeror.",
42             function (I) { show_conkeror_version(I.window); });
43 interactive("version",
44             "Show version information for Conkeror.",
45             "conkeror-version");
47 /* FIXME: maybe this should be supported for non-browser buffers */
48 function scroll_horiz_complete (buffer, n) {
49     var w = buffer.focused_frame;
50     w.scrollTo (n > 0 ? w.scrollMaxX : 0, w.scrollY);
52 interactive("scroll-beginning-of-line",
53             "Scroll the current frame all the way to the left.",
54             function (I) { scroll_horiz_complete(I.buffer, -1); });
56 interactive("scroll-end-of-line",
57             "Scroll the current frame all the way to the right.",
58             function (I) { scroll_horiz_complete(I.buffer, 1); });
60 function delete_window (window) {
61     window.window.close();
63 interactive("delete-window",
64             "Delete the current window.",
65             function (I) { delete_window(I.window); });
67 interactive("jsconsole",
68             "Open the JavaScript console.",
69             "find-url-new-buffer",
70             $browser_object = "chrome://global/content/console.xul");
73 /**
74  * Given a callback func and an interactive context I, call func, passing
75  * either a focused field, or the minibuffer's input element if the
76  * minibuffer is active. Afterward, call `scroll_selection_into_view' on
77  * the field. See `paste_x_primary_selection' and `open_line' for
78  * examples.
79  */
80 function call_on_focused_field (I, func) {
81     var m = I.window.minibuffer;
82     var s = m.current_state;
83     if (m._input_mode_enabled) {
84         m._restore_normal_state();
85         var e = m.input_element;
86     } else
87         var e = I.buffer.focused_element;
88     func(e);
89     scroll_selection_into_view(e);
90     if (s && s.handle_input)
91         s.handle_input(m);
95 /**
96  * Replace the current region with modifier(selection). Deactivates region and
97  * sets point to the end of the inserted text, unless keep_point is true, in
98  * which case the point will be left at the beginning of the inserted text.
99  */
100 function modify_region (field, modifier, keep_point) {
101     if (field.getAttribute("contenteditable") == 'true') {
102         // richedit
103         var doc = field.ownerDocument;
104         var win = doc.defaultView;
105         doc.execCommand("insertHTML", false,
106                         html_escape(modifier(win.getSelection().toString()))
107                             .replace(/\n/g, '<br>')
108                             .replace(/  /g, ' &nbsp;'));
109     } else {
110         // normal text field
111         var replacement =
112             modifier(field.value.substring(field.selectionStart, field.selectionEnd+1));
113         var point = field.selectionStart;
114         field.value =
115             field.value.substr(0, field.selectionStart) + replacement +
116             field.value.substr(field.selectionEnd);
117         if (!keep_point) point += replacement.length;
118         field.setSelectionRange(point, point);
119     }
123 function paste_x_primary_selection (field) {
124     modify_region(field, function (str) read_from_x_primary_selection());
126 interactive("paste-x-primary-selection",
127     "Insert the contents of the X primary selection into the selected field or "+
128     "minibuffer. Deactivates the region if it is active, and leaves the point "+
129     "after the inserted text.",
130     function (I) call_on_focused_field(I, paste_x_primary_selection));
133 function open_line (field) {
134     modify_region(field, function() "\n", true);
136 interactive("open-line",
137     "If there is an active region, replace is with a newline, otherwise just "+
138     "insert a newline. In both cases leave point before the inserted newline.",
139     function (I) call_on_focused_field(I, open_line));
142 function transpose_chars (field) {
143     var value = field.value;
144     var caret = field.selectionStart; // Caret position.
145     var length = value.length;
147     // If we have less than two character in the field or if we are at the
148     // beginning of the field, do nothing.
149     if (length < 2 || caret == 0)
150         return;
152     // If we are at the end of the field, switch places on the two last
153     // characters. TODO: This should happen at the end of every line, not only
154     // at the end of the field.
155     if (caret == length)
156         caret--;
158     // Do the transposing.
159     field.value = switch_subarrays(value, caret - 1, caret, caret, caret + 1);
161     // Increment the caret position. If this is not done, the caret is left at
162     // the end of the field as a result of the replacing of contents.
163     field.selectionStart = caret + 1;
164     field.selectionEnd = caret + 1;
166 interactive("transpose-chars",
167     "Interchange characters around point, moving forward one character.",
168     function (I) call_on_focused_field(I, transpose_chars));
171 interactive("execute-extended-command",
172     "Call a command specified in the minibuffer.",
173     function (I) {
174         var prefix = I.P;
175         var boc = I.browser_object;
176         var prompt = "M-x";
177         if (I.key_sequence)
178             prompt = I.key_sequence.join(" ");
179         if (boc)
180             prompt += ' ['+boc.name+']';
181         if (prefix !== null && prefix !== undefined) {
182             if (typeof prefix == "object")
183                 prompt += prefix[0] == 4 ? " C-u" : " "+prefix[0];
184             else
185                 prompt += " "+prefix;
186         }
187         var command = yield I.minibuffer.read_command($prompt = prompt);
188         call_after_timeout(function () {
189             input_handle_command.call(I.window, new command_event(command));
190         }, 0);
191     },
192     $prefix = true);
195 /// built in commands
196 // see: http://www.xulplanet.com/tutorials/xultu/commandupdate.html
198 // Performs a command on a browser buffer content area
201 define_builtin_commands(
202     "",
203     function (I, command) {
204         var buffer = I.buffer;
205         try {
206             buffer.do_command(command);
207         } catch (e) {
208             /* Ignore exceptions */
209         }
210     },
211     function (I) {
212         I.buffer.mark_active = !I.buffer.mark_active;
213     },
214     function (I) I.buffer.mark_active,
215     false
218 define_builtin_commands(
219     "caret-",
220     function (I, command) {
221         var buffer = I.buffer;
222         try {
223             buffer.do_command(command);
224         } catch (e) {
225             /* Ignore exceptions */
226         }
227     },
228     function (I) {
229         I.buffer.mark_active = !I.buffer.mark_active;
230     },
231     function (I) I.buffer.mark_active,
232     'caret');
234 function get_link_text () {
235     var e = document.commandDispatcher.focusedElement;
236     if (e && e.getAttribute("href")) {
237         return e.getAttribute("href");
238     }
239     return null;
244 function copy_email_address (loc)
246     // Copy the comma-separated list of email addresses only.
247     // There are other ways of embedding email addresses in a mailto:
248     // link, but such complex parsing is beyond us.
249     var qmark = loc.indexOf( "?" );
250     var addresses;
252     if ( qmark > 7 ) {                   // 7 == length of "mailto:"
253         addresses = loc.substring( 7, qmark );
254     } else {
255         addresses = loc.substr( 7 );
256     }
258     //XXX: the original code, which we got from firefox, unescapes the string
259     //     using the current character set.  To do this in conkeror, we
260     //     *should* use an interactive method that gives us the character set,
261     //     rather than fetching it by side-effect.
263     //     // Let's try to unescape it using a character set
264     //     // in case the address is not ASCII.
265     //     try {
266     //         var characterSet = this.target.ownerDocument.characterSet;
267     //         const textToSubURI = Components.classes["@mozilla.org/intl/texttosuburi;1"]
268     //             .getService(Components.interfaces.nsITextToSubURI);
269     //         addresses = textToSubURI.unEscapeURIForUI(characterSet, addresses);
270     //     }
271     //     catch(ex) {
272     //         // Do nothing.
273     //     }
275     writeToClipboard(addresses);
276     message("Copied '" + addresses + "'");
278 interactive("copy-email-address", copy_email_address, ['focused_link_url']);
281 /* FIXME: fix this command */
283 interactive("source",
284             "Load a JavaScript file.",
285             function (fo) { load_rc (fo.path); }, [['f', function (a) { return "Source File: "; }, null, "source"]]);
287 function reinit (window) {
288     var path;
289     try {
290         path = load_rc();
291         window.minibuffer.message("Loaded: " + path);
292     } catch (e) {
293         window.minibuffer.message("Failed to load: "+path);
294     }
297 interactive("reinit",
298             "Reload the Conkeror rc file.",
299             function (I) { reinit(I.window); });
301 interactive("help-page", "Open the Conkeror help page.",
302             "find-url-new-buffer",
303             $browser_object = "chrome://conkeror-help/content/help.html");
305 interactive("tutorial", "Open the Conkeror tutorial.",
306             "find-url-new-buffer",
307             $browser_object = "chrome://conkeror-help/content/tutorial.html");
309 function univ_arg_to_number (prefix, default_value) {
310     if (prefix == null) {
311         if (default_value == null)
312             return 1;
313         else
314             return default_value;
315     }
316     if (typeof prefix == "object")
317         return prefix[0];
318     return prefix;
321 function eval_expression (window, s) {
322     // eval in the global scope.
324     // In addition, the following variables are available:
325     // var window;
326     var buffer = window.buffers.current;
327     var result = eval(s);
328     if (result !== undefined) {
329         window.minibuffer.message(String(result));
330     }
332 interactive("eval-expression",
333             "Evaluate JavaScript statements.",
334             function (I) {
335                 eval_expression(
336                     I.window,
337                     (yield I.minibuffer.read($prompt = "Eval:",
338                                              $history = "eval-expression",
339                                              $completer = javascript_completer(I.buffer))));
340             });
343 function show_extension_manager () {
344     return conkeror.window_watcher.openWindow(
345         null,
346         "chrome://mozapps/content/extensions/extensions.xul?type=extensions",
347         "ExtensionsWindow",
348         "resizable=yes,dialog=no",
349         null);
351 interactive("extensions",
352             "Open the extensions manager in a new window.",
353             show_extension_manager);
355 function print_buffer (buffer) {
356     buffer.top_frame.print();
358 interactive("print-buffer",
359             "Print the currently loaded page.",
360             function (I) { print_buffer(I.buffer); });
362 function view_partial_source (window, charset, selection) {
363     if (charset)
364         charset = "charset=" + charset;
365     window.window.openDialog("chrome://global/content/viewPartialSource.xul",
366                              "_blank", "scrollbars,resizable,chrome,dialog=no",
367                              null, charset, selection, 'selection');
369 //interactive ('view-partial-source', view_partial_source, I.current_window, I.content_charset, I.content_selection);
372 function  view_mathml_source (window, charset, target) {
373     if (charset)
374         charset = "charset=" + charset;
375     window.window.openDialog("chrome://global/content/viewPartialSource.xul",
376                              "_blank", "scrollbars,resizable,chrome,dialog=no",
377                              null, charset, target, 'mathml');
381 function send_key_as_event (window, element, combo) {
382     var split = unformat_key_combo(combo);
383     var event = window.document.createEvent("KeyboardEvent");
384     event.initKeyEvent(
385         "keypress",
386         true,
387         true,
388         null,
389         split.ctrlKey,
390         split.altKey,
391         split.shiftKey,
392         split.metaKey,
393         split.keyCode,
394         split.charCode);
395     if (element) {
396         return element.dispatchEvent(event);
397     } else {
398         return window.dispatchEvent(event);
399     }
403 function ensure_content_focused (buffer) {
404     var foc = buffer.focused_frame_or_null;
405     if (!foc)
406         buffer.top_frame.focus();
408 interactive("ensure-content-focused", "Ensure that the content document has focus.",
409             function (I) { ensure_content_focused(I.buffer); });
412 function network_set_online_status (status) {
413     status = !status;
414     io_service.manageOfflineStatus = false;
415     io_service.offline = status;
417 interactive("network-go-online", "Work online.",
418             function (I) { network_set_online_status(true); });
419 interactive("network-go-offline", "Work offline.",
420             function (I) { network_set_online_status(false); });
423 interactive("submit-form",
424     "Submit the form to which the focused element belongs.",
425     function (I) {
426         var el = I.buffer.focused_element.parentNode;
427         while (el && el.tagName != "FORM")
428             el = el.parentNode;
429         if (el) {
430             var inputs = el.getElementsByTagName("input");
431             for (var i = 0, ilen = inputs.length; i < ilen; i++) {
432                 if (inputs[i].getAttribute("type") == "submit")
433                     return browser_object_follow(I.buffer, FOLLOW_DEFAULT,
434                                                  inputs[i]);
435             }
436             el.submit();
437         }
438     });
442  * Browser Object Commands
443  */
444 interactive("follow", null,
445             alternates(follow, follow_new_buffer, follow_new_window),
446             $browser_object = browser_object_links);
448 interactive("follow-top", null,
449             alternates(follow_current_buffer, follow_current_frame),
450             $browser_object = browser_object_frames,
451             $prompt = "Follow");
453 interactive("follow-new-buffer",
454             "Follow a link in a new buffer",
455             alternates(follow_new_buffer, follow_new_window),
456             $browser_object = browser_object_links,
457             $prompt = "Follow");
459 interactive("follow-new-buffer-background",
460             "Follow a link in a new buffer in the background",
461             alternates(follow_new_buffer_background, follow_new_window),
462             $browser_object = browser_object_links,
463             $prompt = "Follow");
465 interactive("follow-new-window",
466             "Follow a link in a new window",
467             follow_new_window,
468             $browser_object = browser_object_links,
469             $prompt = "Follow");
471 interactive("find-url", "Open a URL in the current buffer",
472             alternates(follow_current_buffer, follow_new_buffer, follow_new_window),
473             $browser_object = browser_object_url);
475 interactive("find-url-new-buffer",
476             "Open a URL in a new buffer",
477             alternates(follow_new_buffer, follow_new_window),
478             $browser_object = browser_object_url,
479             $prompt = "Find url");
481 interactive("find-url-new-window", "Open a URL in a new window",
482             follow_new_window,
483             $browser_object = browser_object_url,
484             $prompt = "Find url");
486 interactive("find-alternate-url", "Edit the current URL in the minibuffer",
487             "find-url",
488             $browser_object =
489                 define_browser_object_class("alternate-url", null,
490                     function (I, prompt) {
491                         check_buffer(I.buffer, content_buffer);
492                         var result = yield I.buffer.window.minibuffer.read_url(
493                             $prompt = prompt,
494                             $initial_value = I.buffer.display_uri_string);
495                         yield co_return(result);
496                     }),
497             $prompt = "Find url");
500 interactive("up", "Go to the parent directory of the current URL",
501             "find-url",
502             $browser_object = browser_object_up_url);
504 interactive("home",
505             "Go to the homepage in the current buffer.", "follow",
506             $browser_object = function () { return homepage; });
508 interactive("make-window",
509             "Make a new window with the homepage.",
510             follow_new_window,
511             $browser_object = function () { return homepage; });
513 interactive("focus", null,
514             function (I) {
515                 var element = yield read_browser_object(I);
516                 browser_element_focus(I.buffer, element);
517             },
518             $browser_object = browser_object_frames);
521 interactive("save",
522     "Save a browser object.",
523     function (I) {
524         var element = yield read_browser_object(I);
525         var spec = load_spec(element);
526         var panel;
527         panel = create_info_panel(I.window, "download-panel",
528                                   [["downloading",
529                                     element_get_operation_label(element, "Saving"),
530                                     load_spec_uri_string(spec)],
531                                    ["mime-type", "Mime type:", load_spec_mime_type(spec)]]);
532         try {
533             var file = yield I.minibuffer.read_file_check_overwrite(
534                 $prompt = "Save as:",
535                 $initial_value = suggest_save_path_from_file_name(suggest_file_name(spec), I.buffer),
536                 $history = "save");
537         } finally {
538             panel.destroy();
539         }
540         save_uri(spec, file,
541                  $buffer = I.buffer,
542                  $use_cache = false);
543     },
544     $browser_object = browser_object_links);
547 interactive("copy", null,
548             function (I) {
549                 var element = yield read_browser_object(I);
550                 browser_element_copy(I.buffer, element);
551             },
552             $browser_object = browser_object_links);
554 interactive("paste-url", "Open a URL from the clipboard in the current buffer.",
555             alternates(follow_current_buffer, follow_new_buffer, follow_new_window),
556             $browser_object = browser_object_paste_url);
558 interactive("paste-url-new-buffer", "Open a URL from the clipboard in a new buffer.",
559             alternates(follow_new_buffer, follow_new_window),
560             $browser_object = browser_object_paste_url);
562 interactive("paste-url-new-window", "Open a URL from the clipboard in a new window.",
563             follow_new_window,
564             $browser_object = browser_object_paste_url);
566 interactive("view-source", null,
567             alternates(view_source, view_source_new_buffer, view_source_new_window),
568             $browser_object = browser_object_frames);
571 interactive("shell-command-on-url",
572     "Run a shell command on the url of a browser object.",
573     function (I) {
574         var cwd = I.local.cwd;
575         var element = yield read_browser_object(I);
576         var spec = load_spec(element);
577         var uri = load_spec_uri_string(spec);
578         var panel;
579         panel = create_info_panel(I.window, "download-panel",
580                                   [["downloading",
581                                     element_get_operation_label(element, "Running on", "URI"),
582                                     load_spec_uri_string(spec)],
583                                    ["mime-type", "Mime type:", load_spec_mime_type(spec)]]);
584         try {
585             var cmd = yield I.minibuffer.read_shell_command(
586                 $cwd = cwd,
587                 $initial_value = load_spec_default_shell_command(spec));
588         } finally {
589             panel.destroy();
590         }
591         shell_command_with_argument_blind(cmd, uri, $cwd = cwd);
592     },
593     $browser_object = browser_object_url,
594     $prompt = "Shell command");
597 interactive("shell-command-on-file",
598     "Download a document to a temporary file and run a shell command on it.",
599     function (I) {
600         var cwd = I.local.cwd;
601         var element = yield read_browser_object(I);
602         var spec = load_spec(element);
603         var uri = load_spec_uri_string(spec);
604         var panel;
605         panel = create_info_panel(I.window, "download-panel",
606                                   [["downloading",
607                                     element_get_operation_label(element, "Running on"),
608                                     load_spec_uri_string(spec)],
609                                    ["mime-type", "Mime type:", load_spec_mime_type(spec)]]);
610         try {
611             var cmd = yield I.minibuffer.read_shell_command(
612                 $cwd = cwd,
613                 $initial_value = load_spec_default_shell_command(spec));
614         } finally {
615             panel.destroy();
616         }
617         yield browser_element_shell_command(I.buffer, element, cmd, cwd);
618     },
619     $browser_object = browser_object_links,
620     $prompt = "Shell command");
623 interactive("bookmark",
624     "Create a bookmark.",
625     function (I) {
626         var element = yield read_browser_object(I);
627         var spec = load_spec(element);
628         var uri_string = load_spec_uri_string(spec);
629         var panel;
630         panel = create_info_panel(I.window, "bookmark-panel",
631                                   [["bookmarking",
632                                     element_get_operation_label(element, "Bookmarking"),
633                                     uri_string]]);
634         try {
635             var title = yield I.minibuffer.read($prompt = "Bookmark with title:", $initial_value = load_spec_title(spec) || "");
636         } finally {
637             panel.destroy();
638         }
639         add_bookmark(uri_string, title);
640         I.minibuffer.message("Added bookmark: " + uri_string + " - " + title);
641     },
642     $browser_object = browser_object_frames);
645 interactive("save-page",
646     "Save a document, not including any embedded documents such as images "+
647     "and css.",
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         if (!load_spec_document(spec))
653             throw interactive_error("Element is not associated with a document.");
654         var suggested_path = suggest_save_path_from_file_name(suggest_file_name(spec), I.buffer);
656         var panel;
657         panel = create_info_panel(I.window, "download-panel",
658                                   [["downloading",
659                                     element_get_operation_label(element, "Saving"),
660                                     load_spec_uri_string(spec)],
661                                    ["mime-type", "Mime type:", load_spec_mime_type(spec)]]);
663         try {
664             var file = yield I.minibuffer.read_file_check_overwrite(
665                 $prompt = "Save page as:",
666                 $history = "save",
667                 $initial_value = suggested_path);
668         } finally {
669             panel.destroy();
670         }
672         save_uri(spec, file, $buffer = I.buffer);
673     },
674     $browser_object = browser_object_frames);
677 interactive("save-page-as-text",
678     "Save a page as plain text.",
679     function (I) {
680         check_buffer(I.buffer, content_buffer);
681         var element = yield read_browser_object(I);
682         var spec = load_spec(element);
683         var doc;
684         if (!(doc = load_spec_document(spec)))
685             throw interactive_error("Element is not associated with a document.");
686         var suggested_path = suggest_save_path_from_file_name(suggest_file_name(spec, "txt"), I.buffer);
688         var panel;
689         panel = create_info_panel(I.window, "download-panel",
690                                   [["downloading",
691                                     element_get_operation_label(element, "Saving", "as text"),
692                                     load_spec_uri_string(spec)],
693                                    ["mime-type", "Mime type:", load_spec_mime_type(spec)]]);
695         try {
696             var file = yield I.minibuffer.read_file_check_overwrite(
697                 $prompt = "Save page as text:",
698                 $history = "save",
699                 $initial_value = suggested_path);
700         } finally {
701             panel.destroy();
702         }
704         save_document_as_text(doc, file, $buffer = I.buffer);
705     },
706     $browser_object = browser_object_frames);
709 interactive("save-page-complete",
710     "Save a page and all supporting documents, including images, css, "+
711     "and child frame documents.",
712     function (I) {
713         check_buffer(I.buffer, content_buffer);
714         var element = yield read_browser_object(I);
715         var spec = load_spec(element);
716         var doc;
717         if (!(doc = load_spec_document(spec)))
718             throw interactive_error("Element is not associated with a document.");
719         var suggested_path = suggest_save_path_from_file_name(suggest_file_name(spec), I.buffer);
721         var panel;
722         panel = create_info_panel(I.window, "download-panel",
723                                   [["downloading",
724                                     element_get_operation_label(element, "Saving complete"),
725                                     load_spec_uri_string(spec)],
726                                    ["mime-type", "Mime type:", load_spec_mime_type(spec)]]);
728         try {
729             var file = yield I.minibuffer.read_file_check_overwrite(
730                 $prompt = "Save page complete:",
731                 $history = "save",
732                 $initial_value = suggested_path);
733             // FIXME: use proper read function
734             var dir = yield I.minibuffer.read_file(
735                 $prompt = "Data Directory:",
736                 $history = "save",
737                 $initial_value = file.path + ".support");
738         } finally {
739             panel.destroy();
740         }
742         save_document_complete(doc, file, dir, $buffer = I.buffer);
743     },
744     $browser_object = browser_object_frames);
747 function view_as_mime_type (I, target) {
748     I.target = target;
749     var element = yield read_browser_object(I);
750     var spec = load_spec(element);
752     if (target == null)
753         target = FOLLOW_CURRENT_FRAME;
755     if (!can_override_mime_type_for_uri(load_spec_uri(spec)))
756         throw interactive_error("Overriding the MIME type is not currently supported for non-HTTP URLs.");
758     var panel;
760     var mime_type = load_spec_mime_type(spec);
761     panel = create_info_panel(I.window, "download-panel",
762                               [["downloading",
763                                 element_get_operation_label(element, "View in browser"),
764                                 load_spec_uri_string(spec)],
765                                ["mime-type", "Mime type:", load_spec_mime_type(spec)]]);
768     try {
769         let suggested_type = mime_type;
770         if (viewable_mime_type_list.indexOf(suggested_type) == -1)
771             suggested_type = "text/plain";
772         mime_type = yield I.minibuffer.read_viewable_mime_type(
773             $prompt = "View internally as",
774             $initial_value = suggested_type,
775             $select);
776         override_mime_type_for_next_load(load_spec_uri(spec), mime_type);
777         browser_object_follow(I.buffer, target, spec);
778     } finally {
779         panel.destroy();
780     }
782 function view_as_mime_type_new_buffer (I) {
783     yield view_as_mime_type(I, OPEN_NEW_BUFFER);
785 function view_as_mime_type_new_window (I) {
786     yield view_as_mime_type(I, OPEN_NEW_WINDOW);
788 interactive("view-as-mime-type",
789             "Display a browser object in the browser using the specified MIME type.",
790             alternates(view_as_mime_type,
791                        view_as_mime_type_new_buffer,
792                        view_as_mime_type_new_window),
793             $browser_object = browser_object_frames);
796 interactive("charset-prefix",
797     "A prefix command that prompts for a charset to use in a "+
798     "subsequent navigation command.",
799     function (I) {
800         var ccman = Cc["@mozilla.org/charset-converter-manager;1"]
801             .getService(Ci.nsICharsetConverterManager);
802         var decoders = ccman.getDecoderList()
803         var charsets = [];
804         while (decoders.hasMore())
805             charsets.push(decoders.getNext());
806         I.forced_charset = yield I.minibuffer.read(
807             $prompt = "Charset:",
808             $completer = prefix_completer(
809                 $completions = charsets,
810                 $get_string = function (x) x.toLowerCase()),
811             $match_required);
812     },
813     $prefix);
816 interactive("reload-with-charset",
817     "Prompt for a charset, and reload the current page, forcing use "+
818     "of that charset.",
819     function (I) {
820         var ccman = Cc["@mozilla.org/charset-converter-manager;1"]
821             .getService(Ci.nsICharsetConverterManager);
822         var decoders = ccman.getDecoderList()
823         var charsets = [];
824         while (decoders.hasMore())
825             charsets.push(decoders.getNext());
826         var forced_charset = yield I.minibuffer.read(
827             $prompt = "Charset:",
828             $completer = prefix_completer(
829                 $completions = charsets,
830                 $get_string = function (x) x.toLowerCase()),
831             $match_required);
832         reload(I.buffer, false, null, forced_charset);
833     });
836 interactive("yank",
837             "Paste the contents of the clipboard",
838             function (I) {
839                 I.buffer.mark_active = false;
840                 I.buffer.do_command("cmd_paste");
841             });
843 interactive("kill-region",
844             "Kill (\"cut\") the selected text.",
845             function (I) {
846                 I.buffer.mark_active = false;
847                 I.buffer.do_command("cmd_cut");
848             });
850 interactive("kill-ring-save",
851             "Save the region as if killed, but don't kill it.",
852             function (I) {
853                 I.buffer.mark_active = false;
854                 I.buffer.do_command("cmd_copy");
855             });