Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:AIChat without running assistant #147

Open
Konfekt opened this issue Feb 26, 2025 · 2 comments
Open

:AIChat without running assistant #147

Konfekt opened this issue Feb 26, 2025 · 2 comments

Comments

@Konfekt
Copy link
Contributor

Konfekt commented Feb 26, 2025

How about running :AIChat without running the assistant if there are non-blank lines following the bottom-most >>> user line, say by appending a bang ! to :AIChat, to paste additional lines below it?

@Konfekt
Copy link
Contributor Author

Konfekt commented Feb 26, 2025

Here's a function to reuse an aichat buffer.
What would be convenient is to know which one was last used.
Is that variable public?
Also ">>> AI chat" is set internally as s:scratch_buffer_name; it would be more future-proof if this string is made public.

let g:aichat_scratch_buffer_name = ">>> AI chat"

function! ReuseChatBuffer()
  if &filetype ==# 'aichat' | return | endif

  " reuse some window of filetype Aichat in this tab
  let buffer_list_window_tab = tabpagebuflist(tabpagenr())
  let buffer_list_window_tab = filter(buffer_list_window_tab, 'getbufvar(v:val, "&filetype") ==# "aichat"')
  if !empty(buffer_list_window_tab) | return win_gotoid(win_findbuf(buffer_list_window_tab[0])[0]) | endif

  " reuse some window of filetype Aichat in any tab
  let buffer_list_window = []
  for i in range(tabpagenr('$'))
    call extend(buffer_list_window, tabpagebuflist(i + 1))
  endfor
  let buffer_list_window = filter(buffer_list_window, 'getbufvar(v:val, "&filetype") ==# "aichat"')
  if !empty(buffer_list_window) | return win_gotoid(win_findbuf(buffer_list_window[0])[0]) | endif

  " reuse some buffer named >>> AIChat
  if bufnr(g:aichat_scratch_buffer_name) >= 0
    exe 'vertical belowright sbuffer' bufnr(g:scratch_buffer_name)
    return
  endif

  " reuse some buffer of filetype Aichat
  let buffer_list = map(getbufinfo(), 'v:val.bufnr')
  let buffer_list = filter(buffer_list, 'getbufvar(v:val, "&filetype") ==# "aichat"')
  if !empty(buffer_list)
    exe 'vertical belowright sbuffer' buffer_list[0]
    return
  endif
endfunction

@madox2
Copy link
Owner

madox2 commented Feb 26, 2025

I am quite confused what is this issue about.

How about running :AIChat without running the assistant

there is no concept of assistant, what do you mean by that?

if there are non-blank lines following the bottom-most >>> user line, say by appending a bang ! to :AIChat, to paste additional lines below it?

I don't get this too

Could you try to explain again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants