53aa7b8963bd0c3184195f24f177f455920db84c
[dotfiles.git] / emacs.d / my-mode-line.el
1 ;;; my-mode-line.el --- my mode line based on powerline  -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2017  Peng Li
4
5 ;; Author: Peng Li <seudut@gmail.com>
6 ;; Keywords: 
7
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
12
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 ;;; Commentary:
22
23 ;; test
24
25 ;;; Code:
26
27 ;; A windows may have six kinds different mode-line
28 ;; type = 1.
29 ;;   -----------------------------
30 ;;   |>>>         O           <<<| 
31 ;;   -----------------------------
32
33 (defun my-get-window-type ()
34   "According to the window layout, separate the windows as six types.
35 Each type will have different mode line. This function return the defined
36 window type."
37   (cond ((and (not (window-in-direction 'right nil t -1))
38               (not (window-in-direction 'left nil t -1))
39               (not (window-in-direction 'below nil t 1)))
40          1)
41         ((and (window-in-direction 'right nil t -1)
42               (not (window-in-direction 'left nil t -1))
43               (not (window-in-direction 'below nil t 1)))
44          2)
45         ((and (not (window-in-direction 'right nil t -1))
46               (window-in-direction 'left nil t -1)
47               (not (window-in-direction 'below nil t 1)))
48          3)
49         ((and (window-in-direction 'right nil t -1)
50               (not (window-in-direction 'left nil t -1))
51               (window-in-direction 'below nil t 1))
52          5)
53         ((and (not (window-in-direction 'right nil t -1))
54               (window-in-direction 'left nil t -1)
55               (window-in-direction 'below nil t 1))
56          6)
57         (t
58          4)))
59
60 (my-get-window-type)
61 (defun sd/powerline-center-theme_revised-2 ()
62   "Setup a mode-line with major and minor modes centered."
63   (interactive)
64   (setq-default mode-line-format
65                 '("%e"
66                   (:eval
67                    (let* ((window-type (my-get-window-type))
68                           (active (powerline-selected-window-active))
69                           ;; (active t)
70                           ;; (my-face1 (if active 'sd/powerline-active1 'powerline-inactive1))
71                           (my-face1 'sd/powerline-active1 )
72                           ;; (my-face-buffer-modified (if (and (sd/buffer-is-eshel-or-scratch) (buffer-modified-p) (not buffer-read-only)) 
73                           ;;                              'sd/buffer-modified-active1
74                           ;;                            (if buffer-read-only 'sd/buffer-view-active1
75                           ;;                              my-face1)))
76                           (face1 'powerline-active1)
77                           (face2 'powerline-active2)
78                           (separator-left (intern (format "powerline-%s-%s"
79                                                           (powerline-current-separator)
80                                                           (car powerline-default-separator-dir))))
81                           (separator-right (intern (format "powerline-%s-%s"
82                                                            (powerline-current-separator)
83                                                            (cdr powerline-default-separator-dir))))
84                           (lface (if (and (not active)
85                                           (or (= window-type 3) (= window-type 6)))
86                                      face2
87                                    my-face1))
88                           (cface (if active my-face1 face2))
89                           (rface (if (and (not active)
90                                           (or (= window-type 2) (= window-type 5)))
91                                      face2
92                                    my-face1))
93                           (lhs (if (or (= window-type 1) (= window-type 2) (= window-type 3) (= window-type 6))
94                                    (list (powerline-raw "%* " lface 'l)
95                                          ;; (powerline-raw "%* " my-face-buffer-modified 'l)
96                                          (powerline-raw " " lface)
97                                          (funcall separator-left lface face1)
98                                          (powerline-narrow face1 'l)
99                                          ;; (sd/powerline-simpler-vc (powerline-vc face1))
100                                          )
101                                  nil))
102                           (center (if (or (= window-type 1) (= window-type 4))
103                                     (list (powerline-raw " " face1)
104                                           (funcall separator-right face1 cface)
105                                           (powerline-raw (concat " ==" (number-to-string (my-get-window-type)) "== ") cface)
106                                           (funcall separator-left cface face1))
107                                     nil))
108                           (rhs (if (or (= window-type 1) (= window-type 3) (= window-type 2) (= window-type 5))
109                                    (list (funcall separator-right face1 rface)
110                                          (powerline-raw (format-time-string " %I:%M %p  ") rface 'r))
111                                  nil)))
112                      (concat (powerline-render lhs)
113                              (powerline-fill-center face1 (/ (powerline-width center) 2.0))
114                              (powerline-render center)
115                              (powerline-fill face1 (powerline-width rhs))
116                              (powerline-render rhs)))))))
117
118 (sd/powerline-center-theme_revised-2)
119
120 (provide 'my-mode-line)
121 ;;; my-mode-line.el ends here