From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eshel Yaron via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#68875: [PATCH] ; Fix mid-symbol updating/cycling completion preview Date: Fri, 02 Feb 2024 13:54:13 +0100 Message-ID: References: Reply-To: Eshel Yaron 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="8626"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: 68875@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Feb 02 13:55:11 2024 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 1rVt4Z-00021D-EG for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 02 Feb 2024 13:55:11 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVt4G-0002oW-KB; Fri, 02 Feb 2024 07:54:52 -0500 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 1rVt4F-0002oO-Fs for bug-gnu-emacs@gnu.org; Fri, 02 Feb 2024 07:54:51 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rVt4F-00072I-6o for bug-gnu-emacs@gnu.org; Fri, 02 Feb 2024 07:54:51 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rVt4P-0005Gg-Sh for bug-gnu-emacs@gnu.org; Fri, 02 Feb 2024 07:55:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eshel Yaron Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 02 Feb 2024 12:55:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68875 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 68875-submit@debbugs.gnu.org id=B68875.170687846920210 (code B ref 68875); Fri, 02 Feb 2024 12:55:01 +0000 Original-Received: (at 68875) by debbugs.gnu.org; 2 Feb 2024 12:54:29 +0000 Original-Received: from localhost ([127.0.0.1]:43812 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rVt3s-0005Ft-Kv for submit@debbugs.gnu.org; Fri, 02 Feb 2024 07:54:29 -0500 Original-Received: from mail.eshelyaron.com ([107.175.124.16]:53440 helo=eshelyaron.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rVt3q-0005Fl-T3 for 68875@debbugs.gnu.org; Fri, 02 Feb 2024 07:54:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1706878455; bh=cCN0GWxEAB+HZsqDKf4KMZlpK1XvmqKwQiqSeAyt1dU=; h=From:To:Subject:In-Reply-To:References:Date:From; b=rUy/T0MnE8C+rb2OneYWoUImPu0k5vStei4pK5/lyaki2BMsCyk7FVA6wWA+Mm1ix jDYrtBPZphA6OOzZjT8HEgXLM6WbGkAOGD93mjlcXPyQnU7HaZ7XiCrvArTCIacVno EwUj5LECyPiYzsSECc8BPWerMIV2PSuGvsQLg4PTPhLgORVwTh/ZOQqMVlJcW9A3ZG v06RJP/+WZZgYeFAb9WEqR+g7XzKHfMF595g02OlN6v6FRh/au33bYacW7Of7dVnB6 NL28PwjWyU1ExpTmDq7lBe6bc3x13ULireRfPsWm2W5aagQnFsLmNcT87LCvZN+N2C aG1yMDhdivqTw== In-Reply-To: (Eshel Yaron via's message of "Thu, 01 Feb 2024 18:06:56 +0100") X-Hashcash: 1:20:240202:bug-gnu-emacs@gnu.org::egfPvVe8c78zsnrQ:1J3D X-Hashcash: 1:20:240202:68875@debbugs.gnu.org::qy/Kl46Pu0Qnur7F:37kx 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:279344 Archived-At: --=-=-= Content-Type: text/plain > Tags: patch > > The attached patch fixes an issue where the completion preview overlay > (of Completion Preview mode) could at certain cases appear in the wrong > place when point is in the middle of a symbol. > > To observe the effect of this patch: > > 1. emacs -Q > 2. In the *scratch* buffer, say M-x completion-preview-mode RET > 3. Type "defaul-di" > 4. C-3 C-b to place point before the hyphen > 5. Type "t" > The completion preview overlay appears after "-di", showing "rectory". > So far so good. > 6. M-x completion-preview-next-candidate RET > Before this patch, the preview now shows "-directory", thus repeating > the existing suffix "-di". With this patch, the preview shows just > "rectory", as expected. Sorry, that patch contained a thinko (which was caught by one of the existing tests, fortunately). I'm attaching an updated patch below. Thanks, Eshel --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=v2-0001-Fix-mid-symbol-updating-cycling-completion-previe.patch >From dd7e8339ec705ebc00ad9a839373d3b668fd39ed Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Thu, 1 Feb 2024 12:30:24 +0100 Subject: [PATCH v2] ; Fix mid-symbol updating/cycling completion preview This fixes an issue where 'completion-preview-next-candidate' would fail to take into account the part of the symbol that follows point (the suffix) when point is at the middle of a symbol, as well as a similar issue in 'completion-preview--show' that would manifest with slow 'completion-at-point-functions'. * lisp/completion-preview.el (completion-preview-next-candidate) (completion-preview--show): Use recorded 'completion-preview-end' position instead of current point. * test/lisp/completion-preview-tests.el (completion-preview-mid-symbol-cycle): New test. (Bug#68875) --- lisp/completion-preview.el | 24 ++++++++++++------------ test/lisp/completion-preview-tests.el | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/lisp/completion-preview.el b/lisp/completion-preview.el index 6fd60f3c416..e827da43a08 100644 --- a/lisp/completion-preview.el +++ b/lisp/completion-preview.el @@ -302,21 +302,21 @@ completion-preview--show ;; never display a stale preview and that the preview doesn't ;; flicker, even with slow completion backends. (let* ((beg (completion-preview--get 'completion-preview-beg)) + (end (max (point) (overlay-start completion-preview--overlay))) (cands (completion-preview--get 'completion-preview-cands)) (index (completion-preview--get 'completion-preview-index)) (cand (nth index cands)) - (len (length cand)) - (end (+ beg len)) - (cur (point)) - (face (get-text-property 0 'face (completion-preview--get 'after-string)))) - (if (and (< beg cur end) (string-prefix-p (buffer-substring beg cur) cand)) + (after (completion-preview--get 'after-string)) + (face (get-text-property 0 'face after))) + (if (and (<= beg (point) end (1- (+ beg (length cand)))) + (string-prefix-p (buffer-substring beg end) cand)) ;; The previous preview is still applicable, update it. (overlay-put (completion-preview--make-overlay - cur (propertize (substring cand (- cur beg)) + end (propertize (substring cand (- end beg)) 'face face 'mouse-face 'completion-preview-highlight 'keymap completion-preview--mouse-map)) - 'completion-preview-end cur) + 'completion-preview-end end) ;; The previous preview is no longer applicable, hide it. (completion-preview-active-mode -1)))) ;; Run `completion-at-point-functions' to get a new candidate. @@ -366,16 +366,16 @@ completion-preview-next-candidate (interactive "p") (when completion-preview-active-mode (let* ((beg (completion-preview--get 'completion-preview-beg)) + (end (completion-preview--get 'completion-preview-end)) (all (completion-preview--get 'completion-preview-cands)) (cur (completion-preview--get 'completion-preview-index)) (len (length all)) (new (mod (+ cur direction) len)) - (str (nth new all)) - (pos (point))) - (while (or (<= (+ beg (length str)) pos) - (not (string-prefix-p (buffer-substring beg pos) str))) + (str (nth new all))) + (while (or (<= (+ beg (length str)) end) + (not (string-prefix-p (buffer-substring beg end) str))) (setq new (mod (+ new direction) len) str (nth new all))) - (let ((aft (propertize (substring str (- pos beg)) + (let ((aft (propertize (substring str (- end beg)) 'face (if (< 1 len) 'completion-preview 'completion-preview-exact) diff --git a/test/lisp/completion-preview-tests.el b/test/lisp/completion-preview-tests.el index 190764e9125..5b2c28bd3dd 100644 --- a/test/lisp/completion-preview-tests.el +++ b/test/lisp/completion-preview-tests.el @@ -181,4 +181,19 @@ completion-preview-capf-errors (completion-preview--post-command)) (completion-preview-tests--check-preview "barbaz" 'exact))) +(ert-deftest completion-preview-mid-symbol-cycle () + "Test cycling the completion preview with point at the middle of a symbol." + (with-temp-buffer + (setq-local completion-at-point-functions + (list + (completion-preview-tests--capf + '("foobar" "foobaz")))) + (insert "fooba") + (forward-char -2) + (let ((this-command 'self-insert-command)) + (completion-preview--post-command)) + (completion-preview-tests--check-preview "r") + (completion-preview-next-candidate 1) + (completion-preview-tests--check-preview "z"))) + ;;; completion-preview-tests.el ends here -- 2.42.0 --=-=-=--