Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an option to add the body key to emitted foreign keys #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ If you want to quickly understand the concept, you can watch
* [`config`](#config)
* [`exit`](#exit)
* [`foreign_keys`](#foreign_keys)
* [`prepend_body_to_foreign_keys`](#prepend_body_to_foreign_keys)
* [`color`](#color)
* [More about colors concept](#more-about-colors-concept)
* [Amaranth color](#amaranth-color)
Expand Down Expand Up @@ -228,6 +229,23 @@ that doesn't belong to any head:
without running the foreign key.
- `foreign_keys = "run"` will not stop the hydra state, and try to run the foreign key.

#### `prepend_body_to_foreign_keys`
`boolean`\
default: `false`\
parent table: `config`

This option is only relevant when `foreign_keys` is set to `nil` or `run`.

- `prepend_body_to_foreign_keys = false` (the default) will pass the foreign key so it
will do whatever it is supposed to do.
- `prepend_body_to_foreign_keys = true` will add the body key(s) before the foreign key.

The main use is to make kepmaps with the same leading body, but defined outside of this
Hydra, reachable. For example, if you have a Hydra with the body `CTRL-W` and 4 heads
`h`, `j`, `k`, `l`, and nothing else, then, with `prepend_body_to_foreign_keys = false`,
when you press `v`, Hydra will pass `v` to nvim for process; on the other hand, with
`prepend_body_to_foreign_keys = true`, Hydra will send `CTRL-W_v`.

#### `color`
`"red" | "amaranth" | "teal" | "pink"`\
default: `"red"`\
Expand Down
22 changes: 22 additions & 0 deletions doc/hydra.txt
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,28 @@ config table
`foreign_keys = "run"`
will not stop the hydra state, and try to run the
foreign key.

*hydra-config.prepend_body_to_foreign_keys*
prepend_body_to_foreign_keys boolean
default: `false`
parent table: `config`

This option is only relevant when `foreign_keys=nil`.

`prepend_body_to_foreign_keys = false` (the default) will pass
the foreign key so it will do whatever it is supposed to do.

`prepend_body_to_foreign_keys = true` will add the body key(s)
before the foreign key.

The main use is to make kepmaps with the same leading body,
but defined outside of this Hydra, reachable. For example, if
you have a Hydra with the body `CTRL-W` and 4 heads `h`, `j`, `k`, `l`, and
nothing else, then, with `prepend_body_to_foreign_keys = false`,
when you press `v`, Hydra will pass `v` to nvim for process; on the
other hand, with `prepend_body_to_foreign_keys = true`, Hydra will
send `CTRL-W_v`.

*hydra-config.color*
color `"red"` | `"amaranth"` | `"teal"` | `"pink"`
default: `"red"`
Expand Down
5 changes: 5 additions & 0 deletions lua/hydra/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ local default_config = {
debug = false,
exit = false,
foreign_keys = nil,
prepend_body_to_foreign_keys = false,
color = 'red',
timeout = false,
invoke_on_body = false,
Expand All @@ -53,6 +54,7 @@ function Hydra:initialize(input)
on_enter = { input.config.on_enter, 'function', true },
on_exit = { input.config.on_exit, 'function', true },
exit = { input.config.exit, 'boolean', true },
prepend_body_to_foreign_keys = { input.config.prepend_body_to_foreign_keys, 'boolean', true },
timeout = { input.config.timeout, { 'boolean', 'number' }, true },
buffer = { input.config.buffer, { 'boolean', 'number' }, true },
hint = { input.config.hint, { 'boolean', 'string', 'table' }, true },
Expand Down Expand Up @@ -499,6 +501,9 @@ function Hydra:_leave()
self:_wait()
return false
else
if self.config.prepend_body_to_foreign_keys and vim.fn.getchar(1) ~= 0 then
api.nvim_feedkeys(termcodes(self.body), 'nix', false)
end
self:exit()
return true
end
Expand Down
1 change: 1 addition & 0 deletions lua/hydra/lib/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
---@field buffer? integer
---@field exit boolean
---@field foreign_keys hydra.foreign_keys
---@field prepend_body_to_foreign_keys boolean
---@field color hydra.color
---@field on_enter? function Before entering hydra
---@field on_exit? function After leaving hydra
Expand Down