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

Commit

Permalink
feat: customizable prompt string
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhao committed Nov 14, 2022
1 parent 90db1b2 commit 598aea5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
10 changes: 10 additions & 0 deletions doc/hop.txt
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,16 @@ below.
Defaults:~
`multi_windows = false`

`prompt` *hop-config-prompt*
Customize the prompts used for commands |HopChar1|, |HopChar2| and
|HopPattern|, respectively.

For example, to use `> ` as prompt for |HopChar2|, you can set up
`prompt = { char2 = '> ' }` to override the default prompt.

Defaults:~
`prompt = { char1 = 'Hop 1 char: ', char2 = 'Hop 2 char: ', pattern = 'Hop pattern: ' }`

==============================================================================
EXTENSION *hop-extension*

Expand Down
1 change: 1 addition & 0 deletions lua/hop/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ M.uppercase_labels = false
M.multi_windows = false
M.hint_position = require'hop.hint'.HintPosition.BEGIN
M.hint_offset = 0
M.prompt = {char1 = 'Hop 1 char: ', char2 = 'Hop 2 char: ', pattern = 'Hop pattern: '}

return M
20 changes: 15 additions & 5 deletions lua/hop/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ function M.hint_patterns(opts, pattern)
else
vim.cmd('redraw')
vim.fn.inputsave()
pat = M.get_input_pattern('Hop pattern: ', nil, opts)
pat = M.get_input_pattern(opts.prompt.pattern, nil, opts)
vim.fn.inputrestore()
if not pat then return end
end
Expand Down Expand Up @@ -508,7 +508,7 @@ function M.hint_char1(opts)

opts = override_opts(opts)

local c = M.get_input_pattern('Hop 1 char: ', 1)
local c = M.get_input_pattern(opts.prompt.char1, 1)
if not c then
return
end
Expand All @@ -531,7 +531,7 @@ function M.hint_char2(opts)

opts = override_opts(opts)

local c = M.get_input_pattern('Hop 2 char: ', 2)
local c = M.get_input_pattern(opts.prompt.char2, 2)
if not c then
return
end
Expand Down Expand Up @@ -628,8 +628,18 @@ end

-- Setup user settings.
function M.setup(opts)
-- Look up keys in user-defined table with fallback to defaults.
M.opts = setmetatable(opts or {}, {__index = require'hop.defaults'})
local default_opts = require'hop.defaults'
-- -- Look up keys in user-defined table with fallback to defaults.
-- M.opts = setmetatable(opts or {}, {__index = default_opts})

-- -- Since the prompt option is a table, user may specify incomplete keys,
-- -- we want to fallback to its default value if a key is not provided.
-- if opts.prompt then
-- opts.prompt = vim.tbl_extend('keep', opts.prompt, default_opts.prompt)
-- end
M.opts = vim.tbl_deep_extend('keep', opts, default_opts)
vim.pretty_print(M.opts)

M.initialized = true

-- Insert the highlights and register the autocommand if asked to.
Expand Down

0 comments on commit 598aea5

Please sign in to comment.