I would like to programmatically call an ivy or counsel function and then immediately execute
ivy-occur to get the ivy-occur buffer.
Instead of doing
M-x counsel-describe-function and
C-c C-o manually to get the ivy-occur buffer I would to do this with a function.
Tried the following (the last three solution work but there has to be a better way):
Works for some (counsel-M-x) but most commands give me an ivy-occur buffer with 0 candidates. So this is probably called too early:
(unwind-protect (progn (add-hook 'minibuffer-setup-hook #'ivy-occur) (ignore-errors (counsel-faces))) (remove-hook 'minibuffer-setup-hook #'ivy-occur))
Same problem as with the hook.
(ignore-errors (minibuffer-with-setup-hook (:append #'ivy-occur) (counsel-faces)))
This actually works, but there has to be a better way to do this. This just simulates the keys pressed:
(execute-kbd-macro (kbd "M-x counsel-faces RET C-c C-o")) ;; Can even change the initial input like this (`ivy-`). (execute-kbd-macro (kbd "M-x counsel-faces RET ivy- C-c C-o"))
This works as well but is sort of strange too. Not even sure if this might be run before calling
counsel-faces in some cases.
(progn (run-with-idle-timer 0.01 nil #'ivy-occur) (counsel-faces))
Found this in the question Clean way to perform commands in the Emacs minibuffer. But this also feels akward.
(progn (setq unread-command-events (append (listify-key-sequence (kbd "C-c C-o")) unread-command-events)) (counsel-faces))
Thanks for any solution or a hint on how to do this properly.