-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-powerline.el
223 lines (197 loc) · 8.09 KB
/
init-powerline.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
;; Credit: https://github.com/hlissner/.emacs.d/blob/master/core/core-modeline.el
;; and https://buildfunthings.com/emacs/emacs-config.html
(use-package powerline
:config
(defvar mode-line-height 20)
(defvar mode-line-bar (eval-when-compile (pl/percent-xpm mode-line-height 100 0 100 0 3 "#FFFFFF" nil)))
;; (defvar mode-line-bar (eval-when-compile (pl/percent-xpm mode-line-height 100 0 100 0 3 "#909fab" nil)))
;; (defvar mode-line-eldoc-bar (eval-when-compile (pl/percent-xpm mode-line-height 100 0 100 0 3 "#B3EF00" nil)))
;; (defvar mode-line-inactive-bar (eval-when-compile (pl/percent-xpm mode-line-height 100 0 100 0 3 "#9091AB" nil)))
;; Custom faces
(defface mode-line-is-modified nil
"Face for mode-line modified symbol")
(defface mode-line-2 nil
"The alternate color for mode-line text.")
(defface mode-line-highlight nil
"Face for bright segments of the mode-line.")
(defface mode-line-count-face nil
"Face for anzu/evil-substitute/evil-search number-of-matches display.")
;; Git/VCS segment faces
(defface mode-line-vcs-info '((t (:inherit warning)))
"")
(defface mode-line-vcs-warning '((t (:inherit warning)))
"")
;; Flycheck segment faces
(defface doom-flycheck-error '((t (:inherit error)))
"Face for flycheck error feedback in the modeline.")
(defface doom-flycheck-warning '((t (:inherit warning)))
"Face for flycheck warning feedback in the modeline.")
(defun doom-ml-flycheck-count (state)
"Return flycheck information for the given error type STATE."
(when (flycheck-has-current-errors-p state)
(if (eq 'running flycheck-last-status-change)
"?"
(cdr-safe (assq state (flycheck-count-errors flycheck-current-errors))))))
(defun doom-fix-unicode (font &rest chars)
"Display certain unicode characters in a specific font.
e.g. (doom-fix-unicode \"DejaVu Sans\" ?⚠ ?★ ?λ)"
(declare (indent 1))
(mapc (lambda (x) (set-fontset-font
t (cons x x)
(cond ((fontp font)
font)
((listp font)
(font-spec :family (car font) :size (nth 1 font)))
((stringp font)
(font-spec :family font))
(t (error "FONT is an invalid type: %s" font)))))
chars))
;; Make certain unicode glyphs bigger for the mode-line.
;; FIXME Replace with all-the-icons?
(doom-fix-unicode '("DejaVu Sans Mono" 15) ?✱) ;; modified symbol
(let ((font "DejaVu Sans Mono for Powerline")) ;;
(doom-fix-unicode (list font 12) ?) ;; git symbol
(doom-fix-unicode (list font 16) ?∄) ;; non-existent-file symbol
(doom-fix-unicode (list font 15) ?)) ;; read-only symbol
;; So the mode-line can keep track of "the current window"
(defvar mode-line-selected-window nil)
(defun doom|set-selected-window (&rest _)
(let ((window (frame-selected-window)))
(when (and (windowp window)
(not (minibuffer-window-active-p window)))
(setq mode-line-selected-window window))))
(add-hook 'window-configuration-change-hook #'doom|set-selected-window)
(add-hook 'focus-in-hook #'doom|set-selected-window)
(advice-add 'select-window :after 'doom|set-selected-window)
(advice-add 'select-frame :after 'doom|set-selected-window)
(defun doom/project-root (&optional strict-p)
"Get the path to the root of your project."
(let (projectile-require-project-root strict-p)
(projectile-project-root)))
(defun *buffer-path ()
"Displays the buffer's full path relative to the project root (includes the
project root). Excludes the file basename. See `*buffer-name' for that."
(when buffer-file-name
(propertize
(f-dirname
(let ((buffer-path (file-relative-name buffer-file-name (doom/project-root)))
(max-length (truncate (/ (window-body-width) 1.75))))
(concat (projectile-project-name) "/"
(if (> (length buffer-path) max-length)
(let ((path (reverse (split-string buffer-path "/" t)))
(output ""))
(when (and path (equal "" (car path)))
(setq path (cdr path)))
(while (and path (<= (length output) (- max-length 4)))
(setq output (concat (car path) "/" output))
(setq path (cdr path)))
(when path
(setq output (concat "../" output)))
(when (string-suffix-p "/" output)
(setq output (substring output 0 -1)))
output)
buffer-path))))
'face (if active 'mode-line-2))))
(defun *buffer-name ()
"The buffer's base name or id."
;; FIXME Don't show uniquify tags
(s-trim-left (format-mode-line "%b")))
(defun *buffer-pwd ()
"Displays `default-directory', for special buffers like the scratch buffer."
(propertize
(concat "[" (abbreviate-file-name default-directory) "]")
'face 'mode-line-2))
(defun *buffer-state ()
"Displays symbols representing the buffer's state (non-existent/modified/read-only)"
(when buffer-file-name
(propertize
(concat (if (not (file-exists-p buffer-file-name))
"∄"
(if (buffer-modified-p) "✱"))
(if buffer-read-only ""))
'face 'mode-line-is-modified)))
(defun *buffer-encoding-abbrev ()
"The line ending convention used in the buffer."
(if (memq buffer-file-coding-system '(utf-8 utf-8-unix))
""
(symbol-name buffer-file-coding-system)))
(defun *major-mode ()
"The major mode, including process, environment and text-scale info."
(concat (format-mode-line mode-name)
(if (stringp mode-line-process) mode-line-process)
(and (featurep 'face-remap)
(/= text-scale-mode-amount 0)
(format " (%+d)" text-scale-mode-amount))))
(defun *vc ()
"Displays the current branch, colored based on its state."
(when vc-mode
(let ((backend (concat " " (substring vc-mode (+ 2 (length (symbol-name (vc-backend buffer-file-name)))))))
(face (let ((state (vc-state buffer-file-name)))
(cond ((memq state '(edited added))
'mode-line-vcs-info)
((memq state '(removed needs-merge needs-update conflict removed unregistered))
'mode-line-vcs-warning)))))
(if active
(propertize backend 'face face)
backend))))
(defvar-local doom--flycheck-err-cache nil "")
(defvar-local doom--flycheck-cache nil "")
(defun *flycheck ()
"Persistent and cached flycheck indicators in the mode-line."
(when (and (featurep 'flycheck)
flycheck-mode
(or flycheck-current-errors
(eq 'running flycheck-last-status-change)))
(or (and (or (eq doom--flycheck-err-cache doom--flycheck-cache)
(memq flycheck-last-status-change '(running not-checked)))
doom--flycheck-cache)
(and (setq doom--flycheck-err-cache flycheck-current-errors)
(setq doom--flycheck-cache
(let ((fe (doom-ml-flycheck-count 'error))
(fw (doom-ml-flycheck-count 'warning)))
(concat
(if fe (propertize (format " •%d " fe)
'face (if active
'doom-flycheck-error
'mode-line)))
(if fw (propertize (format " •%d " fw)
'face (if active
'doom-flycheck-warning
'mode-line))))))))))
(defun *buffer-position ()
"A more vim-like buffer position."
(let ((start (window-start))
(end (window-end))
(pend (point-max)))
(if (and (= start 1)
(= end pend))
":All"
(cond ((= start 1) ":Top")
((= end pend) ":Bot")
(t (format ":%d%%%%" (/ end 0.01 pend)))))))
(defun my-mode-line (&optional id)
`(:eval
(let* ((active (eq (selected-window) mode-line-selected-window))
(lhs (list (propertize " " 'display (if active mode-line-bar mode-line-inactive-bar))
(*flycheck)
" "
(*buffer-path)
(*buffer-name)
" "
(*buffer-state)
,(if (eq id 'scratch) '(*buffer-pwd))))
(rhs (list (*buffer-encoding-abbrev) " "
(*vc)
;; " "
;; (when persp-curr persp-modestring)
" " (*major-mode) " "
(propertize
(concat "(%l,%c) " (*buffer-position))
'face (if active 'mode-line-2))))
(middle (propertize
" " 'display `((space :align-to (- (+ right right-fringe right-margin)
,(1+ (string-width (format-mode-line rhs)))))))))
(list lhs middle rhs))))
(setq-default mode-line-format (my-mode-line)))
(provide 'init-powerline)
;;; init-powerline.el ends here