From 6ae91f76f4ac653eaecc3765b917bbd181ef3f0d Mon Sep 17 00:00:00 2001 From: Oleh Krehel Date: Wed, 30 Mar 2016 06:47:43 +0200 Subject: [PATCH] Make ivy-set-sources work also for sync completion 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 | 1 + 1 file changed, 1 insertion(+) diff --git a/ivy.el b/ivy.el index bd5e27625..964a94757 100644 --- 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))) -- 2.39.2