mjolnir._asm.modal_hotkey

Home: https://github.com/asmagill/mjolnir_asm.hydra

This module extends mjolnir.hotkey for conveniently binding modal hotkeys in the same manner as in Hydra.

Example usage:

    k = modal_hotkey.new({"cmd", "shift"}, "d")

    function k:entered() mjolnir.alert('Entered mode') end
    function k:exited()  mjolnir.alert('Exited mode')  end

    k:bind({}, 'escape', function() k:exit() end)
    k:bind({}, 'J', function() mjolnir.alert("Pressed J") end)

This module is based primarily on code from the previous incarnation of Mjolnir by Steven Degutis.

inject

mjolnir._asm.modal_hotkey.inject()

Injects this module into mjolnir.hotkey as mjolnir.hotkey.modal. This is to provide bindings similar to those used in Hydra, when modal was expected to be found attached to the hydra.hotkey name space. Because of the caching used by Lua with require, invoking this function once will cause these functions to silently be available to any other module or lua input which has required mjolnir.hotkey.

To activate this behavior, put the following somewhere at the top of your ~/.mjolnir/init.lua file:

    require("mjolnir._asm.modal_hotkey").inject()

Calling this function is not a requirement to using this module; it is provided for backwards similarity/compatibility.

new

mjolnir._asm.modal_hotkey.new(mods, key) -> modal

Creates a new modal hotkey and enables it. When mods and key are pressed, all keys bound via modal:bind will be enabled. They are disabled when the "mode" is exited via modal:exit()

bind

mjolnir._asm.modal_hotkey:bind(mods, key, pressedfn, releasedfn)

Registers a new hotkey that will be bound when the modal is enabled.

enter

mjolnir._asm.modal_hotkey:enter()

Enables all hotkeys created via modal:bind and disables the modal itself. Called automatically when the modal's hotkey is pressed.

entered

mjolnir._asm.modal_hotkey:entered()

Optional callback for when a modal is entered; default implementation does nothing.

exit

mjolnir._asm.modal_hotkey:exit()

Disables all hotkeys created via modal:bind and re-enables the modal itself.

exited

mjolnir._asm.modal_hotkey:exited()

Optional callback for when a modal is exited; default implementation does nothing.