copilot.el
copilot.el copied to clipboard
Add integration with lispy
I'm using abo-abo's lispy to edit Lisps. Among other things, the package does a pretty good job of preserving the balance of parentheses, i.e. using its operations (like deleting a line) should never break the balance.
And accepting a suggestion from copilot seems to break the balance in most cases.
So this PR adds an option (copilot-lispy-integration
) that changes two things:
- using
lispy--maybe-safe-delete-region
instead ofdelete-region
to avoid deleting unmatched parenthesis - processing the completion with
lispy--find-safe-regions
to avoid inserting unmatched parenthesis.
From my experience of editing elisp, Copilot preserves the balance of the parentheses in ~2/3 of cases, which is not good enough but acceptable.
lispy
looks like an excellent package. I will try it as well as your PR and give you feedback later.
Is it a good idea to simply extract a function named copilot-insert-completion
so you can use advice-add
? Because I want to make copilot.el
a general package, and the balance problem also exists in other languages.
In that case I'd opt for run-hook-with-args-until-success
. It's easier to change a list of hooks than to advice a function.
Something like the latest commit should do this.
I find the lispy integration doesn't work well with copilot-accept-completion-by-word
. It accidentally deletes some prefix parentheses and quotes.
Yeah, it seems so.
But the problem is that in the lispy paradigm there cannot be an operation that leaves an unbalanced parenthesis. So, if we want to insert (hello
, there are two valid ways:
-
(hello)
-
hello
I.e. the in general case we either insert missing parentheses or delete extra ones. I tried both and the latter seem to backfire way less often (also, lispy has some limitations with regards to quotes). But a single word just doesn't have enough information.
It should be possible to make a more "intelligent" decision. But I have little idea on how to approach this and if it's even worth the effort, because lispy itself fails every now and then (and it's ~16K LoC in total).
This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.
This PR was closed because it has been stalled for 10 days with no activity.