keys.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. // Moving cursor
  2. function al_bind_move_keys (keymap) {
  3. define_key(keymap, "C-o", "backward-char");
  4. define_key(keymap, "M-o", "backward-word");
  5. define_key(keymap, "C-u", "forward-char");
  6. define_key(keymap, "M-u", "forward-word");
  7. define_key(keymap, "C-a", "beginning-of-line");
  8. define_key(keymap, "C-i", "end-of-line");
  9. }
  10. // Editing text (copy, paste, kill, delete)
  11. function al_bind_edit_keys (keymap) {
  12. define_key(keymap, "C-,", "cmd_deleteCharForward");
  13. define_key(keymap, "M-,", "cmd_deleteWordForward");
  14. define_key(keymap, "M-<", "cut-to-end-of-line");
  15. define_key(keymap, "C-p", "cmd_deleteCharBackward");
  16. define_key(keymap, "M-p", "cmd_deleteWordBackward");
  17. define_key(keymap, "M-P", "cut-to-beg-of-line");
  18. define_key(keymap, "C-k", "cut-whole-line");
  19. define_key(keymap, "M-k", "copy-whole-line");
  20. define_key(keymap, "C-x", "kill-region");
  21. define_key(keymap, "M-x", "kill-ring-save");
  22. define_key(keymap, "s-space", "cmd_selectAll");
  23. define_key(keymap, "M-space", "cmd_selectWordNext");
  24. define_key(keymap, "C-'", "transpose-chars");
  25. define_key(keymap, "s-4", "insert-parentheses");
  26. define_key(keymap, "s-'", "insert-double-quotes");
  27. define_key(keymap, "C-M-y", "paste-x-primary-selection");
  28. define_key(keymap, "C-kanji", "downcase-word-backward");
  29. define_key(keymap, "S-kanji", "capitalize-word-backward");
  30. define_key(keymap, "kanji", "upcase-word-backward");
  31. define_key(keymap, "C-M-kanji", "downcase-word");
  32. define_key(keymap, "M-S-kanji", "capitalize-word");
  33. define_key(keymap, "M-kanji", "upcase-word");
  34. define_key(keymap, "s-u", "cmd_undo");
  35. }
  36. // Scrolling screen
  37. function al_bind_scroll_keys (keymap) {
  38. define_key(keymap, "C-M-s-o", "cmd_scrollLeft");
  39. define_key(keymap, "C-M-s-u", "cmd_scrollRight");
  40. define_key(keymap, "C-M-s-.", "cmd_scrollLineUp");
  41. define_key(keymap, "C-M-s-e", "cmd_scrollLineDown");
  42. define_key(keymap, "C-M-s-a", "scroll-beginning-of-line");
  43. define_key(keymap, "C-M-s-i", "scroll-end-of-line");
  44. define_key(keymap, "s-.", "cmd_scrollPageUp");
  45. define_key(keymap, "s-e", "cmd_scrollPageDown");
  46. define_key(keymap, "s-a", "cmd_scrollTop");
  47. define_key(keymap, "s-i", "cmd_scrollBottom");
  48. }
  49. // Selecting text
  50. function al_bind_select_keys (keymap) {
  51. define_key(keymap, "C-o", "cmd_selectCharPrevious");
  52. define_key(keymap, "C-u", "cmd_selectCharNext");
  53. define_key(keymap, "M-o", "cmd_selectWordPrevious");
  54. define_key(keymap, "M-u", "cmd_selectWordNext");
  55. define_key(keymap, "C-.", "cmd_selectLinePrevious");
  56. define_key(keymap, "C-e", "cmd_selectLineNext");
  57. define_key(keymap, "C-a", "cmd_selectBeginLine");
  58. define_key(keymap, "C-i", "cmd_selectEndLine");
  59. define_key(keymap, "M-x", "cmd_copy");
  60. }
  61. // Miscellaneous bindings
  62. function al_bind_misc_keys (keymap) {
  63. define_key(keymap, ".", "focus-previous-link");
  64. define_key(keymap, "e", "focus-next-link");
  65. }
  66. ////////////////////////////////////////////////////////////////
  67. /// Global bindings
  68. define_key(default_base_keymap, "C-4", "universal-argument");
  69. define_key(default_global_keymap, "C-t C-c", "quit");
  70. define_key(default_global_keymap, "C-t 5 j", "find-url-new-window");
  71. define_key(default_global_keymap, "C-t 5 2", "make-window");
  72. define_key(default_global_keymap, "C-t 5 0", "delete-window");
  73. define_key(default_global_keymap, "M-t", "execute-extended-command");
  74. define_key(default_global_keymap, "M-v", "eval-expression");
  75. define_key(default_global_keymap, "M-V t", function (I) {tab_bar_mode()});
  76. define_key(default_global_keymap, "M-V s", "mode-line-mode");
  77. define_key(default_global_keymap, "M-V a", "toggle-all-bars");
  78. define_key(default_global_keymap, "M-V l", "apply-light-theme");
  79. define_key(default_global_keymap, "M-V L", "toggle-light-theme");
  80. define_key(default_global_keymap, "M-V d", "apply-dark-theme");
  81. define_key(default_global_keymap, "M-V D", "toggle-dark-theme");
  82. define_key(default_global_keymap, "C-M-j", "toggle-js");
  83. ////////////////////////////////////////////////////////////////
  84. /// Text
  85. al_bind_move_keys(text_keymap);
  86. al_bind_edit_keys(text_keymap);
  87. define_key(content_buffer_text_keymap, "M-d", "edit-current-field-in-external-editor");
  88. undefine_key(content_buffer_text_keymap, "C-i");
  89. undefine_key(content_buffer_text_keymap, "C-x");
  90. undefine_key(content_buffer_textarea_keymap, "M-v");
  91. undefine_key(content_buffer_textarea_keymap, "C-o");
  92. undefine_key(content_buffer_textarea_keymap, "C-p");
  93. define_key(content_buffer_textarea_keymap, "C-.", "backward-line");
  94. define_key(content_buffer_textarea_keymap, "C-e", "forward-line");
  95. define_key(content_buffer_textarea_keymap, "s-a", "beginning-of-first-line");
  96. define_key(content_buffer_textarea_keymap, "s-i", "end-of-last-line");
  97. define_key(content_buffer_textarea_keymap, "C-;", "open-line");
  98. ////////////////////////////////////////////////////////////////
  99. /// Hints
  100. define_key(hint_keymap, "C-.", "hints-previous");
  101. define_key(hint_keymap, "M-.", "hints-previous");
  102. define_key(hint_keymap, "C-e", "hints-next");
  103. define_key(hint_keymap, "M-e", "hints-next");
  104. ////////////////////////////////////////////////////////////////
  105. /// Formfill
  106. define_key(formfill_keymap, "C-.", "formfill-previous");
  107. define_key(formfill_keymap, "C-e", "formfill-next");
  108. undefine_key(formfill_keymap, "C-p");
  109. ////////////////////////////////////////////////////////////////
  110. /// Minibuffer
  111. define_key(minibuffer_keymap, "M-.", "minibuffer-history-previous");
  112. define_key(minibuffer_keymap, "M-e", "minibuffer-history-next");
  113. define_key(minibuffer_keymap, "C-.", "minibuffer-complete-previous");
  114. define_key(minibuffer_keymap, "C-e", "minibuffer-complete");
  115. undefine_key(minibuffer_keymap, "C-p");
  116. undefine_key(minibuffer_keymap, "M-p");
  117. ////////////////////////////////////////////////////////////////
  118. /// Normal buffer (web-pages)
  119. al_bind_scroll_keys(content_buffer_normal_keymap);
  120. al_bind_select_keys(content_buffer_normal_keymap);
  121. al_bind_misc_keys(content_buffer_normal_keymap);
  122. undefine_key(content_buffer_normal_keymap, "M-v");
  123. undefine_key(content_buffer_normal_keymap, "C-b");
  124. undefine_key(content_buffer_anchor_keymap, "o");
  125. define_key(content_buffer_anchor_keymap, "S-return", "follow-new-buffer-background",
  126. $browser_object = browser_object_focused_element);
  127. define_key(content_buffer_normal_keymap, "o", "up");
  128. define_key(content_buffer_normal_keymap, "u", "follow");
  129. define_key(content_buffer_normal_keymap, "U", "follow-new-buffer-background");
  130. define_key(content_buffer_normal_keymap, "h", "follow-previous");
  131. define_key(content_buffer_normal_keymap, "n", "follow-next");
  132. define_key(content_buffer_normal_keymap, ",", "back");
  133. define_key(content_buffer_normal_keymap, "p", "forward");
  134. define_key(content_buffer_normal_keymap, "y", "restore-killed-buffer-url");
  135. define_key(content_buffer_normal_keymap, "j", "find-alternate-select-url");
  136. define_key(content_buffer_normal_keymap, "g", "reload");
  137. define_key(content_buffer_normal_keymap, "B", "bookmark");
  138. define_key(content_buffer_normal_keymap, "a", "browser-object-dom-node");
  139. define_key(content_buffer_normal_keymap, "l", "browser-object-links");
  140. define_key(content_buffer_normal_keymap, "f", "browser-object-frames");
  141. define_key(content_buffer_normal_keymap, "m", "browser-object-media");
  142. define_key(content_buffer_normal_keymap, "t", "browser-object-text");
  143. define_key(content_buffer_normal_keymap, "S", "save");
  144. define_key(content_buffer_normal_keymap, "C", "copy");
  145. define_key(content_buffer_normal_keymap, "D", "delete");
  146. define_key(content_buffer_normal_keymap, "M-r M-l", "org-store-link");
  147. define_key(content_buffer_normal_keymap, "I", "inspect-click");
  148. ////////////////////////////////////////////////////////////////
  149. /// Special buffer (help, download)
  150. al_bind_scroll_keys(special_buffer_keymap);
  151. al_bind_select_keys(special_buffer_keymap);
  152. al_bind_misc_keys(special_buffer_keymap);
  153. undefine_key(special_buffer_keymap, "M-v");
  154. ////////////////////////////////////////////////////////////////
  155. /// Buffers selecting and switching
  156. define_key(default_global_keymap, "C-S-tab", "buffer-previous");
  157. define_key(default_global_keymap, "C-tab", "buffer-next");
  158. define_key(default_global_keymap, "C-left", "buffer-previous");
  159. define_key(default_global_keymap, "C-right", "buffer-next");
  160. define_key(default_global_keymap, "M-left", "buffer-move-backward");
  161. define_key(default_global_keymap, "M-right", "buffer-move-forward");
  162. define_key(default_global_keymap, "M-b", "switch-to-other-buffer");
  163. define_key(default_global_keymap, "C-b C-b", "switch-to-buffer");
  164. define_key(default_global_keymap, "C-b k", "kill-current-buffer");
  165. define_key(default_global_keymap, "k b", "kill-buffer");
  166. define_key(default_global_keymap, "k k", "kill-current-buffer");
  167. define_key(default_global_keymap, "k f", "delete-window");
  168. // From <http://conkeror.org/Tips?highlight=%28tips%29#Bind_Number_Keys_to_Switch_to_Buffers_1-10>
  169. // "1..0" to switch to buffer; "k 1..0" to kill buffer
  170. function define_switch_buffer_key (key, buf_num) {
  171. define_key(default_global_keymap, key,
  172. function (I) {
  173. switch_to_buffer(I.window,
  174. I.window.buffers.get_buffer(buf_num));
  175. });
  176. }
  177. function define_kill_buffer_key (key, buf_num) {
  178. define_key(default_global_keymap, key,
  179. function (I) {
  180. kill_buffer(I.window.buffers.get_buffer(buf_num));
  181. });
  182. }
  183. for (let i = 0; i < 10; ++i) {
  184. var num = String((i+1) % 10);
  185. define_switch_buffer_key( num, i);
  186. define_kill_buffer_key ("k " + num, i);
  187. }
  188. ////////////////////////////////////////////////////////////////
  189. /// Isearch
  190. al_bind_move_keys(isearch_keymap);
  191. al_bind_edit_keys(isearch_keymap);
  192. ////////////////////////////////////////////////////////////////
  193. /// Duckduckgo
  194. define_key(duckduckgo_keymap, "M-.", "duckduckgo-up");
  195. define_key(duckduckgo_keymap, "M-e", "duckduckgo-down");
  196. define_key(duckduckgo_keymap, "tab", "duckduckgo-focus-search");
  197. undefine_key(duckduckgo_keymap, "k");
  198. undefine_key(duckduckgo_keymap, "j");
  199. ////////////////////////////////////////////////////////////////
  200. /// Wikipedia
  201. define_key(wikipedia_keymap, "M-l", "wikipedia-other-language");
  202. ////////////////////////////////////////////////////////////////
  203. /// Player mode
  204. define_key(player_keymap, "space", "player-play-or-pause");
  205. define_key(player_keymap, "f", "player-fullscreen");