forked from zqwell/lw-editor-color-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditor-color-theme.lisp
342 lines (289 loc) · 12.3 KB
/
editor-color-theme.lisp
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
;;;; Copyright (C) 2013 Paulo Madeira
;;;;
;;;; This Source Code Form is subject to the terms of the Mozilla Public
;;;; License, v. 2.0. If a copy of the MPL was not distributed with this
;;;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;; Interface
(cl:in-package #:cl-user)
(defpackage #:editor-color-theme
(:use #:cl)
(:export #:all-color-themes
#:color-theme-args
#:color-theme
#:define-color-theme
#:remove-color-theme
))
(in-package #:editor-color-theme)
;;; Configuration
(defvar *foreground-color* nil)
(defvar *background-color* nil)
(defconstant +default-parenthesis-font-face-colours+ '(:red :black :darkgreen :darkorange3 :blue :purple))
;;; Implementation
(defvar *all-color-themes* (make-hash-table :test 'string=))
(defun all-color-themes ()
(loop for key being the hash-keys in *all-color-themes*
collect key))
(defun color-theme-data (theme-name)
(multiple-value-bind (color-theme-data found?)
(gethash theme-name *all-color-themes*)
(if found?
color-theme-data
(error "No color theme named ~s found." theme-name))))
(defun color-theme-super-theme-names (theme-name)
(first (color-theme-data theme-name)))
(defun color-theme-args (theme-name)
(rest (color-theme-data theme-name)))
(defvar *all-editor-panes* (make-hash-table :test 'eq
:weak-kind :key))
(defun update-editor-pane (pane)
(setf (capi:simple-pane-foreground pane) (or *foreground-color* :color_windowtext))
(setf (capi:simple-pane-background pane) (or *background-color* :color_window))
(let ((recolorize-p (editor::buffer-font-lock-mode-p (capi:editor-pane-buffer pane))))
(when recolorize-p
(gp:invalidate-rectangle pane)))
(values))
(defun update-editor-panes ()
(maphash #'(lambda (pane value)
(declare (ignore value))
(update-editor-pane pane))
*all-editor-panes*)
(values))
(defvar *editor-face-names*
'(:region
:show-point-face
:interactive-input-face
:highlight
:non-focus-complete-face
:font-lock-function-name-face
:font-lock-comment-face
:font-lock-type-face
:font-lock-variable-name-face
:font-lock-string-face
:font-lock-keyword-face
:font-lock-builtin-face
:compiler-note-highlight
:compiler-warning-highlight
:compiler-error-highlight
))
(defun set-color-theme (theme-name)
(destructuring-bind (&rest color-theme-args
&key foreground background &allow-other-keys)
(color-theme-args theme-name)
(setf *foreground-color* (or foreground :color_windowtext))
(setf *background-color* (or background :color_window))
(lw:when-let (parenthesis-colors
(getf color-theme-args :parenthesis-font-face-colours
+default-parenthesis-font-face-colours+))
(editor::set-parenthesis-colours parenthesis-colors))
(dolist (name *editor-face-names*)
(let* ((color-theme-args-for-face (getf color-theme-args name))
(face-name (intern (string name) '#:editor))
(face (editor:make-face face-name :if-exists t)))
(apply 'editor:make-face face-name :if-exists :overwrite
:documentation (or (getf color-theme-args-for-face :documentation)
(slot-value face 'documentation))
color-theme-args-for-face))))
theme-name)
(defun color-theme (theme-name)
(mapc 'set-color-theme (color-theme-super-theme-names theme-name))
(set-color-theme theme-name)
(update-editor-panes)
theme-name)
(defun define-color-theme (theme-name super-theme-names
&rest color-theme-args &key &allow-other-keys)
(dolist (super-theme-name super-theme-names)
(multiple-value-bind (color-theme-data found?)
(gethash super-theme-name *all-color-themes*)
(declare (ignore color-theme-data))
(unless found?
(warn "Inherited color theme ~s not defined." super-theme-name))))
(setf (gethash theme-name *all-color-themes*) (list* super-theme-names color-theme-args))
theme-name)
(defun remove-color-theme (theme-name)
(remhash theme-name *all-color-themes*))
(sys::without-warning-on-redefinition
(defmethod initialize-instance :around ((pane capi:editor-pane) &key &allow-other-keys)
(multiple-value-prog1
(call-next-method)
(setf (gethash pane *all-editor-panes*) pane)
(when *foreground-color*
(setf (capi:simple-pane-foreground pane) *foreground-color*))
(when *background-color*
(setf (capi:simple-pane-background pane) *background-color*))))
)
;; This makes it "work" after the podium is launched
(defun is-editor-pane-p (obj)
(and (typep obj 'capi:editor-pane)
(not (eq obj (hcl:class-prototype (class-of obj))))))
(defun cache-existing-pane (pane)
(setf (gethash pane *all-editor-panes*) pane))
(defun cache-if-pane (obj)
(when (is-editor-pane-p obj)
(cache-existing-pane obj)))
#+:lispworks-personal-edition
(hcl:sweep-all-objects #'cache-if-pane)
;;; Initial color themes
(define-color-theme "default" ()
:foreground nil :background nil
:region '(:foreground :color_highlighttext
:background :color_highlight)
:show-point-face '(:background :green)
:interactive-input-face '(:foreground :red3)
:highlight '(:bold-p t)
:non-focus-complete-face '(:background :tweak_background)
:font-lock-function-name-face '(:foreground :blue)
:font-lock-comment-face '(:foreground :firebrick)
:font-lock-type-face '(:foreground :forestgreen)
:font-lock-variable-name-face '(:foreground :darkgoldenrod)
:font-lock-string-face '(:foreground :rosybrown)
:font-lock-keyword-face '(:foreground :purple)
:font-lock-builtin-face '(:foreground :orchid)
:compiler-note-highlight '(:foreground :magenta)
:compiler-warning-highlight '(:foreground :orange3)
:compiler-error-highlight '(:foreground :red))
(define-color-theme "plain" ()
:foreground nil :background nil
:region '(:foreground :color_highlighttext
:background :color_highlight)
:show-point-face '()
:interactive-input-face '()
:highlight '(:bold-p t)
:non-focus-complete-face '(:background :tweak_background)
:font-lock-function-name-face '()
:font-lock-comment-face '()
:font-lock-type-face '()
:font-lock-variable-name-face '()
:font-lock-string-face '()
:font-lock-keyword-face '()
:font-lock-builtin-face '()
:compiler-note-highlight '()
:compiler-warning-highlight '()
:compiler-error-highlight '())
(define-color-theme "emacs" ()
:foreground nil :background nil
:region '(:foreground :color_highlighttext
:background :color_highlight)
:show-point-face '(:background :green)
:interactive-input-face '(:foreground :red3)
:highlight '(:bold-p t)
:non-focus-complete-face '(:background :tweak_background)
:font-lock-function-name-face '(:foreground :blue)
:font-lock-comment-face '(:foreground :gray40)
:font-lock-type-face '(:foreground :forestgreen)
:font-lock-variable-name-face '(:foreground :darkgoldenrod)
:font-lock-string-face '(:foreground :rosybrown)
:font-lock-keyword-face '(:foreground :purple)
:font-lock-builtin-face '(:foreground :orchid)
:compiler-note-highlight '(:foreground :magenta)
:compiler-warning-highlight '(:foreground :orange3)
:compiler-error-highlight '(:foreground :red))
(define-color-theme "torte" ()
:foreground (color:make-rgb 0.8s0 0.8s0 0.8s0)
:background (color:make-rgb 0.0s0 0.0s0 0.0s0)
:region '(:foreground :color_highlighttext
:background :color_highlight)
:show-point-face `(:background ,(color:make-rgb 0.6275s0 0.1255s0 0.9412s0))
:interactive-input-face '(:foreground :pink)
:highlight '(:bold-p t)
:non-focus-complete-face '(:background :tweak_background)
:font-lock-function-name-face `(:foreground ,(color:make-rgb 0.0s0 1.0s0 1.0s0))
:font-lock-comment-face `(:foreground ,(color:make-rgb 0.5s0 0.6275s0 1.0s0))
:font-lock-type-face `(:foreground ,(color:make-rgb 0.5s0 1.0s0 0.5s0))
:font-lock-variable-name-face `(:foreground ,(color:make-rgb 1.0s0 1.0s0 1.0s0))
:font-lock-string-face `(:foreground ,(color:make-rgb 1.0s0 0.6275s0 0.6275s0))
:font-lock-keyword-face `(:foreground ,(color:make-rgb 1.0s0 1.0s0 0.0s0))
:font-lock-builtin-face `(:foreground ,(color:make-rgb 1.0s0 1.0s0 0.0s0))
:compiler-note-highlight '(:foreground :magenta)
:compiler-warning-highlight '(:foreground :orange)
:compiler-error-highlight '(:foreground :red))
(defun make-rgb (red green blue &optional alpha)
(color:make-rgb (/ red 255s0)
(/ green 255s0)
(/ blue 255s0)
(and alpha (/ alpha 255s0))))
(defvar *solarized-color-table*
'(:solarized-base03 (#x00 #x2b #x36)
:solarized-base02 (#x07 #x36 #x42)
:solarized-base01 (#x58 #x6e #x75)
:solarized-base00 (#x65 #x7b #x83)
:solarized-base0 (#x83 #x94 #x96)
:solarized-base1 (#x93 #xa1 #xa1)
:solarized-base2 (#xee #xe8 #xd5)
:solarized-base3 (#xfd #xf6 #xe3)
:solarized-yellow (#xb5 #x89 #x00)
:solarized-orange (#xcb #x4b #x16)
:solarized-red (#xdc #x32 #x2f)
:solarized-magenta (#xd3 #x36 #x82)
:solarized-violet (#x6c #x71 #xc4)
:solarized-blue (#x26 #x8b #xd2)
:solarized-cyan (#x2a #xa1 #x98)
:solarized-green (#x85 #x99 #x00)))
(loop for list on *solarized-color-table* by #'cddr
for name = (first list)
for rgb = (second list)
do
(color:define-color-alias
name
(apply #'make-rgb rgb)))
(define-color-theme "solarized-light" ()
:foreground :solarized-base00
:background :solarized-base3
:region '(:foreground :solarized-base1
:background :solarized-base3
:inverse-p t)
:highlight '(:background :solarized-base2)
:font-lock-function-name-face '(:foreground :solarized-blue)
:font-lock-comment-face '(:foreground :solarized-base1 :italic-p t)
:font-lock-type-face '(:foreground :solarized-yellow)
:font-lock-variable-name-face '(:foreground :solarized-blue)
:font-lock-string-face '(:foreground :solarized-cyan)
:font-lock-keyword-face '(:foreground :solarized-green)
:font-lock-builtin-face '(:foreground :solarized-green)
:compiler-note-highlight '(:foreground :solarized-green
:bold-p t)
:compiler-warning-highlight '(:foreground :solarized-orange
:bold-p t)
:compiler-error-highlight '(:foreground :solarized-red
:inverse-p t)
:show-point-face '(:foreground :solarized-cyan
:bold-p t :inverse-p t)
:interactive-input-face '(:foreground :solarized-red)
:non-focus-complete-face '(:background :solarized-base3)
:parenthesis-font-face-colours '(:solarized-red
:solarized-base01
:solarized-green
:solarized-orange
:solarized-blue
:solarized-magenta))
(define-color-theme "solarized-dark" ()
:foreground :solarized-base0
:background :solarized-base03
:region '(:foreground :solarized-base01
:background :solarized-base03
:inverse-p t)
:highlight '(:background :solarized-base02)
:font-lock-function-name-face '(:foreground :solarized-blue)
:font-lock-comment-face '(:foreground :solarized-base01 :italic-p t)
:font-lock-type-face '(:foreground :solarized-yellow)
:font-lock-variable-name-face '(:foreground :solarized-blue)
:font-lock-string-face '(:foreground :solarized-cyan)
:font-lock-keyword-face '(:foreground :solarized-green)
:font-lock-builtin-face '(:foreground :solarized-green)
:compiler-note-highlight '(:foreground :solarized-green
:bold-p t)
:compiler-warning-highlight '(:foreground :solarized-orange
:bold-p t)
:compiler-error-highlight '(:foreground :solarized-red
:inverse-p t)
:show-point-face '(:foreground :solarized-cyan
:bold-p t :inverse-p t)
:interactive-input-face '(:foreground :solarized-red)
:non-focus-complete-face '(:background :solarized-base03)
:parenthesis-font-face-colours '(:solarized-red
:solarized-base1
:solarized-green
:solarized-orange
:solarized-blue
:solarized-magenta))
;;; Show presence when loaded
(pushnew :editor-color-theme *features*)