GNU bug report logs - #74718
29.4; Huge metadata with flex completion style

Previous Next

Package: emacs;

Reported by: Thierry Volpiatto <thievol <at> posteo.net>

Date: Sat, 7 Dec 2024 08:01:01 UTC

Severity: normal

Found in version 29.4

Full log


View this message in rfc822 format

From: Daniel Mendler <mail <at> daniel-mendler.de>
To: Thierry Volpiatto <thievol <at> posteo.net>
Cc: 74718 <at> debbugs.gnu.org, Dmitry Gutov <dmitry <at> gutov.dev>, monnier <at> iro.umontreal.ca
Subject: bug#74718: 29.4; Huge metadata with flex completion style
Date: Tue, 10 Dec 2024 16:24:40 +0100
Thierry Volpiatto <thievol <at> posteo.net> writes:
> From emacs -Q:
>
> 1) Open some buffers
> 2) eval this in scratch:
>
> (setq completion-styles '(flex))
> (let* ((collection (mapcar #'buffer-name (buffer-list)))
>        (metadata (completion-metadata "" collection nil))
>        (completion-function (lambda (str _pred _action)
>                               (let* ((comps (completion-all-completions str collection nil (length str) metadata))
> 				     (sort-fn (completion-metadata-get metadata 'display-sort-function))
> 				     (last (last comps)))
> 				(when (cdr last)
> 				  (setcdr last nil))
> 				(message "%S" metadata)
> 				(if (and sort-fn (> (length str) 0)) (funcall sort-fn comps) comps)))))
>   (completing-read "test: " completion-function))

Hello Thierry,

`completion-all-completions' should not be called inside completion
tables. Instead they should use `all-completions' to perform filtering
instead. `completion-all-completions' is the "frontend" API, which uses
completion styles, which then call the completion table backend.

The prototypical programmable completion table has the following form,
where `complete-with-action' provides the default implementation for the
ACTION argument:

(let ((candidates '("list" "of" "candidates")))
  (lambda (str pred action)
    (complete-with-action action candidates str pred)))

Depending on your use case, you may want to implement some ACTIONs
yourself, e.g., `metadata':

(let ((candidates '("list" "of" "candidates")))
  (lambda (str pred action)
    (if (eq action 'metadata)
        `(metadata (category . my-candidate-category))
      (complete-with-action action candidates str pred))))

Furthermore candidates can be computed dynamically, see the completion
tables `completion-table-dynamic' or `completion-table-with-cache'.

Daniel




This bug report was last modified 187 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.