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.
(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)))