-
Notifications
You must be signed in to change notification settings - Fork 49
/
setup-mode-line.el
executable file
·230 lines (211 loc) · 11 KB
/
setup-mode-line.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
;; Time-stamp: <2015-07-15 11:11:09 kmodi>
;; Customize the mode-line
(defvar modi/show-date-time-in-mode-line nil
"If non-nil, show the date-time in the mode-line.
If nil, show the same in the minibuffer.")
;; Date, time, load average, mail in mode-line
(if modi/show-date-time-in-mode-line
(setq display-time-format "%l:%M %b %d %a" )
(setq display-time-format ""))
;; Do NOT show average system load time
(setq display-time-default-load-average nil)
(display-time-mode 1)
;; Show line and column numbers in the mode-line
(line-number-mode 1)
(column-number-mode 1)
;; Display date+time in the minibuffer instead of in the mode-line
(use-package minibuffer-line
:if (null modi/show-date-time-in-mode-line)
:defer 1 ; to prevent 'Invalid face reference: minibuffer-line'
; when launching emacsclient
:init
(progn
(setq minibuffer-line-format '((:eval
(format-time-string "%l:%M %b %d %a"))))
(defvar modi/time-go-home-reset "07:00am"
"Time when to modify the time face to remove the alert face.")
(defvar modi/time-go-home-alert "05:15pm"
"Time when to modify the time face to alert it's time to go home."))
:config
(progn
(defun modi/minibuffer-line-set-default-face ()
(set-face-attribute 'minibuffer-line nil :inherit font-lock-type-face))
(defun modi/minibuffer-line-set-alert-face ()
(set-face-attribute 'minibuffer-line nil :inherit font-lock-warning-face))
(defun modi/reset-go-home-alert (time)
"Reset the 'go home' alert time interactively.
The timer is canceled and not restarted if TIME is \"nil\" or \"\"."
(interactive "sReset alert time (e.g. 7:00am): ")
(setq modi/time-go-home-reset time)
(when (and (boundp 'modi/timer--go-home-reset) ; cancel the timer if
(timerp modi/timer--go-home-reset)) ; already running
(cancel-timer modi/timer--go-home-reset))
(if (or (string= time "")
(string= time "nil"))
(set-face-attribute 'minibuffer-line nil :inherit font-lock-type-face)
(let ((daily (* 60 60 24)))
(setq modi/timer--go-home-reset (run-at-time
time daily
#'modi/minibuffer-line-set-default-face)))))
(defun modi/set-go-home-alert (time)
"Set the 'go home' alert time interactively.
The `modi/timer--go-home-reset' and `modi/timer--go-home-alert' timers
are canceled and not restarted if TIME is \"nil\" or \"\"."
(interactive "s'Go Home' alert time (e.g. 5:00pm): ")
(setq modi/time-go-home-alert time)
(let (old-go-home-time old-go-home-time-str)
(when (and (boundp 'modi/timer--go-home-alert) ; cancel the timer if
(timerp modi/timer--go-home-alert)) ; already running
(setq old-go-home-time (list (elt modi/timer--go-home-alert 1)
(elt modi/timer--go-home-alert 2)))
(setq old-go-home-time-str (downcase (format-time-string
"%I:%M%p" old-go-home-time)))
(cancel-timer modi/timer--go-home-alert))
(if (or (string= time "")
(string= time "nil"))
(progn
(modi/reset-go-home-alert "nil")
(setq modi/timer--go-home-alert nil)
(message "'Go Home' alert removed."))
(let ((daily (* 60 60 24))
new-go-home-time new-go-home-time-str)
(setq modi/timer--go-home-alert (run-at-time
time daily
#'modi/minibuffer-line-set-alert-face))
(setq new-go-home-time (list (elt modi/timer--go-home-alert 1)
(elt modi/timer--go-home-alert 2)))
(setq new-go-home-time-str (downcase (format-time-string
"%I:%M%p" new-go-home-time)))
(if old-go-home-time
(if (string= new-go-home-time-str old-go-home-time-str)
(message "'Go Home' alert time unchanged: %s"
new-go-home-time-str)
(message "Changed 'Go Home' alert time from %s to %s."
old-go-home-time-str new-go-home-time-str))
(message "'Go Home' alert time set to %s." new-go-home-time-str))))))
(minibuffer-line-mode)
(modi/reset-go-home-alert modi/time-go-home-reset)
(modi/set-go-home-alert modi/time-go-home-alert)))
;; smart-mode-line
;; emacs modeline aka statusbar
;; https://github.com/Malabarba/smart-mode-line
(use-package smart-mode-line
:init
(progn
(setq sml/line-number-format "%4l")
(setq sml/name-width 40) ; buffer name width in the mode-line
(setq sml/mode-width 'full) ; minor mode lighters area width
(setq sml/no-confirm-load-theme t)
(setq sml/theme (if (boundp 'dark-theme)
(if (not dark-theme) 'light 'dark)
'dark))
(setq sml/replacer-regexp-list
`(
("^~/org/" ":Org:")
("^~/\\.emacs\\.d/" ":ED:")
("^~/.*box/uvm/uvm_examples/" ":UVM_EX:")
("^~/.*box/uvm/adsim_uvm_examples/" ":AD_UVM_EX:")
(":\\(.*_EX\\):\\([a-z0-9_]\\{3\\}\\).*?/"
(lambda (string) (concat ":\\1:"
(match-string 2 string)
":")))
;; Prefix with first 2 letters and last letter of project name
;; To distinguish between projects that could have same first 3 letters
;; Using "\,(upcase ...)" only works when calling `replace-regexp` interactively.
;; In lisp code you have to give it a function. So we need to change the
;; replacement string to,
;; `(lambda (string) (concat ":" (upcase (match-string 1 string)) ":")))`.
(,(concat "/proj.*?" ; project base
"/\\([a-z0-9_]\\{2\\}\\).*?\\([a-z0-9_]\\)" ; project name
"/[so]+_\\([a-z0-9]+\\)" ; user project root
"/\\([a-z0-9_]\\{0,3\\}\\).*?/") ; dir in user project root
(lambda (string)
;; (concat ":"
;; (capitalize (match-string 1 string))
;; (upcase (match-string 2 string))
;; (when (not (string= (match-string 3 string) (getenv "USER")))
;; (concat "[" (match-string 3 string) "]"))
;; ":" (upcase (match-string 4 string)) ":"
;; )
(let ((user (match-string-no-properties 3 string))
(abbrev-dir (match-string-no-properties 4 string)))
(concat ":" ; The first char HAS to be `:'
(when (not (string= user (getenv "USER")))
(concat "~" user "/"))
(upcase abbrev-dir) ":"))))
("\\(:.*\\)DIG:tb/" "\\1TB:" )
("\\(:.*\\)TB:agents/" "\\1AGT:" )
("\\(:.*\\)TB:patterns/" "\\1PAT:" )
("\\(:.*\\)TB:uvm.*src/" "\\1UVM:" )
("\\(:.*\\)DIG:design_code/" "\\1DSGN:")
("\\(:.*\\)DSGN:rtl/" "\\1RTL:" )
("\\(:.*\\)DSGN:analog_partition_rtl/" "\\1ANA:" ))))
:config
(progn
(use-package rich-minority
:config
(progn
(setq rm-blacklist
'(" Guide" ; guide-key
" WK" ; which-key
" hc" ; hardcore mode
" AC" ; auto-complete
" vl" ; global visual line mode enabled
" Wrap" ; shows up if visual-line-mode is enabled for that buffer
" Omit" ; omit mode in dired
" yas" ; yasnippet
" drag" ; drag-stuff-mode
" VHl" ; volatile highlights
" ctagsU" ; ctags update
" Undo-Tree" ; undo tree
" wr" ; Wrap Region
" SliNav" ; elisp-slime-nav
" Fly" ; Flycheck
" PgLn" ; page-line-break
" ElDoc" ; eldoc
" hl-highlight" ; hl-anything
" Helm" ; Helm
" GG" ; ggtags
" hs" ; hideshow
" hs+" ;
" ez-esc" ; easy-escape
" ivy" ; ivy
))
(setq rm-text-properties '(("\\` Ovwrt\\'" 'face 'font-lock-warning-face))) ; default
(add-to-list 'rm-text-properties '("\\` Abbrev\\'" 'display "@")) ; Abbrev
(add-to-list 'rm-text-properties '("\\` Ind\\'" 'display "*>")) ; org indent
(add-to-list 'rm-text-properties '("\\` Outl\\'" 'display "ø")) ; outline
(add-to-list 'rm-text-properties '("\\` Server\\'" 'display "Σ")) ; Server
(add-to-list 'rm-text-properties '("\\` μ\\'" 'display "μ")) ; modi-mode
(add-to-list 'rm-text-properties '("\\` Wg\\'" 'display "w")) ; writegood
(add-to-list 'rm-text-properties '("\\` =>\\'" 'display "a")) ; aggressive indent
(with-eval-after-load 'setup-symbola
(if font-symbola-p
(progn
(add-to-list 'rm-text-properties '("\\` Tail\\'" 'display "🢛")) ; auto revert tail
(add-to-list 'rm-text-properties '("\\` Temp\\'" 'display "𝘵")) ; temp
(add-to-list 'rm-text-properties '("\\` rk\\'" 'display "▯")) ; region bindings
(add-to-list 'rm-text-properties '("\\` Vis\\'" 'display "◉"))) ; visible-mode
(progn
(add-to-list 'rm-text-properties '("\\` Tail\\'" 'display "Tail|"))
(add-to-list 'rm-text-properties '("\\` Temp\\'" 'display "t"))
(add-to-list 'rm-text-properties '("\\` rk\\'" 'display "r"))
(add-to-list 'rm-text-properties '("\\` Vis\\'" 'display "v")))))))
(sml/setup)))
(provide 'setup-mode-line)
;; Variables used in display-time-format
;; Source: http://docs.splunk.com/Documentation/Splunk/5.0.2/SearchReference/Commontimeformatvariables
;; %y = year in numbers (2-digit)
;; %Y = year in numbers (4-digit)
;; %m = month in number (eg: 12)
;; %B = full month name (eg: December)
;; %b = short month name (eg: Dec)
;; %d = day in numbers, with leading zeros (eg: 08)
;; %e = day in numbers, no leading zeros (eg: 8)
;; %A = full weekday name (eg: Sunday)
;; %a = short weekday name (eg: Sun)
;; %H = hours in 24-clock, with leading zeros
;; %k = hours in 24-clock, no leading zeros
;; %l = hours in 12-clock, with leading zeros
;; %p = am/pm
;; %T = time in 24-hour notation (%H:%M:%S)