Skip to content

Instantly share code, notes, and snippets.

@franksn
Last active May 2, 2018 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save franksn/5285517a56f7b5310a97 to your computer and use it in GitHub Desktop.
Save franksn/5285517a56f7b5310a97 to your computer and use it in GitHub Desktop.
keybindings-conkeror.js
// NOTE: This file should be loaded finally, after all other files
// define keys for specific keymap
// arguments: keymap, keystroke1, command1, keystroke2, command2,...
function my_define_keys(){
// check if arguments if larger than 1
if(arguments.length > 1){
var args = Array.prototype.slice.call(arguments);
// get the keymap
var keymap = args[0];
// remove the first item (keymap)
args.splice(0, 1);
// the length
var length = 0;
// check the number of elements in arguments
if(args.length % 2 == 0){
length = args.length;
} else {
length = args.length + 1;
// add one more null item to the array
args[length] = null;
}
// loop through the arguments
for(var i = 0; i < length; i+=2){
define_key(keymap, args[i], args[i+1]);
}
}
}
// define key aliases for each pair in the input arguments
function my_define_keys_aliases(){
var args = Array.prototype.slice.call(arguments);
// check if the number of arguments is even
var length;
if(args.length % 2 == 0){
length = args.length;
} else {
length = args.length + 1;
args[length] = null;
}
// loop through the args
for(var i = 0; i < length; i+=2){
define_key_alias(args[i], args[i+1]);
}
}
// undefine all input keys for the specific keymap
// arguments: keymap, key1, key2, key3,...
function my_undefine_keys(){
var args = Array.prototype.slice.call(arguments);
// check if the arguments number is bigger than 1
if(args.length > 1){
var keymap = args[0];
args.splice(0,1);
// loop through the args
for(var i = 0; i < args.length; i++){
undefine_key(keymap, args[i]);
}
}
}
// undefine some built-in keys
my_undefine_keys(content_buffer_normal_keymap, "F", "C-f", "C-b", "M-v", "C-v", "g", "G","t");
my_undefine_keys(text_keymap, "C-f", "C-b","C-o");
my_undefine_keys(default_global_keymap, "M-N", "t");
// redefine some keys
my_define_keys(default_global_keymap,
"C-h", previous_buffer,
"C-l", next_buffer,
"O", "find-url-new-buffer",
"t", "find-url-new-buffer",
"o", "find-url",
"C-o", "find-url",
"C-x C-d", "find-alternate-url", /* whoops emacs gospel */
"A-q", "quit",
"C-R", "show-tab-temporarily",
"A-h", "stop-loading-all-buffers",
"A-r", "reload-all-buffers",
"A-u", "open-closed-buffer",
"A-s", "close-and-save-current-buffer"
);
my_define_keys(content_buffer_normal_keymap,
"f", "follow",
"F", "follow-new-buffer-background",
"* q", "browser-object-tinyurl",
"C-A-v", "paste-url-new-buffer",
"C-D", "caret-mode",
"/", "isearch-forward",
'y', "copy",
'p', "yank",
"t", "find-url-new-buffer",
"C-o", "find-url",
"C-z", "readability_arc90",
// ergoemacs style
"l", "cmd_scrollRight",
"h", "cmd_scrollLeft",
"M-k", "cmd_scrollPageUp",
"M-j", "cmd_scrollPageDown",
// vim style navigation
"k", "cmd_scrollLineUp",
"j", "cmd_scrollLineDown",
"g g", "scroll-top-left",
"G", "cmd_scrollBottom",
"L", "forward",
"H", "back",
// exchange point and mark like emacs
"C-x C-x", "my-back-to-last-position"
);
my_define_keys(text_keymap,
"C-M-l", "forward-char",
"C-M-h", "backward-char",
"C-M-u", "forward-word",
"C-M-o", "backward-word",
"S-delete", "cmd_deleteWordForward"
);
my_define_keys(content_buffer_textarea_keymap,
"M-i", "backward-line",
"M-k", "forward-line",
"A-up", "beginning-of-first-line",
"A-down", "end-of-last-line",
"S-delete", "cmd_deleteWordForward"
);
// and then some aliases
my_define_keys_aliases("A-v", "C-y",
"A-c", "M-w",
"C-m", "return",
"M-J", "C-a",
"C-J", "C-A-z",
"C-L", "C-A-x",
"A-J", "C-A-z",
"C-i", "tab",
"M-d", "delete",
"M-W", "A-k",
"M-f", "back_space");
// text selection
define_key(content_buffer_normal_keymap, "S-M-right", "cmd_selectWordNext");
define_key(content_buffer_normal_keymap, "S-M-left", "cmd_selectWordPrevious");
define_key(content_buffer_normal_keymap, "S-A-right", "cmd_selectEndLine");
define_key(content_buffer_normal_keymap, "C-E", "cmd_selectEndLine");
define_key(content_buffer_normal_keymap, "C-A", "cmd_selectBeginLine");
define_key(content_buffer_normal_keymap, "S-A-left", "cmd_selectBeginLine");
define_key(default_global_keymap, "M-F", "cmd_selectWordNext");
// history
define_key(content_buffer_normal_keymap, "M-h", "find-url-from-history"); // see the snippets below
define_key(content_buffer_normal_keymap, "M-l", "find-url-from-history-new-buffer");
/* below are the functions for interacting with browser history,
you should put the lines below to a new file and source it before conkeror loads keybindings
*/
define_browser_object_class(
"history-url", null,
function (I, prompt) {
check_buffer (I.buffer, content_buffer);
var result = yield I.buffer.window.minibuffer.read_url(
$prompt = prompt, $use_webjumps = false, $use_history = true, $use_bookmarks = false);
yield co_return (result);
});
interactive("find-url-from-history",
"Find a page from history in the current buffer",
"find-url",
$browser_object = browser_object_history_url);
interactive("find-url-from-history-new-buffer",
"Find a page from history in the current buffer",
"find-url-new-buffer",
$browser_object = browser_object_history_url);
// change how many days of browser history to keep
session_pref('browser.history_expire_days', 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment