Skip to content

Instantly share code, notes, and snippets.

@cra
Created August 16, 2012 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cra/3370011 to your computer and use it in GitHub Desktop.
Save cra/3370011 to your computer and use it in GitHub Desktop.
Notion kpress_count test
COUNTER_FILE = "/tmp/notion_counter"
function kpress_count(binding, fn, args)
local counter = {}
local inp = io.open(COUNTER_FILE)
if inp then
-- read
for line in inp:lines() do
local k, v = line:match '(%S+)%s+(%S+)%s'
counter.k = v
end
file:close()
end
-- update
if counter.binding then
counter.binding = counter.binding + 1
else
counter.binding = 1
end
-- dump
local outp = io.open(COUNTER_FILE, "w")
for k, v in pairs(counter) do
outp:write(k .. " " .. v)
end
outp:close()
return kpress(binding, string.format("%s(%s)", fn, args))
end
defbindings("WScreen", {
bdoc("Toggle scratchpad."),
--kpress(ALTMETA.."Shift+C", "named_scratchpad(_, 'ims')"),
kpress_count(ALTMETA.."Shift+C", "named_scratchpad", "_, 'ims'"),
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment