From c94c648fe91247b74a524c438f4fa43e87c70e49 Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Tue, 30 Jan 2024 18:44:14 +0100 Subject: cape-capf-buster: Ensure that point is inside the prefix --- cape.el | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/cape.el b/cape.el index a196c68..b41a422 100644 --- a/cape.el +++ b/cape.el @@ -1007,18 +1007,19 @@ completion table is refreshed on every input change." (input (buffer-substring-no-properties beg end))) (lambda (str pred action) (let ((new-input (cape--input-string beg end))) - (when (and - ;; Only refresh table for the `all-completions' action. - (eq action t) - ;; Point must be inside the input string. It could lie - ;; outside if the Orderless completion style is used. - (<= beg (point) (+ beg (length new-input))) - ;; Current input is not valid. - (not (funcall valid input new-input))) + ;; Only refresh table for the `all-completions' action if the + ;; input is not valid (has changed). + (when (and (eq action t) (not (funcall valid input new-input))) (pcase - ;; Reset in case `all-completions' is used inside CAPF - (let (completion-ignore-case completion-regexp-list) - (funcall capf)) + (save-excursion + ;; Point must be inside the input string. It could lie + ;; outside if the Orderless completion style is used. + (let ((end (+ beg (length new-input)))) + (unless (<= beg (point) end) + (goto-char end))) + ;; Reset in case `all-completions' is used inside CAPF. + (let (completion-ignore-case completion-regexp-list) + (funcall capf))) ((and `(,new-beg ,new-end ,new-table . ,new-plist) ;; new-end can be before end for Orderless completion. (guard (and (= new-beg beg) (<= new-end end)))) -- cgit v1.0