closes window on buffer close

This commit is contained in:
Levi Neely 2024-09-17 20:30:26 +02:00
parent 309fa4ec99
commit 865918293a
1 changed files with 18 additions and 9 deletions

View File

@ -11,10 +11,13 @@
(require 'ellama)
(defvar ellama-capture-buffer-name "*Ellama Input*"
"Name of the buffer used for Ellama input capture.")
(defun ellama-capture ()
"Create a temporary pop-up buffer for Ellama input."
"Create a temporary pop-up buffer for Ellama input with context-adding capabilities."
(interactive)
(let ((buf (get-buffer-create "*Ellama Input*")))
(let ((buf (get-buffer-create ellama-capture-buffer-name)))
(with-current-buffer buf
(erase-buffer)
(text-mode)
@ -23,23 +26,29 @@
(local-set-key (kbd "C-c C-k") 'ellama-capture-abort)
(local-set-key (kbd "C-c f") 'ellama-context-add-file)
(local-set-key (kbd "C-c i") 'ellama-context-add-info-node)
(setq header-line-format
(substitute-command-keys
"(ellama-capture) C-c C-c: send, C-c C-k: abort, C-c f: add file, C-c i: add info node")))
(pop-to-buffer buf)
(setq header-line-format
(substitute-command-keys
"C-c C-c: send, C-c C-k: abort, C-c f: add file, C-c i: add info node")))
(let ((display-buffer-alist
`(((lambda (buffer-name _) (equal buffer-name ,ellama-capture-buffer-name))
(display-buffer-in-side-window)
(side . bottom)
(slot . 0)
(window-height . 0.3)))))
(pop-to-buffer buf))
(message "Type your message, then use the commands shown in the header line")))
(defun ellama-capture-finalize ()
"Send the content of the Ellama input buffer to Ellama and kill the buffer."
"Send the content of the Ellama input buffer to Ellama and close the window."
(interactive)
(let ((content (buffer-string)))
(kill-buffer (current-buffer))
(quit-window t)
(ellama-chat content)))
(defun ellama-capture-abort ()
"Kill the Ellama input buffer without sending its content."
(interactive)
(kill-buffer (current-buffer))
(quit-window t)
(message "Ellama input aborted"))
(global-set-key (kbd "C-x A e SPC") #'ellama-capture)