summaryrefslogtreecommitdiff
path: root/.config/emacs/bd-mode-and-themes.el
blob: 098b733d66359832abb07d6b454593c78d086d8f (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
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
;; -*- lexical-binding: t; -*-

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; excellent resources : https://gitlab.com/mark.feller/emacs.d/-/blob/master/modules/module-solarized.el ;;
;;                       https://protesilaos.com/codelog/2023-07-29-emacs-custom-modeline-tutorial/       ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;; icon components for filename and git status
(use-package all-the-icons
  :init
  (progn (progn (defun modeline-buffer-name ()
                  "Return 'buffer-name' with proper spacing and icon."
                  (format " %s %s" (all-the-icons-icon-for-file (buffer-name)) (buffer-name)))
                (defvar-local bd/buffer-identification-mode-line
                    '(:eval (format "%s" (modeline-buffer-name)))
                  "Formats the modeline-buffer-name."))

         (progn (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.")))
  :config
  (setq emms-mode-line-icon-before-format (format "%s" (all-the-icons-fileicon "owl"))
        emms-mode-line-icon-enabled-p t))

;;;; time and date
(setq display-time-format "%m/%d/%y %H:%M (%a)"
      display-time-default-load-average nil)
(display-time)
(display-battery-mode 1)

(defvar-local bd/misc-mode-line
    '(:eval
      (when (mode-line-window-selected-p)
        global-mode-string))
  "Displays misc mode line content (emms, time, etc.)
only in the selected buffer.")

(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)))))

;;;; pad out space for time (this method is probably horrendous)
(insert-into-list global-mode-string (mode-line-fill 21) (cl-position 'display-time-string global-mode-string))

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

(setq-default mode-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-position
               mode-line-modified
               bd/vc-mode-line
               "      "
               bd/misc-mode-line
               (mode-line-fill 3)))

;;;; 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 m") 'minor-mode-blackout-mode)

(defun disable_mode_line ()
  (setq mode-line-format nil))

;; custom function to remove mode line from images
(add-hook 'image-mode-hook 'disable_mode_line)

(global-display-line-numbers-mode)
(global-visual-line-mode t)
(setq display-line-numbers-type 'relative)
;; required for other customizations later in themes.
(global-hl-line-mode 1)

;;;; true transparency
(add-to-list 'default-frame-alist '(alpha-background . 60))

(defun set-frame-alpha (value)
  "Sets the transparency of the frame background. 0=transparent/100=opaque"
  (interactive "nTransparency Value 0 - 100 opaque:")
  (setq value (clamp 0 100 value))
  (set-frame-parameter (selected-frame) 'alpha-background value)
  (message "Alpha set to %d" value))

;;;; modus themes
(defun modus-themes-custom-faces ()
  (modus-themes-with-colors
    (custom-set-faces
     `(mode-line-inactive ((,class :background ,bg-main
                                   :foreground ,fg-active)))
     `(mode-line-active ((,class :background ,bg-main
                                 :foreground ,fg-active)))

     `(hl-line ((,class :background ,magenta-nuanced-bg)))

     `(emms-playlist-track-face ((,class :foreground ,blue-nuanced-fg)))
     `(emms-playlist-selected-face ((,class :foreground ,fg-special-cold)))
     `(emms-browser-track-face ((,class :foreground ,blue-nuanced-fg))))))

(add-hook 'modus-themes-after-load-theme-hook #'modus-themes-custom-faces)

(setq modus-themes-italic-constructs t
      modus-themes-hl-line '(accented)
      modus-themes-subtle-line-numbers t
      modus-themes-paren-match '(intense)
      modus-themes-region '(bg-only)
      modus-themes-syntax '(faint)
      modus-themes-mode-line '(borderless)
      modus-themes-org-blocks 'gray-background
      modus-themes-headings '(
                              (1 . (rainbow overline))))

(load-theme 'modus-vivendi t)

(modus-themes-custom-faces)