89de26226dad24c39b43527d8c1b69594bf3543c
[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                           (my-face1 'sd/powerline-active1 )
70                           ;; (my-face-buffer-modified (if (and (sd/buffer-is-eshel-or-scratch) (buffer-modified-p) (not buffer-read-only)) 
71                           ;;                              'sd/buffer-modified-active1
72                           ;;                            (if buffer-read-only 'sd/buffer-view-active1
73                           ;;                              my-face1)))
74                           (face1 'powerline-active1)
75                           (face2 'powerline-active2)
76                           (separator-left (intern (format "powerline-%s-%s"
77                                                           (powerline-current-separator)
78                                                           (car powerline-default-separator-dir))))
79                           (separator-right (intern (format "powerline-%s-%s"
80                                                            (powerline-current-separator)
81                                                            (cdr powerline-default-separator-dir))))
82                           (lface (if (and (not active)
83                                           (or (= window-type 3) (= window-type 6)))
84                                      face2
85                                    my-face1))
86                           (cface (if active my-face1 face2))
87                           (rface (if (and (not active)
88                                           (or (= window-type 2) (= window-type 5)))
89                                      face2
90                                    my-face1))
91                           (lhs (cond ((or (= window-type 1) (= window-type 2))
92                                       (list (powerline-raw "%* " lface 'l)
93                                             (funcall separator-left lface face1 )))
94                                      ((or (= window-type 3) (= window-type 6))
95                                       (list (powerline-buffer-id lface 'l)
96                                             (powerline-raw " " lface)
97                                             (funcall separator-left lface face1 )))
98                                      (t
99                                       nil)))
100                           (center (if (or (= window-type 1) (= window-type 4))
101                                     (list (powerline-raw " " face1)
102                                           (funcall separator-right face1 cface)
103                                           (powerline-buffer-id cface 'r)
104                                           (funcall separator-left cface face1))
105                                     nil))                          (rhs (cond ((or (= window-type 1) (= window-type 3))
106                                       (list (funcall separator-right face1 rface)
107                                             (powerline-raw (format-time-string " %I:%M %p ") rface 'r)))
108                                      ((or (= window-type 2) (= window-type 5))
109                                       (list (funcall separator-right face1 rface)
110                                             (powerline-buffer-id rface 'r)
111                                             (powerline-raw " " rface)))
112                                      (t
113                                       nil))))
114                      (concat (powerline-render lhs)
115                              (powerline-fill-center face1 (/ (powerline-width center) 2.0))
116                              (powerline-render center)
117                              (powerline-fill face1 (powerline-width rhs))
118                              (powerline-render rhs)))))))
119
120 (sd/powerline-center-theme_revised-2)
121
122 (provide 'my-mode-line)
123 ;;; my-mode-line.el ends here