Browse code
Replaced global variables with hashmap
Alexey Veretennikov authored on 22/05/2015 09:51:43
Showing 1 changed files
Showing 1 changed files
... | ... |
@@ -11,10 +11,7 @@ |
11 | 11 |
|
12 | 12 |
(defpackage #:editor-color-theme |
13 | 13 |
(:use #:cl) |
14 |
- (:export #:*foreground-color* |
|
15 |
- #:*background-color* |
|
16 |
- #:*listener-foreground-color* |
|
17 |
- #:*listener-background-color* |
|
14 |
+ (:export #:*current-colors* |
|
18 | 15 |
#:all-color-themes |
19 | 16 |
#:color-theme-args |
20 | 17 |
#:color-theme |
... | ... |
@@ -27,19 +24,11 @@ |
27 | 24 |
|
28 | 25 |
;;; Configuration |
29 | 26 |
|
30 |
-;; Editor foreground and background colors |
|
31 |
-(defvar *foreground-color* nil) |
|
32 |
-(defvar *background-color* nil) |
|
33 |
- |
|
34 |
-;; Listener foreground and background colors |
|
35 |
-(defvar *listener-foreground-color* nil) |
|
36 |
-(defvar *listener-background-color* nil) |
|
37 |
- |
|
38 |
- |
|
39 | 27 |
;; Default foreground and background colors |
40 | 28 |
(defconstant +default-foreground-color+ :black) |
41 | 29 |
(defconstant +default-background-color+ :white) |
42 | 30 |
|
31 |
+(defvar *current-colors* (make-hash-table)) |
|
43 | 32 |
|
44 | 33 |
;;; Implementation |
45 | 34 |
|
... | ... |
@@ -80,8 +69,8 @@ |
80 | 69 |
(values)) |
81 | 70 |
|
82 | 71 |
(defun update-editor-panes () |
83 |
- (let ((foreground (or *foreground-color* +default-foreground-color+)) |
|
84 |
- (background (or *background-color* +default-background-color+))) |
|
72 |
+ (let ((foreground (gethash :foreground-color *current-colors*)) |
|
73 |
+ (background (gethash :background-color *current-colors*))) |
|
85 | 74 |
(maphash #'(lambda (pane value) |
86 | 75 |
(declare (ignore value)) |
87 | 76 |
(update-editor-pane pane foreground background)) |
... | ... |
@@ -90,8 +79,8 @@ |
90 | 79 |
|
91 | 80 |
|
92 | 81 |
(defun update-listener-panes () |
93 |
- (let ((foreground (or *listener-foreground-color* +default-foreground-color+)) |
|
94 |
- (background (or *listener-background-color* +default-background-color+))) |
|
82 |
+ (let ((foreground (gethash :listener-foreground-color *current-colors*)) |
|
83 |
+ (background (gethash :listener-background-color *current-colors*))) |
|
95 | 84 |
(maphash #'(lambda (pane value) |
96 | 85 |
(declare (ignore value)) |
97 | 86 |
(update-editor-pane pane foreground background)) |
... | ... |
@@ -119,6 +108,7 @@ |
119 | 108 |
:incremental-search-other-matches-face |
120 | 109 |
)) |
121 | 110 |
|
111 |
+ |
|
122 | 112 |
(defun set-color-theme (theme-name) |
123 | 113 |
(destructuring-bind (&rest color-theme-args |
124 | 114 |
&key foreground background |
... | ... |
@@ -128,12 +118,15 @@ |
128 | 118 |
(color-theme-args theme-name) |
129 | 119 |
|
130 | 120 |
;; editor foreground and background |
131 |
- (setf *foreground-color* (or foreground +default-foreground-color+)) |
|
132 |
- (setf *background-color* (or background +default-background-color+)) |
|
133 |
- |
|
121 |
+ (setf (gethash :foreground-color *current-colors*) |
|
122 |
+ (or foreground +default-foreground-color+) |
|
123 |
+ (gethash :background-color *current-colors*) |
|
124 |
+ (or background +default-background-color+)) |
|
134 | 125 |
;; listener foreground and background |
135 |
- (setf *listener-foreground-color* (or listener-foreground +default-foreground-color+)) |
|
136 |
- (setf *listener-background-color* (or listener-background +default-background-color+)) |
|
126 |
+ (setf (gethash :listener-foreground-color *current-colors*) |
|
127 |
+ (or listener-foreground +default-foreground-color+) |
|
128 |
+ (gethash :listener-background-color *current-colors*) |
|
129 |
+ (or listener-background +default-background-color+)) |
|
137 | 130 |
|
138 | 131 |
(dolist (name *editor-face-names*) |
139 | 132 |
(let* ((color-theme-args-for-face (getf color-theme-args name)) |
... | ... |
@@ -178,28 +171,24 @@ |
178 | 171 |
(capi:editor-pane |
179 | 172 |
(progn |
180 | 173 |
(setf (gethash pane *all-editor-panes*) pane) |
181 |
- (when *foreground-color* |
|
182 |
- (setf (capi:simple-pane-foreground pane) *foreground-color*)) |
|
183 |
- (when *background-color* |
|
184 |
- (setf (capi:simple-pane-background pane) *background-color*)))))) |
|
174 |
+ (let ((bg-color (gethash :background-color *current-colors*)) |
|
175 |
+ (fg-color (gethash :foreground-color *current-colors*))) |
|
176 |
+ (when fg-color |
|
177 |
+ (setf (capi:simple-pane-foreground pane) fg-color)) |
|
178 |
+ (when bg-color |
|
179 |
+ (setf (capi:simple-pane-background pane) bg-color))))))) |
|
185 | 180 |
|
186 | 181 |
(defun set-listener-pane-colors (pane) |
187 | 182 |
(typecase pane |
188 | 183 |
(capi:editor-pane |
189 | 184 |
(progn |
190 | 185 |
(setf (gethash pane *all-listener-editor-panes*) pane) |
191 |
- (when *listener-foreground-color* |
|
192 |
- (setf (capi:simple-pane-foreground pane) *listener-foreground-color*)) |
|
193 |
- (when *listener-background-color* |
|
194 |
- (setf (capi:simple-pane-background pane) *listener-background-color*)))) |
|
195 |
- (capi:editor-pane |
|
196 |
- (progn |
|
197 |
- (setf (gethash pane *all-listener-editor-panes*) pane) |
|
198 |
- (when *listener-foreground-color* |
|
199 |
- (setf (capi:simple-pane-foreground pane) *listener-foreground-color*)) |
|
200 |
- (when *listener-background-color* |
|
201 |
- (setf (capi:simple-pane-background pane) *listener-background-color*)))) |
|
202 |
- )) |
|
186 |
+ (let ((bg-color (gethash :listener-background-color *current-colors*)) |
|
187 |
+ (fg-color (gethash :listener-foreground-color *current-colors*))) |
|
188 |
+ (when fg-color |
|
189 |
+ (setf (capi:simple-pane-foreground pane) fg-color)) |
|
190 |
+ (when bg-color |
|
191 |
+ (setf (capi:simple-pane-background pane) bg-color))))))) |
|
203 | 192 |
|
204 | 193 |
|
205 | 194 |
|