1 ;;; my-mode-line.el --- my mode line based on powerline -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2017 Peng Li
5 ;; Author: Peng Li <seudut@gmail.com>
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.
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.
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/>.
27 ;; A windows may have six kinds different mode-line
29 ;; -----------------------------
31 ;; -----------------------------
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
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)))
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)))
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)))
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))
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))
61 (defun sd/powerline-center-theme_revised-2 ()
62 "Setup a mode-line with major and minor modes centered."
64 (setq-default mode-line-format
67 (let* ((window-type (my-get-window-type))
68 (active (powerline-selected-window-active))
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
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)))
88 (cface (if active my-face1 face2))
89 (rface (if (and (not active)
90 (or (= window-type 2) (= window-type 5)))
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))
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))
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))
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)))))))
118 (sd/powerline-center-theme_revised-2)
120 (provide 'my-mode-line)
121 ;;; my-mode-line.el ends here