diff --git a/doc/hop.txt b/doc/hop.txt index bb18080d..ce5d0619 100644 --- a/doc/hop.txt +++ b/doc/hop.txt @@ -518,7 +518,7 @@ doing that for you. of all the words in the window and will make the cursor jump to the one fully reduced. -`hop.jump_target.regex_by_line_start()` *hop.jump_target.regex_by_line_start* +`hop.jump_target.by_line_start()` *hop.jump_target.by_line_start* Highlight the beginning of each line in the current window. `hop.jump_target.regex_by_line_start_skip_whitespace()` *hop.jump_target.regex_by_line_start_skip_whitespace* diff --git a/lua/hop/init.lua b/lua/hop/init.lua index fd8e8ae3..47262461 100644 --- a/lua/hop/init.lua +++ b/lua/hop/init.lua @@ -539,7 +539,7 @@ function M.hint_lines(opts) end M.hint_with( - generator(jump_target.regex_by_line_start()), + generator(jump_target.by_line_start()), opts ) end diff --git a/lua/hop/jump_target.lua b/lua/hop/jump_target.lua index 1ec1d9af..513fc43f 100644 --- a/lua/hop/jump_target.lua +++ b/lua/hop/jump_target.lua @@ -348,10 +348,13 @@ function M.regex_by_searching(pat, plain_search) if plain_search then pat = vim.fn.escape(pat, '\\/.$^~[]') end + + local regex = vim.regex(pat) + return { oneshot = false, match = function(s) - return vim.regex(pat):match_str(s) + return regex:match_str(s) end } end @@ -370,10 +373,12 @@ function M.regex_by_case_searching(pat, plain_search, opts) pat = '\\c' .. pat end + local regex = vim.regex(pat) + return { oneshot = false, match = function(s) - return vim.regex(pat):match_str(s) + return regex:match_str(s) end } end @@ -384,7 +389,7 @@ function M.regex_by_word_start() end -- Line regex. -function M.regex_by_line_start() +function M.by_line_start() local c = vim.fn.winsaveview().leftcol return { @@ -403,22 +408,23 @@ end -- Line regex at cursor position. function M.regex_by_vertical() local position = vim.api.nvim_win_get_cursor(0)[2] - local pattern = vim.regex(string.format("^.\\{0,%d\\}\\(.\\|$\\)", position)) + local regex = vim.regex(string.format("^.\\{0,%d\\}\\(.\\|$\\)", position)) return { oneshot = true, match = function(s) - return pattern:match_str(s) + return regex:match_str(s) end } end -- Line regex skipping finding the first non-whitespace character on each line. function M.regex_by_line_start_skip_whitespace() - local pat = vim.regex("\\S") + local regex = vim.regex("\\S") + return { oneshot = true, match = function(s) - return pat:match_str(s) + return regex:match_str(s) end } end