Skip to content

Conversation

@basil-conto
Copy link
Collaborator

This PR addresses several shortcomings in the use of ivy-completion-common-length by ivy-completion-in-region; see each commit individually for details.

It takes a slightly more general approach than that in #3051.

Re: #1361, #1755, #2879, #3056, and https://bugs.gnu.org/76440.

* ivy.el (ivy-completion-in-region): Return nil/t on no/sole match
as well, not just in the multi-match case.  Tiny local variable
renaming and simplifications.  Add FIXME for initial-input woes.
When completing ~/foo and ~/foobar is the only completion,
vanilla completion inserts a trailing space on exit to indicate an
exact match, even though completion-try-completion returned a cons.

This is determined by completion--done which calls try-completion on
the completion-try-completion return value i.s.o. the
completion-all-completions candidate that was inserted.

* ivy.el (ivy-completion-in-region-action): Prefer passing
completion-try-completion 'new string' to completion--done when
possible.
* ivy-test.el (ivy-completion-common-length): Extend tests.
Thanks to Kien Nguyen <[email protected]> and
Madhu <[email protected]> for suggestions.

Fixes parts of #1361, #1755, #2879, #3051, #3056,
and https://bugs.gnu.org/76440.
Relates to https://bugs.gnu.org/71419.

* ivy.el (ivy--face-list-p): New compatibility shim.
(ivy-completion-common-length): Use it to handle both atom and list
values for the face property, since it varies across Emacs versions.
Use previous-single-property-change instead of iterating by char.
Improve documentation.
(ivy-completion-in-region): Translate a 'not found' result of
ivy-completion-common-length into a first difference at index 0, not
at the end of the string.  That means, interpret a lack of
completions-first-difference as no commonality.  This is more
consistent with both the definition of ivy-completion-common-length
and completion changes in Emacs 30.

* ivy-test.el (ivy-completion-common-length): Extend tests.
@basil-conto basil-conto added bug Existing behavior is incorrect enhancement Suggestion to improve or extend existing behavior compat Issues relating to backward/forward compatibility labels Feb 24, 2025
@basil-conto basil-conto self-assigned this Feb 24, 2025
@basil-conto

This comment was marked as resolved.

The latter is very problematic: it is specific to a single
candidate, does not necessarily correspond to the string being
completed, complicates bounds calculations, relies on only partially
documented presentation details rather than the usual API, etc.

When completion-all-completions returns a base-size (which in
practice seems to be most if not all the time), it corresponds more
closely to the substring that is being completed and will be
replaced.

This should address most of the remaining issues in
reports #1361, #1755, #2643, #2879, #3051, #3056, and
https://bugs.gnu.org/76440.

* ivy.el (ivy-completion-common-length): Discourage use.
(ivy-completion-in-region): When completion-all-completions
returns a base-size, prefer that over the
completions-first-difference face to determine the completion
boundaries and initial-input.

Fixes #1755.
Fixes #2643.
Fixes #2879.
Closes #3051.
Fixes #3056.
* ivy.el (ivy-completion-in-region): Determine no/sole match based
on completion-try-completion result, not completion-all-completions.
Heed completion-fail-discreetly and completion-show-inline-help and
use minibuffer-message for consistency with vanilla completion.
Move point to end and call exit-function on sole match.

Fixes #2946.
@basil-conto basil-conto linked an issue Feb 24, 2025 that may be closed by this pull request
@basil-conto basil-conto merged commit 5e93415 into master Feb 24, 2025
34 checks passed
@basil-conto basil-conto deleted the blc/comp branch February 24, 2025 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Existing behavior is incorrect compat Issues relating to backward/forward compatibility enhancement Suggestion to improve or extend existing behavior

Projects

None yet

2 participants