Skip to content

Conversation

@ultronozm
Copy link
Contributor

Prefix commands like C-u were clearing the Copilot overlay even when
their command symbols (e.g., 'universal-argument) were listed in
'copilot-clear-overlay-ignore-commands'.

  • copilot.el (copilot--post-command): Check both 'this-command and the
    command bound to the current key sequence.

  • test/copilot-overlay-tests.el
    (copilot-post-command-honors-key-binding-ignore)
    (copilot-post-command-clears-when-not-ignored): New tests.

  • Eask: Add script entry to run the tests.

Eask Outdated
(package-file "copilot.el")

(script "test" "echo \"Error: no test specified\" && exit 1")
(script "test" "emacs -Q --batch -L . -l ert -l test/copilot-overlay-tests.el -f ert-run-tests-batch-and-exit")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we should make this generic and run all test files. (even if there's only one today)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy, will update later

copilot.el Outdated
(or
(string-prefix-p "copilot-" (symbol-name this-command))
(member this-command copilot-clear-overlay-ignore-commands)
(let ((key-command (key-binding (this-command-keys-vector) t)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a good idea to add some comment to this bit of code, as I assume its purpose won't be obvious to many people.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

(require 'cl-lib)
(require 'ert)

(unless (require 'f nil 'noerror)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of those conditional requires/provides? To be able to run the tests without the deps present or something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point here was just to make the tests work when run directly via Emacs -Q in batch mode. Open to suggestions here

* copilot.el (copilot--post-command): Consider 'this-original-command'
when checking whether not to clear the overlay.

Fixes copilot-emacs#434: prefix commands like C-u were clearing the Copilot overlay
even when their command symbols (e.g., 'universal-argument) were
listed in 'copilot-clear-overlay-ignore-commands'.
@ultronozm
Copy link
Contributor Author

I pushed an update to the PR that fixes the issue in a slightly more direct way. I also deleted the tests from the PR -- they were testing the mechanism used to implement the fix rather than the symptom itself, and so did not really serve their intended purpose.

@bbatsov bbatsov merged commit 29bbb9d into copilot-emacs:main Dec 9, 2025
12 of 13 checks passed
@bbatsov
Copy link
Collaborator

bbatsov commented Dec 9, 2025

The new fix looks nicer indeed! Thanks!

I agree we're probably better off without the tests.

@ultronozm ultronozm deleted the fix/overlay-ignore branch December 9, 2025 08:17
@ultronozm
Copy link
Contributor Author

An addendum: I noticed that the README states, regarding copilot-accept-completion-by-word, "You can use prefix argument to specify the number of lines or words to accept." But this seems inaccurate without both

  • the bug fix given in this PR, and
  • a rich enough value of copilot-clear-overlay-ignore-commands, such as '(universal-argument digit-argument negative-argument universal-argument-more).

Perhaps - to keep the README accurate without requiring users to customize anything -- it would be worth making that the default value, or hard-coding those commands to be ignored (e.g., as a separate defconst)?

@bbatsov
Copy link
Collaborator

bbatsov commented Dec 9, 2025

That would be fine by me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants