Skip to content

Commit a05f21b

Browse files
committed
llama.vim : gather chunk on leaving buffer [no ci]
1 parent 92e0413 commit a05f21b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

examples/llama.vim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ function! llama#init()
120120

121121
autocmd TextYankPost * if v:event.operator ==# 'y' | call s:pick_chunk(v:event.regcontents, v:false) | endif
122122

123+
" gather chunks upon entering/leaving a buffer
123124
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)})
125+
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)
124126
augroup END
125127

126128
silent! call llama#fim_cancel()
@@ -146,6 +148,7 @@ function! s:pick_chunk(text, no_mod)
146148
endif
147149

148150
" check if this chunk is already added
151+
" TODO: smarter check for string similarity to evict old chunks that are very similart to the new one
149152
let l:exist = v:false
150153
for i in range(len(s:ring_n_chunks))
151154
if s:ring_n_chunks[i] == l:chunk
@@ -204,7 +207,7 @@ function! llama#fim(is_auto) abort
204207
" pick a prefix chunk
205208
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)
206209

207-
"" pick a suffix chunk
210+
" pick a suffix chunk
208211
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)
209212

210213
let s:pos_y_pick = s:pos_y

0 commit comments

Comments
 (0)