GNU bug report logs - #13322
24.3.50; `completion-all-sorted-completions': sorting and duplicate deletion

Previous Next

Package: emacs;

Reported by: "Drew Adams" <drew.adams <at> oracle.com>

Date: Mon, 31 Dec 2012 19:46:02 UTC

Severity: wishlist

Found in version 24.3.50

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: "Drew Adams" <drew.adams <at> oracle.com>
To: <13322 <at> debbugs.gnu.org>
Subject: bug#13322: 24.3.50; `completion-all-sorted-completions': sorting and duplicate deletion
Date: Mon, 31 Dec 2012 13:10:55 -0800
Oops.  Forgot to handle the second sorting occurrence also.
If a user supplies a sort function then we should not
overrule that to re-sort by history.

This code should do it (but the code is just a suggestion, again):

(defun completion-all-sorted-completions (&optional sort-function
dont-remove-dups)
  "Like `c-a-s-c', but with added optional args."
  (or completion-all-sorted-completions
      (let* ((start (field-beginning))
             (end (field-end))
             (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 sort-function
                           (completion-metadata-get all-md
'cycle-sort-function))))
        (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.
          (unless dont-remove-dups (setq all (delete-dups all)))
          (setq last (last all))
          (setq all (if sort-fun (funcall sort-fun all)
                      ;; Prefer shorter completions, by default.
                      (sort all (lambda (c1 c2) (< (length c1) (length c2))))))
          ;; Prefer recently used completions.
          (when (and (minibufferp)  (not sort-fun))
            (let ((hist (symbol-value minibuffer-history-variable)))
              (setq all (sort all (lambda (c1 c2)
                                    (> (length (member c1 hist))
                                       (length (member c2 hist))))))))
          ;; Cache the result.  This is not just for speed, but also so that
          ;; repeated calls to minibuffer-force-complete can cycle through
          ;; all possibilities.
          (completion--cache-all-sorted-completions (nconc all base-size))))))





This bug report was last modified 9 years and 121 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.