unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Clemens <clemera@posteo.net>
To: 47294@debbugs.gnu.org
Subject: bug#47294: 27.1; completing-read: History handling and sorting
Date: Sun, 21 Mar 2021 15:29:49 +0100	[thread overview]
Message-ID: <00acdb37-028d-10c2-7130-95ae03e3a662@posteo.net> (raw)

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)))))))))
```






             reply	other threads:[~2021-03-21 14:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-21 14:29 Clemens [this message]
2021-03-22 19:50 ` bug#47294: 27.1; completing-read: History handling and sorting Dmitry Gutov
2022-06-25 15:12 ` Lars Ingebrigtsen
2022-06-25 16:32 ` Daniel Mendler
2022-06-26 12:40   ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=00acdb37-028d-10c2-7130-95ae03e3a662@posteo.net \
    --to=clemera@posteo.net \
    --cc=47294@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).