-
-
Save alexdantas/7987616 to your computer and use it in GitHub Desktop.
Autoscroll script for the Luakit browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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