Yevgnen/ivy-rich

ivy-rich only works if i deactivate and activate it again

gugutz opened this issue · 2 comments

I read in the docs that after modifying ivy-rich--display-transformers-list to my liking, i had to call ivy-rich-mode again

So what i did was i made my customizations in the :init part of the use-package declaration, and called ivy-rich-mode 1 in the :config part.

But still ivy-rich only really applies my modifications after i call it a second time after emacs starts.

Does anyone have an idea of why this might be happening? I tried using with-eval-after-load, eval-when-compile and after ivy and nothing seems to work.

Here is my current use-package declaration

(use-package ivy-rich
  :after ivy
  :preface
  ;; use all-the-icons for `ivy-switch-buffer'
  (defun ivy-rich-switch-buffer-icon (candidate)
    (with-current-buffer
      (get-buffer candidate)
      (let ((icon (all-the-icons-icon-for-mode major-mode)))
        (if (symbolp icon)
          (all-the-icons-icon-for-mode 'fundamental-mode)
          icon))))
  :init
  (setq ivy-rich--original-display-transformers-list nil)  ;; needs to be set otherwise (ivy-rich-set-display-transformer) does not get called

  ;; To abbreviate paths using abbreviate-file-name (e.g. replace “/home/username” with “~”)
  (setq ivy-rich-path-style 'abbrev)

  (setq ivy-rich--display-transformers-list
    '(ivy-switch-buffer
       (:columns
         ((ivy-rich-switch-buffer-icon (:width 2))
           (ivy-rich-candidate (:width 30))
           (ivy-rich-switch-buffer-size (:width 7))
           (ivy-rich-switch-buffer-indicators (:width 4 :face error :align right))
           (ivy-rich-switch-buffer-major-mode (:width 12 :face warning))
           (ivy-rich-switch-buffer-project (:width 15 :face success))
           (ivy-rich-switch-buffer-path (:width (lambda (x) (ivy-rich-switch-buffer-shorten-path x (ivy-rich-minibuffer-width 0.3))))))
         :predicate
         (lambda (cand) (get-buffer cand)))
       counsel-find-file
       (:columns
         ((ivy-read-file-transformer)
           (ivy-rich-counsel-find-file-truename (:face font-lock-doc-face))))
       counsel-M-x
       (:columns
         ((counsel-M-x-transformer (:width 35))
           (ivy-rich-counsel-function-docstring (:width 34 :face font-lock-doc-face))))
       counsel-describe-function
       (:columns
         ((counsel-describe-function-transformer (:width 35))
           (ivy-rich-counsel-function-docstring (:width 34 :face font-lock-doc-face))))
       counsel-describe-variable
       (:columns
         ((counsel-describe-variable-transformer (:width 35))
           (ivy-rich-counsel-variable-docstring (:width 34 :face font-lock-doc-face))))
       package-install
       (:columns
         ((ivy-rich-candidate (:width 25))
           (ivy-rich-package-version (:width 12 :face font-lock-comment-face))
           (ivy-rich-package-archive-summary (:width 7 :face font-lock-builtin-face))
           (ivy-rich-package-install-summary (:width 23 :face font-lock-doc-face))))
       counsel-projectile-find-file
       (:columns
         ((ivy-rich-switch-buffer-icon (:width 2))
           (ivy-rich-candidate (:width 30))
           (ivy-rich-switch-buffer-size (:width 7))
           (ivy-rich-switch-buffer-indicators (:width 4 :face error :align right))
           (ivy-rich-switch-buffer-major-mode (:width 12 :face warning))
           (ivy-rich-switch-buffer-project (:width 15 :face success))
           (ivy-rich-switch-buffer-path (:width (lambda (x) (ivy-rich-switch-buffer-shorten-path x (ivy-rich-minibuffer-width 0.3))))))
         :predicate
         (lambda (cand) (get-buffer cand)))
       )
    )
  ;; ivy-rich-mode needs to be called after `ivy-rich--display-transformers-list' is changed
  :config
  (ivy-rich-mode 1)
  )

Thanks in advance!

Here are my suggestions:

  1. Update to the latest version of ivy-rich, and you should change ivy-rich--display-transformers-list to ivy-rich-display-transformers-list since the former has been deprecated.

  2. Remove line (setq ivy-rich--original-display-transformers-list nil).

  3. If you have set use-package-always-defer to t, you will need to add :demand t to the (use-package ivy-rich ...) call, or use :hook, :bind keywords to specify how the package should be loaded. See also the NOTE part of this.

Feel free to reopen if the issue is not fixed.