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 (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
33 (not (window-in-direction 'right nil t -1))
34 (not (window-in-direction 'left nil t -1))
35 (not (window-in-direction 'below nil t 1)))
39 (window-in-direction 'right nil t -1)
40 (not (window-in-direction 'left nil t -1))
41 (not (window-in-direction 'below nil t 1)))
45 (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)))
51 (window-in-direction 'right nil t -1)
52 (not (window-in-direction 'left nil t -1))
53 (window-in-direction 'below nil t 1))
57 (not (window-in-direction 'right nil t -1))
58 (window-in-direction 'left nil t -1)
59 (window-in-direction 'below ni t 1))
66 (defun sd/powerline-center-theme_revised-2 ()
67 "Setup a mode-line with major and minor modes centered."
69 (setq-default mode-line-format
72 (let* ((window-type (my-get-window-type))
73 ;; (active (powerline-selected-window-active))
75 ;; (mode-line-buffer-id (if active 'sd/mode-line-buffer-id 'mode-line-buffer-id-inactive))
76 (mode-line-buffer-id (if active 'sd/mode-line-buffer-id 'powerline-inactive1))
77 (mode-line (if active 'mode-line 'mode-line-inactive))
78 (my-face1 (if active 'sd/powerline-active1 'powerline-inactive1))
79 (my-face-buffer-modified (if (and (sd/buffer-is-eshel-or-scratch) (buffer-modified-p) (not buffer-read-only))
80 'sd/buffer-modified-active1
81 (if buffer-read-only 'sd/buffer-view-active1
83 (face1 (if active 'powerline-active1 'powerline-inactive1))
84 (face2 (if active 'powerline-active2 'powerline-inactive2))
85 (separator-left (intern (format "powerline-%s-%s"
86 (powerline-current-separator)
87 (car powerline-default-separator-dir))))
88 (separator-right (intern (format "powerline-%s-%s"
89 (powerline-current-separator)
90 (cdr powerline-default-separator-dir))))
91 (lhs (if (or (= window-type 1) (= window-type 2) (= window-type 3) (= window-type 5))
92 (list (powerline-raw "%* " my-face-buffer-modified 'l)
93 (powerline-raw " " my-face1)
94 (funcall separator-left my-face1 face1)
95 (powerline-narrow face1 'l)
96 (sd/powerline-simpler-vc (powerline-vc face1)))
98 (center (if (or (= window-type 1) (= window-type 4))
99 (list (powerline-raw " " face1)
100 (funcall separator-right face1 face2)
101 (powerline-raw (concat " ==" (number-to-string (my-get-window-type)) "== ") face2)
102 (funcall separator-left face2 face1))
104 (rhs (if (or (= window-type 1) (= window-type 3) (= window-type 2) (= window-type 6))
105 (list (powerline-raw (format-time-string " %I:%M %p ") my-face1 'r))
107 (concat (powerline-render lhs)
108 (powerline-fill-center face1 (/ (powerline-width center) 2.0))
109 (powerline-render center)
110 (powerline-fill face1 (powerline-width rhs))
111 (powerline-render rhs)))))))
113 (sd/powerline-center-theme_revised-2)
115 (provide 'my-mode-line)
116 ;;; my-mode-line.el ends here