63 lines
2.2 KiB
EmacsLisp
63 lines
2.2 KiB
EmacsLisp
;;; module-ellama-capture.el -- improve ellama chat interaction
|
|
;;;
|
|
;;; Commentary:
|
|
;;;
|
|
;;; This module provides an org-capture-like functionality for
|
|
;;; interacting with Ellama. It allows users to pop up a temporary
|
|
;;; buffer for inputting and submitting text, which can then be fed
|
|
;;; into Ellama's underlying functions.
|
|
|
|
;;; Code:
|
|
|
|
(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."
|
|
(interactive)
|
|
(let ((buf (get-buffer-create ellama-capture-buffer-name)))
|
|
(with-current-buffer buf
|
|
(erase-buffer)
|
|
(text-mode)
|
|
(use-local-map (copy-keymap text-mode-map))
|
|
(local-set-key (kbd "C-c C-c") 'ellama-capture-finalize)
|
|
(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)
|
|
(local-set-key (kbd "C-c d") 'ellama-capture-add-definition)
|
|
(local-set-key (kbd "C-c D") 'dired)
|
|
(setq header-line-format
|
|
(substitute-command-keys
|
|
"C-c C-c: send, C-c C-k: abort, C-c f: file, C-c i: info node, C-c d: definition C-c D: dired")))
|
|
(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 "Chat with the bot using this buffer. C-c C-c to send, C-c C-k to cancel.")))
|
|
|
|
(defun ellama-capture-finalize ()
|
|
"Send the content of the Ellama input buffer to Ellama and close the window."
|
|
(interactive)
|
|
(let ((content (buffer-string)))
|
|
(quit-window t)
|
|
(ellama-chat content)))
|
|
|
|
(defun ellama-capture-abort ()
|
|
"Kill the Ellama input buffer without sending its content."
|
|
(interactive)
|
|
(quit-window t)
|
|
(message "Ellama input aborted"))
|
|
|
|
(require 'module-ellama-capture-definitions)
|
|
|
|
(global-set-key (kbd "C-x A SPC") #'ellama-capture)
|
|
|
|
(provide 'module-ellama-capture)
|
|
|
|
;;; module-ellama-capture.el ends here.
|