<commit_before>if exists('g:loaded_last_closed_buffer') || v:version < 702
  finish
endif
let g:loaded_last_closed_buffer = 1

let s:save_cpo = &cpoptions
set cpoptions&vim

let g:lcb_max_restore_count = 5

let g:lcb_current = 0
let g:lcb_leaved  = 0
let g:lcb_closed  = []

function! s:lcb_remember_on_enter() abort
  let g:lcb_current = bufnr('')

  if g:lcb_leaved > 0 && !bufloaded(g:lcb_leaved) && empty(&buftype)
    let g:lcb_closed = ([g:lcb_leaved] + g:lcb_closed)[0 : g:lcb_max_restore_count - 1]
  endif
endfunction

function! s:lcb_remember_on_leave() abort
  if g:lcb_current > 0 && !empty(bufname(g:lcb_current)) && empty(&buftype)
    let g:lcb_leaved = g:lcb_current
  endif
endfunction

function! s:lcb_restore() abort
  let l:nr = get(g:lcb_closed, 0, 0)
  let g:lcb_closed = g:lcb_closed[1:]

  if l:nr > 0 && bufexists(l:nr)
    exec 'buffer' l:nr
  endif
endfunction

augroup last_closed_buffer
  autocmd!
  autocmd BufEnter * call <SID>lcb_remember_on_enter()
  autocmd BufLeave * call <SID>lcb_remember_on_leave()
augroup END

nnoremap <silent> <Plug>(lcb-restore) <Cmd>call <SID>lcb_restore()<CR>

let &cpoptions = s:save_cpo
unlet s:save_cpo<commit_msg>Fix last_closed_buffer<commit_after>if exists('g:loaded_last_closed_buffer') || v:version < 702
  finish
endif
let g:loaded_last_closed_buffer = 1

let s:save_cpo = &cpoptions
set cpoptions&vim

let g:lcb_max_restore_count = 5
let g:lcb_leaved = 0
let g:lcb_closed = []

function! s:on_enter() abort
  if g:lcb_leaved == 0
    return
  endif
  if !empty(&buftype)
    return
  endif

  let l:info = getbufinfo(g:lcb_leaved)[0]
  if l:info.hidden || !l:info.loaded
    let g:lcb_closed = ([g:lcb_leaved] + g:lcb_closed)[0 : g:lcb_max_restore_count - 1]
  endif
endfunction

function! s:on_leave() abort
  if !empty(bufname()) && empty(&buftype)
    let g:lcb_leaved = bufnr('')
  endif
endfunction

function! s:restore() abort
  let l:nr = get(g:lcb_closed, 0, 0)
  let g:lcb_closed = g:lcb_closed[1:]

  if l:nr > 0 && bufexists(l:nr)
    exec 'buffer' l:nr
  endif
endfunction

augroup last_closed_buffer
  autocmd!
  autocmd BufEnter * call <SID>on_enter()
  autocmd BufLeave * call <SID>on_leave()
augroup END

nnoremap <silent> <Plug>(lcb-restore) <Cmd>call <SID>restore()<CR>

let &cpoptions = s:save_cpo
unlet s:save_cpo
{'fraction_non_alphanumeric': 0.12413194444444445, 'fraction_numerical': 0.012586805555555556, 'mean_word_length': 5.1466666666666665, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, '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': '7229488', 'n_tokens_mistral': 1015, 'n_tokens_neox': 958, 'n_words': 202}