summaryrefslogtreecommitdiffhomepage
path: root/lib/eos/jao-minibuffer-mode-line.el
blob: 6f69630a589d8244ed48b49c667816ef960b7ac6 (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
;;; jao-minibuffer-mode-line.el --- mode-line info in the minibuffer  -*- 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.

;;; Code:

(require 'jao-minibuffer)

(defvar exwm-class-name nil)

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

(defvar jao-minibuffer--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))))
                (t "%b"))))

(defvar jao-minibuffer--mode-line-format
  `("%[" (:propertize ,jao-minibuffer--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 "")))

(defvar jao-minibuffer--original-modeline nil)
(defvar jao-minibuffer--original-line-face nil)
(defvar jao-minibuffer--original-line-inactive-face nil)

(defun jao-minibuffer-mode-line-adjust-faces ()
  (let ((bg (frame-parameter nil 'background-color)))
    (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-minibuffer-add-mode-line (&optional order)
  (interactive)
  (setq jao-minibuffer--original-line-face
        (get 'mode-line 'saved-face))
  (setq jao-minibuffer--original-line-inactive-face
        (get 'mode-line-inactive 'saved-face))
  (setq jao-minibuffer--original-modeline mode-line-format)
  (setq-default mode-line-format '(" "))
  (setq-default mode-line-position jao-minibuffer--mode-line-position)
  (dolist (b (buffer-list))
    (with-current-buffer b (setq-local mode-line-format '(" "))))
  (jao-minibuffer-add-variable 'jao-minibuffer--mode-line-format (or order 90))
  (jao-minibuffer-mode-line-adjust-faces))

;;;###autoload
(defun jao-minibuffer-remove-mode-line ()
  (interactive)
  (face-spec-set 'mode-line jao-minibuffer--original-line-face)
  (face-spec-set 'mode-line-inactive jao-minibuffer--original-line-inactive-face)
  (setq-default mode-line-format jao-minibuffer--original-modeline)
  (dolist (b (buffer-list))
    (with-current-buffer b (setq-local mode-line-format
                                       jao-minibuffer--original-modeline)))
  (setq jao-minibuffer-info
        (remove '(:eval jao-minibuffer--mode-line-format)
                jao-minibuffer-info)))


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