Skip to content

Commit

Permalink
Merge pull request chep#12 from lgfang/master
Browse files Browse the repository at this point in the history
Prepare Copilot Chat buffers in `copilot-chat-ask-region`
  • Loading branch information
chep authored Aug 1, 2024
2 parents 356995b + 873d661 commit 634e4f7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion copilot-chat-copilot.el
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
(review . "Please review the following code:\n")
(doc . "Please write documentation for the following code:\n")
(fix . "There is a problem in this code. Please rewrite the code to show it with the bug fixed.\n")
(optimize . "Please optimize the following code to improve performance and readablilty:\n")
(optimize . "Please optimize the following code to improve performance and readability:\n")
(test . "Please generate tests for the following code:\n"))
"Copilot chat predefined prompts")

Expand Down
12 changes: 10 additions & 2 deletions copilot-chat.el
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@

(defun copilot-chat-ask-region(prompt)
(let ((code (buffer-substring-no-properties (region-beginning) (region-end))))
(copilot-chat--prepare-buffers)
(with-current-buffer copilot-chat-prompt-buffer
(erase-buffer)
(insert (concat (cdr (assoc prompt copilot-chat-prompts)) code)))
Expand Down Expand Up @@ -218,8 +219,8 @@
(copilot-chat-list-mode))
(switch-to-buffer buffer)))

(defun copilot-chat-display ()
(interactive)
(defun copilot-chat--prepare-buffers()
"Create the copilot-chat-buffer and copilot-chat-prompt-buffer."
(unless (copilot-chat-ready-p)
(copilot-chat-reset))
(let ((chat-buffer (get-buffer-create copilot-chat-buffer))
Expand All @@ -228,6 +229,13 @@
(copilot-chat-mode))
(with-current-buffer prompt-buffer
(copilot-chat-prompt-mode))
(list chat-buffer prompt-buffer)))

(defun copilot-chat-display ()
(interactive)
(let* ((buffers (copilot-chat--prepare-buffers))
(chat-buffer (car buffers))
(prompt-buffer (cdr buffers)))
(switch-to-buffer chat-buffer)
(let ((split-window-preferred-function nil)
(split-height-threshold nil)
Expand Down

0 comments on commit 634e4f7

Please sign in to comment.