-
Notifications
You must be signed in to change notification settings - Fork 0
/
taoline.el
239 lines (199 loc) · 8.93 KB
/
taoline.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
;;; taoline.el --- Replace modeline with a slimmer proxy -*- lexical-binding: t; -*-
;; taoline © 2018-∞ Peter 11111000000
;; feebleline © 2018 Benjamin Lindqvist
;; Author of taoline: Peter <11111000000@email.com>
;; Author of feebleline: Benjamin Lindqvist <benjamin.lindqvist@gmail.com>
;; URL: https://github.com/11111000000/taoline
;; Package-Version: 0.1
;; Version: 0.1
;; This file is not part of GNU Emacs.
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; For editing!
;; Taoline removes the modeline and replaces it with a slimmer proxy
;; version, which displays some basic information in the echo area
;; instead. This information is only displayed if the echo area is not used
;; for anything else (but if you switch frame/window, it will replace whatever
;; message is currently displayed).
;; To customize taoline's format, modify `taoline-mode-line-text'.
;; NOTE:
;; taoline.el will look considerably better with the following
;; settings:
;; (window-divider-mode t)
;; (setq window-divider-default-bottom-width 1)
;; (setq window-divider-default-places (quote bottom-only))
;; But this mode does not work for all EMACS versions and may not work with
;; terminal EMACS (but I haven't checked). If you're on GUI EMACS and your
;; version supports it, just place the following in your init file:
;; (taoline-default-settings)
;; Otherwise, do (taoline-mode t) instead, but be warned that I'm not sure
;; if it will look good.
;;; Code:
(require 'advice)
(defvar taoline-use-legacy-settings nil)
(when (< emacs-major-version 25)
(setq taoline-use-legacy-settings t))
(setq taoline-use-legacy-settings nil)
(defface taoline-time-face '((t :background "#002200" :foreground "#00aa00" :height 0.9 :box "#005500" :bold nil :family "Digital Display"))
"Taoline time face."
:group 'taoline)
;; (defface taoline-time-face '((t :inherit 'default))
;; "Taoline timestamp face."
;; :group 'taoline)
(defface taoline-input-face '((t :inherit 'fixed-pitch :height 0.8))
"Taoline input face."
:group 'taoline)
(defface taoline-bufname-face '((t :inherit 'fixed-pitch :height 0.9))
"Taoline filename face."
:group 'taoline)
(defface taoline-linum-face '((t :inherit 'fixed-pitch :height 0.7))
"Taoline linum face."
:group 'taoline)
(defface taoline-asterisk-face '((t :foreground "yellow" :inherit 'fixed-pitch :height 0.8))
"Taoline file modified asterisk face."
:group 'taoline)
(defface taoline-previous-buffer-face '((t :foreground "#7e7e7e" :height 0.9))
"Taoline filename face."
:group 'taoline)
(defface taoline-dir-face '((t :inherit 'font-lock-variable-name-face :height 0.9))
"Taoline filename face."
:group 'taoline)
(defface taoline-git-branch-face '((t :inherit 'font-lock-comment-face :bold nil :italic t :height 0.9))
"Taoline filename face."
:group 'taoline)
;; Customizations
(defcustom taoline-show-previous-buffer nil
"Set this if you want to show the previous 'buffer-name' in the modeline proxy."
:group 'taoline)
(defcustom taoline-show-directory t
"Set this if you want to show the direcory path as well as the file-name in the modeline proxy."
:group 'taoline)
(defun taoline-previous-buffer-name ()
"Get name of previous buffer."
(buffer-name (other-buffer (current-buffer) 1)))
(defvar taoline-mode-line-text nil
"Each element is a list with the following format:
(FORMAT-STRING FORMAT-ARGS PROPS)
FORMAT-STRING will be used as the first argument to `format', and
FORMAT-ARGS (a list) will be expanded as the rest of `format'
arguments. If PROPS is given, it should be a list which will be
sent to `add-text-properties'.")
(defun taoline--git-branch-string ()
"Return current git branch as a string, or the empty string if pwd is not in a git repo (or the git command is not found)."
(interactive)
(require 'esh-ext)
(when (and (eshell-search-path "git")
(locate-dominating-file default-directory ".git"))
(let ((git-output (shell-command-to-string (concat "cd " default-directory " && git branch | grep '\\*' | sed -e 's/^\\* //'"))))
(if (> (length git-output) 0)
(substring git-output 0 -1)
;; (concat " :" (substring git-output 0 -1))
""))))
(defvar taoline--home-dir nil)
(require 'all-the-icons)
(setq taoline-default-icon (all-the-icons-octicon "browser" :height 1 :v-adjust 0))
(setq taoline-mode-line-text
'(
("%s " ((cond ((equal current-input-method "russian-computer") "") (t "EN")))
( '(face taoline-input-face)))
(" %s " ((format-time-string "%H:%M:%S"))
( '(face taoline-time-face)))
(" %s" ((let ((icon (all-the-icons-icon-for-mode major-mode))) (if (symbolp icon) taoline-default-icon icon)))
((let ((icon (all-the-icons-icon-for-mode major-mode :height 0.8))) (if (symbolp icon) nil (text-properties-at 0 icon)))))
(" %s" ((if (and taoline-show-directory (buffer-file-name))
(replace-regexp-in-string
taoline--home-dir "~"
(file-name-directory (buffer-file-name)))
""))
( '(face taoline-dir-face)))
("%s" ((if (buffer-file-name)
(file-name-nondirectory (buffer-file-name))
(buffer-name)))
nil) ;; WAT?!: using face here add props to buffer name in tab-mode!
("%s" ((let ((branch (taoline--git-branch-string))) (if (> (length branch) 0) (concat ":" branch) "")))
( '(face taoline-git-branch-face)))
("%s" ((if (buffer-modified-p) " * "
"" ))
( '(face taoline-asterisk-face)))
(" %s " ((format "%s:%s" (format-mode-line "%l") (current-column)))
( '(face taoline-linum-face)))
;; ("%s" ((concat " | " (taoline-previous-buffer-name)))
;; (face taoline-previous-buffer-face))
))
(defun taoline-default-settings-on ()
"Some default settings that works well with taoline."
(setq window-divider-default-bottom-width 1
window-divider-default-places (quote bottom-only))
(window-divider-mode t)
(setq-default mode-line-format nil)
(setq mode-line-format nil))
(defun taoline-legacy-settings-on ()
"Some default settings for EMACS < 25."
(set-face-attribute 'mode-line nil :height 0.1))
(defvar taoline/timer)
(defvar taoline/mode-line-format-previous)
;;;###autoload
(define-minor-mode taoline-mode
"Replace modeline with a slimmer proxy."
:require 'taoline
:global t
(if taoline-mode
;; Activation:
(progn
(setq taoline--home-dir (expand-file-name "~"))
(setq taoline/mode-line-format-previous mode-line-format)
(setq taoline/timer
(run-with-timer 0 0.08 'taoline-mode-line-proxy-fn))
(if taoline-use-legacy-settings (taoline-legacy-settings-on)
(taoline-default-settings-on))
;; (ad-activate 'handle-switch-frame)
(add-hook 'focus-in-hook 'taoline-mode-line-proxy-fn))
;; Deactivation:
(set-face-attribute 'mode-line nil :height 1.0)
(setq-default mode-line-format taoline/mode-line-format-previous)
(setq mode-line-format taoline/mode-line-format-previous)
(cancel-timer taoline/timer)
;; (ad-deactivate 'handle-switch-frame)
(remove-hook 'focus-in-hook 'taoline-mode-line-proxy-fn)
(force-mode-line-update)
(redraw-display)
(with-current-buffer " *Minibuf-0*"
(erase-buffer))))
(defun taoline--mode-line-part (part)
"Return a PART (an element) of `taoline-mode-line-text` as a propertized string."
(let ((text (apply #'format (append (list (car part))
(mapcar #'eval (cadr part)))))
(props (eval (car (elt part 2)))))
(progn
;(pp props)
(when props
(add-text-properties 0 (length text) props text)))
text))
(defvar taoline-placeholder)
(defun taoline-write-buffer-name-maybe ()
"Replace echo-area message with mode-line proxy."
(progn (setq taoline-placeholder (mapconcat #'taoline--mode-line-part
taoline-mode-line-text ""))
(with-current-buffer " *Minibuf-0*"
(erase-buffer)
(insert taoline-placeholder))))
(defun taoline-mode-line-proxy-fn ()
"Put a mode-line proxy in the echo area *if* echo area is empty."
(unless (current-message)
(taoline-write-buffer-name-maybe)))
;; (defadvice handle-switch-frame (after switch-frame-message-name)
;; "Get the modeline proxy to work with i3 switch focus."
;; (taoline-write-buffer-name-maybe)
;; ad-do-it
;; (taoline-write-buffer-name-maybe))
(provide 'taoline)
;;; taoline.el ends here