modes.lua

Wed, 01 Sep 2010 04:03:42 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 01 Sep 2010 04:03:42 +0100
changeset 2
1e9553b2f9a2
parent 1
4d7540af8518
permissions
-rw-r--r--

Add note about required patch

0
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 -------------------------------
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 -- luakit mode configuration --
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 -------------------------------
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 -- Table of modes and their callback hooks
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 modes = {}
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 -- Currently active mode hooks
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 local current
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 -- Update a modes hook table with new hooks
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 function new_mode(mode, hooks)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 modes[mode] = lousy.util.table.join(modes[mode] or {}, hooks)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 -- Attach window & input bar signals for mode hooks
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 window.init_funcs.modes_setup = function (w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 -- Calls the `enter` and `leave` mode hooks.
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 w.win:add_signal("mode-changed", function (_, mode)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 -- Call the last modes `leave` hook.
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 if current and current.leave then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 current.leave(w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 -- Update window binds
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 w:update_binds(mode)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 -- Get new modes functions
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 current = modes[mode]
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 if not current then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 error("changed to un-handled mode: " .. mode)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 -- Call new modes `enter` hook.
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 if current.enter then current.enter(w) end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 end)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 -- Calls the `changed` hook on input widget changed.
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 w.ibar.input:add_signal("changed", function()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 local text = w.ibar.input.text
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 if current and current.changed then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 current.changed(w, text)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 end)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 -- Calls the `activate` hook on input widget activate.
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 w.ibar.input:add_signal("activate", function()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 local text = w.ibar.input.text
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 if current and current.activate then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 current.activate(w, text)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 end)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 -- Add mode related window methods
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 for name, func in pairs({
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 set_mode = function (w, name) lousy.mode.set(w.win, name) end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 get_mode = function (w) return lousy.mode.get(w.win) end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 is_mode = function (w, name) return name == w:get_mode() end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 }) do window.methods[name] = func end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62 -- Setup normal mode
1
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
63 new_mode("key", {
0
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 enter = function (w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 local i, p = w.ibar.input, w.ibar.prompt
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66 i:hide()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 p:hide()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69 })
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
71 -- Setup insert mode
1
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
72 new_mode("normal", {
0
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73 enter = function (w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74 local i, p = w.ibar.input, w.ibar.prompt
1
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
75 i:hide();
0
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
76 i.text = ""
1
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
77 p:hide();
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
78 p.text = ""
0
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
79 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
80 })
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
81
1
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
82 new_mode("url-entry", {
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
83 enter = function (w)
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
84 local i, p = w.ibar.input, w.ibar.prompt;
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
85 p.text = "Open:";
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
86 p:show();
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
87 i.text = (w:get_current() or {}).uri or "";
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
88 i:show();
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
89 i:focus();
2
1e9553b2f9a2 Add note about required patch
Matthew Wild <mwild1@gmail.com>
parents: 1
diff changeset
90 -- Requires patch to 2010.08.30:
1e9553b2f9a2 Add note about required patch
Matthew Wild <mwild1@gmail.com>
parents: 1
diff changeset
91 -- http://matthewwild.co.uk/code/luakit-select-region.patch
1
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
92 i:select_region(0);
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
93 end;
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
94 activate = function (w, url)
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
95 w:navigate(url);
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
96 w:set_mode();
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
97 end;
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
98 });
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
99
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
100 new_mode("web-search", {
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
101 enter = function (w)
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
102 local i, p = w.ibar.input, w.ibar.prompt;
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
103 p.text = "Open:";
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
104 p:show();
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
105 i.text = (w:get_current() or {}).uri or "";
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
106 i:show();
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
107 i:focus();
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
108 i:set_position(-1);
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
109 end;
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
110 activate = function (w, url)
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
111 w:navigate(url);
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
112 w:set_mode();
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
113 end;
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
114 });
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
115
0
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 -- Setup command mode
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
117 new_mode("command", {
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 enter = function (w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119 local i, p = w.ibar.input, w.ibar.prompt
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120 p:hide()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121 i.text = ":"
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122 i:show()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
123 i:focus()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
124 i:set_position(-1)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
125 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126 changed = function (w, text)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
127 -- Auto-exit command mode if user backspaces ":" in the input bar.
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
128 if not string.match(text, "^:") then w:set_mode() end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
129 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
130 activate = function (w, text)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
131 w:cmd_hist_add(text)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
132 w:match_cmd(string.sub(text, 2))
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
133 w:set_mode()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
134 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
135 })
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
136
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
137 -- Setup search mode
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
138 new_mode("search", {
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
139 enter = function (w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
140 -- Clear old search state
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
141 w.search_state = {}
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
142 local i, p = w.ibar.input, w.ibar.prompt
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
143 p:hide()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
144 p.text = ""
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
145 i.text = "/"
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
146 i:show()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
147 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
148 leave = function (w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
149 -- Check if search was aborted and return to original position
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
150 local s = w.search_state
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
151 if s.marker then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
152 w:get_current():set_scroll_vert(s.marker)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
153 s.marker = nil
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
154 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
155 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
156 changed = function (w, text)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
157 -- Check that the first character is '/' or '?' and update search
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
158 if string.match(text, "^[\?\/]") then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
159 w:search(string.sub(text, 2), (string.sub(text, 1, 1) == "/"))
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
160 else
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
161 w:clear_search()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
162 w:set_mode()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
163 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
164 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
165 activate = function (w, text)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
166 w.search_state.marker = nil
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
167 w:srch_hist_add(text)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
168 w:set_mode()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
169 -- Ghost the search term in the prompt
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
170 local p = w.ibar.prompt
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
171 p.text = lousy.util.escape(text)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
172 p:show()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
173 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
174 })
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
175
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
176 -- Setup follow mode
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
177 new_mode("follow", {
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
178 enter = function (w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
179 local i, p = w.ibar.input, w.ibar.prompt
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
180 w:eval_js_from_file(lousy.util.find_data("scripts/follow.js"))
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
181 w:eval_js("clear(); show_hints();")
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
182 p.text = "Follow:"
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
183 p:show()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
184 i.text = ""
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
185 i:show()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
186 i:focus()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
187 i:set_position(-1)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
188 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
189 leave = function (w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
190 if w.eval_js then w:eval_js("clear();") end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
191 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
192 changed = function (w, text)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
193 local ret = w:eval_js(string.format("update(%q);", text))
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
194 w:emit_form_root_active_signal(ret)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
195 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
196 })

mercurial