From: Eshel Yaron <me@eshelyaron.com>
To: Ergus <spacibba@aol.com>
Cc: emacs-devel@gnu.org
Subject: Re: [PATCH] Completion preview common
Date: Sun, 07 Apr 2024 23:12:18 +0200 [thread overview]
Message-ID: <m1y19oc1xp.fsf@dazzs-mbp.kpn> (raw)
In-Reply-To: <njlevizac6zitj5fulduqcgtfwhac5vmcsz2we562fym7z5u6i@su5oafrms4r7> (Ergus's message of "Sun, 7 Apr 2024 20:38:04 +0200")
Hi there,
Ergus <spacibba@aol.com> writes:
> Recently I have been playing with the new completion-preview mode and
> I'm very happy to see something like this finally added to emacs with a
> simple and clean code.
>
> However, there is a missing detail that I find useful when typing:
> common preview completion.
>
> The goal is to preview a common prefix when available and longer than
> the prefix already inserted. This is a point in between 1) exact match
> with one candidate only and 2) getting the first candidate in the whole
> list.
>
> I tried to avoid adding complexity to the code (because the thing I like
> the most in the package is actually its simplicity and predictability);
> but the extra functionality I think worth the few new lines.
>
> I attach the patch for a first review.
Thank you for your feedback and for the patch! Completing only up the
longest common prefix instead of inserting the full candidate sounds
like a useful option, but I'm not sure that we should also restrict the
completion preview to only showing that common prefix. How about if we
add a command that completes up to the longest common prefix, but still
show the full candidate in the preview as we do now? That way you can
choose on a case-by-case basis whether you want to complete all the way
or just up to the longest common prefix.
To some degree, this is already possible: if your completion-styles are
set to prefix (e.g. "basic") completion, then hitting C-M-i completes to
the longest common prefix in many cases. But we can also add a
dedicated command to completion-preview-active-mode-map that would use
the completion data that's already stored in the preview to complete up
to the longest common prefix, so something like the following:
--8<---------------cut here---------------start------------->8---
(defun completion-preview-insert-common-prefix ()
"Complete text at point to the common prefix of all completion candidates."
(interactive)
(let* ((beg (completion-preview--get 'completion-preview-beg))
(end (completion-preview--get 'completion-preview-end))
(all (completion-preview--get 'completion-preview-cands))
(com (substring (try-completion "" all) (- end beg))))
(if (string-empty-p com)
(message "Next char not unique")
(goto-char end)
(insert com))))
--8<---------------cut here---------------end--------------->8---
A further improvement can be to (optionally) underline the longest
common prefix in the completion preview while showing the full
candidate, similarly to how we currently underline sole candidates.
That way you can tell how far you'd get by completing to the longest
common prefix. WDYT?
next prev parent reply other threads:[~2024-04-07 21:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <njlevizac6zitj5fulduqcgtfwhac5vmcsz2we562fym7z5u6i.ref@su5oafrms4r7>
2024-04-07 18:38 ` [PATCH] Completion preview common Ergus
2024-04-07 21:12 ` Eshel Yaron [this message]
2024-04-07 23:39 ` Ergus
2024-04-09 18:30 ` Eshel Yaron
2024-04-09 23:05 ` Ergus
2024-04-10 11:55 ` Eshel Yaron
2024-04-10 15:54 ` Ergus
2024-04-12 6:18 ` Eshel Yaron
2024-04-07 21:15 ` [External] : " Drew Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m1y19oc1xp.fsf@dazzs-mbp.kpn \
--to=me@eshelyaron.com \
--cc=emacs-devel@gnu.org \
--cc=spacibba@aol.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.