Custom callback feels clunky
NickCondron opened this issue · 0 comments
NickCondron commented
I found out about the custom callback feature, so I decided to implement my first one in my neovim config. This simply extends the HopLineStart to immediately enter insert mode on a new line:
local hop = require("hop")
hop.setup({})
local hop_insert_line = function()
local regex = require("hop.jump_regex").regex_by_line_start_skip_whitespace()
local target = require("hop.jump_target").jump_target_generator(regex)
hop.hint_with_callback(target, hop.opts, function(jt)
hop.move_cursor_to(jt, hop.opts)
-- v this the critical line
vim.api.nvim_input("o")
end)
end
vim.keymap.set("n", "go", hop_insert_line)
I feel this is a lot of boilerplate for a single lua command callback to a single default target. Is there an easier way to implement this? If not, could the default targets accept a callback as an optional parameter?
The help documentation is excellent, but it is lacking an example that would have likely saved me some time. Would adding my example to the wiki, hop.txt, or examples make sense?