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 nil t 1))
65 (defun sd/powerline-center-theme_revised-2 ()
66 "Setup a mode-line with major and minor modes centered."
68 (setq-default mode-line-format
71 (let* ((window-type (my-get-window-type))
72 ;; (active (powerline-selected-window-active))
74 ;; (mode-line-buffer-id (if active 'sd/mode-line-buffer-id 'mode-line-buffer-id-inactive))
75 (mode-line-buffer-id (if active 'sd/mode-line-buffer-id 'powerline-inactive1))
76 (mode-line (if active 'mode-line 'mode-line-inactive))
77 (my-face1 (if active 'sd/powerline-active1 'powerline-inactive1))
78 (my-face-buffer-modified (if (and (sd/buffer-is-eshel-or-scratch) (buffer-modified-p) (not buffer-read-only))
79 'sd/buffer-modified-active1
80 (if buffer-read-only 'sd/buffer-view-active1
82 (face1 (if active 'powerline-active1 'powerline-inactive1))
83 (face2 (if active 'powerline-active2 'powerline-inactive2))
84 (separator-left (intern (format "powerline-%s-%s"
85 (powerline-current-separator)
86 (car powerline-default-separator-dir))))
87 (separator-right (intern (format "powerline-%s-%s"
88 (powerline-current-separator)
89 (cdr powerline-default-separator-dir))))
90 (lhs (if (or (= window-type 1) (= window-type 2) (= window-type 3) (= window-type 6))
91 (list (powerline-raw "%* " my-face-buffer-modified 'l)
92 (powerline-raw " " my-face1)
93 (funcall separator-left my-face1 face1)
94 (powerline-narrow face1 'l)
95 (sd/powerline-simpler-vc (powerline-vc face1)))
97 (center (if (or (= window-type 1) (= window-type 4))
98 (list (powerline-raw " " face1)
99 (funcall separator-right face1 face2)
100 (powerline-raw (concat " ==" (number-to-string (my-get-window-type)) "== ") face2)
101 (funcall separator-left face2 face1))
103 (rhs (if (or (= window-type 1) (= window-type 3) (= window-type 2) (= window-type 5))
104 (list (funcall separator-right face1 my-face1)
105 (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