unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#47294: 27.1; completing-read: History handling and sorting
@ 2021-03-21 14:29 Clemens
  2021-03-22 19:50 ` Dmitry Gutov
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Clemens @ 2021-03-21 14:29 UTC (permalink / raw)
  To: 47294

One can pass `t` to ignore history to `read-from-minibuffer`. I
assumed this is also true for `completing-read` and discovered this
would throw an error (for example when using icomplete
`completion-all-sorted-completions` is called which doesn't handle the
`t` value). Can we change things to allow this API also for
`completing-read`?

Another observation is that the implementation of
`completion-all-sorted-completions` could be made faster by using a
hash table as Daniel Mendler implemented it for Selectrum:

```elisp
(let* ((list (and (not (eq minibuffer-history-variable t))
                   (symbol-value minibuffer-history-variable)))
        (hist (make-hash-table :test #'equal
                               :size (length list))))
   ;; Store the history position first in a hashtable in order to
   ;; keep the sorting fast and the complexity at O(n*log(n)).
   (seq-do-indexed (lambda (elem idx)
                     (unless (gethash elem hist)
                       (puthash elem idx hist)))
                   list)
   (sort candidates
         (lambda (c1 c2)
           (let ((h1 (gethash c1 hist most-positive-fixnum))
                 (h2 (gethash c2 hist most-positive-fixnum))
                 (l1 (length c1))
                 (l2 (length c2)))
             (or (< h1 h2)
                 (and (= h1 h2)
                      (or (< l1 l2)
                          (and (= l1 l2) (string< c1 c2)))))))))
```






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

end of thread, other threads:[~2022-06-26 12:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-21 14:29 bug#47294: 27.1; completing-read: History handling and sorting Clemens
2021-03-22 19:50 ` Dmitry Gutov
2022-06-25 15:12 ` Lars Ingebrigtsen
2022-06-25 16:32 ` Daniel Mendler
2022-06-26 12:40   ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).