Skip to content

Commit

Permalink
Move all link following code into lib/follow.lua
Browse files Browse the repository at this point in the history
Also reverted mode setting with arguments, set options on the window
structure instead.
  • Loading branch information
mason-larobina committed Sep 3, 2010
1 parent 82f0793 commit 757dbe0
Show file tree
Hide file tree
Showing 7 changed files with 442 additions and 407 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ install:
install -m644 README.md AUTHORS COPYING* $(DOCDIR)
cp -r lib/ $(INSTALLDIR)/share/luakit/
chmod -R 755 $(INSTALLDIR)/share/luakit/lib/
cp -r scripts/ $(INSTALLDIR)/share/luakit/
chmod -R 755 $(INSTALLDIR)/share/luakit/scripts/
install -D luakit $(INSTALLDIR)/bin/luakit
install -d $(DESTDIR)/etc/xdg/luakit/
install -D config/*.lua $(DESTDIR)/etc/xdg/luakit/
Expand Down
14 changes: 0 additions & 14 deletions config/binds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,6 @@ binds.mode_binds = {
buf("^ZZ$", function (w) w:close_win() end),
buf("^D$", function (w) w:close_win() end),

-- Link following
key({}, "f", function (w) w:set_mode("follow", nil, function (sig) return sig end) end),
buf("^Fy$", function (w) w:set_mode("follow", "yank", function (uri) luakit.set_selection(uri) return "root-active" end) end),
buf("^FY$", function (w) w:set_mode("follow", "yank description", function (uri) luakit.set_selection(uri) return "root-active" end) end),
buf("^Ft$", function (w) w:set_mode("follow", "tab", function (uri) w:new_tab(uri) return "root-active" end) end),
buf("^Fo$", function (w) w:set_mode("follow", "open", function (uri) w:get_current().uri = uri return "root-active" end) end),
buf("^Fw$", function (w) w:set_mode("follow", "window", function (uri) window.new{uri} return "root-active" end) end),
buf("^FT$", function (w) w:set_mode("follow", "tab prompt", function (uri) w:enter_cmd(":tabopen ".. uri) end) end),
buf("^FO$", function (w) w:set_mode("follow", "open prompt", function (uri) w:enter_cmd(":open ".. uri) end) end),
buf("^FW$", function (w) w:set_mode("follow", "window prompt", function (uri) w:enter_cmd(":winopen ".. uri) end) end),
buf("^Fs$", function (w) w:set_mode("follow", "save", function (uri) w:download(uri) return "root-active" end) end),
buf("^Ff$", function (w) w:set_mode("follow", "focus", function (uri) return "root-active" end) end),
buf("^Fi$", function (w) w:set_mode("follow", "open image", function (uri) w:get_current().uri = uri return "root-active" end) end),

-- Bookmarking
key({}, "B", function (w) w:enter_cmd(":bookmark " .. ((w:get_current() or {}).uri or "http://") .. " ") end),
buf("^gb$", function (w) w:navigate(bookmarks.dump_html()) end),
Expand Down
55 changes: 14 additions & 41 deletions config/modes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,25 @@ end
-- Attach window & input bar signals for mode hooks
window.init_funcs.modes_setup = function (w)
-- Calls the `enter` and `leave` mode hooks.
w.win:add_signal("mode-changed", function (_, mode, ...)
-- Call the last modes `leave` hook.
if current and current.leave then
current.leave(w)
end

-- Update window binds
w:update_binds(mode)
w.win:add_signal("mode-changed", function (_, mode)
local leave = (current or {}).leave

-- Get new modes functions
current = modes[mode]

-- Call the last modes `leave` hook.
if leave then leave(w) end

-- Check new mode
if not current then
error("changed to un-handled mode: " .. mode)
end

-- Update window binds
w:update_binds(mode)

-- Call new modes `enter` hook.
if current.enter then current.enter(w, ...) end
if current.enter then current.enter(w) end
end)

-- Calls the `changed` hook on input widget changed.
Expand All @@ -54,9 +56,9 @@ end

-- Add mode related window methods
for name, func in pairs({
set_mode = function (w, name, ...) lousy.mode.set(w.win, name, ...) end,
get_mode = function (w) return lousy.mode.get(w.win) end,
is_mode = function (w, name) return name == w:get_mode() end,
set_mode = function (w, name) lousy.mode.set(w.win, name) end,
get_mode = function (w) return lousy.mode.get(w.win) end,
is_mode = function (w, name) return name == w:get_mode() end,
}) do window.methods[name] = func end

-- Setup normal mode
Expand Down Expand Up @@ -138,32 +140,3 @@ new_mode("search", {
p:show()
end,
})

-- Setup follow mode
new_mode("follow", {
enter = function (w, mode, fun)
local i, p = w.ibar.input, w.ibar.prompt
w.follow_mode_function = fun
p.text = mode and string.format("Follow (%s):", mode) or "Follow:"
p:show()
i.text = ""
i:show()
i:focus()
i:set_position(-1)
w:eval_js_from_file(lousy.util.find_data("scripts/follow.js"))
w:eval_js(string.format("%s_mode(); clear(); show_hints();", string.gsub(mode or "follow", "%s", "_")))
end,
leave = function (w)
if w.eval_js then w:eval_js("clear();") end
end,
changed = function (w, text)
local ret = w:eval_js(string.format("update(%q);", text))
local fun = w.follow_mode_function
if ret ~= "false" then
local sig
if fun then sig = fun(ret) end
if sig then w:emit_form_root_active_signal(sig) end
end
end,
})

1 change: 1 addition & 0 deletions config/rc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ require "webview"
require "binds"

-- Init scripts
require "follow"
require "formfiller"
require "go_input"
require "follow_selected"
Expand Down
Loading

0 comments on commit 757dbe0

Please sign in to comment.