Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Add premise of HopNormal. #290

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
41 changes: 41 additions & 0 deletions lua/hop/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,30 @@ function M.hint_with(jump_target_gtr, opts)
end)
end

-- Run an arbitrary command at the target.
--
-- This will not update the jump list.
function M.cmd_with(jump_target_gtr, cmd, opts)
if opts == nil then
opts = override_opts(opts)
end

if not cmd then
vim.notify('No command provided', 4)
return
end

M.hint_with_callback(jump_target_gtr, opts, function(jt)
local win = vim.api.nvim_get_current_win()
local pos = vim.api.nvim_win_get_position(0)

M.move_cursor_to(jt.window, jt.line + 1, jt.column - 1, opts.hint_offset)
vim.cmd(cmd)
print('jumping back to', vim.inspect(pos))
M.move_cursor_to(win, pos[1] + 1, pos[2], 0)
end)
end

function M.hint_with_callback(jump_target_gtr, opts, callback)
if opts == nil then
opts = override_opts(opts)
Expand Down Expand Up @@ -571,6 +595,23 @@ function M.hint_anywhere(opts)
)
end

function M.cmd_words(cmd, opts)
opts = override_opts(opts)

local generator
if opts.current_line_only then
generator = jump_target.jump_targets_for_current_line
else
generator = jump_target.jump_targets_by_scanning_lines
end

M.cmd_with(
generator(jump_target.regex_by_word_start()),
cmd,
opts
)
end

-- Setup user settings.
function M.setup(opts)
-- Look up keys in user-defined table with fallback to defaults.
Expand Down