Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transformer does not get applied when calling the command from elisp code #114

Open
mihaiolteanu opened this issue Jan 28, 2022 · 0 comments

Comments

@mihaiolteanu
Copy link

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,
Jan28-133434

The results when calling eshell/install directly, from elisp code,
Jan28-133503

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant