8 local key, buf, but, cmd = lousy.bind.key, lousy.bind.buf, lousy.bind.but, lousy.bind.cmd |
8 local key, buf, but, cmd = lousy.bind.key, lousy.bind.buf, lousy.bind.but, lousy.bind.cmd |
9 |
9 |
10 -- Globals or defaults that are used in binds |
10 -- Globals or defaults that are used in binds |
11 local scroll_step = globals.scroll_step or 20 |
11 local scroll_step = globals.scroll_step or 20 |
12 local zoom_step = globals.zoom_step or 0.1 |
12 local zoom_step = globals.zoom_step or 0.1 |
13 local homepage = globals.homepage or "http://luakit.org" |
13 local homepage = globals.homepage or "http://google.co.uk/" |
14 |
14 |
15 -- Add key bindings to be used across all windows in the given modes. |
15 -- Add key bindings to be used across all windows in the given modes. |
16 binds.mode_binds = { |
16 binds.mode_binds = { |
17 -- buf(Pattern, function (w, buffer, opts) .. end, opts), |
17 -- buf(Pattern, function (w, buffer, opts) .. end, opts), |
18 -- key({Modifiers}, Key name, function (w, opts) .. end, opts), |
18 -- key({Modifiers}, Key name, function (w, opts) .. end, opts), |
19 -- but({Modifiers}, Button num, function (w, opts) .. end, opts), |
19 -- but({Modifiers}, Button num, function (w, opts) .. end, opts), |
20 all = { |
20 all = { |
21 key({}, "Escape", function (w) w:set_mode() end), |
21 key({}, "Escape", function (w) w:set_mode("normal") end), |
22 key({"Control"}, "[", function (w) w:set_mode() end), |
22 key({"Control"}, "e", function (w) w:set_mode("command") end), |
|
23 key({"Control"}, "n", function (w) w:set_mode("normal") end), |
|
24 |
|
25 key({"Control"}, "x", function (w) w:close_tab() end), |
|
26 |
|
27 key({"Control"}, "c", function (w) if w:get_mode() ~= "normal" then w:set_mode("normal"); end end), |
|
28 |
|
29 -- Location |
|
30 key({"Control"}, "t", function (w) w:new_tab(homepage); end), |
|
31 |
|
32 -- Location |
|
33 key({"Control"}, "l", function (w) w:set_mode("url-entry"); end), |
|
34 |
|
35 -- Web search |
|
36 key({"Control"}, "k", function (w) w:enter_cmd(":websearch google ") end); |
|
37 |
|
38 -- Back and forth |
|
39 key({"Mod1"}, "Left", function (w) w:back() end); |
|
40 key({"Mod1"}, "Right", function (w) w:forward() end); |
|
41 |
|
42 -- Tab/buffer switching |
|
43 key({"Mod1"}, ".", function (w) w:next_tab(1) end); |
|
44 key({"Mod1"}, ",", function (w) w:prev_tab(1) end); |
|
45 key({"Control"}, "Page_Up", function (w) w:prev_tab() end), |
|
46 key({"Control"}, "Page_Down", function (w) w:next_tab() end), |
|
47 |
|
48 key({"Control"}, "p", function (w) w:navigate(luakit.get_selection("c")) end), |
|
49 key({"Control"}, "P", function (w) w:new_tab(luakit.get_selection("c")) end), |
|
50 key({"Control"}, "y", function (w) luakit.set_selection((w:get_current() or {}).uri or "", "c") end), |
|
51 key({"Control"}, "Y", function (w) luakit.set_selection(w.win.title, "c") end), |
|
52 |
|
53 key({"Control"}, "r", function (w) w:reload() end), |
|
54 |
|
55 key({"Mod1"}, "Home", function (w) w:navigate(homepage) end); |
|
56 |
|
57 key({"Control"}, "+", function (w) w:zoom_in(zoom_step) end), |
|
58 key({"Control"}, "-", function (w) w:zoom_out(zoom_step) end), |
23 |
59 |
24 but({}, 8, function (w) w:back() end), |
60 but({}, 8, function (w) w:back() end), |
25 but({}, 9, function (w) w:forward() end), |
61 but({}, 9, function (w) w:forward() end), |
26 }, |
|
27 normal = { |
|
28 key({}, "i", function (w) w:set_mode("insert") end), |
|
29 key({}, ":", function (w) w:set_mode("command") end), |
|
30 |
62 |
31 -- Scrolling |
|
32 key({}, "j", function (w) w:scroll_vert("+"..scroll_step.."px") end), |
|
33 key({}, "k", function (w) w:scroll_vert("-"..scroll_step.."px") end), |
|
34 key({}, "h", function (w) w:scroll_horiz("-"..scroll_step.."px") end), |
|
35 key({}, "l", function (w) w:scroll_horiz("+"..scroll_step.."px") end), |
|
36 key({"Control"}, "d", function (w) w:scroll_page(0.5) end), |
|
37 key({"Control"}, "u", function (w) w:scroll_page(-0.5) end), |
|
38 key({"Control"}, "f", function (w) w:scroll_page(1.0) end), |
|
39 key({"Control"}, "b", function (w) w:scroll_page(-1.0) end), |
|
40 buf("^gg$", function (w) w:scroll_vert("0%") end), |
|
41 buf("^G$", function (w) w:scroll_vert("100%") end), |
|
42 buf("^[\-\+]?[0-9]+[%%G]$", function (w, b) w:scroll_vert(string.match(b, "^([\-\+]?%d+)[%%G]$") .. "%") end), |
|
43 |
|
44 -- Traditional scrolling commands |
|
45 key({}, "Down", function (w) w:scroll_vert("+"..scroll_step.."px") end), |
|
46 key({}, "Up", function (w) w:scroll_vert("-"..scroll_step.."px") end), |
|
47 key({}, "Left", function (w) w:scroll_horiz("-"..scroll_step.."px") end), |
|
48 key({}, "Right", function (w) w:scroll_horiz("+"..scroll_step.."px") end), |
|
49 key({}, "Page_Down", function (w) w:scroll_page(1.0) end), |
|
50 key({}, "Page_Up", function (w) w:scroll_page(-1.0) end), |
|
51 key({}, "Home", function (w) w:scroll_vert("0%") end), |
|
52 key({}, "End", function (w) w:scroll_vert("100%") end), |
|
53 |
|
54 -- Zooming |
|
55 buf("^z0$", function (w) w:zoom_reset() end), |
|
56 buf("^zI$", function (w) w:zoom_in(zoom_step) end), |
|
57 buf("^zO$", function (w) w:zoom_out(zoom_step) end), |
|
58 key({"Control"}, "+", function (w) w:zoom_in(zoom_step) end), |
|
59 key({"Control"}, "-", function (w) w:zoom_out(zoom_step) end), |
|
60 |
|
61 -- Clipboard |
|
62 key({}, "p", function (w) w:navigate(luakit.get_selection()) end), |
|
63 key({}, "P", function (w) w:new_tab(luakit.get_selection()) end), |
|
64 buf("^yy$", function (w) luakit.set_selection((w:get_current() or {}).uri or "") end), |
|
65 buf("^yt$", function (w) luakit.set_selection(w.win.title) end), |
|
66 |
|
67 -- Commands |
|
68 buf("^o$", function (w, c) w:enter_cmd(":open ") end), |
|
69 buf("^t$", function (w, c) w:enter_cmd(":tabopen ") end), |
|
70 buf("^w$", function (w, c) w:enter_cmd(":winopen ") end), |
|
71 buf("^O$", function (w, c) w:enter_cmd(":open " .. ((w:get_current() or {}).uri or "")) end), |
|
72 buf("^T$", function (w, c) w:enter_cmd(":tabopen " .. ((w:get_current() or {}).uri or "")) end), |
|
73 buf("^W$", function (w, c) w:enter_cmd(":winopen " .. ((w:get_current() or {}).uri or "")) end), |
|
74 buf("^,g$", function (w, c) w:enter_cmd(":websearch google ") end), |
|
75 |
|
76 -- Debian search shorcut access |
|
77 buf("^\\dbug$", function (w, c) w:enter_cmd(":websearch debbugs ") end), |
|
78 buf("^\\dpts$", function (w, c) w:enter_cmd(":websearch dpts ") end), |
|
79 buf("^\\dpkg$", function (w, c) w:enter_cmd(":websearch dpkg ") end), |
|
80 |
|
81 -- Searching |
|
82 key({}, "/", function (w) w:start_search("/") end), |
|
83 key({}, "?", function (w) w:start_search("?") end), |
|
84 key({}, "n", function (w) w:search(nil, true) end), |
|
85 key({}, "N", function (w) w:search(nil, false) end), |
|
86 |
|
87 -- History |
|
88 buf("^[0-9]*H$", function (w, b) w:back (tonumber(string.match(b, "^(%d*)H$") or 1)) end), |
|
89 buf("^[0-9]*L$", function (w, b) w:forward(tonumber(string.match(b, "^(%d*)L$") or 1)) end), |
|
90 key({}, "b", function (w) w:back() end), |
|
91 key({}, "XF86Back", function (w) w:back() end), |
63 key({}, "XF86Back", function (w) w:back() end), |
92 key({}, "XF86Forward", function (w) w:forward() end), |
64 key({}, "XF86Forward", function (w) w:forward() end), |
93 |
65 |
94 -- Tab |
|
95 key({"Control"}, "Page_Up", function (w) w:prev_tab() end), |
|
96 key({"Control"}, "Page_Down", function (w) w:next_tab() end), |
|
97 buf("^[0-9]*gT$", function (w, b) w:prev_tab(tonumber(string.match(b, "^(%d*)gT$") or 1)) end), |
|
98 buf("^[0-9]*gt$", function (w, b) w:next_tab(tonumber(string.match(b, "^(%d*)gt$") or 1)) end), |
|
99 buf("^gH$", function (w) w:new_tab(homepage) end), |
|
100 buf("^d$", function (w) w:close_tab() end), |
|
101 |
|
102 key({}, "r", function (w) w:reload() end), |
|
103 buf("^gh$", function (w) w:navigate(homepage) end), |
|
104 |
|
105 -- Window |
|
106 buf("^ZZ$", function (w) w:close_win() end), |
|
107 buf("^D$", function (w) w:close_win() end), |
|
108 |
|
109 -- Link following |
66 -- Link following |
110 key({}, "f", function (w) w:set_mode("follow") end), |
67 key({"Mod1"}, "f", function (w) w:set_mode("follow") end), |
111 |
68 |
112 -- Bookmarking |
69 -- Bookmarking |
113 key({}, "B", function (w) w:enter_cmd(":bookmark " .. ((w:get_current() or {}).uri or "http://") .. " ") end), |
70 key({"Control"}, "d", function (w) end), |
114 buf("^gb$", function (w) w:navigate(bookmarks.dump_html()) end), |
71 key({"Control"}, "b", function (w) w:navigate(bookmarks.dump_html()) end), |
115 buf("^gB$", function (w) w:new_tab (bookmarks.dump_html()) end), |
72 key({"Control"}, "B", function (w) w:new_tab(bookmarks.dump_html()) end), |
116 |
73 |
117 -- Mouse bindings |
74 -- Mouse bindings |
118 but({}, 2, function (w) |
75 but({}, 2, function (w) |
119 -- Open hovered uri in new tab |
76 -- Open hovered uri in new tab |
120 local uri = w:get_current().hovered_uri |
77 local uri = w:get_current().hovered_uri |