3939 :group 'comm
4040 :link '(url-link :tag " Repository" " https://github.com/emacs-openai/codegpt" ))
4141
42- (defun codegpt-code--internal (instruction start end )
42+ ; ;
43+ ; ;; Application
44+
45+ (defun codegpt--internal (instruction start end )
4346 " Do INSTRUCTION with partial code.
4447
4548The partial code is defined in with the region, and the START nad END are
@@ -54,8 +57,10 @@ boundaries of that region in buffer."
5457 (openai--with-buffer openai-completion-buffer-name
5558 (openai--pop-to-buffer openai-completion-buffer-name)
5659 (let* ((choices (openai-completion--data-choices data))
57- (result (openai-completion--get-choice choices)))
58- (insert (string-trim result) " \n " ))))))))
60+ (result (openai-completion--get-choice choices))
61+ (original-point (point )))
62+ (insert (string-trim result) " \n " )
63+ (fill-region original-point (point )))))))))
5964
6065;;;### autoload
6166(defun codegpt-doc (start end )
@@ -64,7 +69,7 @@ boundaries of that region in buffer."
6469This command is interactive region only, the START and END are boundaries of
6570that region in buffer."
6671 (interactive " r" )
67- (openai-completion-code --internal
72+ (codegpt --internal
6873 " Please write the documentation for the following function."
6974 start end))
7075
@@ -75,7 +80,7 @@ that region in buffer."
7580This command is interactive region only, the START and END are boundaries of
7681that region in buffer."
7782 (interactive " r" )
78- (openai-completion-code --internal
83+ (codegpt --internal
7984 " There is a bug in the following function, please help me fix it."
8085 start end))
8186
@@ -86,7 +91,7 @@ that region in buffer."
8691This command is interactive region only, the START and END are boundaries of
8792that region in buffer."
8893 (interactive " r" )
89- (openai-completion-code --internal
94+ (codegpt --internal
9095 " What is the following?"
9196 start end))
9297
@@ -97,7 +102,7 @@ that region in buffer."
97102This command is interactive region only, the START and END are boundaries of
98103that region in buffer."
99104 (interactive " r" )
100- (openai-completion-code --internal
105+ (codegpt --internal
101106 " Please improve the following."
102107 start end))
103108
@@ -108,7 +113,7 @@ that region in buffer."
108113This command is interactive region only, the START and END are boundaries of
109114that region in buffer."
110115 (interactive " r" )
111- (openai-completion-code --internal
116+ (codegpt --internal
112117 (read-string " Instruction: " )
113118 start end))
114119
0 commit comments