forked from doomemacs/themes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doom-themes-ext-treemacs.el
285 lines (250 loc) · 12.7 KB
/
doom-themes-ext-treemacs.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
;;; doom-themes-ext-treemacs.el --- description -*- lexical-binding: t; no-byte-compile: t -*-
(defgroup doom-themes-treemacs nil
"Options for doom's treemacs theme"
:group 'doom-themes)
;;
;;; Variables
(defcustom doom-themes-treemacs-enable-variable-pitch t
"If non-nil, the labels for files, folders and projects are displayed with the
variable-pitch face."
:type 'boolean
:group 'doom-themes-treemacs)
(defcustom doom-themes-treemacs-line-spacing 1
"Line-spacing for treemacs buffer."
:type 'integer
:group 'doom-themes-treemacs)
(defcustom doom-themes-treemacs-theme "doom-atom"
"Default treemacs theme."
:type '(radio (const :doc "A minimalistic atom-inspired icon theme" "doom-atom")
(const :doc "A colorful icon theme leveraging all-the-icons" "doom-colors"))
:group 'doom-themes-treemacs)
(defcustom doom-themes-treemacs-bitmap-indicator-width 3
"Default treemacs bitmap indicators width"
:type 'integer
:group 'doom-themes-treemacs)
;;
;;; Faces
(defface doom-themes-treemacs-root-face
'((t (:inherit font-lock-string-face)))
"Face used for the root icon in doom themes' treemacs theme."
:group 'doom-themes-treemacs)
(defface doom-themes-treemacs-file-face
'((t (:inherit font-lock-doc-face :slant normal)))
"Face used for the directory and file icons in doom themes' treemacs theme."
:group 'doom-themes-treemacs)
;;
;;; Library
(defun doom-themes-hide-fringes-maybe ()
"Remove fringes in current window if `treemacs-fringe-indicator-mode' is nil"
(when (display-graphic-p)
(if treemacs-fringe-indicator-mode
(set-window-fringes nil doom-themes-treemacs-bitmap-indicator-width 0)
(set-window-fringes nil 0 0))))
(defun doom-themes-setup-tab-width (&rest _)
"Set `tab-width' to 1, so tab characters don't ruin formatting."
(setq tab-width 1))
(defun doom-themes-define-treemacs-fringe-indicator-bitmap ()
"Defines `treemacs--fringe-indicator-bitmap'"
(if (fboundp 'define-fringe-bitmap)
(define-fringe-bitmap 'treemacs--fringe-indicator-bitmap
(make-vector 26 #b111) nil doom-themes-treemacs-bitmap-indicator-width)))
(defun doom-themes-setup-line-spacing ()
"Set `line-spacing' in treemacs buffers."
(setq line-spacing doom-themes-treemacs-line-spacing))
(defun doom-themes-hide-modeline ()
(setq mode-line-format nil))
(defun doom-themes-enable-treemacs-variable-pitch-labels (&rest _)
(when doom-themes-treemacs-enable-variable-pitch
(dolist (face '(treemacs-root-face
treemacs-git-unmodified-face
treemacs-git-modified-face
treemacs-git-renamed-face
treemacs-git-ignored-face
treemacs-git-untracked-face
treemacs-git-added-face
treemacs-git-conflict-face
treemacs-directory-face
treemacs-directory-collapsed-face
treemacs-file-face
treemacs-tags-face))
(let ((faces (face-attribute face :inherit nil)))
(set-face-attribute
face nil :inherit
`(variable-pitch ,@(delq 'unspecified (if (listp faces) faces (list faces)))))))))
(defun doom-themes-fix-treemacs-icons-dired-mode ()
"Set `tab-width' to 1 in dired-mode if `treemacs-icons-dired-mode' is active."
(funcall (if treemacs-icons-dired-mode #'add-hook #'remove-hook)
'dired-mode-hook
#'doom-themes-setup-tab-width))
(defun doom-themes--get-treemacs-extensions (ext)
"Expand the extension pattern EXT into a list of extensions.
This is used to generate extensions for `treemacs' from `all-the-icons-icon-alist'."
(let* ((e (s-replace-all
'((".\\?" . "") ("\\?" . "") ("\\." . "")
("\\" . "") ("^" . "") ("$" . "")
("'" . "") ("*." . "") ("*" . ""))
ext))
(exts (list e)))
;; Handle "[]"
(when-let* ((s (s-split "\\[\\|\\]" e))
(f (car s))
(m (cadr s))
(l (cadr (cdr s)))
(mcs (delete "" (s-split "" m))))
(setq exts nil)
(dolist (c mcs)
(push (s-concat f c l) exts)))
;; Handle '?
(dolist (ext exts)
(when (s-match "?" ext)
(when-let ((s (s-split "?" ext)))
(setq exts nil)
(push (s-join "" s) exts)
(push (s-concat (if (> (length (car s)) 1)
(substring (car s) 0 -1))
(cadr s)) exts))))
exts))
;;
;;; Bootstrap
(with-eval-after-load 'treemacs
(unless (require 'all-the-icons nil t)
(error "all-the-icons isn't installed"))
(add-hook 'treemacs-mode-hook #'doom-themes-setup-tab-width)
(add-hook 'treemacs-mode-hook #'doom-themes-setup-line-spacing)
(add-hook 'treemacs-mode-hook #'doom-themes-define-treemacs-fringe-indicator-bitmap)
;; Fix #293: tabs messing up formatting in `treemacs-icons-dired-mode'
(add-hook 'treemacs-icons-dired-mode-hook #'doom-themes-fix-treemacs-icons-dired-mode)
;; The modeline isn't useful in treemacs
(add-hook 'treemacs-mode-hook #'doom-themes-hide-modeline)
;; Disable fringes (and reset them everytime treemacs is selected because it
;; may change due to outside factors)
(add-hook 'treemacs-mode-hook #'doom-themes-hide-fringes-maybe)
(advice-add #'treemacs-select-window :after #'doom-themes-hide-fringes-maybe)
;; variable-pitch labels for files/folders
(doom-themes-enable-treemacs-variable-pitch-labels)
(advice-add #'load-theme :after #'doom-themes-enable-treemacs-variable-pitch-labels)
;; minimalistic atom-inspired icon theme
(let ((face-spec 'doom-themes-treemacs-file-face))
(treemacs-create-theme "doom-atom"
:config
(progn
(treemacs-create-icon
:icon (format " %s\t" (all-the-icons-octicon "repo" :height 1.2 :v-adjust -0.1 :face 'doom-themes-treemacs-root-face))
:extensions (root))
(treemacs-create-icon
:icon (format "%s\t%s\t"
(all-the-icons-octicon "chevron-down" :height 0.75 :v-adjust 0.1 :face face-spec)
(all-the-icons-octicon "file-directory" :v-adjust 0 :face face-spec))
:extensions (dir-open))
(treemacs-create-icon
:icon (format "%s\t%s\t"
(all-the-icons-octicon "chevron-right" :height 0.75 :v-adjust 0.1 :face face-spec)
(all-the-icons-octicon "file-directory" :v-adjust 0 :face face-spec))
:extensions (dir-closed))
(treemacs-create-icon
:icon (format "%s\t%s\t"
(all-the-icons-octicon "chevron-down" :height 0.75 :v-adjust 0.1 :face face-spec)
(all-the-icons-octicon "package" :v-adjust 0 :face face-spec)) :extensions (tag-open))
(treemacs-create-icon
:icon (format "%s\t%s\t"
(all-the-icons-octicon "chevron-right" :height 0.75 :v-adjust 0.1 :face face-spec)
(all-the-icons-octicon "package" :v-adjust 0 :face face-spec))
:extensions (tag-closed))
(treemacs-create-icon
:icon (format "%s\t" (all-the-icons-octicon "tag" :height 0.9 :v-adjust 0 :face face-spec))
:extensions (tag-leaf))
(treemacs-create-icon
:icon (format "%s\t" (all-the-icons-octicon "flame" :v-adjust 0 :face face-spec))
:extensions (error))
(treemacs-create-icon
:icon (format "%s\t" (all-the-icons-octicon "stop" :v-adjust 0 :face face-spec))
:extensions (warning))
(treemacs-create-icon
:icon (format "%s\t" (all-the-icons-octicon "info" :height 0.75 :v-adjust 0.1 :face face-spec))
:extensions (info))
(treemacs-create-icon
:icon (format " %s\t" (all-the-icons-octicon "file-media" :v-adjust 0 :face face-spec))
:extensions ("png" "jpg" "jpeg" "gif" "ico" "tif" "tiff" "svg" "bmp"
"psd" "ai" "eps" "indd" "mov" "avi" "mp4" "webm" "mkv"
"wav" "mp3" "ogg" "midi"))
(treemacs-create-icon
:icon (format " %s\t" (all-the-icons-octicon "file-code" :v-adjust 0 :face face-spec))
:extensions ("adoc" "asciidoc" "bashrc" "c" "cabal" "cabal" "cask" "cc"
"clj" "cljc" "cljs" "cpp" "css" "csv" "cxx" "dart"
"dockerfile" "dockerfile" "editorconfig" "eex" "el" "elm"
"ex" "exs" "fish" "gitconfig" "gitignore" "go" "h" "hh"
"hpp" "hs" "htm" "html" "hy" "ideavimrc" "inputrc" "j2"
"j2" "java" "jinja2" "jinja2" "jl" "js" "json" "jsx" "kt"
"kt" "kts" "lhs" "lisp" "lua" "lua" "makefile" "ml" "mli"
"nim" "nim" "nims" "nix" "perl" "php" "pl" "plt" "pm"
"pm6" "pp" "pp" "py" "pyc" "r" "racket" "rb" "re" "rei"
"rkt" "rktd" "rktl" "rs" "sbt" "scala" "scm" "scrbl"
"scribble" "scss" "sh" "sql" "sql" "styles" "sv" "tex"
"toml" "tpp" "tridactylrc" "ts" "tsx" "v" "vagrantfile"
"vagrantfile" "vh" "vimperatorrc" "vimrc" "vrapperrc"
"vue" "xml" "xsl" "yaml" "yml" "zsh" "zshrc"))
(treemacs-create-icon
:icon (format " %s\t" (all-the-icons-octicon "book" :v-adjust 0 :face face-spec))
:extensions ("lrf" "lrx" "cbr" "cbz" "cb7" "cbt" "cba" "chm" "djvu"
"doc" "docx" "pdb" "pdb" "fb2" "xeb" "ceb" "inf" "azw"
"azw3" "kf8" "kfx" "lit" "prc" "mobi" "exe" "or" "html"
"pkg" "opf" "txt" "pdb" "ps" "rtf" "pdg" "xml" "tr2"
"tr3" "oxps" "xps"))
(treemacs-create-icon
:icon (format " %s\t" (all-the-icons-octicon "file-text" :v-adjust 0 :face face-spec))
:extensions ("md" "markdown" "rst" "log" "org" "txt"
"CONTRIBUTE" "LICENSE" "README" "CHANGELOG"))
(treemacs-create-icon
:icon (format " %s\t" (all-the-icons-octicon "file-binary" :v-adjust 0 :face face-spec))
:extensions ("exe" "dll" "obj" "so" "o" "out" "elc"))
(treemacs-create-icon
:icon (format " %s\t" (all-the-icons-octicon "file-pdf" :v-adjust 0 :face face-spec))
:extensions ("pdf"))
(treemacs-create-icon
:icon (format " %s\t" (all-the-icons-octicon "file-zip" :v-adjust 0 :face face-spec))
:extensions ("zip" "7z" "tar" "gz" "rar" "tgz"))
(treemacs-create-icon
:icon (format " %s\t" (all-the-icons-octicon "file-text" :v-adjust 0 :face face-spec))
:extensions (fallback))))
(treemacs-create-theme "doom-colors"
:extends "doom-atom"
:config
(progn
(treemacs-create-icon
:icon (format " %s\t" (all-the-icons-octicon "repo" :height 1.2 :v-adjust -0.1 :face 'doom-themes-treemacs-root-face))
:extensions (root))
(treemacs-create-icon
:icon (format "%s\t" (all-the-icons-octicon "flame" :height 0.8 :v-adjust 0 :face 'all-the-icons-red))
:extensions (error))
(treemacs-create-icon
:icon (format "%s\t" (all-the-icons-octicon "stop" :height 0.8 :v-adjust 0 :face 'all-the-icons-yellow))
:extensions (warning))
(treemacs-create-icon
:icon (format "%s\t" (all-the-icons-octicon "info" :height 0.75 :v-adjust 0.1 :face 'all-the-icons-green))
:extensions (info))
(treemacs-create-icon
:icon (format " %s\t" (all-the-icons-alltheicon "git" :height 0.85 :v-adjust 0.0 :face 'all-the-icons-red))
:extensions ("gitignore" "git" "gitconfig" "gitmodules"))
(dolist (item all-the-icons-icon-alist)
(let* ((extensions (doom-themes--get-treemacs-extensions (car item)))
(func (cadr item))
(args (append (list (cadr (cdr item))) '(:v-adjust -0.05 :height 0.85) (cdr (cddr item))))
(icon (apply func args)))
(let* ((icon-pair (cons (format " %s\t" icon) " "))
(gui-icons (treemacs-theme->gui-icons treemacs--current-theme))
(tui-icons (treemacs-theme->tui-icons treemacs--current-theme))
(gui-icon (car icon-pair))
(tui-icon (cdr icon-pair)))
(--each extensions
(ht-set! gui-icons it gui-icon)
(ht-set! tui-icons it tui-icon)))))
(treemacs-create-icon
:icon (format " %s\t" (all-the-icons-octicon "file-code" :v-adjust 0 :face face-spec))
:extensions ("elc")))))
(treemacs-load-theme doom-themes-treemacs-theme))
;;;###autoload
(defun doom-themes-treemacs-config ()
"Install doom-themes' treemacs configuration.
Includes an Atom-esque icon theme and highlighting based on filetype.")
(provide 'doom-themes-ext-treemacs)
;;; doom-themes-treemacs.el ends here