about summary refs log tree commit diff
path: root/users/wpcarro/emacs/.emacs.d/wpc/modeline.el
blob: df1cddec9d9249e16ec91c6b5f255e2981e33728 (plain) (blame)
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
;;; modeline.el --- Customize my mode-line -*- lexical-binding: t -*-

;; Author: William Carroll <wpcarro@gmail.com>
;; Version: 0.0.1
;; Package-Requires: ((emacs "25.1"))

;;; Commentary:
;; Because I use EXWM, I treat my Emacs mode-line like my system bar: I need to
;; quickly check the system time, and I expect it to be at the bottom-right of
;; my Emacs frame.  I used doom-modeline for awhile, which is an impressive
;; package, but it conditionally colorizes on the modeline for the active
;; buffer.  So if my bottom-right window is inactive, I cannot see the time.
;;
;; My friend, @tazjin, has a modeline setup that I think is more compatible with
;; EXWM, so I'm going to base my setup off of his.

;;; Code:

(use-package telephone-line)

(defun modeline-bottom-right-window? ()
  "Determines whether the last (i.e.
bottom-right) window of the
active frame is showing the buffer in which this function is
  executed."
  (let* ((frame (selected-frame))
         (right-windows (window-at-side-list frame 'right))
         (bottom-windows (window-at-side-list frame 'bottom))
         (last-window (car (seq-intersection right-windows bottom-windows))))
    (eq (current-buffer) (window-buffer last-window))))

(defun modeline-maybe-render-time ()
  "Conditionally renders the `mode-line-misc-info' string.

  The idea is to not display information like the current time,
  load, battery levels on all buffers."
  (when (modeline-bottom-right-window?)
    (telephone-line-raw mode-line-misc-info t)))

(defun modeline-setup ()
  "Render my custom modeline."
  (telephone-line-defsegment telephone-line-last-window-segment ()
    (modeline-maybe-render-time))
  ;; Display the current EXWM workspace index in the mode-line
  (telephone-line-defsegment telephone-line-exwm-workspace-index ()
    (when (modeline-bottom-right-window?)
      (format "[%s]" exwm-workspace-current-index)))
  ;; Define a highlight font for ~ important ~ information in the last
  ;; window.
  (defface special-highlight
    '((t (:foreground "white" :background "#5f627f"))) "")
  (add-to-list 'telephone-line-faces
               '(highlight . (special-highlight . special-highlight)))
  (setq telephone-line-lhs
        '((nil . (telephone-line-position-segment))
          (accent . (telephone-line-buffer-segment))))
  (setq telephone-line-rhs
        '((accent . (telephone-line-major-mode-segment))
          (nil . (telephone-line-last-window-segment
                  telephone-line-exwm-workspace-index))))
  (setq telephone-line-primary-left-separator 'telephone-line-tan-left
        telephone-line-primary-right-separator 'telephone-line-tan-right
        telephone-line-secondary-left-separator 'telephone-line-tan-hollow-left
        telephone-line-secondary-right-separator 'telephone-line-tan-hollow-right)
  (telephone-line-mode 1))

(provide 'modeline)
;;; modeline.el ends here