-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphd-modeline.el
776 lines (682 loc) · 27.2 KB
/
phd-modeline.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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
;;; phd-modeline.el --- My modeline customization
;; ----------------------------------------------
;;; Author: phdenzel
;;
;;
;;; Commentary:
;; ------------
;; This is my module for customising the Emacs mode-line.
;;
;;; Installation (for example):
;; ----------------------------
;; (add-to-list 'load-path "~/phd-modeline/")
;; (require 'phd-modeline)
;; (phd-modeline-mode 1)
;; (global-set-key (kbd "C-x |") 'phd-modeline-mode)
;;
;; or
;;
;; (use-package phd-modeline
;; :ensure nil
;; :load-path "~/phd-modeline/"
;; :after all-the-icons
;; :hook (after-init . phd-modeline-mode)
;; :bind (("C-x |" . phd-modeline-mode))
;; :config (...))
;;
;;; Code:
(require 'all-the-icons)
(when (display-graphic-p)
(require 'all-the-icons))
(defgroup phd-modeline nil
"A minimal mode-line."
:group 'mode-line
:link '(url-link :tag "Homepage" "https://github.com/phdenzel/phd-modeline"))
;; --- Mode
(defvar phd-modeline-mode-map (make-sparse-keymap))
(define-minor-mode phd-modeline-mode
"Toggle phd-modeline on or off."
:init-value nil
:group 'phd-modeline
:global t
:keymap phd-modeline-mode-map
(if phd-modeline-mode
(if phd-modeline-format
(progn
(setq-default mode-line-format phd-modeline-format)
(message "phd-modeline-mode activated!"))
(progn
(setq-default mode-line-format phd-modeline-format-default)
(message "phd-modeline-mode activated!")))
(progn
(setq-default mode-line-format phd-modeline-format-original)
(message "phd-modeline deactivated!")))
(force-mode-line-update))
;; --- Style
(defface phd-modeline-buffer-name-face
`((t (:inherit 'minibuffer-prompt)))
"The phd-modeline normal buffer name face."
:group 'phd-modeline)
(defface phd-modeline-space-face
`((t (:inherit 'mode-line)))
"The phd-modeline face of empty space."
:group 'phd-modeline)
(defface phd-modeline-buffer-modified-face
`((t (:inherit 'font-lock-function-name-face)))
"The phd-modeline modified buffer name face."
:group 'phd-modeline)
(defface phd-modeline-buffer-read-only-face
`((t (:inherit 'font-lock-keyword-face)))
"The phd-modeline read-only buffer name face."
:group 'phd-modeline)
(defface phd-modeline-buffer-line-face
`((t (:inherit 'mode-line)))
"The phd-modeline buffer line face."
:group 'phd-modeline)
(defface phd-modeline-buffer-column-face
`((t (:inherit 'mode-line)))
"The phd-modeline buffer column face."
:group 'phd-modeline)
(defface phd-modeline-buffer-percentage-face
`((t (:inherit 'mode-line)))
"The phd-modeline buffer percentage face."
:group 'phd-modeline)
(defface phd-modeline-mode-face
`((t (:inherit 'mode-line)))
"The phd-modeline buffer percentage face."
:group 'phd-modeline)
(defface phd-modeline-inactive-face
`((t (:inherit 'mode-line-inactive)))
"The phd-modeline face for inactive frames."
:group 'phd-modeline)
(defface phd-modeline-highlight-face
`((t (:inherit 'mode-line-highlight)))
"The phd-modeline highlight face."
:group 'phd-modeline)
(defface phd-modeline-flycheck-success-face
`((t (:inherit 'success)))
"The phd-modeline flycheck face for success."
:group 'phd-modeline)
(defface phd-modeline-flycheck-warning-face
`((t (:inherit 'warning)))
"The phd-modeline flycheck face for warnings."
:group 'phd-modeline)
(defface phd-modeline-flycheck-error-face
`((t (:inherit 'success)))
"The phd-modeline flycheck face for errors."
:group 'phd-modeline)
(defface phd-modeline-vc-icon-face
`((t (:inherit 'font-lock-keyword-face)))
"The phd-modeline version control icon face."
:group 'phd-modeline)
(defface phd-modeline-vc-branch-face
`((t (:inherit 'warning)))
"The phd-modeline version control info face."
:group 'phd-modeline)
(defface phd-modeline-vc-status-face
`((t (:inherit 'font-lock-constant-face)))
"The phd-modeline version control info face."
:group 'phd-modeline)
(defface phd-modeline-mail-icon-face
`((t (:inherit 'font-lock-string-face)))
"The phd-modeline mail icon face."
:group 'phd-modeline)
(defface phd-modeline-mail-status-face
`((t (:inherit 'font-lock-string-face)))
"The phd-modeline mail info face."
:group 'phd-modeline)
(defface phd-modeline-bar-face
`((t (:inherit 'phd-modeline-buffer-name-face)))
"The phd-modeline bar face."
:group 'phd-modeline)
(defcustom phd-modeline-height 25
"The height of the mode-line (only in GUI)."
:type 'integer
:group 'phd-modeline)
(defcustom phd-modeline-bar-width 17
"The width of the phd-modeline bar (only in GUI)."
:type 'integer
:set (lambda (sym val) (set sym (if (> val 0) val 1)))
:group 'phd-modeline)
(defcustom phd-modeline-bar-data-func 'phd-ml/bar-tri-data
"The data function for the bar image.
Choose between
- `phd-ml/bar-rec-data' - rectangular bar image
- `phd-ml/bar-tri-data' - triangular bar image"
:type 'function
:set (lambda (sym val) (fset sym val))
:group 'phd-modeline)
(defcustom phd-modeline-mail-update-interval 60
"Update interval of phd-modeline's mail component."
:type 'integer
:group 'phd-modeline)
(defvar phd-modeline-mail-update-timer nil
"Interval timer for phd-modeline's mail component.")
(defvar phd-modeline-mail-count-string ""
"Count string for phd-modeline's mail component.")
(defun phd-ml/set-mu4e-command (&optional sym val op where)
"Set `phd-modeline-mu4e-command' using custom variables:
- `phd-modeline-mu4e-mu-executable'
- `phd-modeline-mu4e-find'
- `phd-modeline-mu4e-unread-query'"
(when (and (boundp 'phd-modeline-mu4e-mu-executable)
(boundp 'phd-modeline-mu4e-find)
(boundp 'phd-modeline-mu4e-unread-query))
(let ((exec phd-modeline-mu4e-mu-executable)
(subc phd-modeline-mu4e-find)
(qry phd-modeline-mu4e-unread-query))
(setq phd-modeline-mu4e-command
(format "%s %s \"%s\"" exec subc qry)))))
(defcustom phd-modeline-mu4e-mu-executable (executable-find "mu")
"The mu4e executable."
:type 'string
:set (lambda (sym val)
(set sym val)
(phd-ml/set-mu4e-command))
:group 'phd-modeline)
(defcustom phd-modeline-mu4e-find "find"
"The mu4e find sub-command."
:type 'string
:set (lambda (sym val)
(set sym val)
(phd-ml/set-mu4e-command))
:group 'phd-modeline)
(defcustom phd-modeline-mu4e-unread-query "maildir:/INBOX AND flag:unread"
"The mu4e query for counting the unread messages."
:type 'string
:set (lambda (sym val)
(set sym val)
(phd-ml/set-mu4e-command))
:group 'phd-modeline)
(defcustom phd-modeline-mu4e-command (phd-ml/set-mu4e-command)
"The full mu-find query built from custom variables:
- `phd-modeline-mu4e-mu-executable'
- `phd-modeline-mu4e-find'
- `phd-modeline-mu4e-unread-query'"
:type 'string
:group 'phd-modeline)
(defcustom phd-modeline-use-icons t
"Enable all icon drawing functionality.
TODO: Not yet implemented."
:type 'boolean
:group 'phd-modeline)
(define-minor-mode phd-modeline-column-mode
"Enable buffer column position functionality in phd-modeline."
:group 'phd-modeline
:global t
:keymap phd-modeline-mode-map)
(define-minor-mode phd-modeline-percentage-mode
"Enable buffer position percentage functionality in phd-modeline."
:group 'phd-modeline
:global t
:keymap phd-modeline-mode-map)
(define-minor-mode phd-modeline-mail-mode
"Enable unread mail indicator functionality in phd-modeline."
:group 'phd-modeline
:global t
(setq phd-modeline-mail-count-string "")
(and phd-modeline-mail-update-timer
(cancel-timer phd-modeline-mail-update-timer))
(when phd-modeline-mail-mode
(setq phd-modeline-mail-update-timer
(run-with-timer nil phd-modeline-mail-update-interval
'phd-modeline-mail-update-handler))
(phd-modeline-mail-update-handler))
)
(setq all-the-icons-scale-factor 1.1)
(setq all-the-icons-default-adjust 0)
;; for terminal mode
;; (unless window-system
;; (defun all-the-icons-octicon (&rest _) "" "")
;; (defun all-the-icons-faicon (&rest _) "" "")
;; (defun all-the-icons-fileicon (&rest _) "" "")
;; (defun all-the-icons-wicon (&rest _) "" "")
;; (defun all-the-icons-alltheicon (&rest _) "" ""))
;; --- Utilities
;; Frame/window focussing
(defvar phd-ml/selected-window (frame-selected-window))
(defun phd-ml/set-selected-window (&rest _args)
"Update the `phd-ml/selected-window' variable."
(when (not (minibuffer-window-active-p (frame-selected-window)))
(setq phd-ml/selected-window (frame-selected-window))
(force-mode-line-update)))
(defun phd-ml/reset-selected-window ()
"Nil-ify the `phd-ml/selected-window' variable."
(setq phd-ml/selected-window nil)
(force-mode-line-update))
(defun phd-ml/selected-window-active-p ()
"Return whether the current window is active."
(eq phd-ml/selected-window (selected-window)))
(defadvice handle-switch-frame (after phd-ml/handle-switch-frame activate)
"Update the `phd-ml/selected-window' variable."
(phd-ml/set-selected-window))
(add-hook 'window-configuration-change-hook 'phd-ml/set-selected-window)
(add-hook 'buffer-list-update-hook #'phd-ml/set-selected-window)
(add-function
:after after-focus-change-function
(lambda ()
(if (frame-focus-state)
(phd-ml/set-selected-window)
(phd-ml/reset-selected-window))))
;; Bitmapping
(defun phd-ml/bar-rec-data (width height)
"Return PBM data for rectangular bar image with dimensions (WIDTH, HEIGHT)."
(make-string (* width height) ?1))
(defun phd-ml/bar-tri-data (width height)
"Return PBM data for triangular bar image with dimensions (WIDTH, HEIGHT)."
(let ((data-list nil)
(half-height (/ height 2))
(repeats 1)
(tri-width width)
(block-width 0)
(iter 0)
(temp-str nil))
(progn
(if (< width height)
(progn
(setq repeats (/ half-height width))
(when (> width half-height)
(setq tri-width half-height)
(setq block-width (- width half-height))))
(setq tri-width half-height
block-width (- width half-height)))
;; loop through upper half of the arrow
(setq iter 0)
(while (< iter tri-width)
(setq temp-str (concat (make-string block-width ?1)
(make-string iter ?1)
(make-string (- tri-width iter) ?0))
iter (1+ iter))
(if (> repeats 1)
(dotimes (number repeats)
(push temp-str data-list))
(push temp-str data-list)))
;; arrow tip
(push (make-string width ?1) data-list)
;; loop through lower half of the arrow
(setq iter 0)
(while (< iter tri-width)
(setq iter (1+ iter)
temp-str (concat (make-string block-width ?1)
(make-string (- tri-width iter) ?1)
(make-string iter ?0)))
(if (> repeats 1)
(dotimes (number repeats)
(push temp-str data-list))
(push temp-str data-list))))
(combine-and-quote-strings data-list "\n")))
(defun phd-ml/bar-image (face width height)
"Create a PBM image of the modeline bar with dimensions (WIDTH, HEIGHT) using FACE."
(when (and (display-graphic-p)
(image-type-available-p 'pbm))
(propertize
" " 'display
(let ((color (or (face-foreground face nil t) "None"))
(bgcolor (or (face-background face nil t) "None")))
(ignore-errors
(create-image
(concat (format "P1\n%i %i\n" width height)
(phd-modeline-bar-data-func width height)
"\n")
'pbm t :foreground color :background bgcolor :ascent 'center))))))
;; Misc
(defun phd-ml/s-replace (old new s)
"Replace OLD with NEW in string S."
(replace-regexp-in-string (regexp-quote old) new s t t))
(defun phd-ml/s-count-regexp (regexp s &optional start end)
"Count REGEXP expression in string S from START to END."
(save-match-data
(with-temp-buffer
(insert s)
(goto-char (point-min))
(count-matches regexp (or start 1) (or end (point-max))))))
;; Mail
(defun phd-ml/mu4e-count-unread ()
"Count all unread mails using `phd-modeline-mu4e-command'."
(phd-ml/set-mu4e-command)
(let* ((cmd phd-modeline-mu4e-command)
(read (shell-command-to-string cmd)))
(if (string-equal read "no matches for search expression\n")
0
(phd-ml/s-count-regexp "\n" read))
))
(defun phd-modeline-mail-update ()
"Update unread mail count."
(interactive)
(let ((count (phd-ml/mu4e-count-unread)))
(if (eq count 0)
(setq count "")
(setq count (format " · %s" count)))
;; (message "Mail count%s" count)
(setq phd-modeline-mail-count-string count))
)
(defun phd-modeline-mail-update-handler ()
"Handler for updating unread mail count."
(phd-modeline-mail-update))
;; --- Components (for phd-modeline-format)
;; Space fillers
(defun phd-modeline-whitespace (&optional number)
"Add NUMBER of spaces in phd-modeline."
(unless number (setq number 1))
(list (propertize (make-string number ?\s)
'face (if (phd-ml/selected-window-active-p)
'phd-modeline-space-face
'phd-modeline-inactive-face))))
(defun phd-modeline-hairspace (&optional number)
"Add NUMBER of spaces in phd-modeline."
(unless number (setq number 1))
(list (propertize (make-string number (string-to-char " ")) ;; or hairspace " "
'face (if (phd-ml/selected-window-active-p)
'phd-modeline-space-face
'phd-modeline-inactive-face))))
(defun phd-modeline-space-between (&optional reserve)
"Add spaces inbetween left-aligned and right-aligned components.
The right aligned components use pad RESERVE number of spaces on the right."
(unless reserve (setq reserve 1))
(propertize " "
'face (if (phd-ml/selected-window-active-p)
'phd-modeline-space-face
'phd-modeline-inactive-face)
'display `((space :align-to (- (+ right right-fringe right-margin)
,(+ reserve (string-width
(if (listp mode-name)
(car mode-name)
mode-name))))))))
(defun phd-modeline-dot-separator (&optional pad-l pad-r)
"Add dot character in phd-modeline.
Optionally pad the separator by PAD-L on the left, PAD-R on the right."
(unless pad-l (setq pad-l 0))
(unless pad-r (setq pad-r 0))
(list
(phd-modeline-whitespace pad-l)
(propertize "·"
'face (if (phd-ml/selected-window-active-p)
'phd-modeline-space-face
'phd-modeline-inactive-face))
(phd-modeline-whitespace pad-r)))
;; Bar
(defvar phd-modeline-active-bar nil)
(defvar phd-modeline-inactive-bar nil)
(defsubst phd-modeline-bar ()
"The default bar regulates the height of the mode-line in GUI."
(unless (and phd-modeline-active-bar phd-modeline-inactive-bar)
(let ((width phd-modeline-bar-width)
(height phd-modeline-height ))
(when (and (numberp width) (numberp height))
(setq phd-modeline-active-bar
(phd-ml/bar-image 'phd-modeline-bar-face width height)
phd-modeline-inactive-bar
(phd-ml/bar-image 'phd-modeline-inactive-face width height)))))
(if (phd-ml/selected-window-active-p)
phd-modeline-active-bar
phd-modeline-inactive-bar))
;; Text info
(defun phd-modeline-buffer-name ()
"Format buffer name in phd-modeline depending on its state."
(list
(cond
(buffer-read-only
(propertize "%b"
'face (if (phd-ml/selected-window-active-p)
'phd-modeline-buffer-read-only-face
'phd-modeline-inactive-face)
'mouse-face 'phd-modeline-highlight-face
'help-echo "Buffer name\nmouse-1: Previous buffer\nmouse-3: Next buffer"
'local-map mode-line-buffer-identification-keymap))
((buffer-modified-p)
(propertize "%b"
'face (if (phd-ml/selected-window-active-p)
'phd-modeline-buffer-modified-face
'phd-modeline-inactive-face)
'mouse-face 'phd-modeline-highlight-face
'help-echo "Buffer name\nmouse-1: Previous buffer\nmouse-3: Next buffer"
'local-map mode-line-buffer-identification-keymap))
(t
(propertize "%b"
'face (if (phd-ml/selected-window-active-p)
'phd-modeline-buffer-name-face
'phd-modeline-inactive-face)
'mouse-face 'phd-modeline-highlight-face
'help-echo "Buffer name\nmouse-1: Previous buffer\nmouse-3: Next buffer"
'local-map mode-line-buffer-identification-keymap)))))
(defun phd-modeline-buffer-position ()
"Format buffer position in phd-modeline depending on its state."
(list
(propertize "L:[%3l]"
'face (if (phd-ml/selected-window-active-p)
'phd-modeline-buffer-line-face
'phd-modeline-inactive-face))
(when phd-modeline-column-mode
(propertize " · C:[%3c]"
'face (if (phd-ml/selected-window-active-p)
'phd-modeline-buffer-column-face
'phd-modeline-inactive-face)))
(when phd-modeline-percentage-mode
(propertize " @"
'face (if (phd-ml/selected-window-active-p)
'mode-line
'phd-modeline-inactive-face)))
(when phd-modeline-percentage-mode
(propertize "%p "
'face (if (phd-ml/selected-window-active-p)
'phd-modeline-buffer-percentage-face
'phd-modeline-inactive-face)))))
(defun phd-modeline-media-info ()
"Show image dimension when in `image-mode'."
(when (eq major-mode 'image-mode)
(let ((size (image-size (image-get-display-property) :pixels)))
(list
(phd-modeline-whitespace)
(format " %dx%d " (car size) (cdr size))))))
(defun phd-modeline-major-mode ()
"Format major mode name in phd-modeline."
(let* ((modename-string
(pcase mode-name
((pred stringp) mode-name)
((pred listp) (car mode-name)))))
(list
(propertize modename-string
'face (if (phd-ml/selected-window-active-p)
'phd-modeline-mode-face
'phd-modeline-inactive-face)))))
(defun phd-modeline-flycheck-status ()
"Flycheck status info for phd-modeline."
(let* ((text
(pcase flycheck-last-status-change
(`finished
(if flycheck-current-errors
(let ((count (let-alist (flycheck-count-errors flycheck-current-errors)
(+ (or .warning 0) (or .error 0)))))
(propertize (format "⚠ %s" count)
'face (if (phd-ml/selected-window-active-p)
'phd-modeline-flycheck-warning-face
'phd-modeline-inactive-face)))
(propertize "✔"
'face (if (phd-ml/selected-window-active-p)
'phd-modeline-flycheck-success-face
'phd-modeline-inactive-face))))
(`running "⟲")
(`errored (propertize "✖" 'face (if (phd-ml/selected-window-active-p)
'phd-modeline-flycheck-error-face
'phd-modeline-inactive-face)))
(`interrupted (propertize "⛔" 'face (if (phd-ml/selected-window-active-p)
'phd-modeline-flycheck-error-face
'phd-modeline-inactive-face)))
(`not-checked "")
(`no-checker "")
(`suspicious ""))))
(list
(propertize text
'help-echo "Show Flycheck Errors"
'mouse-face 'phd-modeline-highlight-face
'local-map (make-mode-line-mouse-map
'mouse-1 (lambda () (interactive) (flycheck-list-errors))))
(phd-modeline-whitespace))))
(defvar vc-status-symbol-alist
'((up-to-date . nil)
(edited . "!")
(needs-update . "@")
(needs-merge . "x")
(unlocked-changes . "&")
(added . "+")
(removed . "-")
(conflict . "#")
(missing . "%")
(ignored . ";")
(unregistered . "?"))
"String symbol map for `vs-state' output.")
(defun phd-modeline-vc-status ()
"Fetch git repository status info for phd-modeline."
(when-let ((vc vc-mode)
(vcb (vc-backend buffer-file-name))
(vcs (vc-state buffer-file-name)))
(setq vcs-symbol (cdr (assoc vcs vc-status-symbol-alist)))
(setq vcbranch (phd-ml/s-replace (format "%s" vcb) "" vc))
(setq vcbranch (phd-ml/s-replace ":" "" vcbranch))
(setq vcbranch (phd-ml/s-replace "-" "" vcbranch))
(list
(propertize vcbranch
'face (if (phd-ml/selected-window-active-p)
'phd-modeline-vc-branch-face
'phd-modeline-inactive-face))
(when vcs-symbol
(propertize (format "[%s]" vcs-symbol)
'face (if (phd-ml/selected-window-active-p)
'phd-modeline-vc-status-face
'phd-modeline-inactive-face)))
(phd-modeline-whitespace))))
(defun phd-modeline-mail-status ()
"Fetch mu4e status info for phd-modeline."
(when phd-modeline-mail-mode
(let ((count phd-modeline-mail-count-string))
(list
(propertize count
'face (if (phd-ml/selected-window-active-p)
'phd-modeline-mail-status-face
'phd-modeline-inactive-face))))))
;; Icons
(defun phd-modeline-buffer-lock-icon ()
"Iconify read-only buffer in phd-modeline."
(when buffer-read-only
(list
(all-the-icons-octicon "lock"
:face (if (phd-ml/selected-window-active-p)
'phd-modeline-buffer-read-only-face
'phd-modeline-inactive-face))
(phd-modeline-whitespace))))
(defun phd-modeline-buffer-modified-icon ()
"Iconify modified buffer in phd-modeline."
(when (and (buffer-modified-p) (not buffer-read-only))
(list
(phd-modeline-whitespace)
(all-the-icons-faicon "floppy-o"
:face (if (phd-ml/selected-window-active-p)
'phd-modeline-buffer-modified-face
'phd-modeline-inactive-face)))))
(defvar vc-status-icon-set-alist
'((Git . all-the-icons-alltheicon)
(SVN . all-the-icons-fileicon)
(Hg . all-the-icons-fileicon))
"Icon map for `vs-backend' icons.")
(defun phd-modeline-vc-icon (&optional with-logo with-sep with-branch)
"Iconify git repository status in phd-modeline if WITH-LOGO is positive.
Include separator if WITH-SEP is positive.
Include branch icon if WITH-BRANCH is positive.
If no arguments are given, only return logo icon."
(unless with-logo (setq with-logo 0))
(unless with-sep (setq with-sep 0))
(unless with-branch (setq with-branch 0))
(when (and (not with-logo) (not with-branch)) (setq with-logo 1))
(when-let ((vc vc-mode)
(vcb (vc-backend buffer-file-name))
(vcs (vc-state buffer-file-name)))
(fset 'vcb-icon-set (cdr (assoc vcb vc-status-icon-set-alist)))
(setq vc-icons nil)
(when (> with-logo 0)
(add-to-list 'vc-icons
(propertize (format "%s" (vcb-icon-set (downcase (format "%s" vcb))))
'face (if (phd-ml/selected-window-active-p)
'phd-modeline-vc-icon-face
'phd-modeline-inactive-face))
t))
(when (> with-sep 0)
(add-to-list 'vc-icons (phd-modeline-dot-separator 2 2) t))
(when (> with-branch 0)
(add-to-list 'vc-icons
(propertize (all-the-icons-octicon "git-branch")
'face (if (phd-ml/selected-window-active-p)
'phd-modeline-vc-branch-face
'phd-modeline-inactive-face))
t))
vc-icons))
(defun phd-modeline-mail-icon ()
"Iconify mail status in phd-modeline."
(when phd-modeline-mail-mode
(list
(propertize (all-the-icons-octicon "mail")
'face (if (phd-ml/selected-window-active-p)
'phd-modeline-mail-icon-face
'phd-modeline-inactive-face)))))
(defun phd-modeline-mode-icon ()
"Iconify major mode in phd-modeline."
(list
(if (phd-ml/selected-window-active-p)
(all-the-icons-icon-for-mode major-mode)
(all-the-icons-icon-for-mode major-mode
:face 'phd-modeline-inactive-face))))
;; --- Formats
(defvar phd-modeline-format-original
'("%e" mode-line-front-space
mode-line-mule-info mode-line-client mode-line-modified mode-line-remote
mode-line-frame-identification mode-line-buffer-identification " "
mode-line-position
(vc-mode vc-mode) " "
mode-name
mode-line-misc-info mode-line-end-spaces)
"Original format of the mode-line (except only the major mode is shown).")
(defvar phd-modeline-format-default
(list
'(:eval (phd-modeline-bar))
'(:eval (phd-modeline-whitespace))
'(:eval (phd-modeline-buffer-name))
'(:eval (phd-modeline-whitespace))
'(:eval (phd-modeline-buffer-position))
'(:eval (phd-modeline-whitespace))
'(:eval (phd-modeline-space-between 2))
'(:eval (phd-modeline-major-mode))
'(:eval (phd-modeline-whitespace)))
"Default format of the phd-modeline.")
(defcustom phd-modeline-format nil
"The customizable phd-modeline format."
:type (list))
;; --- Customization
;; My personal configuration:
;; (setq phd-modeline-column-mode t
;; phd-modeline-mail-mode t)
;; (setq phd-modeline-format
;; (list
;; '(:eval (phd-modeline-bar))
;; '(:eval (phd-modeline-whitespace))
;; '(:eval (phd-modeline-buffer-lock-icon))
;; '(:eval (phd-modeline-buffer-name))
;; '(:eval (phd-modeline-buffer-modified-icon))
;; '(:eval (phd-modeline-whitespace))
;; '(:eval (phd-modeline-buffer-position))
;; '(:eval (phd-modeline-media-info))
;; '(:eval (phd-modeline-whitespace))
;; '(:eval (phd-modeline-flycheck-status))
;; '(:eval (phd-modeline-whitespace 4))
;; '(:eval (phd-modeline-vc-icon 1 1 1))
;; '(:eval (phd-modeline-vc-status))
;; '(:eval (phd-modeline-mail-icon))
;; '(:eval (phd-modeline-mail-status))
;; '(:eval (phd-modeline-whitespace))
;; '(:eval (phd-modeline-space-between 4))
;; '(:eval (phd-modeline-mode-icon))
;; '(:eval (phd-modeline-whitespace))
;; '(:eval (phd-modeline-major-mode))
;; '(:eval (phd-modeline-whitespace))
;; ))
(provide 'phd-modeline)
(provide 'phd-modeline-mode)
;;; phd-modeline.el ends here