<commit_before>" Stores the current window in the quit history, so we can undo the :quit
" later.
function! undoquit#SaveWindowQuitHistory()
  if !buflisted(expand('%'))
    return
  endif

  if !exists('g:undoquit_stack')
    let g:undoquit_stack = []
  endif

  let window_data = undoquit#GetWindowRestoreData()

  call add(g:undoquit_stack, window_data)
endfunction

" Restores the last-:quit window.
function! undoquit#UndoQuitWindow()
  if !exists('g:undoquit_stack') || empty(g:undoquit_stack)
    echo "No closed windows to undo"
    return
  endif

  let window_data = remove(g:undoquit_stack, -1)
  let real_buffers = s:RealTabBuffers()

  if len(real_buffers) == 0
    " then there's nothing of importance in this tab, let's just clear it and
    " use "edit"
    let window_data.open_command = 'only | edit'
  endif

  if window_data.neighbour_buffer != '' && bufnr(window_data.neighbour_buffer) >= 0
    let neighbour_window = bufwinnr(bufnr(window_data.neighbour_buffer))
    exe neighbour_window.'wincmd w'
  endif

  exe window_data.open_command.' '.escape(window_data.filename, ' ')
endfunction

" Fetches the data we need to successfully restore a window we're just about
" to :quit.
function! undoquit#GetWindowRestoreData()
  let window_data = {<commit_msg>Fix odd window number bug<commit_after>" Stores the current window in the quit history, so we can undo the :quit
" later.
function! undoquit#SaveWindowQuitHistory()
  if !buflisted(expand('%'))
    return
  endif

  if !exists('g:undoquit_stack')
    let g:undoquit_stack = []
  endif

  let window_data = undoquit#GetWindowRestoreData()

  call add(g:undoquit_stack, window_data)
endfunction

" Restores the last-:quit window.
function! undoquit#UndoQuitWindow()
  if !exists('g:undoquit_stack') || empty(g:undoquit_stack)
    echo "No closed windows to undo"
    return
  endif

  let window_data = remove(g:undoquit_stack, -1)
  let real_buffers = s:RealTabBuffers()

  if len(real_buffers) == 0
    " then there's nothing of importance in this tab, let's just clear it and
    " use "edit"
    let window_data.open_command = 'only | edit'
  endif

  if window_data.neighbour_buffer != '' &&
        \ bufnr(window_data.neighbour_buffer) >= 0 &&
        \ bufwinnr(bufnr(window_data.neighbour_buffer)) >= 0
    let neighbour_window = bufwinnr(bufnr(window_data.neighbour_buffer))
    exe neighbour_window.'wincmd w'
  endif

  exe window_data.open_command.' '.escape(window_data.filename, ' ')
endfunction

" Fetches the data we need to successfully restore a window we're just about
" to :quit.
function! undoquit#GetWindowRestoreData()
  let window_data = {
{'fraction_non_alphanumeric': 0.10121304018195602, 'fraction_numerical': 0.00265352539802881, 'mean_word_length': 4.407786885245901, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6234542', 'n_tokens_mistral': 941, 'n_tokens_neox': 861, 'n_words': 236}