From a47f4e537db980fcbb8c7060be62443a08c0b150 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Thu, 25 Jul 2024 21:10:14 -0400 Subject: [PATCH] Add gptel-chat-with-buffer function and keybinding This commit introduces the gptel-chat-with-buffer function, allowing users to start a chat with the buffer content. It also updates keybindings, assigning "b" to the new function and moving gptel-select-backend to "B". --- emacs/.emacs.d/config/init-ai.el | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/emacs/.emacs.d/config/init-ai.el b/emacs/.emacs.d/config/init-ai.el index cc0526b..652d168 100644 --- a/emacs/.emacs.d/config/init-ai.el +++ b/emacs/.emacs.d/config/init-ai.el @@ -57,6 +57,17 @@ (gptel buffer nil initial interactivep)) (with-current-buffer buffer (setq-local gptel--system-message (alist-get 'org-mode gptel-directives)))) + (defun gptel-chat-with-buffer (&optional arg interactivep) + (interactive (list current-prefix-arg t)) + (let* ((name (format "*gptel: %s*"(buffer-name))) + (buffer (if arg + (generate-new-buffer name) + name))) + (gptel buffer nil (buffer-string) interactivep) + (with-current-buffer buffer + (goto-char (point-max)) + (newline) + (insert (gptel-prompt-prefix-string))))) :general ("C-c RET" #'gptel-send "C-c C-" #'gptel-menu) @@ -65,7 +76,8 @@ "o" #'gptel-org "s" #'gptel-send "m" #'gptel-menu - "b" #'gptel-select-backend + "b" #'gptel-chat-with-buffer + "B" #'gptel-select-backend "a" #'gptel-context-add "f" #'gptel-context-add-file "k" #'gptel-abort))