<commit_before>function! prettier#utils#buffer#replace(lines, startSelection, endSelection) abort
  " store view
  let l:winview = winsaveview()
  let l:newBuffer = prettier#utils#buffer#createBufferFromUpdatedLines(a:lines, a:startSelection, a:endSelection)

  " we should not replace contents if the newBuffer is empty
  if empty(l:newBuffer)
    return
  endif

  " https://vim.fandom.com/wiki/Restore_the_cursor_position_after_undoing_text_change_made_by_a_script
  " create a fake change entry and merge with undo stack prior to do formating
  execute "normal! i "
  execute "normal! a\<BS>"
  try | silent undojoin | catch | endtry

  " delete all lines on the current buffer
  silent! execute '%delete _'

  " replace all lines from the current buffer with output from prettier
  let l:idx = 0
  for l:line in l:newBuffer
    silent! call append(l:idx, l:line)
    let l:idx += 1
  endfor
  
  " delete trailing newline introduced by the above append procedure
  silent! execute '$delete _'

  " Restore view
  call winrestview(l:winview)

endfunction

" Replace and save the buffer
function! prettier#utils#buffer#replaceAndSave(lines, startSelection, endSelection) abort<commit_msg>enh: save buffer marks between runs<commit_after>function! prettier#utils#buffer#replace(lines, startSelection, endSelection) abort
  " store view
  let l:winview = winsaveview()
  let l:newBuffer = prettier#utils#buffer#createBufferFromUpdatedLines(a:lines, a:startSelection, a:endSelection)

  " we should not replace contents if the newBuffer is empty
  if empty(l:newBuffer)
    return
  endif

  " https://vim.fandom.com/wiki/Restore_the_cursor_position_after_undoing_text_change_made_by_a_script
  " create a fake change entry and merge with undo stack prior to do formating
  execute "normal! i "
  execute "normal! a\<BS>"
  try | silent undojoin | catch | endtry

  " delete all lines on the current buffer
  silent! execute 'lockmarks %delete _'

  " replace all lines from the current buffer with output from prettier
  let l:idx = 0
  for l:line in l:newBuffer
    silent! lockmarks call append(l:idx, l:line)
    let l:idx += 1
  endfor

  " delete trailing newline introduced by the above append procedure
  silent! lockmarks execute '$delete _'

  " Restore view
  call winrestview(l:winview)

endfunction

" Replace and save the buffer
function! prettier#utils#buffer#replaceAndSave(lines, startSelection, endSelection) abort
{'fraction_non_alphanumeric': 0.07442434210526316, 'fraction_numerical': 0.001644736842105263, 'mean_word_length': 4.779097387173397, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '503432', 'n_tokens_mistral': 755, 'n_tokens_neox': 733, 'n_words': 243}