unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Lars Ingebrigtsen <larsi@gnus.org>
To: Clemens <clemera@posteo.net>
Cc: 47294@debbugs.gnu.org
Subject: bug#47294: 27.1; completing-read: History handling and sorting
Date: Sat, 25 Jun 2022 17:12:46 +0200	[thread overview]
Message-ID: <87tu88hj4h.fsf@gnus.org> (raw)
In-Reply-To: <00acdb37-028d-10c2-7130-95ae03e3a662@posteo.net> (Clemens's message of "Sun, 21 Mar 2021 15:29:49 +0100")

Clemens <clemera@posteo.net> writes:

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

(I'm going through old bug reports that unfortunately weren't resolved
at the time.)

I'm unable to reproduce this in Emacs 27.1 and the current trunk.

(completing-read "foo" nil nil nil nil t)

doesn't throw an error for me.  Do you have a complete recipe to
reproduce the problem?

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

It's not immediately obvious to me what this code is supposed to
replace.  Do you have a patch for this instead?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





  parent reply	other threads:[~2022-06-25 15:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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=87tu88hj4h.fsf@gnus.org \
    --to=larsi@gnus.org \
    --cc=47294@debbugs.gnu.org \
    --cc=clemera@posteo.net \
    /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).