diff --git a/modules/completion/ivy/autoload/ivy.el b/modules/completion/ivy/autoload/ivy.el index aba051707..49ec0e9fd 100644 --- a/modules/completion/ivy/autoload/ivy.el +++ b/modules/completion/ivy/autoload/ivy.el @@ -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 - (with-current-buffer buf - (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))) + (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)) + (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) diff --git a/modules/completion/ivy/config.el b/modules/completion/ivy/config.el index d860a3a57..a9bc09ee9 100644 --- a/modules/completion/ivy/config.el +++ b/modules/completion/ivy/config.el @@ -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?\\)") diff --git a/modules/completion/ivy/packages.el b/modules/completion/ivy/packages.el index 8ec066214..9777d1000 100644 --- a/modules/completion/ivy/packages.el +++ b/modules/completion/ivy/packages.el @@ -7,3 +7,4 @@ (package! smex) (package! swiper) (package! ivy-hydra) +(package! ivy-rich)