Emacs: Rewrite icons-in-buffer-switcher thing.

This commit is contained in:
tastytea 2020-02-06 20:13:30 +01:00
parent 7983b8000d
commit f1f134c40f
1 changed files with 20 additions and 54 deletions

View File

@ -1,6 +1,6 @@
;;; ui.el --- Configure user interfaces. -*- lexical-binding: t; -*-
;; Time-stamp: <2020-02-03T06:37:56+0100>
;; Time-stamp: <2020-02-06T20:12:39+0100>
;;; Commentary:
;; * treemacs
@ -83,7 +83,8 @@
:functions (ivy-format-function-line)
:config
(defun ivy-rich-switch-buffer-icon (candidate)
(defun my/ivy-rich-switch-buffer-icon (candidate)
"Return icon for `candidate'."
(with-current-buffer
(get-buffer candidate)
(let ((icon (all-the-icons-icon-for-mode major-mode)))
@ -91,60 +92,25 @@
(all-the-icons-icon-for-mode 'fundamental-mode)
icon))))
;; Add icons to buffer switcher.
;; <https://github.com/Yevgnen/ivy-rich/issues/37#issuecomment-583033211>
(setq ivy-rich-display-transformers-list
(plist-put ivy-rich-display-transformers-list 'ivy-switch-buffer
'(:columns
((my/ivy-rich-switch-buffer-icon (:width 1))
(ivy-rich-candidate (:width 0.25))
(ivy-rich-switch-buffer-size (:width 0.05 :face font-lock-comment-face))
(ivy-rich-switch-buffer-indicators (:width 0.05 :face error :align right))
(ivy-rich-switch-buffer-major-mode (:width 0.1 :face font-lock-function-name-face))
(ivy-rich-switch-buffer-project (:width 0.15 :face success))
(ivy-rich-switch-buffer-path (:width (lambda (x) (ivy-rich-switch-buffer-shorten-path x (ivy-rich-minibuffer-width 0.4))) :face font-lock-keyword-face)))
:predicate
(lambda (cand) (get-buffer cand))
:delimiter "\t"
)))
(ivy-rich-mode 1)
(setcdr (assq t ivy-format-functions-alist) #'ivy-format-function-line)
:custom
;; It seems I have to copy this whole list to get icons in switch-buffer.
(ivy-rich-display-transformers-list
(quote
(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-M-x
(:columns
((counsel-M-x-transformer
(:width 40))
(ivy-rich-counsel-function-docstring
(:face font-lock-doc-face))))
counsel-describe-function
(:columns
((counsel-describe-function-transformer
(:width 40))
(ivy-rich-counsel-function-docstring
(:face font-lock-doc-face))))
counsel-describe-variable
(:columns
((counsel-describe-variable-transformer
(:width 40))
(ivy-rich-counsel-variable-docstring
(:face font-lock-doc-face))))
counsel-recentf
(:columns
((ivy-rich-candidate
(:width 0.8))
(ivy-rich-file-last-modified-time
(:face font-lock-comment-face)))))))
)
(use-package ivy-purpose