aboutsummaryrefslogtreecommitdiff
path: root/conkerorrc
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2016-08-07 19:26:12 +0200
committerKarel Kočí <cynerd@email.cz>2016-08-07 19:26:12 +0200
commit87e8b76dd51b451b8d25454850973824209b4b18 (patch)
tree0c44ff8e6addba0ffc4c7d871e8362007d3a019d /conkerorrc
parent1fe0811086f5154ed46e9d35eac88c94c44ce1df (diff)
downloadmyconfigs-87e8b76dd51b451b8d25454850973824209b4b18.tar.gz
myconfigs-87e8b76dd51b451b8d25454850973824209b4b18.tar.bz2
myconfigs-87e8b76dd51b451b8d25454850973824209b4b18.zip
conkeror: fix buffer revive
Diffstat (limited to 'conkerorrc')
-rw-r--r--conkerorrc85
1 files changed, 55 insertions, 30 deletions
diff --git a/conkerorrc b/conkerorrc
index aaa5b66..2adf1e5 100644
--- a/conkerorrc
+++ b/conkerorrc
@@ -3,7 +3,6 @@ require("theme.js");
theme_load_paths.unshift("~/.conkeror/");
theme_unload("default");
theme_load("theme");
-//theme_load("conkeror-theme-zenburn");
require("session.js");
session_auto_save_auto_load = true;
@@ -30,35 +29,61 @@ session_pref("layout.css.devPixelsPerPx", "0.9");
/////////////////////////////////////////////////////////////////////////////////
// reopening closed buffers
-var my_closed_buffers = new Array();
-
-//save the URL of the current buffer before closing it
-interactive("my-close-and-save-current-buffer",
- "close and save the current buffer for later restore",
- function(I) {
- if(my_closed_buffers.length==10){
- my_closed_buffers.shift(); // remove older item to save
- // memory, just save maximum 10 buffers
- }
- my_closed_buffers.push(I.buffer.document.URL);
- kill_buffer(I.buffer); //kill the current buffer
- });
-
-undefine_key(default_global_keymap, "q");
-define_key(default_global_keymap, "q", "my-close-and-save-current-buffer");
-
-interactive("my-open-closed-buffer",
- "open the last closed buffer",
- function(I){
- // check if the array length > 0
- if(my_closed_buffers.length>0){
- // load the URL in new windows
- load_url_in_new_buffer(
- my_closed_buffers[my_closed_buffers.length - 1], I.window);
- // remove the first item in the array
- my_closed_buffers.pop();
+define_key(default_global_keymap, "A-W", "revive-buffer");
+
+// Save origin kill_buffer command
+var kill_buffer_original = kill_buffer_original || kill_buffer;
+
+var killed_buffer_urls = [];
+var killed_buffer_histories = [];
+
+// remember_killed_buffer
+kill_buffer = function (buffer, force) {
+ var hist = buffer.web_navigation.sessionHistory;
+
+ if (buffer.display_uri_string && hist) {
+ killed_buffer_histories.push(hist);
+ killed_buffer_urls.push(buffer.display_uri_string);
}
- });
-define_key(default_global_keymap, "A-W", "my-open-closed-buffer")
+ kill_buffer_original(buffer,force);
+};
+
+interactive("revive-buffer",
+ "Loads url from a previously killed buffer",
+ function restore_killed_buffer (I) {
+ if (killed_buffer_urls.length !== 0) {
+ var url = yield I.minibuffer.read(
+ $prompt = "Restore killed url:",
+ $completer = new all_word_completer($completions = killed_buffer_urls),
+ $default_completion = killed_buffer_urls[killed_buffer_urls.length - 1],
+ $auto_complete = "url",
+ $auto_complete_initial = true,
+ $auto_complete_delay = 0,
+ $require_match = true);
+
+ var window = I.window;
+ var creator = buffer_creator(content_buffer);
+ var idx = killed_buffer_urls.indexOf(url);
+
+ // Create the buffer
+ var buf = creator(window, null);
+
+ // Recover the history
+ buf.web_navigation.sessionHistory = killed_buffer_histories[idx];
+
+ // This line may seem redundant, but it's necessary.
+ var original_index = buf.web_navigation.sessionHistory.index;
+ buf.web_navigation.gotoIndex(original_index);
+
+ // Focus the new tab
+ window.buffers.current = buf;
+
+ // Remove revived from cemitery
+ killed_buffer_urls.splice(idx,1);
+ killed_buffer_histories.splice(idx,1);
+ } else {
+ I.window.minibuffer.message("No killed buffer urls");
+ }
+ });
/////////////////////////////////////////////////////////////////////////////////