Transformer does not get applied when calling the command from elisp code
mihaiolteanu opened this issue · 0 comments
I've defined my own command using ivy-read and added ivy-rich transformers to it. When calling it interactively it works as expected, but when called directly from elisp code the transformers do not get applied.
A command to install packages using pacman,
(defun eshell/install (&optional item)
(interactive)
(ivy-read
"Package: "
(mapcar (lambda (strings) (s-join " | " strings))
(-partition 2 (s-lines (shell-command-to-string "pacman -Ss \"\""))))
:initial-input item
:action (lambda (choice)
(with-current-buffer
;; If not in an eshell buffer, create one and switch to it.
(or (and (buffer-mode-p (buffer-name) 'eshell-mode)
(buffer-name))
(open-eshell-in-eshells-tab-here))
(insert "sudo pacman -S ")
(insert (car (s-split " " (-second-item (s-split "/" choice)))))
(funcall 'eshell-send-input)))))
The transformers to display the package name, version and info,
(defun eshell/install-package-transformer (entry)
(-second-item (s-split "/" (-first-item (s-split " " entry)))))
(defun eshell/install-version-transformer (entry)
(-second-item (s-split " " entry)))
(defun eshell/install-package-docstring-transformer (entry)
(-last-item (s-split "|" entry)))
Setting up the transformers for the above command,
(ivy-rich-set-columns
'eshell/install
`((eshell/install-package-transformer
(:width 0.10))
(eshell/install-version-transformer
(:width 0.06 :face window-divider :box (:line-width 2 :color "PowderBlue" :style 1)))
(eshell/install-package-docstring-transformer
(:width 100 :face window-divider :box (:line-width 2 :color "PowderBlue" :style 1)))))
The results when calling eshell/install
interactively,
The results when calling eshell/install
directly, from elisp code,
In the first instance the transformers take effect, in the second not. This bad behavior does not happen with the default enriched commands, like counsel-describe-function
and the like so I assume it is my fault. I did look at the other commands, like the already mentioned counsel-describe-function
, for example, to figure out how to implement my own, so maybe I've missed some details in the process?