diff --git a/README.md b/README.md index af6288f..bfb3869 100644 --- a/README.md +++ b/README.md @@ -62,9 +62,22 @@ You can override settings in `setup`: ```lua require("makemapper").setup({ prefix = "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 @@ -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` diff --git a/lua/makemapper/init.lua b/lua/makemapper/init.lua index cedfe62..a113ce3 100644 --- a/lua/makemapper/init.lua +++ b/lua/makemapper/init.lua @@ -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) @@ -16,6 +20,7 @@ end local default_opts = { prefix = "m", + runner = "nvim_vsplit", } local opts @@ -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