summaryrefslogtreecommitdiff
path: root/.config/emacs/modules/bd--modeline.el
blob: 1b0f5ee251f254e78088d2ca727ba6a65924d82b (plain)
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
;;; -*- lexical-binding: t; -*-
;;; Commentary:
;;; Note this currently requires many of the previous modules to be loaded
;;; to function properly.
;;; Code:


(defun mode-line-fill (reserve)
  "Return empty space, leaving RESERVE space on the right."
  (unless reserve
    (setq reserve 20))
  (when (and window-system (eq 'right (get-scroll-bar-mode)))
    (setq reserve (- reserve 3)))
  (propertize " "
              'display `((space :align-to (- (+ right right-fringe right-margin) ,reserve)))))


;;;; remove mode-line-clutter
(define-minor-mode minor-mode-blackout-mode
  "Hides minor modes from the mode line."
  t)

(catch 'done
  (mapc (lambda (x)
          (when (and (consp x)
                     (equal (cadr x) '("" minor-mode-alist)))
            (let ((original (copy-sequence x)))
              (setcar x 'minor-mode-blackout-mode)
              (setcdr x (list "" original)))
            (throw 'done t)))
        mode-line-modes))

(global-set-key (kbd "C-c ,") 'minor-mode-blackout-mode)


(defvar-local bd/time-mode-line
    '(:eval
      (when (mode-line-window-selected-p)
        display-time-string))
  "displays current time and date in selected window.")


;;;; buffer name
(defun modeline-buffer-name ()
  "Return 'buffer-name' with proper spacing and icon."
  (format " %s %s" (all-the-icons-icon-for-mode major-mode) (buffer-name)))

(defvar-local bd/buffer-identification-mode-line
    '(:eval (format "%s" (modeline-buffer-name)))
  "Formats the modeline-buffer-name.")

;;;; pos
(defvar-local bd/line-position
    '(:eval
      (when (mode-line-window-selected-p)
        mode-line-position)))
;; show column number
(column-number-mode)

;;;; git
(defun git-vc-modeline ()
  (let ((branch (mapconcat 'concat (cdr (split-string vc-mode "[:-]")) "-")))
    (concat
     (propertize (format " %s" (all-the-icons-octicon "git-branch"))
                 'face `(:height 1 :family ,(all-the-icons-octicon-family))
                 'display '(raise 0))
     (propertize (format " %s" branch))
     (propertize "  "))))

(defvar-local bd/vc-mode-line
    '(:eval (when (and vc-mode (not (eq major-mode 'magit-status-mode))) ; temp fix to avoid bug which occurs in magit buffer
              (format "%s"
                      (propertize (git-vc-modeline) 'face 'shadow))))
  "Formats the checked out git repository.")


(dolist (construct '(bd/time-mode-line
                     bd/buffer-identification-mode-line
                     bd/vc-mode-line
                     bd/line-position))
  (put construct 'risky-local-variable t))


;; set elements; move modeline to top
(setq-default header-line-format
              (list
               mode-line-front-space
               ;; mode-line-mule-info
               ;; mode-line-frame-identification
               bd/buffer-identification-mode-line
               " "
               mode-line-modes
               " "
               mode-line-modified
               bd/vc-mode-line
               "      "
               (mode-line-fill 19)
               bd/line-position
               "  "
               bd/time-mode-line))
(setq-default mode-line-format nil)


(provide 'bd--modeline)
;;; bd-modeline ends here