5252
5353(defmacro codegpt--ask-in-buffer (instruction &rest body )
5454 " Insert INSTRUCTION then execute BODY form."
55+ (declare (indent 1 ))
5556 `(progn
5657 (openai--pop-to-buffer codegpt-buffer-name) ; create it
5758 (openai--with-buffer codegpt-buffer-name
@@ -66,23 +67,22 @@ The partial code is defined in with the region, and the START nad END are
6667boundaries of that region in buffer."
6768 (let ((text (string-trim (buffer-substring start end)))
6869 (original-window (selected-window )))
69- (codegpt--ask-in-buffer
70- instruction
71- (insert text " \n\n " )
72- (openai-completion
73- (buffer-string )
74- (lambda (data )
75- (openai--with-buffer codegpt-buffer-name
76- (openai--pop-to-buffer codegpt-buffer-name)
77- (let* ((choices (openai-completion--data-choices data))
78- (result (openai-completion--get-choice choices))
79- (original-point (point )))
80- (insert (string-trim result) " \n " )
81- (fill-region original-point (point ))))
82- (unless codegpt-focus-p
83- (select-window original-window))))
84- (unless codegpt-focus-p
85- (select-window original-window)))))
70+ (codegpt--ask-in-buffer instruction
71+ (insert text " \n\n " )
72+ (openai-completion
73+ (buffer-string )
74+ (lambda (data )
75+ (openai--with-buffer codegpt-buffer-name
76+ (openai--pop-to-buffer codegpt-buffer-name)
77+ (let* ((choices (openai-completion--data-choices data))
78+ (result (openai-completion--get-choice choices))
79+ (original-point (point )))
80+ (insert (string-trim result) " \n " )
81+ (fill-region original-point (point ))))
82+ (unless codegpt-focus-p
83+ (select-window original-window))))
84+ (unless codegpt-focus-p
85+ (select-window original-window)))))
8686
8787;;;### autoload
8888(defun codegpt-doc (start end )
0 commit comments