From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dario Gjorgjevski Newsgroups: gmane.emacs.bugs Subject: bug#42149: Substring and flex completion ignore implicit trailing =?UTF-8?Q?=E2=80=98any=E2=80=99?= Date: Wed, 09 Sep 2020 12:17:34 +0200 Message-ID: References: <87k0znsdjb.fsf@gmail.com> <87sgbsv7gg.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4123"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 42149@debbugs.gnu.org, Stefan Monnier To: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 09 12:19:53 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1kFxCi-0000wy-Oz for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 09 Sep 2020 12:19:52 +0200 Original-Received: from localhost ([::1]:54056 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kFxCh-00084c-RB for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 09 Sep 2020 06:19:51 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36306) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kFxAw-0005tF-O4 for bug-gnu-emacs@gnu.org; Wed, 09 Sep 2020 06:18:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45737) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kFxAw-0003DV-Cj for bug-gnu-emacs@gnu.org; Wed, 09 Sep 2020 06:18:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kFxAw-0006Kx-8O for bug-gnu-emacs@gnu.org; Wed, 09 Sep 2020 06:18:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dario Gjorgjevski Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 09 Sep 2020 10:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42149 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 42149-submit@debbugs.gnu.org id=B42149.159964666524338 (code B ref 42149); Wed, 09 Sep 2020 10:18:02 +0000 Original-Received: (at 42149) by debbugs.gnu.org; 9 Sep 2020 10:17:45 +0000 Original-Received: from localhost ([127.0.0.1]:57283 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kFxAf-0006KU-3v for submit@debbugs.gnu.org; Wed, 09 Sep 2020 06:17:45 -0400 Original-Received: from mail-ed1-f45.google.com ([209.85.208.45]:37162) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kFxAd-0006KG-FC for 42149@debbugs.gnu.org; Wed, 09 Sep 2020 06:17:44 -0400 Original-Received: by mail-ed1-f45.google.com with SMTP id n22so2085264edt.4 for <42149@debbugs.gnu.org>; Wed, 09 Sep 2020 03:17:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=oI4gUcmTxMV/SEiBa3dyQ9CELWW9mckdQCqUuTZbBNg=; b=dK7273OUBrDf41+NuwMd2aYb/aV4xs8+O7ta9kHVOYqbiR5TchYKYZ13ozT49LKPs8 72Rwd5/E7wEH/mb4QjO7iieBQosl1kBF2g0kmY8uPAX+o6/o1OhCvmQGl1+JY1b7SY3Q J0UCnoYP9OKlNQQCx+K/cl++B3iiahIz/p69g34TnoCidlmaW4nsnwvM0rb3BbJ2Knnd 2WepYweOyab8mzwQ7P45ko/A4sdKM0xvhjHxzEvXB1osyc+EEbvhJriGqGjWWs0tgV+Y wGEPZFnJ8NuIZZhSAg1AciNlNIkAX8Fh9CqYC53jUJ/fr9LbNMBZ7U2iVcLyOZTuDDxD HKEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=oI4gUcmTxMV/SEiBa3dyQ9CELWW9mckdQCqUuTZbBNg=; b=U1q4H2Jo0GYMESREeC4Kx6lnOa7r+kvWRa8nBQi+GlkcfoRLhlDmySy2WAxi4P6QQB 0JEGQNTha9Ui1lacfIwidKnCj126TgVllgd8KMkuvWU3KW3KvsBzRj042E56psiI4IPd pVLMaqy6z1rnpv8uunHyePVE0gJUd+63mnK6zHVfLLZ7tE8B2HG0bV2Go7rVNkcb77yh rAk3VYSSJWiKEENNVpDIhnKZRhyGHBAMLv8bEJWoaMknnwzUu2VVCYJ2Idpje4sJYKL+ bDg/dDK/o6BnFOTJU/8tKPAhbWHCTf9SI/vYgSW4LLXr8DxyRSI9RPytbnhQngKdgw0Q FnUQ== X-Gm-Message-State: AOAM531AlZIIKIHx4oioqVN5gRyfkcwiy+yMxPlGTeVOyl+B2CAt/ip1 NRv97JqUzF4eGQEKzJZZ9QlL/4DYAo83Rg== X-Google-Smtp-Source: ABdhPJwSLB7oLEWVFBn1uXRDu7EEjlmOPJqnYdo7LRj1fWBl9+ojONxS3ubDe5jD1caj/p5IatwQKg== X-Received: by 2002:a05:6402:1710:: with SMTP id y16mr3467085edu.197.1599646657362; Wed, 09 Sep 2020 03:17:37 -0700 (PDT) Original-Received: from ZALANDO-31298 ([79.140.114.32]) by smtp.gmail.com with ESMTPSA id v6sm1676533edj.59.2020.09.09.03.17.35 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 Sep 2020 03:17:36 -0700 (PDT) In-Reply-To: ("=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?="'s message of "Tue, 8 Sep 2020 12:32:31 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:187625 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Jo=C3=A3o, hi Stefan, Please find attached a patch that fixes this issue and optimizes the scoring in PCM completion a bit. As far as I can tell, this works fine and can be merged, but please have a look and do some testing yourself. --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename=0001-Fix-and-optimize-scoring-in-PCM-completion.patch Content-Transfer-Encoding: quoted-printable Content-Description: Fix (and optimize) scoring in PCM completion >From 8699e72f92524da8041f63949cf29858caded4a5 Mon Sep 17 00:00:00 2001 From: Dario Gjorgjevski Date: Wed, 9 Sep 2020 12:10:52 +0200 Subject: [PATCH] Fix (and optimize) scoring in PCM completion MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit * lisp/minibuffer.el (completion-pcm--hilit-commonality): Fix scoring to also include the last part of the query string. This was especially evident for single-character query strings, e.g., =E2=80=98(completion-flex-all-completions "1" '("1" "foo1") nil 1)=E2=80=99= would match both "1" and "foo1" with a completion-score of 0. This adjustment makes the completion-score of "1" be 1 and of "foo1" by 0.25. See also bug#42149. Furthermore, some optimizations are done. --- lisp/minibuffer.el | 78 ++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 41 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 62a33f3e2d..7fa132f3c5 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -3191,17 +3191,20 @@ one-letter-long matches).") (when completions (let* ((re (completion-pcm--pattern->regex pattern 'group)) (point-idx (completion-pcm--pattern-point-idx pattern)) - (case-fold-search completion-ignore-case)) + (case-fold-search completion-ignore-case) + (score-numerator (float (apply #'+ (mapcar (lambda (part) + (if (stringp part) + (length part) + 0)) + pattern))))) (mapcar (lambda (str) - ;; Don't modify the string itself. + ;; Don't modify the string itself. (setq str (copy-sequence str)) (unless (string-match re str) (error "Internal error: %s does not match %s" re str)) (let* ((pos (if point-idx (match-beginning point-idx) (match-end = 0))) (md (match-data)) - (start (pop md)) - (end (pop md)) (len (length str)) ;; To understand how this works, consider these bad ;; ascii(tm) diagrams showing how the pattern "foo" @@ -3237,47 +3240,40 @@ one-letter-long matches).") ;; (SUM_across_i(hole_i_contrib) + 1) * len ;; ;; , where "len" is the string's length. - (score-numerator 0) - (score-denominator 0) - (last-b 0) - (update-score - (lambda (a b) - "Update score variables given match range (A B)." - (setq - score-numerator (+ score-numerator (- b a))) - (unless (or (=3D a last-b) - (zerop last-b) - (=3D a (length str))) - (setq - score-denominator (+ score-denominator - 1 - (expt (- a last-b 1) - (/ 1.0 - flex-score-match-tight= ness))))) - (setq - last-b b)))) - (funcall update-score start start) + (full-match-start (pop md)) + (full-match-end (pop md)) + (leading-hole-start (pop md)) + (leading-hole-end (pop md)) + (match-start leading-hole-end) + (score-denominator 0)) (while md - (funcall update-score start (car md)) - (add-face-text-property - start (pop md) - 'completions-common-part - nil str) - (setq start (pop md))) - (funcall update-score len len) + (let ((hole-start (pop md)) + (hole-end (pop md))) + (add-face-text-property + match-start hole-start + 'completions-common-part + nil str) + (unless (=3D hole-start hole-end) + (setq + score-denominator (+ score-denominator + 1 + (expt + (- hole-end hole-start 1) + (/ 1.0 flex-score-match-tightness)= )))) + (setq match-start hole-end))) (add-face-text-property - start end + match-start full-match-end 'completions-common-part nil str) - (if (> (length str) pos) - (add-face-text-property - pos (1+ pos) - 'completions-first-difference - nil str)) - (unless (zerop (length str)) - (put-text-property - 0 1 'completion-score - (/ score-numerator (* len (1+ score-denominator)) 1.0) str))) + (when (> len pos) + (add-face-text-property + pos (1+ pos) + 'completions-first-difference + nil str)) + (put-text-property + 0 1 + 'completion-score + (/ score-numerator (* len (1+ score-denominator))) str)) str) completions)))) =20 --=20 2.17.1 --=-=-= Content-Type: text/plain Best regards, Dario -- dario.gjorgjevski@gmail.com :: +49 1525 8666837 % gpg --keyserver 'hkps://hkps.pool.sks-keyservers.net' \ \`> --recv-keys '744A4F0B4F1C9371' --=-=-=--