Skip to content

Commit

Permalink
confirm window close
Browse files Browse the repository at this point in the history
  • Loading branch information
noscript committed Oct 17, 2021
1 parent 68a9514 commit 1c5ff7c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Default mappings:
| `<C-W>,` | Go to tab on the right. |
| `<C-W>.` | Move the current tab one position to the left. |
| `<C-W>/` | Move the current tab one position to the right. |
| `<C-W>c` | Check if there are any taberian tabs present and ask user to confirm closing the window. |
| `<A-1>` | Go to tab 1. |
| `<A-2>` | Go to tab 2. |
| `<A-3>` | Go to tab 3. |
Expand Down Expand Up @@ -50,6 +51,7 @@ map <silent> <C-W>m <Cmd>TaberianGotoLeftTab<CR>
map <silent> <C-W>, <Cmd>TaberianGotoRightTab<CR>
map <silent> <C-W>. <Cmd>TaberianMoveCurrentTabLeft<CR>
map <silent> <C-W>/ <Cmd>TaberianMoveCurrentTabRight<CR>
map <silent> <C-W>c <Cmd>TaberianConfirmWindowClose<CR>
map <silent> <A-1> <Cmd>TaberianGoToTabNr 0<CR>
map <silent> <A-2> <Cmd>TaberianGoToTabNr 1<CR>
map <silent> <A-3> <Cmd>TaberianGoToTabNr 2<CR>
Expand Down
14 changes: 14 additions & 0 deletions autoload/taberian.vim
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,17 @@ function! taberian#render_all_windows()
call win_execute(winid, 'call taberian#update_current_window()')
endfor
endfunction

function! taberian#confirm_window_close()
if len(w:taberian.tabs) > 1
echo 'This window has ' . len(w:taberian.tabs) . ' tabs open: '
echo w:taberian.tabs->deepcopy()->map({_, tab -> fnamemodify(bufname(tab.bufnr), ':t')})->string()
echo 'Are you sure you wish to close the window (yN):'
let choice = nr2char(getchar())
redraw
if choice !=# 'y'
return
endif
endif
close
endfunction
7 changes: 7 additions & 0 deletions doc/taberian.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ mappings:
*taberian-move-tab-right*
<C-W>/ Move the current tab one position to the right.

*taberian-confirm-window-close*
<C-W>c Check if there are any taberian tabs present and ask user
to confirm closing the window.

<A-1> Go to tab 1.
<A-2> Go to tab 2.
<A-3> Go to tab 3.
Expand All @@ -72,6 +76,7 @@ using this example:
map <silent> <C-W>, <Cmd>TaberianGotoRightTab<CR>
map <silent> <C-W>. <Cmd>TaberianMoveCurrentTabLeft<CR>
map <silent> <C-W>/ <Cmd>TaberianMoveCurrentTabRight<CR>
map <silent> <C-W>c <Cmd>TaberianConfirmWindowClose<CR>
map <silent> <A-1> <Cmd>TaberianGoToTabNr 0<CR>
map <silent> <A-2> <Cmd>TaberianGoToTabNr 1<CR>
map <silent> <A-3> <Cmd>TaberianGoToTabNr 2<CR>
Expand Down Expand Up @@ -100,6 +105,8 @@ COMMANDS *taberian-commands*

:TaberianMoveCurrentTabRight See |taberian-move-tab-right|.

:TaberianConfirmWindowClose See |taberian-confirm-window-close|.

:TaberianGoToTabNr N Go to tab with index N. Taberian tab indices
are zero-based, use 0 to go to the first tab.

Expand Down
2 changes: 2 additions & 0 deletions plugin/taberian.vim
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ command! -nargs=0 TaberianGotoLeftTab :call taberian#goto_tab_offset(-1)
command! -nargs=0 TaberianGotoRightTab :call taberian#goto_tab_offset(+1)
command! -nargs=0 TaberianMoveCurrentTabLeft :call taberian#move_current_tab_offset(-1)
command! -nargs=0 TaberianMoveCurrentTabRight :call taberian#move_current_tab_offset(+1)
command! -nargs=0 TaberianConfirmWindowClose :call taberian#confirm_window_close()
command! -nargs=1 TaberianGoToTabNr :call taberian#goto_tab_nr(<q-args>)
command! -nargs=0 TaberianGoToPreviousTab :call taberian#goto_previous_tab()

Expand All @@ -25,6 +26,7 @@ if !exists('g:taberian_no_default_mappings') || !g:taberian_no_default_mappings
map <silent> <C-W>, <Cmd>TaberianGotoRightTab<CR>
map <silent> <C-W>. <Cmd>TaberianMoveCurrentTabLeft<CR>
map <silent> <C-W>/ <Cmd>TaberianMoveCurrentTabRight<CR>
map <silent> <C-W>c <Cmd>TaberianConfirmWindowClose<CR>
map <silent> <A-1> <Cmd>TaberianGoToTabNr 0<CR>
map <silent> <A-2> <Cmd>TaberianGoToTabNr 1<CR>
map <silent> <A-3> <Cmd>TaberianGoToTabNr 2<CR>
Expand Down

0 comments on commit 1c5ff7c

Please sign in to comment.