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: Thu, 01 Feb 2024 18:06:56 +0100 Message-ID: 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="39043"; mail-complaints-to="usenet@ciao.gmane.io" To: 68875@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Feb 01 18:08:05 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 1rVaXk-0009rZ-O2 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 01 Feb 2024 18:08:04 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVaXb-0004JJ-DP; Thu, 01 Feb 2024 12:07:55 -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 1rVaXZ-0004Ia-Dc for bug-gnu-emacs@gnu.org; Thu, 01 Feb 2024 12:07:53 -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 1rVaXY-0001L0-JN for bug-gnu-emacs@gnu.org; Thu, 01 Feb 2024 12:07:52 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rVaXi-0001zK-9C for bug-gnu-emacs@gnu.org; Thu, 01 Feb 2024 12:08:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eshel Yaron Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 01 Feb 2024 17:08:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 68875 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.17068072447565 (code B ref -1); Thu, 01 Feb 2024 17:08:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 1 Feb 2024 17:07:24 +0000 Original-Received: from localhost ([127.0.0.1]:43093 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rVaX6-0001xx-04 for submit@debbugs.gnu.org; Thu, 01 Feb 2024 12:07:24 -0500 Original-Received: from lists.gnu.org ([2001:470:142::17]:50938) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rVaX1-0001xd-VZ for submit@debbugs.gnu.org; Thu, 01 Feb 2024 12:07:22 -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 1rVaWk-0003fv-Eh for bug-gnu-emacs@gnu.org; Thu, 01 Feb 2024 12:07:02 -0500 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 1rVaWi-00012v-0m for bug-gnu-emacs@gnu.org; Thu, 01 Feb 2024 12:07:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1706807219; bh=US04eHX+O/vulvn8JFl+yXgQ491jY9gJmKZAZb16lb0=; h=From:To:Subject:Date:From; b=vx+WRCTNfO9OtGe1fKdKvxz+wmzns7v3anZvoBzu85lgqTfx3ghtIhXiV16H86uKp 8Qj9SFNoupE0UcvTwtPz/Mfph9O7BleY7WSTdK3vg08otJQInIOy9DSADPhBB6O6pZ mXC3p6mZbbUmYcrZXCsZNqEBPvOMVV3t6Ao4z9HI7UUWp4HXPJaM4WC2+s0afm86N3 0mxcEtxfQJ17k9WN9BUyiPKnm7dqkiJRoxaQVPlH/IqJ6bKs9wdjjf45T9vxATxuQU F/GmW0udbODszvUxH/pFzdkN+9UC2hw8/cu0fbCA69yZOXepW+h+YCPCrFHOuT4l5R MKuY1kSKVoKZA== X-Hashcash: 1:20:240201:bug-gnu-emacs@gnu.org::rnu6FLuIssH18sYZ:1S3Z 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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:279299 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. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Fix-mid-symbol-updating-cycling-completion-preview.patch >From e64361b0fbd78bb48b859658f9d0c1bb36916f50 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Thu, 1 Feb 2024 12:30:24 +0100 Subject: [PATCH] ; 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. --- 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..d7d3e9bf9f7 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) (completion-preview--get 'completion-preview-end))) (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 --=-=-=--