public
Last active

Autoscrolling script for luakit

  • Download Gist
autoscroll.lua
Lua
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
----------------------------------------------------------------
-- 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,
})

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

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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.