google-search-results.js: also add binding for return
[conkeror.git] / modules / buffer.js
blobfb82b49aedc573798e0414f1e1b1ec452a4e8ec3
1 var define_buffer_local_hook = local_hook_definer("window");
3 function define_current_buffer_hook(hook_name, existing_hook)
5     define_buffer_local_hook(hook_name);
6     add_hook(existing_hook, function (buffer) {
7             if (!buffer.window.buffers || buffer != buffer.window.buffers.current)
8                 return;
9             var hook = conkeror[hook_name];
10             hook.run.apply(hook, Array.prototype.slice.call(arguments));
11         });
14 define_buffer_local_hook("buffer_title_change_hook");
15 define_buffer_local_hook("buffer_description_change_hook");
16 define_buffer_local_hook("select_buffer_hook");
17 define_buffer_local_hook("create_buffer_hook");
18 define_buffer_local_hook("kill_buffer_hook");
19 define_buffer_local_hook("buffer_scroll_hook");
20 define_buffer_local_hook("buffer_dom_content_loaded_hook");
21 define_buffer_local_hook("buffer_loaded_hook");
23 define_current_buffer_hook("current_buffer_title_change_hook", "buffer_title_change_hook");
24 define_current_buffer_hook("current_buffer_description_change_hook", "buffer_description_change_hook");
25 define_current_buffer_hook("current_buffer_scroll_hook", "buffer_scroll_hook");
26 define_current_buffer_hook("current_buffer_dom_content_loaded_hook", "buffer_dom_content_loaded_hook");
28 function buffer_configuration(existing_configuration) {
29     if (existing_configuration != null) {
30         this.cwd = existing_configuration.cwd;
31     }
32     else {
33         this.cwd = default_directory.path;
34     }
37 define_keywords("$configuration", "$element");
38 function buffer_creator(type) {
39     var args = forward_keywords(arguments);
40     return function (window, element) {
41         return new type(window, element, args);
42     }
45 define_variable("allow_browser_window_close", true,
46                      "If this is set to true, if a content buffer page calls " +
47                      "window.close() from JavaScript and is not prevented by the " +
48                      "normal Mozilla mechanism that restricts pages from closing " +
49                      "a window that was not opened by a script, the buffer will be " +
50                      "killed, deleting the window as well if it is the only buffer.");
52 function buffer(window, element)
54     this.constructor_begin();
55     keywords(arguments, $configuration = null);
56     this.window = window;
57     this.configuration = new buffer_configuration(arguments.$configuration);
58     if (element == null)
59     {
60         element = create_XUL(window, "vbox");
61         element.setAttribute("flex", "1");
62         var browser = create_XUL(window, "browser");
63         browser.setAttribute("type", "content");
64         browser.setAttribute("flex", "1");
65         element.appendChild(browser);
66         this.window.buffers.container.appendChild(element);
67     } else {
68         /* Manually set up session history.
69          *
70          * This is needed because when constructor for the XBL binding
71          * (mozilla/toolkit/content/widgets/browser.xml#browser) for
72          * the initial browser element of the window is called, the
73          * docShell is not yet initialized and setting up the session
74          * history will fail.  To work around this problem, we do as
75          * tabbrowser.xml (Firefox) does and set the initial browser
76          * to have the disablehistory=true attribute, and then repeat
77          * the work that would normally be done in the XBL
78          * constructor.
79          */
81         // This code is taken from mozilla/browser/base/content/browser.js
82         let browser = element.firstChild;
83         browser.webNavigation.sessionHistory =
84             Cc["@mozilla.org/browser/shistory;1"].createInstance(Ci.nsISHistory);
85         observer_service.addObserver(browser, "browser:purge-session-history", false);
87         // remove the disablehistory attribute so the browser cleans up, as
88         // though it had done this work itself
89         browser.removeAttribute("disablehistory");
91         // enable global history
92         browser.docShell.QueryInterface(Ci.nsIDocShellHistory).useGlobalHistory = true;
93     }
94     this.window.buffers.buffer_list.push(this);
95     this.element = element;
96     this.browser = element.firstChild;
97     this.element.conkeror_buffer_object = this;
99     this.enabled_modes = [];
100     this.local_variables = {};
102     var buffer = this;
104     this.browser.addEventListener("scroll", function (event) {
105             buffer_scroll_hook.run(buffer);
106         }, true /* capture */, false /* ignore untrusted events */);
108     this.browser.addEventListener("DOMContentLoaded", function (event) {
109             buffer_dom_content_loaded_hook.run(buffer);
110         }, true /* capture */, false /*ignore untrusted events */);
112     this.browser.addEventListener("load", function (event) {
113             buffer_loaded_hook.run(buffer);
114         }, true /* capture */, false /*ignore untrusted events */);
116     this.browser.addEventListener("DOMWindowClose", function (event) {
117             /* This call to preventDefault is very important; without
118              * it, somehow Mozilla does something bad and as a result
119              * the window loses focus, causing keyboard commands to
120              * stop working. */
121             event.preventDefault();
123             if (allow_browser_window_close)
124                 kill_buffer(buffer, true);
125         }, true);
127     this.constructor_end();
130 buffer.prototype = {
131     /* Saved focus state */
132     saved_focused_frame : null,
133     saved_focused_element : null,
134     on_switch_to : null,
135     on_switch_away : null,
136     // get title ()   [must be defined by subclasses]
137     // get name ()    [must be defined by subclasses]
138     dead : false, /* This is set when the buffer is killed */
140     default_message : "",
142     get : function (x) {
143         if (x in this.local_variables)
144             return this.local_variables[x];
145         return conkeror[x];
146     },
148     set_default_message : function (str) {
149         this.default_message = str;
150         if (this == this.window.buffers.current)
151             this.window.minibuffer.set_default_message(str);
152     },
154     constructors_running : 0,
156     constructor_begin : function () {
157         this.constructors_running++;
158     },
160     constructor_end : function () {
161         if (--this.constructors_running == 0)
162             create_buffer_hook.run(this);
163     },
165     /* General accessors */
166     get cwd () { return this.configuration.cwd; },
168     /* Browser accessors */
169     get top_frame () { return this.browser.contentWindow; },
170     get document () { return this.browser.contentDocument; },
171     get web_navigation () { return this.browser.webNavigation; },
172     get doc_shell () { return this.browser.docShell; },
173     get markup_document_viewer () { return this.browser.markupDocumentViewer; },
174     get current_URI () { return this.browser.currentURI; },
176     is_child_element : function (element)
177     {
178         return (element && this.is_child_frame(element.ownerDocument.defaultView));
179     },
181     is_child_frame : function (frame)
182     {
183         return (frame && frame.top == this.top_frame);
184     },
186     // This method is like focused_frame, except that if no content
187     // frame actually has focus, this returns null.
188     get focused_frame_or_null () {
189         var frame = this.window.document.commandDispatcher.focusedWindow;
190         var top = this.top_frame;
191         if (this.is_child_frame(frame))
192             return frame;
193         return null;
194     },
196     get focused_frame () {
197         var frame = this.window.document.commandDispatcher.focusedWindow;
198         var top = this.top_frame;
199         if (this.is_child_frame(frame))
200             return frame;
201         return this.top_frame;
202     },
204     get focused_element () {
205         var element = this.window.document.commandDispatcher.focusedElement;
206         if (this.is_child_element(element))
207             return element;
208         return null;
209     },
211     do_command : function (command)
212     {
213         function attempt_command(element, command)
214         {
215             var controller;
216             if (element.controllers
217                 && (controller = element.controllers.getControllerForCommand(command)) != null
218                 && controller.isCommandEnabled(command))
219             {
220                 controller.doCommand(command);
221                 return true;
222             }
223             return false;
224         }
226         var element = this.focused_element;
227         if (element && attempt_command(element, command))
228             return;
229         var win = this.focused_frame;
230         do  {
231             if (attempt_command(win, command))
232                 return;
233             if (!win.parent || win == win.parent)
234                 break;
235             win = win.parent;
236         } while (true);
237     },
239     handle_kill : function () {
240         this.dead = true;
241         this.browser = null;
242         this.element = null;
243         this.saved_focused_frame = null;
244         this.saved_focused_element = null;
245         kill_buffer_hook.run(this);
246     }
249 function check_buffer(obj, type) {
250     if (!(obj instanceof type))
251         throw interactive_error("Buffer has invalid type.");
252     if (obj.dead)
253         throw interactive_error("Buffer has already been killed.");
254     return obj;
257 function buffer_container(window, create_initial_buffer)
259     this.window = window;
260     this.container = window.document.getElementById("buffer-container");
261     this.buffer_list = [];
262     window.buffers = this;
264     create_initial_buffer(window, this.container.firstChild);
267 buffer_container.prototype = {
268     constructor : buffer_container,
270     get current () {
271         return this.container.selectedPanel.conkeror_buffer_object;
272     },
274     set current (buffer) {
275         var old_value = this.current;
276         if (old_value == buffer)
277             return;
279         this.buffer_list.splice(this.buffer_list.indexOf(buffer), 1);
280         this.buffer_list.unshift(buffer);
282         this._switch_away_from(this.current);
283         this._switch_to(buffer);
285         // Run hooks
286         select_buffer_hook.run(buffer);
287     },
289     _switch_away_from : function (old_value) {
290         // Save focus state
291         old_value.saved_focused_frame = old_value.focused_frame;
292         old_value.saved_focused_element = old_value.focused_element;
294         old_value.browser.setAttribute("type", "content");
295     },
297     _switch_to : function (buffer) {
298         // Select new buffer in the XUL deck
299         this.container.selectedPanel = buffer.element;
301         buffer.browser.setAttribute("type", "content-primary");
303         /**
304          * This next focus call seems to be needed to avoid focus
305          * somehow getting lost (and the keypress handler therefore
306          * not getting called at all) when killing buffers.
307          */
308         this.window.focus();
310         // Restore focus state
311         if (buffer.saved_focused_element)
312             set_focus_no_scroll(this.window, buffer.saved_focused_element);
313         else if (buffer.saved_focused_frame)
314             set_focus_no_scroll(this.window, buffer.saved_focused_frame);
316         buffer.saved_focused_element = null;
317         buffer.saved_focused_frame = null;
319         this.window.minibuffer.set_default_message(buffer.default_message);
320     },
322     get count () {
323         return this.container.childNodes.length;
324     },
326     get_buffer : function (index) {
327         if (index >= 0 && index < this.count)
328             return this.container.childNodes.item(index).conkeror_buffer_object;
329         return null;
330     },
332     get selected_index () {
333         var nodes = this.container.childNodes;
334         var count = nodes.length;
335         for (var i = 0; i < count; ++i)
336             if (nodes.item(i) == this.container.selectedPanel)
337                 return i;
338         return null;
339     },
341     index_of : function (b) {
342         var nodes = this.container.childNodes;
343         var count = nodes.length;
344         for (var i = 0; i < count; ++i)
345             if (nodes.item(i) == b.element)
346                 return i;
347         return null;
348     },
350     get unique_name_list () {
351         var existing_names = new string_hashset();
352         var bufs = [];
353         this.for_each(function(b) {
354                 var base_name = b.name;
355                 var name = base_name;
356                 var index = 1;
357                 while (existing_names.contains(name))
358                 {
359                     ++index;
360                     name = base_name + "<" + index + ">";
361                 }
362                 existing_names.add(name);
363                 bufs.push([name, b]);
364             });
365         return bufs;
366     },
368     kill_buffer : function (b) {
369         if (b.dead)
370             return true;
371         var count = this.count;
372         if (count <= 1)
373             return false;
374         var new_buffer = this.buffer_list[0];
375         var changed = false;
376         if (b == new_buffer) {
377             new_buffer = this.buffer_list[1];
378             changed = true;
379         }
380         this._switch_away_from(this.current);
381         this.container.removeChild(b.element);
382         this.buffer_list.splice(this.buffer_list.indexOf(b), 1);
383         this._switch_to(new_buffer);
384         if (changed) {
385             select_buffer_hook.run(new_buffer);
386             this.buffer_list.splice(this.buffer_list.indexOf(new_buffer), 1);
387             this.buffer_list.unshift(new_buffer);
388         }
389         b.handle_kill();
390         return true;
391     },
393     for_each : function (f) {
394         var count = this.count;
395         for (var i = 0; i < count; ++i)
396             f(this.get_buffer(i));
397     }
400 function buffer_initialize_window_early(window)
402     /**
403      * Use content_buffer by default to handle an unusual case where
404      * browser.chromeURI is used perhaps.  In general this default
405      * should not be needed.
406      */
408     var create_initial_buffer
409         = window.args.initial_buffer_creator || buffer_creator(content_buffer);
410     new buffer_container(window, create_initial_buffer);
413 add_hook("window_initialize_early_hook", buffer_initialize_window_early);
416 define_buffer_local_hook("buffer_kill_before_hook", RUN_HOOK_UNTIL_FAILURE);
417 function buffer_before_window_close(window)
419     var bs = window.buffers;
420     var count = bs.count;
421     for (let i = 0; i < count; ++i) {
422         if (!buffer_kill_before_hook.run(bs.get_buffer(i)))
423             return false;
424     }
425     return true;
427 add_hook("window_before_close_hook", buffer_before_window_close);
429 function buffer_window_close_handler(window)
431     var bs = window.buffers;
432     var count = bs.count;
433     for (let i = 0; i < count; ++i) {
434         let b = bs.get_buffer(i);
435         b.handle_kill();
436     }
438 add_hook("window_close_hook", buffer_window_close_handler);
440 /* open/follow targets */
441 const OPEN_CURRENT_BUFFER = 0; // only valid for open if the current
442                                // buffer is a content_buffer; for
443                                // follow, equivalent to
444                                // FOLLOW_TOP_FRAME.
445 const OPEN_NEW_BUFFER = 1;
446 const OPEN_NEW_BUFFER_BACKGROUND = 2;
447 const OPEN_NEW_WINDOW = 3;
449 const FOLLOW_DEFAULT = 4; // for open, implies OPEN_CURRENT_BUFFER
450 const FOLLOW_CURRENT_FRAME = 5; // for open, implies OPEN_CURRENT_BUFFER
451 const FOLLOW_TOP_FRAME = 6; // for open, implies OPEN_CURRENT_BUFFER
453 var TARGET_PROMPTS = [" in current buffer",
454                       " in new buffer",
455                       " in new buffer (background)",
456                       " in new window",
457                       "",
458                       " in current frame",
459                       " in top frame"];
461 var TARGET_NAMES = ["current buffer",
462                     "new buffer",
463                     "new buffer (background)",
464                     "new window",
465                     "default",
466                     "current frame",
467                     "top frame"];
470 function browse_target_prompt(target, prefix) {
471     if (prefix == null)
472         prefix = "Open URL";
473     return prefix + TARGET_PROMPTS[target] + ":";
477 var default_browse_targets = {};
478 default_browse_targets["open"] = [OPEN_CURRENT_BUFFER, OPEN_NEW_BUFFER, OPEN_NEW_WINDOW];
479 default_browse_targets["follow"] = [FOLLOW_DEFAULT, OPEN_NEW_BUFFER, OPEN_NEW_WINDOW];
480 default_browse_targets["follow-top"] = [FOLLOW_TOP_FRAME, FOLLOW_CURRENT_FRAME];
482 interactive_context.prototype.browse_target = function (action) {
483     var prefix = this.prefix_argument;
484     var targets = action;
485     while (typeof(targets) == "string")
486         targets = default_browse_targets[targets];
487     if (prefix == null || typeof(prefix) != "object")
488         return targets[0];
489     var num = prefix[0];
490     var index = 0;
491     while (num >= 4 && index + 1 < targets.length) {
492         num = num / 4;
493         index++;
494     }
495     return targets[index];
498 function create_buffer(window, creator, target) {
499     switch (target) {
500     case OPEN_NEW_BUFFER:
501         window.buffers.current = creator(window, null);
502         break;
503     case OPEN_NEW_BUFFER_BACKGROUND:
504         creator(window, null);
505         break;
506     case OPEN_NEW_WINDOW:
507         make_window(creator);
508         break;
509     default:
510         throw new Error("invalid target");
511     }
514 var queued_buffer_creators = null;
515 function _process_queued_buffer_creators(window) {
516     for (var i = 0; i < queued_buffer_creators.length; ++i) {
517         var x = queued_buffer_creators[i];
518         create_buffer(window, x[0], x[1]);
519     }
520     queued_buffer_creators = null;
522 function create_buffer_in_current_window(creator, target, focus_existing) {
523     if (target == OPEN_NEW_WINDOW)
524         throw new Error("invalid target");
525     var window = get_recent_conkeror_window();
526     if (window) {
527         if (focus_existing)
528             window.focus();
529         create_buffer(window, creator, target);
530     } else if (queued_buffer_creators != null) {
531         queued_buffer_creators.push([creator,target]);
532     } else {
533         queued_buffer_creators = [];
534         window = make_window(creator);
535         add_hook.call(window, "window_initialize_late_hook", _process_queued_buffer_creators);
536     }
539 minibuffer_auto_complete_preferences["buffer"] = true;
540 define_keywords("$default");
541 minibuffer.prototype.read_buffer = function () {
542     var window = this.window;
543     var buffer = this.window.buffers.current;
544     keywords(arguments, $prompt = "Buffer:",
545              $default = buffer,
546              $history = "buffer");
547     var completer = all_word_completer(
548         $completions = function (visitor) window.buffers.for_each(visitor),
549         $get_string = function (x) x.description,
550         $get_description = function (x) x.title);
551     var result = yield this.read(
552         $prompt = arguments.$prompt,
553         $history = arguments.$history,
554         $completer = completer,
555         $match_required = true,
556         $auto_complete = "buffer",
557         $auto_complete_initial = true,
558         $auto_complete_delay = 0,
559         $default_completion = arguments.$default);
560     yield co_return(result);
563 interactive_context.prototype.__defineGetter__("cwd", function () this.buffer.cwd);
565 function buffer_next (window, count)
567     var index = window.buffers.selected_index;
568     var total = window.buffers.count;
569     index = (index + count) % total;
570     if (index < 0)
571         index += total;
572     window.buffers.current = window.buffers.get_buffer(index);
574 interactive("buffer-next",
575             "Switch to the next buffer.",
576             function (I) {buffer_next(I.window, I.p);});
577 interactive("buffer-previous",
578             "Switch to the previous buffer.",
579             function (I) {buffer_next(I.window, -I.p);});
581 function switch_to_buffer (window, buffer)
583     if (buffer && !buffer.dead)
584         window.buffers.current = buffer;
586 interactive("switch-to-buffer",
587             "Switch to a buffer specified in the minibuffer.",
588             function (I) {
589                 switch_to_buffer(
590                     I.window,
591                     (yield I.minibuffer.read_buffer(
592                         $prompt = "Switch to buffer:",
593                         $default = (I.window.buffers.count > 1 ?
594                                     I.window.buffers.buffer_list[1] :
595                                     I.buffer)))
596                 )
597             });
599 define_variable("can_kill_last_buffer", true,
600                      "If this is set to true, kill-buffer can kill the last remaining buffer, and close the window.");
602 function kill_buffer(buffer, force)
604     if (!buffer)
605         return;
606     var buffers = buffer.window.buffers;
607     if (buffers.count == 1 && buffer == buffers.current) {
608         if (can_kill_last_buffer || force) {
609             delete_window(buffer.window);
610             return;
611         }
612         else
613             throw interactive_error("Can't kill last buffer.");
614     }
615     buffers.kill_buffer(buffer);
617 interactive("kill-buffer",
618             "Kill a buffer specified in the minibuffer.\n" +
619             "If `can_kill_last_buffer' is set to true, an attempt to kill the last remaining " +
620             "buffer in a window will cause the window to be closed.",
621             function (I) {kill_buffer((yield I.minibuffer.read_buffer($prompt = "Kill buffer:")))});
623 interactive("kill-current-buffer",
624             "Kill the current buffer.\n" +
625             "If `can_kill_last_buffer' is set to true, an attempt to kill the last remaining " +
626             "buffer in a window will cause the window to be closed.",
627             function (I) {kill_buffer(I.buffer)});
629 function change_directory(buffer, dir) {
630     buffer.configuration.cwd = dir;
632 interactive("change-current-directory",
633             "Change the current directory of the selected buffer.",
634             function (I) {
635                 change_directory(
636                     I.buffer,
637                     (yield I.minibuffer.read_existing_directory_path(
638                         $prompt = "New current directory:",
639                         $initial_value = I.cwd)));
640             });
642 interactive("shell-command", function (I) {
643     var cwd = I.cwd;
644     var cmd = (yield I.minibuffer.read_shell_command($cwd = cwd));
645     yield shell_command(cmd, $cwd = cwd);
648 function unfocus(buffer)
650     var elem = buffer.focused_element;
651     if (elem) {
652         elem.blur();
653         return;
654     }
655     var win = buffer.focused_frame;
656     if (win != buffer.top_frame)
657         return;
658     buffer.top_frame.focus();
660 interactive("unfocus", function (I) {unfocus(I.buffer)});
662 require_later("content-buffer.js");
664 var mode_functions = {};
666 var mode_display_names = {};
668 define_buffer_local_hook("buffer_mode_change_hook");
669 define_current_buffer_hook("current_buffer_mode_change_hook", "buffer_mode_change_hook");
671 define_keywords("$class", "$enable", "$disable", "$doc");
672 function define_buffer_mode(name, display_name) {
673     keywords(arguments);
675     var hyphen_name = name.replace("_","-","g");
676     var mode_class = arguments.$class;
677     var enable = arguments.$enable;
678     var disable = arguments.$disable;
680     mode_display_names[name] = display_name;
682     var can_disable;
684     if (disable == false) {
685         can_disable = false;
686         disable = null;
687     } else
688         can_disable = true;
690     var state = (mode_class != null) ? mode_class : (name + "_enabled");
691     var enable_hook_name = name + "_enable_hook";
692     var disable_hook_name = name + "_disable_hook";
693     define_buffer_local_hook(enable_hook_name);
694     define_buffer_local_hook(disable_hook_name);
696     var change_hook_name = null;
698     if (mode_class) {
699         mode_functions[name] = {enable: enable,
700                                 disable: disable,
701                                 mode_class: mode_class,
702                                 disable_hook_name: disable_hook_name};
703         change_hook_name = mode_class + "_change_hook";
704         define_buffer_local_hook(change_hook_name);
705     }
707     function func(buffer, arg) {
708         var old_state = buffer[state];
709         var cur_state = (old_state == name);
710         var new_state = (arg == null) ? !cur_state : (arg > 0);
711         if ((new_state == cur_state) || (!can_disable && !new_state))
712             return null;
713         if (new_state) {
714             if (mode_class && old_state != null)  {
715                 buffer.enabled_modes.splice(buffer.enabled_modes.indexOf(old_state), 1);
716                 let x = mode_functions[old_state];
717                 let y = x.disable;
718                 if (y) y(buffer);
719                 conkeror[x.disable_hook_name].run(buffer);
720             }
721             buffer[state] = name;
722             if (enable)
723                 enable(buffer);
724             conkeror[enable_hook_name].run(buffer);
725             buffer.enabled_modes.push(name);
726         } else {
727             buffer.enabled_modes.splice(buffer.enabled_modes.indexOf(name), 1);
728             disable(buffer);
729             conkeror[disable_hook_name].run(buffer);
730             buffer[state] = null;
731         }
732         if (change_hook_name)
733             conkeror[change_hook_name].run(buffer, buffer[state]);
734         buffer_mode_change_hook.run(buffer);
735         return new_state;
736     };
737     conkeror[name] = func;
738     interactive(hyphen_name, arguments.$doc, function (I) {
739         var arg = I.P;
740         var new_state = func(I.buffer, arg && univ_arg_to_number(arg));
741         I.minibuffer.message(hyphen_name + (new_state ? " enabled" : " disabled"));
742     });
744 ignore_function_for_get_caller_source_code_reference("define_buffer_mode");
747 function minibuffer_mode_indicator(window) {
748     this.window = window;
749     var element = create_XUL(window, "label");
750     element.setAttribute("id", "minibuffer-mode-indicator");
751     element.collapsed = true;
752     element.setAttribute("class", "minibuffer");
753     window.document.getElementById("minibuffer").appendChild(element);
754     this.element = element;
755     this.hook_func = method_caller(this, this.update);
756     add_hook.call(window, "select_buffer_hook", this.hook_func);
757     add_hook.call(window, "current_buffer_mode_change_hook", this.hook_func);
758     this.update();
760 minibuffer_mode_indicator.prototype = {
761     update : function () {
762         var buf = this.window.buffers.current;
763         var modes = buf.enabled_modes;
764         var str = modes.map( function (x) {
765             let y = mode_display_names[x];
766             if (y)
767                 return "[" + y + "]";
768             else
769                 return null;
770         } ).filter( function (x) x != null ).join(" ");
771         this.element.collapsed = (str.length == 0);
772         this.element.value = str;
773     },
774     uninstall : function () {
775         remove_hook.call(window, "select_buffer_hook", this.hook_fun);
776         remove_hook.call(window, "current_buffer_mode_change_hook", this.hook_fun);
777         this.element.parentNode.removeChild(this.element);
778     }
780 define_global_window_mode("minibuffer_mode_indicator", "window_initialize_hook");
781 minibuffer_mode_indicator_mode(true);