From e41b1d376f1c9628445d67fa75360b1ddad2783d Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Wed, 21 Feb 2024 13:24:06 +0100 Subject: [PATCH] ; Reposition cursor after refreshing *Completions* * lisp/minibuffer.el (minibuffer-completion-help): If *Completions* is already visible and some candidate is highlighted, try to highlight it again after populating the buffer anew. --- lisp/minibuffer.el | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 6dbc3202290..4fc95f4e7b4 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -2860,8 +2860,26 @@ completions list." (defun minibuffer-completion-help (&optional start end) "Display a list of possible completions of the current minibuffer contents." (interactive) - (message "Making completion list...") - (let* ((start (or start (minibuffer--completion-prompt-end))) + (let* ((current (when-let ((win (get-buffer-window "*Completions*" 0))) + (get-text-property (window-point win) 'completion--string + (get-buffer "*Completions*")))) + (prev-next (when current + (with-current-buffer "*Completions*" + (save-excursion + (goto-char (point-min)) + (text-property-search-forward 'completion--string current t) + (cons + (save-excursion + (when-let ((pm (text-property-search-backward 'completion--string current))) + (goto-char (prop-match-end pm)) + (when-let ((pm (text-property-search-backward 'cursor-face nil))) + (goto-char (prop-match-beginning pm)) + (get-text-property (point) 'completion--string)))) + (save-excursion + (when-let ((pm (text-property-search-forward 'cursor-face nil t))) + (goto-char (prop-match-end pm)) + (get-text-property (point) 'completion--string)))))))) + (start (or start (minibuffer--completion-prompt-end))) (end (or end (point-max))) (string (buffer-substring start end)) (md (completion--field-metadata start)) @@ -3052,7 +3070,20 @@ completions list." (if (eq (car bounds) (length result)) 'exact 'finished))))))) - (display-completion-list completions group-fun))))) + (display-completion-list completions group-fun) + (with-current-buffer standard-output + (goto-char (point-min)) + (when-let + ((pm + (or (and current (text-property-search-forward 'completion--string current t)) + (when-let ((next (cdr prev-next))) + (text-property-search-forward 'completion--string next t)) + (when-let ((prev (car prev-next))) + (text-property-search-forward 'completion--string prev t))))) + (goto-char (prop-match-beginning pm)) + (setq pm (text-property-search-forward 'cursor-face)) + (setq-local cursor-face-highlight-nonselected-window t) + (set-window-point (get-buffer-window) (prop-match-beginning pm)))))))) nil))) nil)) -- 2.39.5