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

130 lines
4.3 KiB
EmacsLisp

;;; ui.el --- Configure user interfaces. -*- lexical-binding: t; -*-
;; Time-stamp: <2020-11-29T15:49:11+0100>
;;; Commentary:
;; * treemacs
;; * ivy + counsel.
;;; Code:
;; Directory tree.
(require 'basics/package-management)
(use-package treemacs
:after (display-line-numbers doom-themes hl-line)
:commands (my/treemacs-show-maybe)
:custom ((treemacs-project-follow-cleanup t) ; Collapse projects when leaving.
(treemacs-silent-refresh t)) ; No log message on refresh.
:config (progn
;; (treemacs-tag-follow-mode)
(make-face 'hl-line-treemacs-face)
(set-face-attribute 'hl-line-treemacs-face nil
:background "#080011")
(when (>= emacs-major-version 27)
(set-face-attribute 'hl-line-treemacs-face nil
:extend t))
(defun my/treemacs-set-hl-line ()
(set (make-local-variable 'hl-line-face)
'hl-line-treemacs-face))
(defun my/treemacs-show-maybe ()
(when (and (>= (frame-width) 120)
(file-exists-p treemacs-persist-file)
(<= (length (frame-list)) 2))
(treemacs-select-window)
(other-window 1))))
:bind (("<f9>" . treemacs-select-window) ; Focus treemacs.
("C-<f9>" . treemacs) ; Toggle treemacs.
("M-<f9>" . treemacs-add-and-display-current-project)
(:map treemacs-mode-map
("<mouse-1>" . treemacs-single-click-expand-action)))
:hook ((treemacs-mode . my/disable-line-numbers)
(treemacs-mode . my/treemacs-set-hl-line)
(after-init . (lambda () (when (display-graphic-p)
(my/treemacs-show-maybe))))
(server-after-make-frame . my/treemacs-show-maybe)))
(use-package treemacs-projectile
:demand t
:after (treemacs projectile))
(use-package treemacs-magit
:demand t
: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
:demand t
:after (ivy imenu)
:bind (("C-x C-f" . counsel-find-file)
("M-x" . counsel-M-x)
("M-i" . counsel-imenu)))
;; More information in ivy mini-buffers.
(use-package ivy-rich
:demand t
:after (counsel)
:config (ivy-rich-mode 1))
;; Use icons in ivy-rich.
(use-package all-the-icons-ivy-rich
:demand t
:after (all-the-icons ivy-rich)
:config (all-the-icons-ivy-rich-mode 1))
(use-package ivy-purpose
:after (window-purpose)
:config (ivy-purpose-setup)
:bind (:map purpose-mode-map
("C-x b" . ivy-switch-buffer)))
(use-package ivy-emoji ; Insert emojis with ivy.
:after (ivy)
:bind ("C-c e" . ivy-emoji))
(use-package counsel-projectile
:demand t
:after (projectile)
:config (progn
;; I'm not exactly sure what I did here but it seems to work.
(defun my/counsel-projectile-switch-project-action (project)
"Call `my/switch-project'."
(let ((projectile-switch-project-action 'my/switch-project))
(counsel-projectile-switch-project-by-name project)))
(counsel-projectile-modify-action
'counsel-projectile-switch-project-action
'((add ("Y" my/counsel-projectile-switch-project-action
"open project in treemacs") 1)))
;; Overwrite keybindings and so on.
(counsel-projectile-mode)))
;; Shows tabs of all visible buffers per window.
(when (>= emacs-major-version 27)
(use-package tab-line
:defer 4
: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 ruler-mode-fill-column))))
(tab-line-highlight ((t (:inherit tab-line-tab-current))))))
(provide 'basics/ui)
;;; ui.el ends here