Skip to content

Commit

Permalink
feat: add windows-list to allow custom window candidates (#70)
Browse files Browse the repository at this point in the history
* feat: add windows-list to allow custom window candidates

* fix: always check focusable window
  • Loading branch information
henry-hsieh authored Apr 21, 2024
1 parent 696c33a commit 059e88e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
21 changes: 15 additions & 6 deletions doc/hop.txt
Original file line number Diff line number Diff line change
Expand Up @@ -945,16 +945,25 @@ below.
`extensions = nil`

`multi_windows` *hop-config-multi_windows*
Enable cross-windows support and hint all the currently visible windows.
This behavior allows you to jump around any position in any buffer
currently visible in a window. Although a powerful a feature, remember
that enabling this will also generate many more sequence combinations, so
you could get deeper sequences to type (most of the time it should be good
if you have enough keys in |hop-config-keys|).
Enable cross-windows support and hint all the windows listed in
`windows_list`. This behavior allows you to jump around any position in any
buffer currently visible in an editor. Although a powerful a feature,
remember that enabling this will also generate many more sequence
combinations, so you could get deeper sequences to type (most of the time
it should be good if you have enough keys in |hop-config-keys|).

Defaults:~
`multi_windows = false`

`windows_list` *hop-config-windows_list*
A function returns a list-table of windows to jump to. When `multi_windows`
is enabled, only the windows on the list will be hint.

Defaults:~ >
windows_list = function ()
return vim.api.nvim_tabpage_list_wins(0)
end
<
`excluded_filetypes`
Skip hinting windows with the excluded filetypes. Those windows to check
filetypes are collected only when you enable `multi_windows` or execute
Expand Down
3 changes: 3 additions & 0 deletions lua/hop/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ M.current_line_only = false
M.dim_unmatched = true
M.uppercase_labels = false
M.multi_windows = false
M.windows_list = function ()
return vim.api.nvim_tabpage_list_wins(0)
end
M.ignore_injections = false
M.hint_position = hint.HintPosition.BEGIN ---@type HintPosition
M.hint_offset = 0 ---@type WindowCell
Expand Down
6 changes: 3 additions & 3 deletions lua/hop/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ function M.get_windows_context(opts)
end

-- Get the context for all the windows in current tab
for _, w in ipairs(api.nvim_tabpage_list_wins(0)) do
for _, w in ipairs(opts.windows_list()) do
local valid_win = api.nvim_win_is_valid(w)
local not_relative = api.nvim_win_get_config(w).relative == ''
if valid_win and not_relative and w ~= cur_hwin then
local focusable_win = vim.api.nvim_win_get_config(w).focusable
if valid_win and focusable_win and w ~= cur_hwin then
local b = api.nvim_win_get_buf(w)

-- Skips current window and excluded filetypes
Expand Down

0 comments on commit 059e88e

Please sign in to comment.