.emacs.d/init.d/basics/ui.el

161 lines
4.6 KiB
EmacsLisp

;;; ui.el --- Configure user interfaces. -*- lexical-binding: t; -*-
;; Time-stamp: <2020-02-11T17:45:47+0100>
;;; Commentary:
;; * treemacs
;; * ivy + counsel.
;;; Code:
;; Directory tree.
(use-package treemacs
:pin melpa ; We need > 2.6 for lsp-treemacs.
:demand t
:after (display-line-numbers)
:custom
(treemacs-project-follow-cleanup t) ; Collapse projects when leaving.
(treemacs-silent-refresh t) ; No log message on refresh.
:bind
("<f8>" . treemacs-select-window) ; Focus treemacs.
("C-<f8>" . treemacs) ; Toggle treemacs.
("M-<f8>" . treemacs-add-and-display-current-project) ; Add current project.
(:map treemacs-mode-map
("<mouse-1>" . treemacs-single-click-expand-action))
:hook
(treemacs-mode . my/disable-line-numbers)
)
(use-package treemacs-projectile
:after (treemacs projectile)
)
(use-package treemacs-magit
:after (treemacs magit)
)
;; Completion in many Emacs commands.
(use-package ivy
:demand t
:diminish ivy-mode
:custom
(ivy-use-virtual-buffers t)
(ivy-count-format "[%d/%d] ")
(ivy-wrap t)
:config
(ivy-mode 1)
:bind
("C-c C-r" . ivy-resume)
(:map ivy-minibuffer-map
("M-<up>" . ivy-previous-history-element)
("M-<down>" . ivy-next-history-element)
("S-<return>" . ivy-immediate-done) ; Ignore completion.
)
)
;; Extensions for ivy
(use-package counsel
:after (ivy)
:demand t
:bind
("C-x C-f" . counsel-find-file)
("M-x" . counsel-M-x)
)
;; Use icons in ivy.
(use-package all-the-icons-ivy
:after (all-the-icons counsel)
:config
(all-the-icons-ivy-setup)
)
;; More information in ivy mini-buffers.
(use-package ivy-rich
;; all-the-icons-ivy would override the ivy-rich switch-buffer improvements.
:after (all-the-icons-ivy counsel)
:functions (ivy-format-function-line)
:config
(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)))
(if (symbolp icon)
(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)
)
(use-package ivy-purpose
:after (window-purpose)
:config
(ivy-purpose-setup)
:bind
(:map purpose-mode-map
("C-x b" . ivy-switch-buffer)
;; ("C-x b" . ivy-purpose-switch-buffer-without-purpose)
)
)
(use-package counsel-projectile
:after (projectile)
:custom
(counsel-projectile-mode t) ; Turn on projectile-mode and enable keybindings.
)
;; Switch between named persistent window configurations.
(when (>= emacs-major-version 27)
(use-package tab-bar
:bind
("C-<prior>" . tab-bar-switch-to-prev-tab)
("C-<next>" . tab-bar-switch-to-next-tab)
))
;; Shows tabs of all visible buffers per window.
(when (>= emacs-major-version 27)
(use-package tab-line
:custom-face
(tab-line ((t (:inherit ruler-mode-default))))
(tab-line-tab ((t (:inherit ruler-mode-default))))
(tab-line-tab-inactive ((t (:inherit tab-line-tab))))
(tab-line-tab-current ((t (:inherit tab-line-tab
:background "grey10"
:foreground "grey70"))))
(tab-line-highlight ((t (:inherit tab-line-tab-current
:foreground "white"))))
))
(provide 'basics/ui)
;;; ui.el ends here