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.