Skip to content

Commit 1c5ff7c

Browse files
committed
confirm window close
1 parent 68a9514 commit 1c5ff7c

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Default mappings:
2222
| `<C-W>,` | Go to tab on the right. |
2323
| `<C-W>.` | Move the current tab one position to the left. |
2424
| `<C-W>/` | Move the current tab one position to the right. |
25+
| `<C-W>c` | Check if there are any taberian tabs present and ask user to confirm closing the window. |
2526
| `<A-1>` | Go to tab 1. |
2627
| `<A-2>` | Go to tab 2. |
2728
| `<A-3>` | Go to tab 3. |
@@ -50,6 +51,7 @@ map <silent> <C-W>m <Cmd>TaberianGotoLeftTab<CR>
5051
map <silent> <C-W>, <Cmd>TaberianGotoRightTab<CR>
5152
map <silent> <C-W>. <Cmd>TaberianMoveCurrentTabLeft<CR>
5253
map <silent> <C-W>/ <Cmd>TaberianMoveCurrentTabRight<CR>
54+
map <silent> <C-W>c <Cmd>TaberianConfirmWindowClose<CR>
5355
map <silent> <A-1> <Cmd>TaberianGoToTabNr 0<CR>
5456
map <silent> <A-2> <Cmd>TaberianGoToTabNr 1<CR>
5557
map <silent> <A-3> <Cmd>TaberianGoToTabNr 2<CR>

autoload/taberian.vim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,17 @@ function! taberian#render_all_windows()
198198
call win_execute(winid, 'call taberian#update_current_window()')
199199
endfor
200200
endfunction
201+
202+
function! taberian#confirm_window_close()
203+
if len(w:taberian.tabs) > 1
204+
echo 'This window has ' . len(w:taberian.tabs) . ' tabs open: '
205+
echo w:taberian.tabs->deepcopy()->map({_, tab -> fnamemodify(bufname(tab.bufnr), ':t')})->string()
206+
echo 'Are you sure you wish to close the window (yN):'
207+
let choice = nr2char(getchar())
208+
redraw
209+
if choice !=# 'y'
210+
return
211+
endif
212+
endif
213+
close
214+
endfunction

doc/taberian.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ mappings:
4747
*taberian-move-tab-right*
4848
<C-W>/ Move the current tab one position to the right.
4949

50+
*taberian-confirm-window-close*
51+
<C-W>c Check if there are any taberian tabs present and ask user
52+
to confirm closing the window.
53+
5054
<A-1> Go to tab 1.
5155
<A-2> Go to tab 2.
5256
<A-3> Go to tab 3.
@@ -72,6 +76,7 @@ using this example:
7276
map <silent> <C-W>, <Cmd>TaberianGotoRightTab<CR>
7377
map <silent> <C-W>. <Cmd>TaberianMoveCurrentTabLeft<CR>
7478
map <silent> <C-W>/ <Cmd>TaberianMoveCurrentTabRight<CR>
79+
map <silent> <C-W>c <Cmd>TaberianConfirmWindowClose<CR>
7580
map <silent> <A-1> <Cmd>TaberianGoToTabNr 0<CR>
7681
map <silent> <A-2> <Cmd>TaberianGoToTabNr 1<CR>
7782
map <silent> <A-3> <Cmd>TaberianGoToTabNr 2<CR>
@@ -100,6 +105,8 @@ COMMANDS *taberian-commands*
100105

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

108+
:TaberianConfirmWindowClose See |taberian-confirm-window-close|.
109+
103110
:TaberianGoToTabNr N Go to tab with index N. Taberian tab indices
104111
are zero-based, use 0 to go to the first tab.
105112

plugin/taberian.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ command! -nargs=0 TaberianGotoLeftTab :call taberian#goto_tab_offset(-1)
1515
command! -nargs=0 TaberianGotoRightTab :call taberian#goto_tab_offset(+1)
1616
command! -nargs=0 TaberianMoveCurrentTabLeft :call taberian#move_current_tab_offset(-1)
1717
command! -nargs=0 TaberianMoveCurrentTabRight :call taberian#move_current_tab_offset(+1)
18+
command! -nargs=0 TaberianConfirmWindowClose :call taberian#confirm_window_close()
1819
command! -nargs=1 TaberianGoToTabNr :call taberian#goto_tab_nr(<q-args>)
1920
command! -nargs=0 TaberianGoToPreviousTab :call taberian#goto_previous_tab()
2021

@@ -25,6 +26,7 @@ if !exists('g:taberian_no_default_mappings') || !g:taberian_no_default_mappings
2526
map <silent> <C-W>, <Cmd>TaberianGotoRightTab<CR>
2627
map <silent> <C-W>. <Cmd>TaberianMoveCurrentTabLeft<CR>
2728
map <silent> <C-W>/ <Cmd>TaberianMoveCurrentTabRight<CR>
29+
map <silent> <C-W>c <Cmd>TaberianConfirmWindowClose<CR>
2830
map <silent> <A-1> <Cmd>TaberianGoToTabNr 0<CR>
2931
map <silent> <A-2> <Cmd>TaberianGoToTabNr 1<CR>
3032
map <silent> <A-3> <Cmd>TaberianGoToTabNr 2<CR>

0 commit comments

Comments
 (0)