copilot-emacs / copilot.el

An unofficial Copilot plugin for Emacs.
MIT License
1.79k stars 126 forks source link

emacs in non-gui mode (-nw): how to accept copilot suggestion? #158

Closed cpbl closed 1 year ago

cpbl commented 1 year ago

Apologies if this is off-topic or if the answer ends up being idiosyncratic, but pressing "tab", which works to accept copilot suggestions in my GUI emacs window, does not work when using Emacs with -nw option. Instead, it makes the suggestion go away. Would this happen to be something to do with the plugin??

zerolfx commented 1 year ago

To determine which key you pressed and the command it is bound to, use M-x describe-key.

cpbl commented 1 year ago

Oh, thank you very much. It says : indent-for-tab-command &optional ARG So maybe it's possible for my settings to have different bindings for gui and non-gui emacs?

This is what's in my init.el, which makes things work in the GUI!

(defun my/copilot-tab ()
  (interactive)
  (or (copilot-accept-completion)
      (indent-for-tab-command)))

(with-eval-after-load 'copilot
  (define-key copilot-mode-map (kbd "<tab>") #'my/copilot-tab))
zerolfx commented 1 year ago

What is the key you pressed? I guess that it is TAB rather than <tab>.

cpbl commented 1 year ago

Thank you for the hint! It was TAB, and Ctrl-i gives the same response.

So, from reading sources linked below:

Other references: https://stackoverflow.com/questions/26195884/tab-v-tab-in-emacs

zerolfx commented 1 year ago

Thanks for sharing your findings! I also found it a bit confusing, so in the example configurations, I ended up binding both <tab> and TAB.