completion/ivy: update ivy-rich integration

And remove unused/defunct code. Also fixes a `file-in-directory-p: Wrong
type argument: stringp, nil` error when invoking counsel-recentf.
This commit is contained in:
Henrik Lissner 2018-10-17 14:34:43 -04:00
parent 11793be240
commit c6c3054fbb
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 23 additions and 45 deletions

View file

@ -7,52 +7,27 @@
(and (not (eq buffer (current-buffer))) (and (not (eq buffer (current-buffer)))
(+workspace-contains-buffer-p buffer)))) (+workspace-contains-buffer-p buffer))))
(defun +ivy*rich-switch-buffer-buffer-name (str) ;;;###autoload
(propertize (defun +ivy-rich-buffer-name (candidate)
(ivy-rich-pad str ivy-rich-switch-buffer-name-max-length) "Display the buffer name.
'face (cond ((string-match-p "^ *\\*" str)
Displays buffers in other projects in `font-lock-doc-face', and
temporary/special buffers in `font-lock-comment-face'."
(with-current-buffer (get-buffer candidate)
(propertize candidate
'face (cond ((string-match-p "^ *\\*" candidate)
'font-lock-comment-face) 'font-lock-comment-face)
((and buffer-file-truename ((not buffer-file-name) nil)
(not (file-in-directory-p buffer-file-truename (doom-project-root)))) ((not (file-in-directory-p
'font-lock-doc-face) buffer-file-name
(t nil)))) (or (doom-project-root)
(advice-add 'ivy-rich-switch-buffer-buffer-name :override #'+ivy*rich-switch-buffer-buffer-name) default-directory)))
'font-lock-doc-face)))))
;; ;;
;; Library ;; Library
;;;###autoload
(defun +ivy-projectile-find-file-transformer (str)
"Highlight entries that have been visited. This is the opposite of
`counsel-projectile-find-file'."
(cond ((get-file-buffer (projectile-expand-root str))
(propertize str 'face '(:weight ultra-bold :slant italic)))
(t str)))
;;;###autoload
(defun +ivy-recentf-transformer (str)
"Dim recentf entries that are not in the current project of the buffer you
started `counsel-recentf' from. Also uses `abbreviate-file-name'."
(let ((str (abbreviate-file-name str)))
(if (file-in-directory-p str (doom-project-root))
str
(propertize str 'face 'ivy-virtual))))
;;;###autoload
(defun +ivy-buffer-transformer (str)
"Dim special buffers, buffers whose file aren't in the current buffer, and
virtual buffers. Uses `ivy-rich' under the hood."
(let ((buf (get-buffer str)))
(require 'ivy-rich)
(cond (buf (ivy-rich-switch-buffer-transformer str))
((and (eq ivy-virtual-abbreviate 'full)
ivy-rich-switch-buffer-align-virtual-buffer)
(ivy-rich-switch-buffer-virtual-buffer str))
((eq ivy-virtual-abbreviate 'full)
(propertize (abbreviate-file-name str) 'str 'ivy-virtual))
(t (propertize str 'face 'ivy-virtual)))))
;;;###autoload ;;;###autoload
(defun +ivy/switch-workspace-buffer (&optional arg) (defun +ivy/switch-workspace-buffer (&optional arg)
"Switch to another buffer within the current workspace. "Switch to another buffer within the current workspace.

View file

@ -79,7 +79,13 @@ immediately runs it on the current candidate (ending the ivy session)."
;; Show more buffer information in other switch-buffer commands too ;; Show more buffer information in other switch-buffer commands too
(dolist (cmd '(+ivy/switch-workspace-buffer (dolist (cmd '(+ivy/switch-workspace-buffer
counsel-projectile-switch-to-buffer)) counsel-projectile-switch-to-buffer))
(ivy-set-display-transformer cmd 'ivy-rich--ivy-switch-buffer-transformer))) (ivy-set-display-transformer cmd 'ivy-rich--ivy-switch-buffer-transformer))
;; Use `+ivy-rich-buffer-name' to display buffer names
(let* ((plist (plist-get ivy-rich--display-transformers-list 'ivy-switch-buffer))
(colplist (plist-get plist :columns))
(switch-buffer-alist (assq 'ivy-rich-candidate colplist)))
(when switch-buffer-alist
(setcar switch-buffer-alist '+ivy-rich-buffer-name))))
(def-package! counsel (def-package! counsel
@ -114,9 +120,6 @@ immediately runs it on the current candidate (ending the ivy session)."
(add-to-list 'swiper-font-lock-exclude #'+doom-dashboard-mode nil #'eq) (add-to-list 'swiper-font-lock-exclude #'+doom-dashboard-mode nil #'eq)
;; Dim recentf entries that are not in the current project.
(ivy-set-display-transformer #'counsel-recentf #'+ivy-recentf-transformer)
;; Factories ;; Factories
(defun +ivy-action-reloading (cmd) (defun +ivy-action-reloading (cmd)
(lambda (x) (lambda (x)