* 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
* bug#47294: 27.1; completing-read: History handling and sorting
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
2 siblings, 0 replies; 5+ messages in thread
From: Dmitry Gutov @ 2021-03-22 19:50 UTC (permalink / raw)
To: Clemens, 47294
On 21.03.2021 16:29, Clemens wrote:
> 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:
This sounds sensible, but some supporting numbers couldn't hurt.
And a patch in the form of a diff against master.
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#47294: 27.1; completing-read: History handling and sorting
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
2 siblings, 0 replies; 5+ messages in thread
From: Lars Ingebrigtsen @ 2022-06-25 15:12 UTC (permalink / raw)
To: Clemens; +Cc: 47294
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#47294: 27.1; completing-read: History handling and sorting
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
2 siblings, 1 reply; 5+ messages in thread
From: Daniel Mendler @ 2022-06-25 16:32 UTC (permalink / raw)
To: 47294; +Cc: Lars Ingebrigtsen
As far as I know, both issues have already been fixed in Emacs 28.
completing-read accepts t now to disable the history. I contributed the
patch for sorting by history using a hashtable (see
minibuffer--sort-by-position).
Daniel
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#47294: 27.1; completing-read: History handling and sorting
2022-06-25 16:32 ` Daniel Mendler
@ 2022-06-26 12:40 ` Lars Ingebrigtsen
0 siblings, 0 replies; 5+ messages in thread
From: Lars Ingebrigtsen @ 2022-06-26 12:40 UTC (permalink / raw)
To: Daniel Mendler; +Cc: 47294
Daniel Mendler <mail@daniel-mendler.de> writes:
> As far as I know, both issues have already been fixed in Emacs 28.
> completing-read accepts t now to disable the history. I contributed the
> patch for sorting by history using a hashtable (see
> minibuffer--sort-by-position).
Ah, thanks. I'm closing this bug report, then.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ 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).