Conkeror - Reopen Closed tab

Anyone of you who have been using Conkeror all know that Conkeror does not have Reopen last Closed Tab function. How painful it is compare to the other browsers! But we can do it by ourself by adding our own code into the .conkerorrc file.

First, we have to create an Array to hold the closed tabs.

var my_closed_buffers = new Array();

Next, rewrite the built-in close buffer function to make Conkeror save the current tab URL before closing it. In the code below I save only maximum 10 closed buffers. If you want you can set it to more.

//save the URL of the current buffer before closing it
	"close and save the current buffer for later restore",
	function(I) {
		    my_closed_buffers.shift(); // remove older item to save
		    // memory, just save maximum 10 buffers
		kill_buffer(I.buffer); //kill the current buffer

Rebind the key so that when press q, Conkeror call our new function instead of its built-in one.

undefine_key(default_global_keymap, "q");
define_key(default_global_keymap, "q", "my-close-and-save-current-buffer");

Implement another function to reopen the closed buffers

  "open the last closed buffer", 
    // check if the array length > 0
      // load the URL in new windows
        my_closed_buffers[my_closed_buffers.length - 1], I.window);
      // remove the first item in the array

Finally, bind it to whatever key combination you want to reopen the last closed buffer.

define_key(default_global_keymap, "A-W", "my-open-closed-buffer")