chep / copilot-chat.el

Chat with Github copilot in Emacs !
MIT License
107 stars 14 forks source link

Allow questions and answers in the same buffer #20

Closed dov closed 2 months ago

dov commented 2 months ago

First of all, thanks a lot for the copilot chat interface! I have really been waiting for such an interface since I got access to github copilot! :-)

I'm missing the ability to have shell (comint) like experience where the question and answer are written in the same buffer.

The advantage is obviously that you only need to change to a single buffer in order to provide both the input and the output.

chep commented 2 months ago

Try shell-maker frontend. It does what you need.

Very easy with straight:

(use-package shell-maker
  :straight (:host github :repo "xenodium/chatgpt-shell" :files ("shell-maker.el")))

(use-package copilot-chat
  :straight (:host github :repo "chep/copilot-chat.el" :files ("*.el"))
  :after (request shell-maker)
  :custom
  (copilot-chat-frontend 'shell-maker)
  :config
  (require 'copilot-chat-shell-maker)
  (push '(shell-maker . copilot-chat-shell-maker-init) copilot-chat-frontend-list)
  (copilot-chat-shell-maker-init))

It should not be very complicated without straight anyway. It's available in melpa. https://github.com/xenodium/chatgpt-shell

dov commented 2 months ago

Thanks! It's working fine!

However, I then lost all the syntax highlighting. What I'd like is the following:

  1. Variable pitch font for the interaction
  2. Markdown interpretation of backticks and hashes, and anything else that github copilot outputs.
  3. Syntax highlighting of code sections with a different background color, which should be shown in a fixed font

In short, I'd like to something visually similar to the VSCode github chat, but in emacs.

dov commented 2 months ago

Meanwhile I "solved" this by writing the following function which displays the current buffer as markdown in the a temporary buffer:

(defun copy-buffer-to-temp-markdown ()
  "Copy the current buffer to a temporary read-only buffer and display it in markdown mode."
  (interactive)
  (let* ((ctx (buffer-substring-no-properties (point-min) (point-max)))
         (temp-buffer (generate-new-buffer "*Temp Markdown*"))
         (original-buffer (current-buffer)))
    (with-current-buffer temp-buffer
      (insert ctx)
      (markdown-mode)
      (read-only-mode 1)
      (local-set-key (kbd "q")
                     (lambda ()
                       (interactive)
                       (kill-buffer (current-buffer))))
    (switch-to-buffer temp-buffer)
    (variable-pitch-mode t))))
chep commented 2 months ago

I pushed a new branch: shell-polymode. It uses polymode to enable mardown-mode for copilot answers.

Can you try it and tell me if this is what you are looking for ?

dov commented 2 months ago

Great! Thanks a lot! For me it is almost perfect. Here are a few few remaining nitpicks.

nitpicks

chep commented 2 months ago

My mystake. Now it uses mardown-view-mode which display the result and not the markdown code.

For the background, I can't do anything but maybe this is a face defined by mardown-view-mode. You could try to customize it.

dov commented 2 months ago

Great! Indeed markdown-view works much better.

Regarding the background, I have learned that if you turn on the face attribute extent then the background face extents to margin and you get a boxed feeling.

The only thing remaining is the "redundent line". But I can certainly live with that.

Thanks a lot again! I have already created a binding for jumping straight to the copilot-chat-shell buffer, which I will certainly use a lot.

Now, if we could only customize the prompt?

chep commented 2 months ago

I think that the redundant line is inside copilot answer, I do not modify anything, just write the received tokens as-is. Customizing the prompt may be a bad idea as it is used by polymode to detect the end of the markdown area. It uses regexp for that. Or the regexp must depend on the customization. This could lead to a lot of side effects…