commit eec1a68b009961e74d08a57bdbba5b0851dbe42f (HEAD, refs/remotes/origin/master) Author: Daniel Mendler Date: Mon Nov 18 00:58:48 2024 +0100 New function `completion-list-candidate-at-point' Replace `completions--start-of-candidate-at' with the new function `completion-list-candidate-at-point' which returns the candidate string and the candidate bounds as a list in the format (STR BEG END). * lisp/simple.el (completions--start-of-candidate-at): Remove. (completion-list-candidate-at-point): New function. (choose-completion): Use it. * lisp/minibuffer.el (minibuffer-completion-help): Use it. diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 9b498615926..405ee21cdb2 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -2628,8 +2628,9 @@ The candidate will still be chosen by `choose-completion' unless (when-let* ((buffer (get-buffer "*Completions*")) (window (get-buffer-window buffer 0))) (with-current-buffer buffer - (when-let* ((beg (completions--start-of-candidate-at (window-point window)))) - (cons (get-text-property beg 'completion--string) (- (point) beg)))))) + (when-let* ((cand (completion-list-candidate-at-point + (window-point window)))) + (cons (car cand) (- (point) (cadr cand))))))) ;; If the *Completions* buffer is shown in a new ;; window, mark it as softly-dedicated, so bury-buffer in ;; minibuffer-hide-completions will know whether to diff --git a/lisp/simple.el b/lisp/simple.el index 1ad7f7282f3..f2ee4a5df67 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -10249,22 +10249,21 @@ Also see the `completion-auto-wrap' variable." This makes `completions--deselect' effective.") -(defun completions--start-of-candidate-at (position) - "Return the start position of the completion candidate at POSITION." - (save-excursion - (goto-char position) - (let (beg) - (cond - ((and (not (eobp)) - (get-text-property (point) 'completion--string)) - (setq beg (1+ (point)))) - ((and (not (bobp)) - (get-text-property (1- (point)) 'completion--string)) - (setq beg (point)))) - (when beg - (or (previous-single-property-change - beg 'completion--string) - beg))))) +(defun completion-list-candidate-at-point (&optional pt) + "Candidate string and bounds at PT in completions buffer. +The return value has the format (STR BEG END). +The optional argument PT defaults to (point)." + (setq pt (or pt (point))) + (when (cond + ((and (/= pt (point-max)) + (get-text-property pt 'completion--string)) + (cl-incf pt)) + ((and (/= pt (point-min)) + (get-text-property (1- pt) 'completion--string)))) + (setq pt (or (previous-single-property-change pt 'completion--string) pt)) + (list (get-text-property pt 'completion--string) pt + (or (next-single-property-change pt 'completion--string) + (point-max))))) (defun choose-completion (&optional event no-exit no-quit) "Choose the completion at point. @@ -10289,11 +10288,9 @@ minibuffer, but don't quit the completions window." (or (get-text-property (posn-point (event-start event)) 'completion--string) (error "No completion here")) - (if-let* ((candidate-start - (completions--start-of-candidate-at - (posn-point (event-start event))))) - (get-text-property candidate-start 'completion--string) - (error "No completion here"))))) + (or (car (completion-list-candidate-at-point + (posn-point (event-start event)))) + (error "No completion here"))))) (unless (buffer-live-p buffer) (error "Destination buffer is dead"))