completion/ivy: add ivy-rich; rewrite custom transformer #331
+ivy-buffer-transformer does *most* of what ivy-rich does, so lets cut down on our own code, bring in ivy-rich, and add our customizations on top of it. This fixes ivy-use-virtual-buffers support, too.
This commit is contained in:
parent
35594f0729
commit
1c2683ce9d
3 changed files with 51 additions and 36 deletions
|
@ -1,36 +1,42 @@
|
|||
;;; completion/ivy/autoload/ivy.el -*- lexical-binding: t; -*-
|
||||
;;; completion/ivy/autoload/ivy.el -*- lexical-binding: nil; -*-
|
||||
|
||||
(defsubst +ivy--icon-for-mode (mode)
|
||||
"Apply `all-the-icons-for-mode' on MODE but either return an icon or nil."
|
||||
(let ((icon (all-the-icons-icon-for-mode mode)))
|
||||
(unless (symbolp icon) icon)))
|
||||
(defun +ivy--is-workspace-or-other-buffer-p (buffer)
|
||||
(let ((buffer (car buffer)))
|
||||
(when (stringp buffer)
|
||||
(setq buffer (get-buffer buffer)))
|
||||
(and (not (eq buffer (current-buffer)))
|
||||
(+workspace-contains-buffer-p buffer))))
|
||||
|
||||
|
||||
;;
|
||||
;; Library
|
||||
;;
|
||||
|
||||
;;;###autoload
|
||||
(defun +ivy-buffer-transformer (str)
|
||||
(let* ((buf (get-buffer str))
|
||||
(path (buffer-file-name buf))
|
||||
(mode (buffer-local-value 'major-mode buf))
|
||||
(faces
|
||||
(let ((buf (get-buffer str))
|
||||
(project-root (doom-project-root)))
|
||||
(require 'ivy-rich)
|
||||
(cond (buf
|
||||
(with-current-buffer buf
|
||||
(let* ((indicator (ivy-rich-switch-buffer-indicators))
|
||||
(size (ivy-rich-switch-buffer-size))
|
||||
(buf-name (ivy-rich-switch-buffer-buffer-name))
|
||||
(mode (ivy-rich-switch-buffer-major-mode))
|
||||
(project (ivy-rich-switch-buffer-project))
|
||||
(path (ivy-rich-switch-buffer-path project)))
|
||||
(cond ((string-match-p "^ ?\\*" (buffer-name buf))
|
||||
'font-lock-comment-face)
|
||||
((buffer-modified-p buf)
|
||||
'doom-modeline-buffer-modified)
|
||||
(buffer-read-only
|
||||
'error)))))
|
||||
(propertize
|
||||
(format "%-40s %s%-20s %s"
|
||||
str
|
||||
(if +ivy-buffer-icons
|
||||
(concat (propertize " " 'display
|
||||
(or (+ivy--icon-for-mode mode)
|
||||
(+ivy--icon-for-mode (get mode 'derived-mode-parent))))
|
||||
"\t")
|
||||
"")
|
||||
mode
|
||||
(or (and path (abbreviate-file-name (file-name-directory (file-truename path))))
|
||||
""))
|
||||
'face faces)))
|
||||
(setq buf-name (propertize buf-name 'face 'font-lock-comment-face)))
|
||||
((and buffer-file-name
|
||||
(not (file-in-directory-p (buffer-file-name buf) project-root)))
|
||||
(setq buf-name (propertize buf-name 'face 'ivy-remote))))
|
||||
(ivy-rich-switch-buffer-format (list buf-name size indicator mode project path)))))
|
||||
((and (eq ivy-virtual-abbreviate 'full)
|
||||
ivy-rich-switch-buffer-align-virtual-buffer)
|
||||
(ivy-rich-switch-buffer-virtual-buffer))
|
||||
((eq ivy-virtual-abbreviate 'full)
|
||||
(propertize (abbreviate-file-name str) 'str 'ivy-virtual))
|
||||
(t (propertize str 'face 'ivy-virtual)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +ivy/switch-workspace-buffer (&optional arg)
|
||||
|
|
|
@ -38,7 +38,11 @@ immediately runs it on the current candidate (ending the ivy session)."
|
|||
;; highlight til EOL
|
||||
ivy-format-function #'ivy-format-function-line
|
||||
;; disable magic slash on non-match
|
||||
ivy-magic-slash-non-match-action nil)
|
||||
ivy-magic-slash-non-match-action nil
|
||||
;; don't show recent files in switch-buffer
|
||||
ivy-use-virtual-buffers nil
|
||||
;; ...but if that ever changes, show their full path
|
||||
ivy-virtual-abbreviate 'full)
|
||||
|
||||
(after! magit (setq magit-completing-read-function #'ivy-completing-read))
|
||||
(after! yasnippet (push #'+ivy-yas-prompt yas-prompt-functions))
|
||||
|
@ -57,12 +61,6 @@ immediately runs it on the current candidate (ending the ivy session)."
|
|||
[remap describe-function] #'counsel-describe-function
|
||||
[remap describe-variable] #'counsel-describe-variable)
|
||||
|
||||
;; Show more buffer information in switch-buffer commands
|
||||
(ivy-set-display-transformer #'ivy-switch-buffer #'+ivy-buffer-transformer)
|
||||
(ivy-set-display-transformer #'ivy-switch-buffer-other-window #'+ivy-buffer-transformer)
|
||||
(ivy-set-display-transformer #'+ivy/switch-workspace-buffer #'+ivy-buffer-transformer)
|
||||
(ivy-set-display-transformer #'counsel-recentf #'abbreviate-file-name)
|
||||
|
||||
(nconc ivy-sort-functions-alist
|
||||
'((persp-kill-buffer . nil)
|
||||
(persp-remove-buffer . nil)
|
||||
|
@ -74,12 +72,22 @@ immediately runs it on the current candidate (ending the ivy session)."
|
|||
(+workspace/delete . nil))))
|
||||
|
||||
|
||||
;; Show more buffer information in switch-buffer commands
|
||||
(def-package! ivy-rich
|
||||
:after ivy
|
||||
:config
|
||||
(dolist (cmd '(ivy-switch-buffer +ivy/switch-workspace-buffer))
|
||||
(ivy-set-display-transformer cmd '+ivy-buffer-transformer)))
|
||||
|
||||
|
||||
(def-package! swiper :commands (swiper swiper-all))
|
||||
|
||||
|
||||
(def-package! counsel
|
||||
:requires ivy
|
||||
:config
|
||||
(ivy-set-display-transformer #'counsel-recentf #'abbreviate-file-name)
|
||||
|
||||
(require 'counsel-projectile)
|
||||
(setq counsel-find-file-ignore-regexp "\\(?:^[#.]\\)\\|\\(?:[#~]$\\)\\|\\(?:^Icon?\\)")
|
||||
|
||||
|
|
|
@ -7,3 +7,4 @@
|
|||
(package! smex)
|
||||
(package! swiper)
|
||||
(package! ivy-hydra)
|
||||
(package! ivy-rich)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue