copilot-emacs / copilot.el

An unofficial Copilot plugin for Emacs.
MIT License
1.71k stars 122 forks source link

How to prevent copilot from trying to write comments #285

Open asmeurer opened 3 months ago

asmeurer commented 3 months ago

I use the following to prevent copilot from trying to complete inside of comments:

(defun my-copilot-disable-predicates ()
  "Disable Copilot display when the cursor is in a string or comment."
  (or (nth 3 (syntax-ppss)) ;; check if cursor is in a string
      (nth 4 (syntax-ppss)))) ;; check if cursor is in a comment

;; Don't show copilot completions in strings or comments unless manually
;; triggered with C-Enter.
(add-hook 'copilot-disable-predicates #'my-copilot-disable-predicates)

This works if the cursor is already in a comment or string. But sometimes, copilot will decide all on its own that the next line should be a comment or docstring.

Is there an easy way to do this? Basically, I want to write a predicate that doesn't show the completion if it is a comment. Is there a way to access the proposed completion from within the copilot-disable-predicate or some other predicate?