Skip to content

Commit

Permalink
Changing and fixing indentation handling
Browse files Browse the repository at this point in the history
Correct for indentation after accepting a completion rather than during
typing. This is less confusing than being impeded while typing spaces or
tabs on a new line while there is completion preview, and behaves more
like VSCode.

Fixes copilot-emacs#28 and copilot-emacs#200.
  • Loading branch information
Alexis Asseman committed Dec 21, 2024
1 parent b7bff7b commit a31d43d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions copilot.el
Original file line number Diff line number Diff line change
Expand Up @@ -759,14 +759,12 @@ To work around posn problems with after-string property.")
already saving an excursion. This is also a private function."
(copilot-clear-overlay)
(when (and (s-present-p completion)
(or (= start (point)) ; up-to-date completion
(and (< start (point)) ; special case for removing indentation
(s-blank-p (s-trim (buffer-substring-no-properties start (point)))))))
(goto-char start) ; indentation
(let* ((ov (copilot--get-overlay)))
(or (<= start (point))))
(let* ((ov (copilot--get-overlay)))
(overlay-put ov 'tail-length (- (line-end-position) end))
(copilot--set-overlay-text ov completion)
(overlay-put ov 'uuid uuid)
(overlay-put ov 'indent-start start) ; save "start" as it is corrected for any leading indentation
(copilot--async-request 'notifyShown (list :uuid uuid)))))

(defun copilot-clear-overlay (&optional is-accepted)
Expand All @@ -791,7 +789,9 @@ provided."
(start (overlay-get copilot--overlay 'start))
(end (copilot--overlay-end copilot--overlay))
(uuid (overlay-get copilot--overlay 'uuid))
(t-completion (funcall (or transform-fn #'identity) completion)))
(t-completion (funcall (or transform-fn #'identity) completion))
(indent-start (overlay-get copilot--overlay 'indent-start)))
(goto-char indent-start) ; move to the start of the completion if there is an indent
(copilot--async-request 'notifyAccepted (list :uuid uuid))
(copilot-clear-overlay t)
(if (derived-mode-p 'vterm-mode)
Expand Down

0 comments on commit a31d43d

Please sign in to comment.