From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ergus Newsgroups: gmane.emacs.devel Subject: [PATCH] Completion preview common Date: Sun, 7 Apr 2024 20:38:04 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="n74l2jzk6tdzcfie" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40141"; mail-complaints-to="usenet@ciao.gmane.io" Cc: me@eshelyaron.com To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Apr 07 20:39:04 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 1rtXQ0-000AAd-GC for ged-emacs-devel@m.gmane-mx.org; Sun, 07 Apr 2024 20:39:04 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rtXPD-000767-Gp; Sun, 07 Apr 2024 14:38:15 -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 1rtXPB-00075q-Mz for emacs-devel@gnu.org; Sun, 07 Apr 2024 14:38:13 -0400 Original-Received: from sonic314-14.consmr.mail.bf2.yahoo.com ([74.6.132.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rtXP9-0002KM-Ps for emacs-devel@gnu.org; Sun, 07 Apr 2024 14:38:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1712515088; bh=jMGIatoQc5jSHaH6o2aQQf0PsVSsGB8wxJKNVevk6us=; h=Date:From:To:Cc:Subject:References:From:Subject:Reply-To; b=nHzj/+y9FBmt9sdqH7oz4KHlcc9jMAX53DqGdSBIr5neNvIoBoVLFWJChUhJ7EVMAaY0hpn9X2j72ix50YBTO37SXPFqbmuQn4jzorUPD5dWQhyFfjLmmzbknQj6m+DxQ+wOVQKo+DTZ2Ju6SadfVYG8PPQ1dXkcBsNZ7MqmJAyhoOq2r1pTrUEHQ8+JERGetir5HpU7eS7iayI2URQnQA4jMZRGKAcR2k4pQ5vmL6EOmhIqUDEstp+c7TXFLLbTm3E8blLH0SBCMiGPa3NeDEDpEyofXP2qqLkmqaI/E06Z+/AuUFlBFLbGWpoIYg+M+sKmkxTpjtcukmM1Xe+Sag== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1712515088; bh=647T7113pf4umKymjznNl4d/gN8D3pwPV/uVLqwTyXP=; h=X-Sonic-MF:Date:From:To:Subject:From:Subject; b=OoBqZ4PWjDdt/A+TRXrbE/9DokX1JM5yqZbEIf6v3VM9ra3VpAVsBFQo+y/tqRx561u8YjM6wX4vQyvs14U0k65uRatmiWiQ3ZcovdwIKPUyckxCxMPlyoINJ7PQlo1kzJsvdGmd7javV9q4tV7D6fJWlSoxAoyWo0acYwOqOnLJO6f4+erG9PAmGegyOY0YQIni+mBqPSj50fX/d8scb7aQEb9eFkfGMIUUJ3wuzoQD65tFiY01LJ8Au9jVdM+VlRaoTGmiN08e/1DqJeLcHi6O5q+O/O/ovfzCQH4ifytdEUXcxwuFbSchi4HoZGir6jGNnSOjqo9Z7If12xfGaw== X-YMail-OSG: Qm17ogYVM1njPI7tbnbaFMkzebaBzPMgRjQ1zPres3kETTmZNAhrICRdnlNVCFG iMZcymUAUgynhEVoPzqYvb7X95gGRlnEwn40eeqSocJqdKokJ9GPIi9cQqjXC8GQ5GGKu1sf7mbL A1z5K4IiSTXkpv_8Pwc38yoMI3BQBakD7yHoQvjnD72eBDN5iIui03_JTTmTwEkS8TyV_MokuWm3 2IrnNoBu66jwdL494PbZfruptWo_FUbteMzMP1uNwEpum62dn1YoooriYQc4pC9TtMfVTzIGGmtz U0MRaVJu38DhxVLZpGNlxXOBis2YZ.gANFeAKLs6E8pKAoPm9nnOqL1E_VNBR0K3eL402xJQhEGt fR4zkLCXutZXxkSXtbuOt_138kQeRxmw1dzd_rntwfSwhdDJALxR4mAEALltVqulpMg2H2CaP.gM Ikds6wx9ymqkU.GWZgRdE3Z5ycXkJzSG.a83jxN0x.KNylGDdaoZvNdKmMZewzTKxqlmjrxnIfdI akY7QZNR8rE.SByOgvFxJRxy4Muks7IGucztXvGeoSLFwqD1YZ8S1WwkV6dG1IJoam16LXbFO2Yi Gvy1WtrfOmk6sqZIBeXpE88XMVObfcuDS0NCsQOzESj4sEeayEfRPCg6IY9Aq4AHFLCTRHGBmJN4 OQVUuY7mJlrc28N4Hah9PGOqkoDwOshvFyEpTFxWxVVXEW50rq_z0upNWwNSvbP5rFWxR3dwiLcE qjr1g2C_d5DjETIXqXvQOT6PCqt2F1m3WLeYR1FG1jr7gXOfp18_QzYWQ.ntpwRGUQg89w29zvhC s4ZZNeRsVavZj9eRMGWShN9V0SzqatB1zSDDiYpqT4 X-Sonic-MF: X-Sonic-ID: 39e49762-a942-49b1-9bee-50290702f56e Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.bf2.yahoo.com with HTTP; Sun, 7 Apr 2024 18:38:08 +0000 Original-Received: by hermes--production-ir2-7bc88bfc75-2gzvg (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID f6fc113f2377d2d05656b99ded4646d6; Sun, 07 Apr 2024 18:38:06 +0000 (UTC) Content-Disposition: inline X-Mailer: WebService/1.1.22205 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.aol Received-SPF: pass client-ip=74.6.132.124; envelope-from=spacibba@aol.com; helo=sonic314-14.consmr.mail.bf2.yahoo.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=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:317592 Archived-At: --n74l2jzk6tdzcfie Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline Hi all: 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. Best, Ergus --n74l2jzk6tdzcfie Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="completion-preview-common.patch" diff --git a/lisp/completion-preview.el b/lisp/completion-preview.el index a86c1ba1cc9..11ac929efcf 100644 --- a/lisp/completion-preview.el +++ b/lisp/completion-preview.el @@ -59,16 +59,21 @@ completion-preview :group 'completion) (defcustom completion-preview-exact-match-only nil - "Whether to show completion preview only when there is an exact match. - -If this option is non-nil, Completion Preview mode only shows the -preview when there is exactly one completion candidate that -matches the symbol at point. Otherwise, if this option is nil, -when there are multiple matching candidates the preview shows the -first candidate, and you can cycle between the candidates with + "Show completion preview only when there is an exact or common prefix match. + + If this option is t, Completion Preview mode only shows the preview when +there is exactly one completion candidate that matches the symbol at +point. + If the option is `common', only shows the preview if there is a common +prefix in all the candidates and it is longer than the current input. + Otherwise, if this option is nil, when there are multiple matching +candidates the preview shows the first candidate, and you can cycle +between the candidates with \\[completion-preview-next-candidate] and \\[completion-preview-prev-candidate]." - :type 'boolean + :type '(choice (const :tag "Yes" t) + (const :tag "No" nil) + (const :tag "Common" common)) :version "30.1") (defcustom completion-preview-commands '(self-insert-command @@ -236,7 +241,10 @@ completion-preview--try-table (sort-fn (or (completion-metadata-get md 'cycle-sort-function) (completion-metadata-get md 'display-sort-function) completion-preview-sort-function)) - (all (let ((completion-lazy-hilit t)) + (all (let ((completion-lazy-hilit t) + (completion-styles (pcase completion-preview-exact-match-only + ('common '(basic)) + (_ completion-styles)))) (completion-all-completions string table pred (- (point) beg) md))) (last (last all)) @@ -244,17 +252,28 @@ completion-preview--try-table (prefix (substring string base))) (when last (setcdr last nil) - (when-let ((sorted (funcall sort-fn - (delete prefix (all-completions prefix all))))) - (unless (and (cdr sorted) completion-preview-exact-match-only) - (list (propertize (substring (car sorted) (length prefix)) - 'face (if (cdr sorted) - 'completion-preview - 'completion-preview-exact) - 'mouse-face 'completion-preview-highlight - 'keymap completion-preview--mouse-map) - (+ beg base) end sorted - (substring string 0 base) exit-fn)))))) + (when-let ((sorted (cond + ((not completion-preview-exact-match-only) + (funcall sort-fn + (delete prefix (all-completions prefix all)))) + ((eq completion-preview-exact-match-only t) + (when-let ((cands (delete prefix (all-completions prefix all)))) + (unless (cdr cands) cands))) + ((eq completion-preview-exact-match-only 'common) + (when-let ((cand (try-completion prefix all))) + (when (and (stringp cand) + (> (length cand) (length prefix))) + (list cand)))) + ))) + + (list (propertize (substring (car sorted) (length prefix)) + 'face (if (cdr sorted) + 'completion-preview + 'completion-preview-exact) + 'mouse-face 'completion-preview-highlight + 'keymap completion-preview--mouse-map) + (+ beg base) end sorted + (substring string 0 base) exit-fn))))) (defun completion-preview--capf-wrapper (capf) "Translate return value of CAPF to properties for completion preview overlay." --n74l2jzk6tdzcfie--