095b415df6481fb6482a3fdc9299030d7f20e7fe
[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 (defun my-get-window-type ()
28   "According to the window layout, separate the windows as six types.
29 Each type will have different mode line. This function return the defined
30 window type."
31   (cond ((and (not (window-in-direction 'right nil t -1))
32               (not (window-in-direction 'left nil t -1))
33               (not (window-in-direction 'below nil t 1)))
34          1)
35         ((and (window-in-direction 'right nil t -1)
36               (not (window-in-direction 'left nil t -1))
37               (not (window-in-direction 'below nil t 1)))
38          2)
39         ((and (not (window-in-direction 'right nil t -1))
40               (window-in-direction 'left nil t -1)
41               (not (window-in-direction 'below nil t 1)))
42          3)
43         ((and (window-in-direction 'right nil t -1)
44               (not (window-in-direction 'left nil t -1))
45               (window-in-direction 'below nil t 1))
46          5)
47         ((and (not (window-in-direction 'right nil t -1))
48               (window-in-direction 'left nil t -1)
49               (window-in-direction 'below nil t 1))
50          6)
51         (t
52          4)))
53
54
55 (defun sd/powerline-center-theme_revised-2 ()
56   "Setup a mode-line with major and minor modes centered."
57   (interactive)
58   (setq-default mode-line-format
59                 '("%e"
60                   (:eval
61                    (let* ((window-type (my-get-window-type))
62                           ;; (active (powerline-selected-window-active))
63                           (active t)
64                           ;; (mode-line-buffer-id (if active 'sd/mode-line-buffer-id 'mode-line-buffer-id-inactive))
65                           (mode-line-buffer-id (if active 'sd/mode-line-buffer-id 'powerline-inactive1))
66                           (mode-line (if active 'mode-line 'mode-line-inactive))
67                           (my-face1 (if active 'sd/powerline-active1 'powerline-inactive1))
68                           (my-face-buffer-modified (if (and (sd/buffer-is-eshel-or-scratch) (buffer-modified-p) (not buffer-read-only)) 
69                                                        'sd/buffer-modified-active1
70                                                      (if buffer-read-only 'sd/buffer-view-active1
71                                                        my-face1)))
72                           (face1 (if active 'powerline-active1 'powerline-inactive1))
73                           (face2 (if active 'powerline-active2 'powerline-inactive2))
74                           (separator-left (intern (format "powerline-%s-%s"
75                                                           (powerline-current-separator)
76                                                           (car powerline-default-separator-dir))))
77                           (separator-right (intern (format "powerline-%s-%s"
78                                                            (powerline-current-separator)
79                                                            (cdr powerline-default-separator-dir))))
80                           (lhs (if (or (= window-type 1) (= window-type 2) (= window-type 3) (= window-type 6))
81                                    (list (powerline-raw "%* " my-face-buffer-modified 'l)
82                                          (powerline-raw " " my-face1)
83                                          (funcall separator-left my-face1 face1)
84                                          (powerline-narrow face1 'l)
85                                          (sd/powerline-simpler-vc (powerline-vc face1)))
86                                  nil))
87                           (center (if (or (= window-type 1) (= window-type 4))
88                                       (list (powerline-raw " " face1)
89                                             (funcall separator-right face1 face2)
90                                             (powerline-raw (concat " ==" (number-to-string (my-get-window-type)) "== ") face2)
91                                             (funcall separator-left face2 face1))
92                                     nil))
93                           (rhs (if (or (= window-type 1) (= window-type 3) (= window-type 2) (= window-type 5))
94                                    (list (funcall separator-right face1 my-face1)
95                                     (powerline-raw (format-time-string " %I:%M %p  ") my-face1 'r))
96                                  nil)))
97                      (concat (powerline-render lhs)
98                              (powerline-fill-center face1 (/ (powerline-width center) 2.0))
99                              (powerline-render center)
100                              (powerline-fill face1 (powerline-width rhs))
101                              (powerline-render rhs)))))))
102
103 (sd/powerline-center-theme_revised-2)
104
105 (provide 'my-mode-line)
106 ;;; my-mode-line.el ends here