summaryrefslogtreecommitdiffhomepage
path: root/lib/eos/jao-mode-line.el
blob: 0fd5a2e6ac15f8fda93841329eb5ed7351dd43fd (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
151
152
153
154
155
156
157
158
159
160
161
;;; jao-mode-line.el --- mode-line info -*- lexical-binding: t; -*-

;; Copyright (C) 2022  jao

;; Author: jao <mail@jao.io>
;; Keywords: convenience

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; Using jao-minibuffer to display mode-line info in the minibuffer,
;; or toggle it off in non-active windows.

;;; Code:

(require 'jao-minibuffer)


;;;; mode line toggle
(defun jao-mode-line--face-height (face &optional all)
  (let* ((h (face-attribute face :height (window-frame)))
         (nh (if (eq 'unspecified h) 1 'unspecified)))
    (set-face-attribute face (when (not all) (window-frame)) :height nh)))

(defun jao-mode-line--set-inactive-face (x frame)
  (unless (eq x (face-attribute 'mode-line-inactive :height frame))
    (set-face-attribute 'mode-line-inactive frame :height x)))

;;;###autoload
(defun jao-mode-line-toggle (&optional all)
  (interactive "P")
  (jao-mode-line--face-height 'mode-line all))

;;;###autoload
(defun jao-mode-line-toggle-inactive (&optional all)
  (interactive "P")
  (jao-mode-line--face-height 'mode-line-inactive all))

;;;###autoload
(defun jao-mode-line-echo ()
  (interactive)
  (message "%s" (format-mode-line mode-line-format)))

;;;###autoload
(defun jao-mode-line-hide-inactive (frame)
  (jao-mode-line--set-inactive-face 1 frame))

;;;###autoload
(defun jao-mode-line-show-inactive (frame)
  (jao-mode-line--set-inactive-face 'unspecified frame))


;;;; mode line format

(defvar exwm-class-name nil)

(defvar jao-mode-line--position
  '(exwm-class-name
    ("")
    ("%n %2c %l " (:eval (format "%d" (line-number-at-pos (point-max)))))))

(defvar-local eww-data nil)

(defvar jao-mode-line--bid
  '(:eval (cond ((derived-mode-p 'gnus-group-mode
                                 'gnus-article-mode
                                 'gnus-summary-mode)
                 mode-line-buffer-identification)
                ((derived-mode-p 'circe-channel-mode)
                 (format "%s [%d]" (buffer-name) (length (circe-channel-nicks))))
                ((not (null eww-data))
                 (or (plist-get eww-data :title) "No title"))
                (t "%b"))))

(defvar jao-mode-line--format
  `("%[" (:propertize ,jao-mode-line--bid face jao-themes-f00) "%]"
    (:propertize " (" face jao-themes-dimm)
    (:propertize mode-name face jao-themes-f00)
    (:propertize ("" minor-mode-alist) face jao-themes-f11)
    (:propertize ")" face jao-themes-dimm)
    (:propertize (vc-mode vc-mode) face jao-themes-f10)
    (:propertize mode-line-position face jao-themes-f12)
    " "
    global-mode-string
    (:propertize (" %Z%*%+ " (current-input-method current-input-method-title))
                 face jao-themes-warning)
    (:propertize "·" display "")))


;;;; mode line in minibuffer

(defvar jao-mode-line--old-format nil)
(defvar jao-mode-line--face nil)
(defvar jao-mode-line--inactive-face nil)
(defvar jao-mode-line--props
  '(:box :height :background :foreground :overline :underline :extend))

(defun jao-mode-line--extract-face (inactive)
  (let ((atts nil)
        (face (if inactive 'mode-line-inactive 'mode-line)))
    (dolist (a jao-mode-line--props)
      (push (face-attribute face a) atts)
      (push a atts))
    (set (if inactive 'jao-mode-line--inactive-face 'jao-mode-line--face) atts)))

(defun jao-mode-line--revert-face (inactive)
  (apply #'set-face-attribute (if inactive 'mode-line-inactive 'mode-line) nil
         (if inactive jao-mode-line--inactive-face jao-mode-line--face)))

(defun jao-mode-line-adjust-faces ()
  (let ((bg (frame-parameter nil 'background-color)))
    (jao-mode-line--extract-face nil)
    (jao-mode-line--extract-face t)
    (set-face-attribute 'mode-line nil :box nil :height 1
                        :background bg :foreground bg
                        :overline jao-minibuffer-active-buffer-line-color
                        :underline jao-minibuffer-inactive-buffer-line-color
                        :extend t)
    (set-face-attribute 'mode-line-inactive nil :box nil :height 1
                        :background bg :foreground bg
                        ;; :overline bg
                        :underline jao-minibuffer-inactive-buffer-line-color
                        :extend t)))

;;;###autoload
(defun jao-mode-line-add-to-minibuffer (&optional order)
  (interactive)
  (setq jao-mode-line--old-format mode-line-format)
  (setq-default mode-line-format '(" "))
  (setq-default mode-line-position jao-mode-line--position)
  (dolist (b (buffer-list))
    (with-current-buffer b (setq-local mode-line-format '(" "))))
  (jao-minibuffer-add-variable 'jao-mode-line--format (or order 90))
  (jao-mode-line-adjust-faces))

;;;###autoload
(defun jao-mode-line-remove-from-minibuffer ()
  (interactive)
  (jao-mode-line--revert-face nil)
  (jao-mode-line--revert-face t)
  (setq-default mode-line-format jao-mode-line--old-format)
  (dolist (b (buffer-list))
    (with-current-buffer b
      (setq-local mode-line-format jao-mode-line--old-format)))
  (jao-minibuffer-remove-variable 'jao-mode-line--format))


(provide 'jao-mode-line)
;;; jao-mode-line.el ends here