Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 33 additions & 17 deletions codegpt.el
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@
(defconst codegpt-buffer-name "*CodeGPT*"
"Buffer name to do completion task.")

(defcustom codegpt-action-alist
`(("custom" . "Write your own instruction")
("doc" . "Automatically write documentation for your code")
("fix" . "Find problems with it")
("explain" . "Explain the selected code")
("improve" . "Improve, refactor or optimize it"))
"Alist of code completion actions and its' description."
:type 'list
:group 'codegpt)

(defconst codegpt--actions-functions
'(("custom" . codegpt-custom)
("doc" . codegpt-doc)
("fix" . codegpt-fix)
("explain" . codegpt-explain)
("improve" . codegpt-improve))
"Alist of code completion actions and its functions.")

;;
;;; Application

Expand Down Expand Up @@ -139,17 +157,16 @@ that region in buffer."
(read-string "Instruction: ")
start end))

(defconst codegpt-action-alist
`(("custom" . "Write your own instruction")
("doc" . "Automatically write documentation for your code")
("fix" . "Find problems with it")
("explain" . "Explain the selected code")
("improve" . "Improve, refactor or optimize it"))
"Alist of code completion actions and its' description.")
(defun codegept--execute-predefined-template (start end question)
"Ask predefined QUESTION for provided region.
the START and END are boundaries of that region in buffer."
(codegpt--internal
question
start end))

;;;###autoload
(defun codegpt (start end)
"Do completon with OpenAI to your code.
"Do completion with OpenAI to your code.

This command is interactive region only, the START and END are boundaries of
that region in buffer."
Expand All @@ -168,15 +185,14 @@ that region in buffer."
(concat (propertize " " 'display `((space :align-to (- right ,offset))))
(cdr (assoc cand codegpt-action-alist))))))
(complete-with-action action codegpt-action-alist string predicate)))
nil t)))
(funcall
(pcase action
("custom" #'codegpt-custom)
("doc" #'codegpt-doc)
("fix" #'codegpt-fix)
("explain" #'codegpt-explain)
("improve" #'codegpt-improve))
start end)))
nil t))
(action-fn (cdr-safe (assoc action codegpt--actions-functions))))
(if action-fn
(funcall action-fn start end)
(codegept--execute-predefined-template
start
end
(cdr (assoc action codegpt-action-alist))))))

(provide 'codegpt)
;;; codegpt.el ends here