From f794549baedc4d78a5580fb40f646f80da8598e7 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Sun, 13 Oct 2024 14:17:58 +0300 Subject: [PATCH] llama.vim : gather chunk on leaving buffer [no ci] --- examples/llama.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/llama.vim b/examples/llama.vim index 130af3a26..8d85fb862 100644 --- a/examples/llama.vim +++ b/examples/llama.vim @@ -120,7 +120,9 @@ function! llama#init() autocmd TextYankPost * if v:event.operator ==# 'y' | call s:pick_chunk(v:event.regcontents, v:false) | endif + " gather chunks upon entering/leaving a buffer autocmd BufEnter * call timer_start(100, {-> s:pick_chunk(getline(max([1, line('.') - g:llama_config.ring_chunk_size/2]), min([line('.') + g:llama_config.ring_chunk_size/2, line('$')])), v:true)}) + autocmd BufLeave * call s:pick_chunk(getline(max([1, line('.') - g:llama_config.ring_chunk_size/2]), min([line('.') + g:llama_config.ring_chunk_size/2, line('$')])), v:true) augroup END silent! call llama#fim_cancel() @@ -146,6 +148,7 @@ function! s:pick_chunk(text, no_mod) endif " check if this chunk is already added + " TODO: smarter check for string similarity to evict old chunks that are very similart to the new one let l:exist = v:false for i in range(len(s:ring_n_chunks)) if s:ring_n_chunks[i] == l:chunk @@ -204,7 +207,7 @@ function! llama#fim(is_auto) abort " pick a prefix chunk call s:pick_chunk(getline(max([1, s:pos_y - g:llama_config.ring_scope]), max([1, s:pos_y - g:llama_config.n_prefix])), v:false) - "" pick a suffix chunk + " pick a suffix chunk call s:pick_chunk(getline(min([l:max_y, s:pos_y + g:llama_config.n_suffix]), min([l:max_y, s:pos_y + g:llama_config.ring_scope])), v:false) let s:pos_y_pick = s:pos_y