]> code.delx.au - gnu-emacs-elpa/commitdiff
Make ivy-set-sources work also for sync completion
authorOleh Krehel <ohwoeowho@gmail.com>
Wed, 30 Mar 2016 04:47:43 +0000 (06:47 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Wed, 30 Mar 2016 04:47:43 +0000 (06:47 +0200)
Here's a contrived example of how to use it:

    (defun my-extra-source ()
      (append
       (when (eq 'Git (vc-backend (buffer-file-name)))
         (list "git1" "git2" "git3"))
       (when (file-exists-p "doc/Changelog.org")
         (list (propertize "doc/Changelog.org" 'face '(:background "red"))))))

    (defun my-find-file ()
      (interactive)
      (ivy-read "Find file: " 'read-file-name-internal
                :action (lambda (x)
                          (with-ivy-window
                            (find-file (expand-file-name x ivy--directory))))
                :require-match 'confirm-after-completion
                :history 'file-name-history
                :caller 'my-find-file))

    (ivy-set-sources
     'my-find-file
     '((my-extra-source)
       (original-source)))

The function `my-find-file' knows nothing about the extra source, it's
only purpose is to introduce a :caller to attach things to, as to not to
mess up e.g. `counsel-find-file'.

The function `my-extra-source' gets called once in `ivy-read' via
`ivy--reset-state'. It takes no args and returns a list of strings,
possibly empty.

ivy.el

diff --git a/ivy.el b/ivy.el
index bd5e276254a3284f94c74652ec09552b6cfc5a73..964a94757916a076cebb1d8ede6eb94e71de56d9 100644 (file)
--- a/ivy.el
+++ b/ivy.el
@@ -1429,6 +1429,7 @@ This is useful for recursive `ivy-read'."
             (if (and (setq sort-fn (cdr (assoc t ivy-sort-functions-alist)))
                      (<= (length coll) ivy-sort-max-size))
                 (setq coll (cl-sort (copy-sequence coll) sort-fn))))))
+      (setq coll (ivy--set-candidates coll))
       (when preselect
         (unless (or (and require-match
                          (not (eq collection 'internal-complete-buffer)))