Recently, when using Ivy and calling completing-read, my output is being sorted (instead of showing up in the order passed in).

How can I prevent sorting the input to completing-read when using Ivy?

2 Answers 2


You need your completion-table to tell the completion-UI not to perform sorting (typically because the completion-table already arranges for its own sorting to take place).

See C-h f completion-metadata. Here's an example:

(let* ((presorted-completions ...)
       (lambda (string pred action)
         (if (eq action 'metadata)
             '(metadata (display-sort-function . identity)
                        (cycle-sort-function . identity))
            action presorted-completions string pred))))
  (completing-read "Prompt" completion-table))
  • This stops ivy from being used, is there a general way to handle this so ivy keeps working?
    – ideasman42
    Commented Jun 3, 2018 at 6:16
  • Sounds like a bug in ivy that you might like to report.
    – Stefan
    Commented Jun 3, 2018 at 8:56
  • @ideasman42 Stefan's answer works with Ivy. How is it not working for you? If Ivy still performs unwanted sorting, customise ivy-sort-functions-alist. See also github.com/abo-abo/swiper/issues/1611.
    – Basil
    Commented Jun 17, 2018 at 17:57

Sorting can be disabled by setting (ivy-sort-functions-alist nil), in the scope you're using completing-read (so as not to change defaults everywhere).

See this complete example.

  • You don't need to set the entire ivy-sort-functions-alist to nil, only the the entries corresponding to the callers of completing-read.
    – Basil
    Commented Jun 2, 2018 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.