all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#13322: 24.3.50; `completion-all-sorted-completions': sorting and duplicate deletion
@ 2012-12-31 19:43 Drew Adams
  2012-12-31 21:10 ` Drew Adams
  2013-01-03 17:02 ` Stefan Monnier
  0 siblings, 2 replies; 6+ messages in thread
From: Drew Adams @ 2012-12-31 19:43 UTC (permalink / raw)
  To: 13322

1. Please provide for `completion-all-sorted-completions' to sort using
a function other than what is returned by `cycle-sort-function' from the
metadata.  E.g., an optional arg SORT-FUN.
 
2. Please make duplicate deletion optional.  E.g., an optional arg
DONT-REMOVE-DUPS.
 
Suggested code below - it just adds the args and respects them.
But please also add a doc string in any case.
 
(defun completion-all-sorted-completions (&optional sort-fun dont-remove-dups)
  "FIXME - I NEED A HELPFUL DOC STRING"
  (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)))
        (unless sort-fun
          (setq sort-fun (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 (minibufferp)
            (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))))))
 

`completion-all-sorted-completions' currently does a mix of things.
Perhaps those things should be separated into different functions that
users could use on their own.  Is there a good reason to couple these
things?
 
a. calculation of the completions
b. duplicate deletion
c. sorting
d. caching
 
Dunnow whether caching should be separated out, but perhaps b and c
could be.

In GNU Emacs 24.3.50.1 (i386-mingw-nt5.1.2600)
 of 2012-12-18 on MS-W7-DANI
Bzr revision: 111265 eliz@gnu.org-20121218190556-x9wmq083vwecgu0f
Windowing system distributor `Microsoft Corp.', version 5.1.2600
Configured using:
 `configure --with-gcc (4.7) --no-opt --enable-checking --cflags
 -Ic:/emacs/libs/libXpm-3.5.10/include -Ic:/emacs/libs/libXpm-3.5.10/src
 -Ic:/emacs/libs/libpng-dev_1.4.3-1_win32/include
 -Ic:/emacs/libs/zlib-dev_1.2.5-2_win32/include
 -Ic:/emacs/libs/giflib-4.1.4-1-lib/include
 -Ic:/emacs/libs/jpeg-6b-4-lib/include
 -Ic:/emacs/libs/tiff-3.8.2-1-lib/include
 -Ic:/emacs/libs/libxml2-2.7.8-w32-bin/include/libxml2
 -Ic:/emacs/libs/gnutls-3.0.9-w32-bin/include
 -Ic:/emacs/libs/libiconv-1.9.2-1-lib/include'






^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-04-29  0:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-31 19:43 bug#13322: 24.3.50; `completion-all-sorted-completions': sorting and duplicate deletion Drew Adams
2012-12-31 21:10 ` Drew Adams
2013-01-03 17:02 ` Stefan Monnier
2013-01-03 17:39   ` Drew Adams
2016-04-28 19:15   ` Lars Ingebrigtsen
2016-04-29  0:45     ` Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.