-
Notifications
You must be signed in to change notification settings - Fork 0
/
rangho-theme.el
289 lines (253 loc) · 11 KB
/
rangho-theme.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
;;; rangho-theme.el --- RangHo's Emacs theme
;;; Commentary:
;; My Emacs theme.
;;; Code:
(deftheme rangho "RangHo's day-to-day Emacs theme")
;; ==============
;; User Interface
;; ==============
;; Set default frame style
(setq default-frame-alist
(list '(width . 115) ; 80 col of editor + 35 col of treemacs
'(height . 25)
'(left-fringe . 0)
'(right-fringe . 0)
'(horizontal-scroll-bar . nil)
'(vertical-scroll-bar . nil)))
;; No stupid startup stuff
(setq inhibit-startup-screen t)
(setq inhibit-startup-message t)
(setq inhibit-startup-echo-area-message t)
;; Disable unnecessary UI elements after loading
(menu-bar-mode 0)
(scroll-bar-mode 0)
(tool-bar-mode 0)
;; No ugly checkboxes
(setq widget-image-enable nil)
;; Always show matching parentheses
(show-paren-mode t)
;; Enable visual bell
(setq visual-bell t)
;; ============
;; Font-related
;; ============
;; Emacs has weird way of implementing font lookup, so the function calls below cannot be
;; tampered, or things *will* break.
;;
;; Sample sentences are provided below for reference:
;; - Alphabet : The quick brown fox jumps over the lazy dog.
;; - Hangul : 다람쥐 헌 쳇바퀴에 타고파.
;; - Kana : いろはにほへと ちりぬるを / わかよたれそ つねならむ
;; - Emoji(?) : I'm blue, da💨🎟 ba🐋🐟 dee 🐦👖da📘🔷 ba💙💠 dai🌊🌀
(defun rangho/set-fontset-font ()
"Set the default font to use throughout Emacs."
(interactive)
(set-face-attribute 'default nil
:font "semteulche"
:height 110)
(set-face-attribute 'variable-pitch nil
:font "Noto Sans CJK KR"
:height 110)
(set-fontset-font t 'hangul (font-spec :name "Noto Sans Mono CJK KR"))
(set-fontset-font t 'kana (font-spec :name "Noto Sans Mono CJK JP"))
(set-fontset-font t 'han (font-spec :name "Noto Sans Mono CJK CN"))
(set-fontset-font t 'unicode (font-spec :name "semteulche"))
(set-fontset-font t
;; The `emoji' charset is introduced in Emacs 28.1
(if (version< emacs-version "28.1")
'(#x1f300 . #x1fad0)
'emoji)
(font-spec :name "Noto Color Emoji")))
(defvar rangho/serif-font-ignore-face-list
'( ;; Texts highlighted with font-lock
font-lock-builtin-face
font-lock-comment-face
font-lock-comment-delimiter-face
font-lock-constant-face
font-lock-doc-face
font-lock-function-name-face
font-lock-keyword-face
font-lock-negation-char-face
font-lock-preprocessor-face
font-lock-regexp-grouping-backslash
font-lock-regexp-grouping-construct
font-lock-string-face
font-lock-type-face
font-lock-variable-name-face
font-lock-warning-face
font-lock-error-face)
"List of faces to ignore when setting serif font.")
(defun rangho/toggle-serif-font ()
"Toggle serif font for the current buffer non-code related texts."
(interactive)
(when (display-graphic-p)
(let ((serif-family "Noto Serif CJK KR")
(serif-height 120)
(default-family (face-attribute 'default :family))
(default-height (face-attribute 'default :height)))
(if (not (bound-and-true-p rangho/serif-font-enabled))
(progn
;; Serif is not enabled now; enable it
(make-local-variable 'rangho/serif-font-enabled)
(make-local-variable 'rangho/serif-font-preserved)
(setq rangho/serif-font-enabled
(face-remap-add-relative 'default
:family serif-family
:height serif-height))
(setq rangho/serif-font-preserved nil)
;; Restore the default font for code-related texts
(dolist (face rangho/serif-font-ignore-face-list)
(add-to-list 'rangho/serif-font-preserved
(face-remap-add-relative face
:family default-family
:height default-height)))
(message "Serif font enabled in the current buffer."))
(progn
;; Serif is enabled; disable it
(face-remap-remove-relative rangho/serif-font-enabled)
(dolist (face rangho/serif-font-preserved)
(face-remap-remove-relative face))
(setq rangho/serif-font-enabled nil)
(setq rangho/serif-font-preserved nil)
(message "Serif font disabled in the current buffer."))))))
;; There are three cases:
;; 1. daemon mode,
;; 2. graphical mode,
;; 3. terminal mode.
(cond ((daemonp) (add-hook 'after-make-frame-functions
(lambda (frame)
(select-frame frame)
(if (display-graphic-p frame)
(rangho/set-fontset-font)))))
((display-graphic-p) (rangho/set-fontset-font))
(t nil))
;; Enable font ligatures
;; Emacs 27 has a problem dealing with ligatures.
;; It's not worth trying to workaround this issue as I have to do make significant
;; changes that I'd rather compile Emacs myself.
(unless (= emacs-major-version 27)
(use-package ligature
:config
(global-ligature-mode)))
;; ===========
;; Colorscheme
;; ===========
;; Load values from pywal, if available
;; If colorscheme is not available, use a sensible "grayscale" as default
(if (file-exists-p (concat user-cache-directory "wal/colors.el"))
(require 'pywal-colors (concat user-cache-directory "wal/colors.el") 'noerror)
(setq-default wal/foreground "#f7f7f7"
wal/background "#101010"
wal/cursor "#f7f7f7"
wal/color0 "#101010"
wal/color1 "#7c7c7c"
wal/color2 "#5c5c5c"
wal/color3 "#a0a0a0"
wal/color4 "#686868"
wal/color5 "#747474"
wal/color6 "#868686"
wal/color7 "#b9b9b9"
wal/color8 "#525252"
wal/color9 "#b0b0b0"
wal/color10 "#8f8f8f"
wal/color11 "#d4d4d4"
wal/color12 "#9c9c9c"
wal/color13 "#a6a6a6"
wal/color14 "#bababa"
wal/color15 "#f7f7f7"))
;; Map color values to their representative colors
;; Note: An `i' next to color name represents that
;; it is the "intense" variant of the color
(defvar rangho/color-name-alist
`((color/fg . ,wal/foreground)
(color/bg . ,wal/background)
(color/cursor . ,wal/cursor)
(color/black . ,wal/color0)
(color/blacki . ,wal/color8)
(color/red . ,wal/color1)
(color/redi . ,wal/color9)
(color/green . ,wal/color2)
(color/greeni . ,wal/color10)
(color/yellow . ,wal/color3)
(color/yellowi . ,wal/color11)
(color/blue . ,wal/color4)
(color/bluei . ,wal/color12)
(color/magenta . ,wal/color5)
(color/magentai . ,wal/color13)
(color/cyan . ,wal/color6)
(color/cyani . ,wal/color14)
(color/white . ,wal/color7)
(color/whitei . ,wal/color15))
"Association list to map wal colors to friendly names.")
;; Load color utility
(require 'color)
;; List of shades to generate for each colors
(defvar rangho/color-shade-list
(number-sequence -20 20 5)
"List of percentage values to lighten/darken the original colors.")
;; Color manipulation utility
(defun color-hex-to-rgb (color)
"Decompose hex representation of a COLOR to 3-tuple (r, g, b)."
(list (/ (string-to-number (substring color 1 3) 16) 255.0)
(/ (string-to-number (substring color 3 5) 16) 255.0)
(/ (string-to-number (substring color 5) 16) 255.0)))
(defun color-lighten-hex (color percent)
"Lighten or darken an RGB color string COLOR by PERCENT."
(let* ((rgb (color-hex-to-rgb color))
(hsl (apply 'color-rgb-to-hsl rgb))
(hsl2 (apply 'color-lighten-hsl (nconc hsl `(,percent))))
(rgb2 (apply 'color-hsl-to-rgb hsl2)))
(apply 'color-rgb-to-hex (nconc rgb2 '(2)))))
;; Color shade creation utility
(defun rangho/create-color-matrix-alist (color-alist lighten-list)
"Create a matrix of colors based on a COLOR-ALIST and LIGHTEN-LIST."
;; For each color association...
(append color-alist
(mapcan (lambda (original-color)
;; And then for each lighten value...
(mapcar (lambda (lighten-value)
;; Create a list of...
(cons (intern (concat (symbol-name (car original-color))
(if (>= lighten-value 0) "+" "")
(number-to-string lighten-value)))
(color-lighten-hex (cdr original-color) lighten-value)))
lighten-list))
color-alist)))
;; Create a color matrix
(defvar rangho/color-matrix-alist
(rangho/create-color-matrix-alist rangho/color-name-alist
rangho/color-shade-list))
;; Apply the color theme
(require 'let-alist)
(let-alist rangho/color-matrix-alist
(custom-theme-set-faces
'rangho
;; Base faces
;; Basic UI elements
`(default ((t (:foreground ,.color/fg :background ,.color/bg))))
`(cursor ((t (:foreground ,.color/bg :background ,.color/cursor))))
`(region ((t (:foreground ,.color/bg :background ,.color/fg))))
`(highlight ((t (:background ,.color/blacki))))
`(button ((t (:underline t))))
`(link ((t (:foreground ,.color/bluei :underline t :weight bold))))
`(link-visited ((t (:foreground ,.color/blue :underline t :weight normal))))
`(success ((t (:foreground ,.color/green :weight bold))))
`(warning ((t (:foreground ,.color/yellow :weight bold))))
;; Modeline configuration
`(mode-line ((t (:foreground ,.color/bg-10 :background ,.color/fg+10 :box (:line-width 3 :color ,.color/fg+10 :style nil)))))
`(mode-line-inactive ((t (:foreground ,.color/fg-10 :background ,.color/bg+10 :box (:line-width 3 :color ,.color/bg+10 :style nil)))))
`(mode-line-highlight ((t (:inherit highlight))))
`(mode-line-emphasis ((t (:weight regular))))
`(mode-line-buffer-id ((t (:weight regular))))
;; font-lock!
`(font-lock-comment-face ((t (:foreground ,.color/green))))
`(font-lock-doc-face ((t (:foreground ,.color/greeni))))
`(font-lock-keyword-face ((t (:foreground ,.color/bluei))))
`(font-lock-builtin-face ((t (:foreground ,.color/blue))))
`(font-lock-type-face ((t (:foreground ,.color/cyan))))
`(font-lock-string-face ((t (:foreground ,.color/yellowi))))
`(font-lock-variable-name-face ((t (:foreground ,.color/yellow))))
`(font-lock-constant-face ((t (:foreground ,.color/magentai))))
`(font-lock-function-name-face ((t (:foreground ,.color/magenta))))))
(provide-theme 'rangho)
;;; rangho-theme.el ends here