Skip to content

Sorting issue #2 #554

@jkitchin

Description

@jkitchin

Say I have some candidates as a list of cons cells, and I want them sorted on the cdr of the cell. Is this the right way to do it?

#+BEGIN_SRC emacs-lisp
(defvar ivy-sorter-data '(("b 1" . 1) ("a 2" . 2) ("d 0" . 0) ("c 5" . 5)))

(defun isn (a b)
  (< (cdr (assoc a ivy-sorter-data)) (cdr (assoc b ivy-sorter-data))))

(add-to-list 'ivy-sort-functions-alist '(ivy-sorter . isn))

(defun ivy-sorter (&rest args) (mapcar 'car ivy-sorter-data))

(ivy-read "string: " 'ivy-sorter
      :sort t)
#+END_SRC

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions