Skip to content

Instantly share code, notes, and snippets.

@timcharper
Last active February 9, 2024 04:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timcharper/faf25e59fcf1aee876f25a754395e40c to your computer and use it in GitHub Desktop.
Save timcharper/faf25e59fcf1aee876f25a754395e40c to your computer and use it in GitHub Desktop.
Some modes, like typescript-mode, cause electric-indent-mode to interfere with copilot
;; see https://github.com/copilot-emacs/copilot.el/issues/250
(defun copilot/cancel-on-electric-indent-chars (arg)
"Cancel copilot completion eagerly when electric-indent-mode is triggered."
(interactive "p")
;; clear the overlay if visible and keypress is in electric-indent-chars. Not really a rejection, so maybe let's not notify it as such?
(when (and (copilot--overlay-visible)
(memq last-command-event electric-indent-chars))
(delete-overlay copilot--overlay)
(setq copilot--real-posn nil))
;; continue on to self-insert command. With the copilot overlay cleared, electric-indent-mode will not be misbehave.
(self-insert-command arg))
(defun copilot/override-electric-keys ()
"Override electric keys for copilot."
(dolist (char electric-indent-chars)
(message "disable electric-indent-mode for %s" (char-to-string char))
(define-key copilot-completion-map (vector char) 'copilot/cancel-on-electric-indent-chars)))
(add-hook 'typescript-mode-hook 'copilot/override-electric-keys)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment