(defun completion-all-sorted-completions (&optional start end)
(let* ((start (or start (minibuffer-prompt-end)))
(end (or end (point-max)))
- (string (buffer-substring start end))
- (md (completion--field-metadata start))
- (all (completion-all-completions
- string
- minibuffer-completion-table
- minibuffer-completion-predicate
- (- (point) start)
- md))
- (last (last all))
- (base-size (or (cdr last) 0))
- (all-md (completion--metadata (buffer-substring-no-properties
- start (point))
- base-size md
- minibuffer-completion-table
- minibuffer-completion-predicate))
- (sort-fun
- (or minibuffer-completions-sort-function
- (completion-metadata-get all-md 'sort-function)
- (pcase completions-sort
- ('nil #'identity)
- ('alphabetical #'minibuffer-sort-alphabetically)
- ('historical #'minibuffer-sort-by-history)
- (_ completions-sort))))
- (full-base (substring string 0 base-size))
- (minibuffer-completion-base
- (funcall (or (alist-get 'adjust-base-function all-md) #'identity)
- full-base)))
- (when last
- (setcdr last nil)
-
- ;; Delete duplicates: do it after setting last's cdr to nil (so
- ;; it's a proper list), and be careful to reset `last' since it
- ;; may be a different cons-cell.
- (setq all (delete-dups all))
- (setq last (last all))
-
- (when sort-fun (setq all (funcall sort-fun all)))
-
- (let ((result (nconc all base-size)))
- ;; Cache the result. This is not just for speed, but also so that
- ;; repeated calls to minibuffer-force-complete can cycle through
- ;; all possibilities.
- (setq completion-all-sorted-completions result)))))
+ all base-size)
+ (unless (and (get-buffer-window completions-buffer-name 0)
+ (with-current-buffer completions-buffer-name
+ (when-let ((cur (get-text-property (point) 'completion--string)))
+ (let ((tail nil))
+ (while (and completions-candidates
+ (not (eq cur (car completions-candidates))))
+ (push (pop completions-candidates) tail))
+ (setq base-size (- (car completion-base-position) start)
+ completions-candidates
+ (nconc completions-candidates
+ (nreverse tail))
+ all (copy-sequence completions-candidates))))))
+ (let* ((string (buffer-substring start end))
+ (md (completion--field-metadata start))
+ (sub (completion-all-completions
+ (buffer-substring start end)
+ minibuffer-completion-table
+ minibuffer-completion-predicate
+ (- (point) start)
+ (completion--field-metadata start)))
+ (last (last sub))
+ (size (or (cdr last) 0))
+ (sort-fun
+ (or minibuffer-completions-sort-function
+ (completion-metadata-get md 'sort-function)
+ (pcase completions-sort
+ ('nil #'identity)
+ ('alphabetical #'minibuffer-sort-alphabetically)
+ ('historical #'minibuffer-sort-by-history)
+ (_ completions-sort))))
+ (full-base (substring string 0 size))
+ (minibuffer-completion-base
+ (funcall (or (alist-get 'adjust-base-function md) #'identity)
+ full-base)))
+ (when last
+ (setcdr last nil)
+ (when sort-fun (setq sub (funcall sort-fun sub)))
+ (setq all sub base-size size))))
+ (setq completion-all-sorted-completions (nconc all base-size))))
(defun minibuffer-toggle-completion-ignore-case ()
"Toggle completion case-sensitively for the current minibuffer."
(set-window-point (get-buffer-window) (prop-match-beginning pm)))
(setq-local
completion-reference-buffer mainbuf
- completions-candidates completions
+ completions-candidates (mapcar (lambda (c) (if (atom c) c (car c))) completions)
completions-group-function group-fun
completions-annotations (plist-get plist :annotations)
completions-style (plist-get plist :style)