From ece59c9a6a2ef1e3fab196d3b9468bd6910de001 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Fri, 27 Sep 2024 13:14:44 +0800 Subject: [PATCH] Binding RET to gptel-return-dwim, don't need press C-c to send prompt. --- gptel.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gptel.el b/gptel.el index 4ec232b..ef6c83d 100644 --- a/gptel.el +++ b/gptel.el @@ -830,6 +830,7 @@ file." :keymap (let ((map (make-sparse-keymap))) (define-key map (kbd "C-c RET") #'gptel-send) + (define-key map (kbd "RET") #'gptel-return-dwim) map) (if gptel-mode (progn @@ -1072,6 +1073,18 @@ waiting for the response." (gptel-request nil :stream gptel-stream) (gptel--update-status " Waiting..." 'warning))) +;;;###autoload +(defun gptel-return-dwim (&optional arg) + "If cursor at prompt line, call `gptel-send', otherwise call RET function." + (interactive "P") + (let ((in-prompt-line-p + (save-excursion + (beginning-of-line) + (search-forward-regexp "^#+\\s-" (line-end-position) t)))) + (if in-prompt-line-p + (gptel-send arg) + (call-interactively (key-binding (kbd "C-m")))))) + (declare-function json-pretty-print-buffer "json") (defun gptel--inspect-query (request-data &optional arg) "Show REQUEST-DATA, the full LLM query to be sent, in a buffer.