Browse code
feature: various lispworks color improvements
Showing 1 changed files
... | ... |
@@ -10,8 +10,7 @@ |
10 | 10 |
|
11 | 11 |
(defpackage #:editor-color-theme |
12 | 12 |
(:use #:cl) |
13 |
- (:export #:*current-colors* |
|
14 |
- #:all-color-themes |
|
13 |
+ (:export #:all-color-themes |
|
15 | 14 |
#:color-theme-args |
16 | 15 |
#:color-theme |
17 | 16 |
#:define-color-theme |
... | ... |
@@ -21,73 +20,25 @@ |
21 | 20 |
|
22 | 21 |
;;; Configuration |
23 | 22 |
|
24 |
-;; Default foreground and background colors |
|
25 |
-(defconstant +default-foreground-color+ :black) |
|
26 |
-(defconstant +default-background-color+ :white) |
|
23 |
+(defvar *foreground-color* nil) |
|
27 | 24 |
|
28 |
-(defvar *current-colors* (make-hash-table)) |
|
25 |
+(defvar *background-color* nil) |
|
26 |
+ |
|
27 |
+(defconstant +default-parenthesis-font-face-colours+ '(:red :black :darkgreen :darkorange3 :blue :purple)) |
|
29 | 28 |
|
30 | 29 |
;;; Implementation |
31 | 30 |
|
32 | 31 |
(defvar *all-color-themes* (make-hash-table :test 'string=)) |
33 | 32 |
|
34 |
-(defvar *editor-face-names* |
|
35 |
- '(:region |
|
36 |
- :show-point-face |
|
37 |
- :interactive-input-face |
|
38 |
- :highlight |
|
39 |
- :non-focus-complete-face |
|
40 |
- :font-lock-function-name-face |
|
41 |
- :font-lock-comment-face |
|
42 |
- :font-lock-type-face |
|
43 |
- :font-lock-variable-name-face |
|
44 |
- :font-lock-string-face |
|
45 |
- :font-lock-keyword-face |
|
46 |
- :font-lock-builtin-face |
|
47 |
- :compiler-note-highlight |
|
48 |
- :compiler-warning-highlight |
|
49 |
- :compiler-error-highlight |
|
50 |
- :incremental-search-face |
|
51 |
- :incremental-search-other-matches-face |
|
52 |
- )) |
|
53 |
- |
|
54 |
- |
|
55 |
- |
|
56 |
-(defclass editor-panes-theme () |
|
57 |
- ((editor-panes :initform nil :accessor editor-panes) |
|
58 |
- (buffers-panes :initform nil :accessor buffers-panes) |
|
59 |
- (editor-background :initform +default-background-color+ :accessor bg) |
|
60 |
- (editor-foreground :initform +default-foreground-color+ :accessor fg) |
|
61 |
- (buffers-background :initform +default-background-color+ :accessor buffers-bg) |
|
62 |
- (buffers-foreground :initform +default-foreground-color+ :accessor buffers-fg) |
|
63 |
- (buffers-selected-foreground :initform +default-foreground-color+ :accessor buffers-selected-fg))) |
|
64 |
- |
|
65 |
-(defclass listener-panes-theme () |
|
66 |
- ((listener-panes :initform nil :accessor listener-panes) |
|
67 |
- (listener-foreground :initform +default-foreground-color+ :accessor bg) |
|
68 |
- (listener-background :initform +default-background-color+ :accessor fg))) |
|
69 |
- |
|
70 |
- |
|
71 |
-(defclass general-panes-theme () |
|
72 |
- ((output-panes :initform nil :accessor output-panes) |
|
73 |
- (output-foreground :initform +default-foreground-color+ :accessor output-fg) |
|
74 |
- (output-background :initform +default-background-color+ :accessor output-bg))) |
|
75 |
- |
|
76 |
-(defvar *editor-tool* (make-instance 'editor-panes-theme)) |
|
77 |
-(defvar *listener-tool* (make-instance 'listener-panes-theme)) |
|
78 |
-(defvar *all-tools* (make-instance 'general-panes-theme)) |
|
79 |
- |
|
80 | 33 |
(defun all-color-themes () |
81 |
- (maphash #'(lambda (key value) |
|
82 |
- (declare (ignore value)) |
|
83 |
- key) |
|
84 |
- *all-color-themes*)) |
|
34 |
+ (loop for key being the hash-keys in *all-color-themes* |
|
35 |
+ collect key)) |
|
85 | 36 |
|
86 | 37 |
(defun color-theme-data (theme-name) |
87 |
- (multiple-value-bind (data found?) |
|
38 |
+ (multiple-value-bind (color-theme-data found?) |
|
88 | 39 |
(gethash theme-name *all-color-themes*) |
89 | 40 |
(if found? |
90 |
- data |
|
41 |
+ color-theme-data |
|
91 | 42 |
(error "No color theme named ~s found." theme-name)))) |
92 | 43 |
|
93 | 44 |
(defun color-theme-super-theme-names (theme-name) |
... | ... |
@@ -96,118 +47,56 @@ |
96 | 47 |
(defun color-theme-args (theme-name) |
97 | 48 |
(rest (color-theme-data theme-name))) |
98 | 49 |
|
50 |
+(defvar *all-editor-panes* (make-hash-table :test 'eq |
|
51 |
+ :weak-kind :key)) |
|
99 | 52 |
|
100 |
-(defun buffers-color-function (lp symbol state) |
|
101 |
- (declare (ignore lp)) |
|
102 |
- (cond ((eq state :normal) |
|
103 |
- (buffers-fg *editor-tool*)) |
|
104 |
- ((eq state :selected) |
|
105 |
- (buffers-selected-fg *editor-tool*)))) |
|
106 |
- |
|
107 |
-(defun update-pane-colors (pane foreground background) |
|
108 |
- (setf (capi:simple-pane-foreground pane) foreground) |
|
109 |
- (setf (capi:simple-pane-background pane) background) |
|
53 |
+(defun update-editor-pane (pane) |
|
54 |
+ (setf (capi:simple-pane-foreground pane) (or *foreground-color* :color_windowtext)) |
|
55 |
+ (setf (capi:simple-pane-background pane) (or *background-color* :color_window)) |
|
110 | 56 |
|
111 |
- (when (and (typep pane 'capi:editor-pane) |
|
112 |
- (editor::buffer-font-lock-mode-p (capi:editor-pane-buffer pane))) |
|
57 |
+ (let ((recolorize-p (editor::buffer-font-lock-mode-p (capi:editor-pane-buffer pane)))) |
|
58 |
+ (when recolorize-p |
|
113 | 59 |
(gp:invalidate-rectangle pane))) |
60 |
+ (values)) |
|
114 | 61 |
|
62 |
+(defun update-editor-panes () |
|
63 |
+ (maphash #'(lambda (pane value) |
|
64 |
+ (declare (ignore value)) |
|
65 |
+ (update-editor-pane pane)) |
|
66 |
+ *all-editor-panes*) |
|
67 |
+ (values)) |
|
115 | 68 |
|
116 |
-(defgeneric clear-colors (tool) |
|
117 |
- (:documentation "Clear colors for tool keeping other data untouched")) |
|
118 |
- |
|
119 |
-(defgeneric update (tool) |
|
120 |
- (:documentation "Update tool's colors")) |
|
121 |
- |
|
122 |
- |
|
123 |
-(defmethod clear-colors ((self editor-panes-theme)) |
|
124 |
- (with-slots (editor-background editor-foreground) self |
|
125 |
- (setf editor-background +default-background-color+) |
|
126 |
- (setf editor-foreground +default-foreground-color+))) |
|
127 |
- |
|
128 |
-(defmethod clear-colors ((self listener-panes-theme)) |
|
129 |
- (with-slots (listener-background listener-foreground) self |
|
130 |
- (setf listener-background +default-background-color+) |
|
131 |
- (setf listener-foreground +default-foreground-color+))) |
|
132 |
- |
|
133 |
-(defmethod clear-colors ((self general-panes-theme)) |
|
134 |
- (with-slots (output-background output-foreground) self |
|
135 |
- (setf output-background +default-background-color+) |
|
136 |
- (setf output-foreground +default-foreground-color+))) |
|
137 |
- |
|
138 |
- |
|
139 |
-(defmethod update ((self editor-panes-theme)) |
|
140 |
- (mapcar #'(lambda (pane) |
|
141 |
- (update-pane-colors pane (fg self) (bg self))) |
|
142 |
- (editor-panes self)) |
|
143 |
- (mapcar #'(lambda (pane) |
|
144 |
- (update-pane-colors pane (buffers-fg self) (buffers-bg self))) |
|
145 |
- (buffers-panes self))) |
|
146 |
- |
|
147 |
-(defmethod update ((self listener-panes-theme)) |
|
148 |
- (mapcar #'(lambda (pane) |
|
149 |
- (update-pane-colors pane (fg self) (bg self))) |
|
150 |
- (listener-panes self))) |
|
151 |
- |
|
152 |
-(defmethod update ((self general-panes-theme)) |
|
153 |
- (mapcar #'(lambda (pane) |
|
154 |
- (update-pane-colors pane (output-fg self) (output-bg self))) |
|
155 |
- (output-panes self))) |
|
156 |
- |
|
69 |
+(defvar *editor-face-names* |
|
70 |
+ '(:region |
|
71 |
+ :show-point-face |
|
72 |
+ :interactive-input-face |
|
73 |
+ :highlight |
|
74 |
+ :non-focus-complete-face |
|
75 |
+ :font-lock-function-name-face |
|
76 |
+ :font-lock-comment-face |
|
77 |
+ :font-lock-type-face |
|
78 |
+ :font-lock-variable-name-face |
|
79 |
+ :font-lock-string-face |
|
80 |
+ :font-lock-keyword-face |
|
81 |
+ :font-lock-builtin-face |
|
82 |
+ :compiler-note-highlight |
|
83 |
+ :compiler-warning-highlight |
|
84 |
+ :compiler-error-highlight |
|
85 |
+ )) |
|
157 | 86 |
|
158 | 87 |
(defun set-color-theme (theme-name) |
159 | 88 |
(destructuring-bind (&rest color-theme-args |
160 |
- &key foreground background |
|
161 |
- listener-foreground |
|
162 |
- listener-background |
|
163 |
- output-foreground |
|
164 |
- output-background |
|
165 |
- buffers-foreground |
|
166 |
- buffers-selected-foreground |
|
167 |
- buffers-background |
|
168 |
- &allow-other-keys) |
|
89 |
+ &key foreground background &allow-other-keys) |
|
169 | 90 |
(color-theme-args theme-name) |
170 | 91 |
|
171 |
- ;; new instances of tools wrappers |
|
172 |
- (clear-colors *editor-tool*) |
|
173 |
- (clear-colors *listener-tool*) |
|
174 |
- (clear-colors *all-tools*) |
|
175 |
- |
|
176 |
- ;; editor foreground and background |
|
177 |
- (when foreground |
|
178 |
- (setf (fg *editor-tool*) foreground)) |
|
179 |
- (when background |
|
180 |
- (setf (bg *editor-tool*) background)) |
|
181 |
- ;; listener foreground and background, uses |
|
182 |
- ;; the :background and :foreground if not specified |
|
183 |
- (setf (fg *listener-tool*) |
|
184 |
- (or listener-foreground |
|
185 |
- (fg *editor-tool*)) |
|
186 |
- (bg *listener-tool*) |
|
187 |
- (or listener-background |
|
188 |
- (bg *editor-tool*))) |
|
189 |
- |
|
190 |
- ;; output foreground and background, uses :background and |
|
191 |
- ;; :foreground if not specified |
|
192 |
- (setf (output-fg *all-tools*) |
|
193 |
- (or output-foreground |
|
194 |
- (fg *editor-tool*)) |
|
195 |
- (output-bg *all-tools*) |
|
196 |
- (or output-background |
|
197 |
- (bg *editor-tool*))) |
|
198 |
- |
|
199 |
- ;; buffers list colors |
|
200 |
- (setf (buffers-fg *editor-tool*) |
|
201 |
- (or buffers-foreground |
|
202 |
- (fg *editor-tool*)) |
|
203 |
- (buffers-selected-fg *editor-tool*) |
|
204 |
- (or buffers-selected-foreground |
|
205 |
- (buffers-fg *editor-tool*)) |
|
206 |
- (buffers-bg *editor-tool*) |
|
207 |
- (or buffers-background |
|
208 |
- (bg *editor-tool*))) |
|
209 |
- |
|
210 |
- |
|
92 |
+ (setf *foreground-color* (or foreground :color_windowtext)) |
|
93 |
+ (setf *background-color* (or background :color_window)) |
|
94 |
+ |
|
95 |
+ (lw:when-let (parenthesis-colors |
|
96 |
+ (getf color-theme-args :parenthesis-font-face-colours |
|
97 |
+ +default-parenthesis-font-face-colours+)) |
|
98 |
+ (editor::set-parenthesis-colours parenthesis-colors)) |
|
99 |
+ |
|
211 | 100 |
(dolist (name *editor-face-names*) |
212 | 101 |
(let* ((color-theme-args-for-face (getf color-theme-args name)) |
213 | 102 |
(face-name (intern (string name) '#:editor)) |
... | ... |
@@ -222,101 +111,39 @@ |
222 | 111 |
(defun color-theme (theme-name) |
223 | 112 |
(mapc 'set-color-theme (color-theme-super-theme-names theme-name)) |
224 | 113 |
(set-color-theme theme-name) |
225 |
- |
|
226 |
- (update *editor-tool*) |
|
227 |
- (update *listener-tool*) |
|
228 |
- (update *all-tools*) |
|
229 |
- |
|
114 |
+ |
|
115 |
+ (update-editor-panes) |
|
116 |
+ |
|
230 | 117 |
theme-name) |
231 | 118 |
|
232 | 119 |
(defun define-color-theme (theme-name super-theme-names |
233 | 120 |
&rest color-theme-args &key &allow-other-keys) |
234 |
- (unless super-theme-names |
|
235 |
- (setf super-theme-names '("default"))) |
|
236 | 121 |
(dolist (super-theme-name super-theme-names) |
237 | 122 |
(multiple-value-bind (color-theme-data found?) |
238 | 123 |
(gethash super-theme-name *all-color-themes*) |
239 | 124 |
(declare (ignore color-theme-data)) |
240 | 125 |
(unless found? |
241 | 126 |
(warn "Inherited color theme ~s not defined." super-theme-name)))) |
242 |
- |
|
127 |
+ |
|
243 | 128 |
(setf (gethash theme-name *all-color-themes*) (list* super-theme-names color-theme-args)) |
244 |
- |
|
129 |
+ |
|
245 | 130 |
theme-name) |
246 | 131 |
|
247 | 132 |
(defun remove-color-theme (theme-name) |
248 | 133 |
(remhash theme-name *all-color-themes*)) |
249 | 134 |
|
250 |
-(defun set-editor-pane-colors (pane) |
|
251 |
- (typecase pane |
|
252 |
- (capi:editor-pane |
|
253 |
- (progn |
|
254 |
- (pushnew pane (editor-panes *editor-tool*)) |
|
255 |
- (let ((bg-color (bg *editor-tool*)) |
|
256 |
- (fg-color (fg *editor-tool*))) |
|
257 |
- (setf (capi:simple-pane-foreground pane) fg-color) |
|
258 |
- (setf (capi:simple-pane-background pane) bg-color)))))) |
|
259 |
- |
|
260 |
- |
|
261 |
-(defun set-listener-pane-colors (pane) |
|
262 |
- (typecase pane |
|
263 |
- (capi:editor-pane |
|
264 |
- (progn |
|
265 |
- (pushnew pane (listener-panes *listener-tool*)) |
|
266 |
- (let ((bg-color (bg *listener-tool*)) |
|
267 |
- (fg-color (fg *listener-tool*))) |
|
268 |
- (setf (capi:simple-pane-foreground pane) fg-color) |
|
269 |
- (setf (capi:simple-pane-background pane) bg-color)))))) |
|
270 |
- |
|
271 |
- |
|
272 |
-(defun set-collector-pane-colors (pane) |
|
273 |
- ;;(when (typep (capi:top-level-interface pane) 'lw-tools:listener) |
|
274 |
- (pushnew pane (output-panes *all-tools*)) |
|
275 |
- (let ((bg-color (output-bg *all-tools*)) |
|
276 |
- (fg-color (output-fg *all-tools*))) |
|
277 |
- (setf (capi:simple-pane-foreground pane) fg-color) |
|
278 |
- (setf (capi:simple-pane-background pane) bg-color))) |
|
279 |
- |
|
280 |
-(defun set-mulitcolumn-list-panel-colors (pane) |
|
281 |
- (when (or (eq (capi:capi-object-name pane) 'lw-tools::buffers-list) |
|
282 |
- (eq (capi:capi-object-name pane) 'lispworks-tools::narrow-buffers-list)) |
|
283 |
- (pushnew pane (buffers-panes *editor-tool*)) |
|
284 |
- (when (eq (capi:capi-object-name pane) 'lispworks-tools::narrow-buffers-list) |
|
285 |
- (setf (slot-value pane 'capi::color-function) #'buffers-color-function)) |
|
286 |
- (update-pane-colors pane (buffers-fg *editor-tool*) (buffers-bg *editor-tool*)))) |
|
287 |
- |
|
288 |
- |
|
289 |
-(lispworks:defadvice ((method capi:interface-display :before (lw-tools:editor)) |
|
290 |
- change-editor-colors |
|
291 |
- :before |
|
292 |
- :documentation "Change editor colors.") |
|
293 |
- (interface) |
|
294 |
- (capi:map-pane-descendant-children interface 'set-editor-pane-colors)) |
|
295 |
- |
|
296 |
- |
|
297 |
-;; we don't have defined capi:interface-display for lw-tools::listener, |
|
298 |
-;; so nothing to advice. Instead we need to define our own |
|
299 |
-(sys::without-warning-on-redefinition |
|
300 |
- (defmethod capi:interface-display :before ((self lw-tools::listener)) |
|
301 |
- (capi:map-pane-descendant-children |
|
302 |
- self 'set-listener-pane-colors))) |
|
303 |
- |
|
304 |
-;; capi:collector-pane does'nt have interface-display method called, |
|
305 |
-;; so we adding the :after constuctor instead |
|
306 | 135 |
(sys::without-warning-on-redefinition |
307 |
- (defmethod initialize-instance :after ((self capi:collector-pane) &rest |
|
308 |
- clos::initargs &key &allow-other-keys) |
|
309 |
- (set-collector-pane-colors self))) |
|
310 |
- |
|
311 |
-(lispworks:defadvice ((method initialize-instance :after (capi:multi-column-list-panel)) |
|
312 |
- change-multicolumn-colors |
|
313 |
- :after |
|
314 |
- :documentation "Change capi:multi-column-list-panel colors") |
|
315 |
- (self &rest initargs &key &allow-other-keys) |
|
316 |
- (declare (ignore initargs)) |
|
317 |
- (set-mulitcolumn-list-panel-colors self)) |
|
136 |
+ (defmethod initialize-instance :around ((pane capi:editor-pane) &key &allow-other-keys) |
|
137 |
+ (multiple-value-prog1 |
|
138 |
+ (call-next-method) |
|
318 | 139 |
|
140 |
+ (setf (gethash pane *all-editor-panes*) pane) |
|
319 | 141 |
|
142 |
+ (when *foreground-color* |
|
143 |
+ (setf (capi:simple-pane-foreground pane) *foreground-color*)) |
|
144 |
+ (when *background-color* |
|
145 |
+ (setf (capi:simple-pane-background pane) *background-color*)))) |
|
146 |
+ ) |
|
320 | 147 |
|
321 | 148 |
;; This makes it "work" after the podium is launched |
322 | 149 |
(defun is-editor-pane-p (obj) |
... | ... |
@@ -324,7 +151,7 @@ |
324 | 151 |
(not (eq obj (hcl:class-prototype (class-of obj)))))) |
325 | 152 |
|
326 | 153 |
(defun cache-existing-pane (pane) |
327 |
- (pushnew pane (editor-panes *editor-tool*))) |
|
154 |
+ (setf (gethash pane *all-editor-panes*) pane)) |
|
328 | 155 |
|
329 | 156 |
(defun cache-if-pane (obj) |
330 | 157 |
(when (is-editor-pane-p obj) |
... | ... |
@@ -353,9 +180,7 @@ |
353 | 180 |
:font-lock-builtin-face '(:foreground :orchid) |
354 | 181 |
:compiler-note-highlight '(:foreground :magenta) |
355 | 182 |
:compiler-warning-highlight '(:foreground :orange3) |
356 |
- :compiler-error-highlight '(:foreground :red) |
|
357 |
- :incremental-search-face '(:background :tweak_background) |
|
358 |
- :incremental-search-other-matches-face '(:underline-p t)) |
|
183 |
+ :compiler-error-highlight '(:foreground :red)) |
|
359 | 184 |
|
360 | 185 |
(define-color-theme "plain" () |
361 | 186 |
:foreground nil :background nil |
... | ... |
@@ -374,13 +199,10 @@ |
374 | 199 |
:font-lock-builtin-face '() |
375 | 200 |
:compiler-note-highlight '() |
376 | 201 |
:compiler-warning-highlight '() |
377 |
- :compiler-error-highlight '() |
|
378 |
- :incremental-search-face '(:background :tweak_background) |
|
379 |
- :incremental-search-other-matches-face '(:underline-p t)) |
|
380 |
- |
|
202 |
+ :compiler-error-highlight '()) |
|
381 | 203 |
|
382 | 204 |
(define-color-theme "emacs" () |
383 |
- ;; :foreground nil :background nil |
|
205 |
+ :foreground nil :background nil |
|
384 | 206 |
:region '(:foreground :color_highlighttext |
385 | 207 |
:background :color_highlight) |
386 | 208 |
:show-point-face '(:background :green) |
... | ... |
@@ -396,10 +218,7 @@ |
396 | 218 |
:font-lock-builtin-face '(:foreground :orchid) |
397 | 219 |
:compiler-note-highlight '(:foreground :magenta) |
398 | 220 |
:compiler-warning-highlight '(:foreground :orange3) |
399 |
- :compiler-error-highlight '(:foreground :red) |
|
400 |
- :incremental-search-face '(:background :tweak_background) |
|
401 |
- :incremental-search-other-matches-face '(:underline-p t)) |
|
402 |
- |
|
221 |
+ :compiler-error-highlight '(:foreground :red)) |
|
403 | 222 |
|
404 | 223 |
(define-color-theme "torte" () |
405 | 224 |
:foreground (color:make-rgb 0.8s0 0.8s0 0.8s0) |
... | ... |
@@ -419,9 +238,7 @@ |
419 | 238 |
:font-lock-builtin-face `(:foreground ,(color:make-rgb 1.0s0 1.0s0 0.0s0)) |
420 | 239 |
:compiler-note-highlight '(:foreground :magenta) |
421 | 240 |
:compiler-warning-highlight '(:foreground :orange) |
422 |
- :compiler-error-highlight '(:foreground :red) |
|
423 |
- :incremental-search-face '(:background :tweak_background) |
|
424 |
- :incremental-search-other-matches-face '(:underline-p t)) |
|
241 |
+ :compiler-error-highlight '(:foreground :red)) |
|
425 | 242 |
|
426 | 243 |
|
427 | 244 |
(defun make-rgb (red green blue &optional alpha) |