From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eshel Yaron Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Completion preview common Date: Sun, 07 Apr 2024 23:12:18 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32031"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: emacs-devel@gnu.org To: Ergus Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Apr 07 23:13:17 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rtZpE-00088A-Q0 for ged-emacs-devel@m.gmane-mx.org; Sun, 07 Apr 2024 23:13:16 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtZoS-00060D-LH; Sun, 07 Apr 2024 17:12:28 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rtZoO-0005zl-Ki for emacs-devel@gnu.org; Sun, 07 Apr 2024 17:12:25 -0400 Original-Received: from mail.eshelyaron.com ([107.175.124.16] helo=eshelyaron.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rtZoM-0002hH-VI for emacs-devel@gnu.org; Sun, 07 Apr 2024 17:12:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1712524341; bh=JvVhvyw4GzlD2m8Lhx5M8iCXU0QICKt7q/dEe+QMF7U=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=gxekFV0glpsUbyX6T5fSIQ6oWOsJp4jPYzcDuFVa5ONk4GB4lGcGSmwgmDP7fMtW/ KsmS1Z8m2pMflz8cK8Osl7RcpzRbQfwfsZT/MWAlhWe8fG9TkFr6zgcuKdPdxIX5X0 +WQ173OPUSwbsdxOq+aqZn6xWwvBGlXXy69wJHWUAx9cnLvBRWh22wdc8DSi5Xe9DV oaD6VgiYyzB3CDllsNf7IonuLyLvOSvsiwPyrCbgzfQ2E4jF0cpHo6a8N4ELgrVFfG 8kvmrQBBpYs3BTbgRIE2RM9h9PoNrFwnuJ39GT8RgVIg+jyS7nXOXx27+2aowITqix 3GubRVJX3HI+w== In-Reply-To: (Ergus's message of "Sun, 7 Apr 2024 20:38:04 +0200") Received-SPF: pass client-ip=107.175.124.16; envelope-from=me@eshelyaron.com; helo=eshelyaron.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:317594 Archived-At: Hi there, Ergus 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?