Create a gist now

Instantly share code, notes, and snippets.

Autoscrolling script for luakit
----------------------------------------------------------------
-- Simple autoscroll script for luakit (luakit.org) --
-- Install instructions: --
-- 1. Add to rc.lua before window spawning code. --
-- 2. Save to $XDG_CONFIG_HOME/luakit/autoscroll.lua and add --
-- a `require "autoscroll"` to your rc.lua --
----------------------------------------------------------------
local buf, key = lousy.bind.buf, lousy.bind.key
add_binds("normal", {
-- Start autoscroll with ,a
buf("^,a$", function (w) w:set_mode("autoscroll") end),
})
add_binds("autoscroll", {
-- Increase scrolling speed
key({}, "+", function (w)
w.autoscroll_timer:stop()
w.autoscroll_timer.interval = math.max(5, w.autoscroll_timer.interval - 5)
w.autoscroll_timer:start()
end),
-- Decrease scrolling speed
key({}, "-", function (w)
w.autoscroll_timer:stop()
w.autoscroll_timer.interval = w.autoscroll_timer.interval + 5
w.autoscroll_timer:start()
end),
})
new_mode("autoscroll", {
-- Start autoscroll timer
enter = function (w)
local t = timer{interval=50}
t:add_signal("timeout", function ()
w:scroll_vert("+1px")
end)
w.autoscroll_timer = t
t:start()
end,
-- Stop autoscroll timer
leave = function (w)
if w.autoscroll_timer then
w.autoscroll_timer:stop()
w.autoscroll_timer = nil
end
end,
})
@alexdantas

Nice mode!
Just a suggestion, could you set the prompt when the mode starts?
w:set_prompt("-- AUTOSCROLL MODE --") or something like that.

@alexdantas

As of luakit 0d5f4ab, this doesn't work.
Apparently scroll_vert is not a valid function.

I've made some changes:

  • Replaced scroll_vert for scroll
  • Added default scroll keybindings.

Link's here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment