2

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?

3

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 ...)
      (completion-table
       (lambda (string pred action)
         (if (eq action 'metadata)
             '(metadata (display-sort-function . identity)
                        (cycle-sort-function . identity))
           (complete-with-action
            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 Jun 3 '18 at 6:16
  • Sounds like a bug in ivy that you might like to report. – Stefan Jun 3 '18 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 Jun 17 '18 at 17:57
1

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 Jun 2 '18 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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