Skip to content

Commit

Permalink
feat: New commands for opening/closing multiple windows (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed May 13, 2022
1 parent f1dfb0a commit 19e7391
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 17 deletions.
37 changes: 20 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,23 +201,26 @@ require("aerial").setup({

## Commands

| Command | arg | description |
| --------------------- | ---------------------- | -------------------------------------------------------------------------- |
| `AerialToggle[!]` | `left`/`right`/`float` | Open or close the aerial window. With `[!]` cursor stays in current window |
| `AerialOpen[!]` | `left`/`right`/`float` | Open the aerial window. With `[!]` cursor stays in current window |
| `AerialClose` | | Close the aerial window |
| `AerialPrev` | N=1 | Jump backwards N symbols |
| `AerialNext` | N=1 | Jump forwards N symbols |
| `AerialPrevUp` | N=1 | Jump up the tree N levels, moving backwards |
| `AerialNextUp` | N=1 | Jump up the tree N levels, moving forwards |
| `AerialGo` | N=1, `v`/`h` | Jump to the Nth symbol |
| `AerialTreeOpen[!]` | | Expand tree at current location. `[!]` makes it recursive. |
| `AerialTreeClose[!]` | | Collapse tree at current location. `[!]` makes it recursive. |
| `AerialTreeToggle[!]` | | Toggle tree at current location. `[!]` makes it recursive. |
| `AerialTreeOpenAll` | | Open all tree nodes |
| `AerialTreeCloseAll` | | Collapse all tree nodes |
| `AerialTreeSyncFolds` | | Sync code folding with current tree state |
| `AerialInfo` | | Print out debug info related to aerial |
| Command | arg | description |
| -------------------------- | ---------------------- | -------------------------------------------------------------------------- |
| `AerialToggle[!]` | `left`/`right`/`float` | Open or close the aerial window. With `[!]` cursor stays in current window |
| `AerialOpen[!]` | `left`/`right`/`float` | Open the aerial window. With `[!]` cursor stays in current window |
| `AerialOpenAll` | | Open an aerial window for each visible window |
| `AerialClose` | | Close the aerial window |
| `AerialCloseAll` | | Close all visible aerial windows |
| `AerialCloseAllButCurrent` | | Close all visible aerial windows except for the focused one |
| `AerialPrev` | N=1 | Jump backwards N symbols |
| `AerialNext` | N=1 | Jump forwards N symbols |
| `AerialPrevUp` | N=1 | Jump up the tree N levels, moving backwards |
| `AerialNextUp` | N=1 | Jump up the tree N levels, moving forwards |
| `AerialGo` | N=1, `v`/`h` | Jump to the Nth symbol |
| `AerialTreeOpen[!]` | | Expand tree at current location. `[!]` makes it recursive. |
| `AerialTreeClose[!]` | | Collapse tree at current location. `[!]` makes it recursive. |
| `AerialTreeToggle[!]` | | Toggle tree at current location. `[!]` makes it recursive. |
| `AerialTreeOpenAll` | | Open all tree nodes |
| `AerialTreeCloseAll` | | Collapse all tree nodes |
| `AerialTreeSyncFolds` | | Sync code folding with current tree state |
| `AerialInfo` | | Print out debug info related to aerial |

## Options

Expand Down
13 changes: 13 additions & 0 deletions doc/aerial.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,23 @@ COMMANDS *aerial-commands
Open the aerial window. [direction] can be either `left`, `right`, or
`float`. If without [!] the cursor will jump to the aerial window.

*:AerialOpenAll*
:AerialOpenAll
Open an aerial window for each visible window.

*:AerialClose*
:AerialClose
Close the aerial window.

*:AerialCloseAll*
:AerialCloseAll
Close all visible aerial windows.

*:AerialCloseAllButCurrent*
:AerialCloseAllButCurrent
Close all visible aerial windows except for the one currently focused
or for the currently focused window.

*:AerialInfo*
:AerialInfo
Print out debug info related to aerial.
Expand Down
3 changes: 3 additions & 0 deletions doc/tags
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
:AerialClose aerial.txt /*:AerialClose*
:AerialCloseAll aerial.txt /*:AerialCloseAll*
:AerialCloseAllButCurrent aerial.txt /*:AerialCloseAllButCurrent*
:AerialGo aerial.txt /*:AerialGo*
:AerialInfo aerial.txt /*:AerialInfo*
:AerialNext aerial.txt /*:AerialNext*
:AerialNextUp aerial.txt /*:AerialNextUp*
:AerialOpen aerial.txt /*:AerialOpen*
:AerialOpenAll aerial.txt /*:AerialOpenAll*
:AerialPrev aerial.txt /*:AerialPrev*
:AerialPrevUp aerial.txt /*:AerialPrevUp*
:AerialToggle aerial.txt /*:AerialToggle*
Expand Down
3 changes: 3 additions & 0 deletions lua/aerial/command.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ M.create_commands = function()
vim.cmd([[
command! -bang -complete=customlist,v:lua.aerial_complete_open_direction -nargs=? AerialToggle call luaeval("require'aerial'.toggle(_A[1], _A[2])", [expand('<bang>'), expand('<args>')])
command! -bang -complete=customlist,v:lua.aerial_complete_open_direction -nargs=? AerialOpen call luaeval("require'aerial'.open(_A[1], _A[2])", [expand('<bang>'), expand('<args>')])
command! -bang AerialOpenAll lua require('aerial').open_all()
command! AerialClose lua require'aerial'.close()
command! AerialCloseAll lua require'aerial'.close_all()
command! AerialCloseAllButCurrent lua require'aerial'.close_all_but_current()
command! -count=1 AerialNext call luaeval("require'aerial'.next(tonumber(_A))", expand('<count>'))
command! -count=1 AerialPrev call luaeval("require'aerial'.next(-1*tonumber(_A))", expand('<count>'))
command! -count=1 AerialNextUp call luaeval("require'aerial'.up(1, tonumber(_A))", expand('<count>'))
Expand Down
6 changes: 6 additions & 0 deletions lua/aerial/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ M.close = function()
window.close()
end

M.close_all = window.close_all

M.close_all_but_current = window.close_all_but_current

-- Open the aerial window for the current buffer.
-- focus (bool): If true, jump to aerial window
-- direction (enum): "left", "right", or "float"
Expand All @@ -57,6 +61,8 @@ M.open = function(focus, direction)
window.open(focus, direction)
end

M.open_all = window.open_all

-- Jump to the aerial window for the current buffer, if it is open
M.focus = function()
window.focus()
Expand Down
31 changes: 31 additions & 0 deletions lua/aerial/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,24 @@ M.close = function()
end
end

M.close_all = function()
for _, winid in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
if util.is_aerial_buffer(vim.api.nvim_win_get_buf(winid)) then
vim.api.nvim_win_close(winid, false)
end
end
end

M.close_all_but_current = function()
local _, aer_bufnr = util.get_buffers(0)
for _, winid in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
local bufnr = vim.api.nvim_win_get_buf(winid)
if bufnr ~= aer_bufnr and util.is_aerial_buffer(bufnr) then
vim.api.nvim_win_close(winid, false)
end
end
end

M.maybe_open_automatic = function(bufnr)
if config.open_automatic(bufnr or 0) then
local opts = {}
Expand Down Expand Up @@ -216,6 +234,19 @@ M.open = function(focus, direction, opts)
end
end

M.open_all = function()
if config.close_behavior == "global" then
return M.open()
end
for _, winid in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
if not util.is_ignored_win(winid) and not util.is_floating_win(winid) then
vim.api.nvim_win_call(winid, function()
M.open()
end)
end
end
end

M.focus = function()
if not M.is_open() then
return
Expand Down

0 comments on commit 19e7391

Please sign in to comment.