summaryrefslogtreecommitdiff
path: root/autoload/vim_ai.vim
diff options
context:
space:
mode:
authorMartin Bielik <martin.bielik@instea.sk>2024-07-29 19:32:16 +0200
committerMartin Bielik <martin.bielik@instea.sk>2024-07-29 19:32:16 +0200
commitbe5ccb9e7b79063d3a2ad44d91f7631b3272779c (patch)
tree4d0c70aa6a5cbd91ccfc29b3bb6afcc260aac810 /autoload/vim_ai.vim
parente18d29dac7fdf616a6a738fdb8ab017e0c3f8549 (diff)
downloadvim-ai-be5ccb9e7b79063d3a2ad44d91f7631b3272779c.tar.gz
remove useless buffer in keep open mode
Diffstat (limited to '')
-rw-r--r--autoload/vim_ai.vim22
1 files changed, 12 insertions, 10 deletions
diff --git a/autoload/vim_ai.vim b/autoload/vim_ai.vim
index a9c3d0a..a7d2bf9 100644
--- a/autoload/vim_ai.vim
+++ b/autoload/vim_ai.vim
@@ -37,14 +37,25 @@ endfunction
" - scratch_buffer_keep_open = 1
" - opens last ai-chat buffer (unless force_new = 1)
" - keeps the buffer in the buffer list
-function! s:MakeScratchWindow(force_new) abort
+function! s:OpenChatWindow(open_conf, force_new) abort
+ " open new buffer that will be used as a chat
+ let l:open_cmd = has_key(g:vim_ai_open_chat_presets, a:open_conf)
+ \ ? g:vim_ai_open_chat_presets[a:open_conf]
+ \ : a:open_conf
+ execute l:open_cmd
+
+ " reuse chat in keep-open mode
let l:keep_open = g:vim_ai_chat['ui']['scratch_buffer_keep_open']
let l:last_scratch_buffer_name = s:GetLastScratchBufferName()
if l:keep_open && bufexists(l:last_scratch_buffer_name) && !a:force_new
+ let l:current_buffer = bufnr('%')
" reuse chat buffer
execute "buffer " . l:last_scratch_buffer_name
+ " close new buffer that was created by l:open_cmd
+ execute "bd " . l:current_buffer
return
endif
+
setlocal buftype=nofile
setlocal noswapfile
setlocal ft=aichat
@@ -88,15 +99,6 @@ function! s:MakePrompt(selection, instruction, config)
return join([l:instruction, l:delimiter, l:selection], "")
endfunction
-function! s:OpenChatWindow(open_conf, force_new)
- let l:open_cmd = has_key(g:vim_ai_open_chat_presets, a:open_conf)
- \ ? g:vim_ai_open_chat_presets[a:open_conf]
- \ : a:open_conf
- execute l:open_cmd
- call s:MakeScratchWindow(a:force_new)
-endfunction
-
-
let s:is_handling_paste_mode = 0
function! s:set_paste(config)