From unknown Fri Jun 20 07:09:25 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#68875 <68875@debbugs.gnu.org> To: bug#68875 <68875@debbugs.gnu.org> Subject: Status: [PATCH] ; Fix mid-symbol updating/cycling completion preview Reply-To: bug#68875 <68875@debbugs.gnu.org> Date: Fri, 20 Jun 2025 14:09:25 +0000 retitle 68875 [PATCH] ; Fix mid-symbol updating/cycling completion preview reassign 68875 emacs submitter 68875 Eshel Yaron severity 68875 normal tag 68875 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Thu Feb 01 12:07:24 2024 Received: (at submit) by debbugs.gnu.org; 1 Feb 2024 17:07:24 +0000 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 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 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 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== From: Eshel Yaron To: bug-gnu-emacs@gnu.org Subject: [PATCH] ; Fix mid-symbol updating/cycling completion preview X-Hashcash: 1:20:240201:bug-gnu-emacs@gnu.org::rnu6FLuIssH18sYZ:1S3Z Date: Thu, 01 Feb 2024 18:06:56 +0100 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" 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-Spam-Score: 0.9 (/) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.1 (/) --=-=-= 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 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Fri Feb 02 07:54:29 2024 Received: (at 68875) by debbugs.gnu.org; 2 Feb 2024 12:54:29 +0000 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 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== From: Eshel Yaron To: 68875@debbugs.gnu.org Subject: Re: bug#68875: [PATCH] ; Fix mid-symbol updating/cycling completion preview In-Reply-To: (Eshel Yaron via's message of "Thu, 01 Feb 2024 18:06:56 +0100") References: X-Hashcash: 1:20:240202:bug-gnu-emacs@gnu.org::egfPvVe8c78zsnrQ:1J3D X-Hashcash: 1:20:240202:68875@debbugs.gnu.org::qy/Kl46Pu0Qnur7F:37kx Date: Fri, 02 Feb 2024 13:54:13 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 68875 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= 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 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Wed Feb 21 12:25:13 2024 Received: (at 68875) by debbugs.gnu.org; 21 Feb 2024 17:25:13 +0000 Received: from localhost ([127.0.0.1]:56118 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcqLI-0000Oi-FR for submit@debbugs.gnu.org; Wed, 21 Feb 2024 12:25:13 -0500 Received: from mail.eshelyaron.com ([107.175.124.16]:34928 helo=eshelyaron.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcqEv-0008Ui-4W; Wed, 21 Feb 2024 12:18:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1708534788; bh=jbGREnJxzzCwQEJg0GNe8xc8TuyR3g+ed7Bi9YC2Rc8=; h=From:To:Subject:In-Reply-To:References:Date:From; b=C44MNqkh3MTIowhP9BK8tbw3h/v+qS6NFh5V2ncV66IzmIUJCTyh/wLGfLuxzWST4 lb+8cCjCgvtKFLwW/A7LlEgmY1Zyvt63hduN6eG99tI9PDQJTB0PLGvgTlE+E/ePZ+ WqjatEQUt++p3244yfUXo1+QcwtBHeNFgPGBtHJl9f4XeNXUt2Tpov15LlMvGH6Vpg SKcFbKLri6WMr9+hLDBrEiwC1E+C9YuE/fF5PPqYqi+AvC9avpVoahnNbbLclECdBA 03WMb0Jck7dv0BOA923c+TCicUkJzeRvhWFeKp/Ka/9gpFfvJcY6AHOKHUBimXPKEk Xn05O8mOhVYzA== From: Eshel Yaron To: 68875@debbugs.gnu.org Subject: Re: bug#68875: [PATCH] ; Fix mid-symbol updating/cycling completion preview In-Reply-To: (Eshel Yaron's message of "Fri, 02 Feb 2024 13:54:13 +0100") References: X-Hashcash: 1:20:240221:68875@debbugs.gnu.org::So9h7MH7Ee2/VXcJ:PnH Date: Wed, 21 Feb 2024 17:59:46 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -1.9 (-) X-Debbugs-Envelope-To: 68875 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.9 (--) close 68875 30.1 quit Eshel Yaron writes: >> 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. Pushed to master, and closing the bug. From unknown Fri Jun 20 07:09:25 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 21 Mar 2024 11:24:08 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator