Skip to content
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
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,22 @@ You can override settings in `setup`:
```lua
require("makemapper").setup({
prefix = "<leader>m", -- the prefix applied to all keymaps generated from annotations
runner = "nvim_vsplit",
-- runner can be one of:
-- "nvim_vsplit" (default)
-- "harpoon_tmux" (requires harpoon.nvim)
-- your own custom runner (a function taking a command string)
})
```

## Changing Runners

If you want to change runner after calling `setup`, then use:

```lua
require("makemapper").set_runner(...)
```

# Which-key

[whick-key](https://github.com/folke/which-key.nvim) users may wish to add a description to the
Expand All @@ -79,6 +92,5 @@ require("which-key").register({
# TODO

+ Document requirement for `make` treesitter parser to be installed
+ Other configurable run strategies, not just terminal in a vertical split!
+ Provide an option to change the annotation from `nvim_map(.*)` to something user-defined.
+ Filter out "special" targets like `.PHONY`
27 changes: 22 additions & 5 deletions lua/makemapper/init.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
local M = {}

local term_nvim = function(cmd)
vim.cmd("vsplit | terminal " .. cmd)
end
local runners = {
nvim_vsplit = function(cmd)
vim.cmd("vsplit | terminal " .. cmd)
end,
harpoon_tmux = function(cmd)
require("harpoon.tmux").sendCommand(1, cmd .. "\n")
end,
}

-- TODO have options select different runners
local runner = term_nvim
local runner

-- given a general strategy for running commands, curry in "make {target}"
M.make_runner = function(target)
Expand All @@ -16,6 +20,7 @@ end

local default_opts = {
prefix = "<leader>m",
runner = "nvim_vsplit",
}

local opts
Expand All @@ -27,9 +32,21 @@ local set_mappings = function(m)
end
end

local get_runner = function(spec)
if type(spec) == "function" then
return spec
end
return runners[spec]
end

M.set_runner = function(spec)
runner = get_runner(spec) or get_runner(default_opts.runner)
end

M.setup = function(o)
opts = vim.tbl_deep_extend("force", {}, default_opts, o or {})

M.set_runner(opts.runner)
set_mappings(require("makemapper.makefile").parse_mappings())
end

Expand Down