Skip to content

Instantly share code, notes, and snippets.

@alexdantas
Forked from mason-larobina/autoscroll.lua
Last active January 3, 2022 04:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexdantas/7987616 to your computer and use it in GitHub Desktop.
Save alexdantas/7987616 to your computer and use it in GitHub Desktop.
Autoscroll script for the Luakit browser
-- Autoscroll script for luakit (luakit.org).
-- Originally by @mason-larobina
-- (https://gist.github.com/mason-larobina/726550)
--
-- Install instructions:
-- * Add to rc.lua before window spawning code
-- Or
-- * Save to $XDG_CONFIG_HOME/luakit/autoscroll.lua and
-- add `require "autoscroll"` to your rc.lua
----------------------------------------------------------------
local buf, key = lousy.bind.buf, lousy.bind.key
local scroll_step = 1 -- globals.scroll_step -- (too fast)
add_binds("normal", {
-- Start autoscroll with a (previously ,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),
-- Default page scroll keybindings,
-- so we can still scroll while autoscrolling.
key({}, "Page_Down", "Scroll page down.",
function (w) w:scroll{ ypagerel = 1.0 } end),
key({}, "Page_Up", "Scroll page up.",
function (w) w:scroll{ ypagerel = -1.0 } end),
})
new_mode("autoscroll", {
-- Start autoscroll timer
enter = function (w)
w:set_prompt("-- AUTOSCROLL MODE --")
local t = timer{interval=50}
t:add_signal("timeout", function ()
w:scroll { yrel = scroll_step }
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,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment