git.fiddlerwoaroof.com
Browse code

Added new faces; started separation between listener and editor

Alexey Veretennikov authored on 19/05/2015 21:02:17
Showing 1 changed files
... ...
@@ -1,245 +1,275 @@
1
-;;;; Copyright (C) 2013 Paulo Madeira
2
-;;;;
3
-;;;; This Source Code Form is subject to the terms of the Mozilla Public
4
-;;;; License, v. 2.0. If a copy of the MPL was not distributed with this
5
-;;;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
-
7
-;;; Interface
8
-
9
-(cl:in-package #:cl-user)
10
-
11
-(defpackage #:editor-color-theme
12
-  (:use #:cl)
13
-  (:export #:*foreground-color*
14
-	   #:*background-color*
15
-	   #:all-color-themes
16
-	   #:color-theme-args
17
-	   #:color-theme
18
-	   #:define-color-theme
19
-	   #:remove-color-theme
20
-	   ))
21
-
22
-(in-package #:editor-color-theme)
23
-
24
-
25
-;;; Configuration
26
-
27
-(defvar *foreground-color* nil)
28
-
29
-(defvar *background-color* nil)
30
-
31
-
32
-;;; Implementation
33
-
34
-(defvar *all-color-themes* (make-hash-table :test 'string=))
35
-
36
-(defun all-color-themes ()
37
-  (maphash #'(lambda (key value)
38
-	       (declare (ignore value))
39
-	       key)
40
-	   *all-color-themes*))
41
-
42
-(defun color-theme-data (theme-name)
43
-  (multiple-value-bind (color-theme-data found?)
44
-      (gethash theme-name *all-color-themes*)
45
-    (if found?
46
-	color-theme-data
47
-	(error "No color theme named ~s found." theme-name))))
48
-
49
-(defun color-theme-super-theme-names (theme-name)
50
-  (first (color-theme-data theme-name)))
51
-
52
-(defun color-theme-args (theme-name)
53
-  (rest (color-theme-data theme-name)))
54
-
55
-(defvar *all-editor-panes* (make-hash-table :test 'eq
56
-					    :weak-kind :key))
57
-
58
-(defun update-editor-pane (pane)
59
-  (setf (capi:simple-pane-foreground pane) (or *foreground-color* :color_windowtext))
60
-  (setf (capi:simple-pane-background pane) (or *background-color* :color_window))
61
-  
62
-  (let ((recolorize-p (editor::buffer-font-lock-mode-p (capi:editor-pane-buffer pane))))
63
-    (when recolorize-p
64
-      (gp:invalidate-rectangle pane)))
65
-  (values))
66
-
67
-(defun update-editor-panes ()
68
-  (maphash #'(lambda (pane value)
69
-	       (declare (ignore value))
70
-	       (update-editor-pane pane))
71
-	   *all-editor-panes*)
72
-  (values))
73
-
74
-(defvar *editor-face-names*
75
-  '(:region
76
-    :show-point-face
77
-    :interactive-input-face
78
-    :highlight
79
-    :non-focus-complete-face
80
-    :font-lock-function-name-face
81
-    :font-lock-comment-face
82
-    :font-lock-type-face
83
-    :font-lock-variable-name-face
84
-    :font-lock-string-face
85
-    :font-lock-keyword-face
86
-    :font-lock-builtin-face
87
-    :compiler-note-highlight
88
-    :compiler-warning-highlight
89
-    :compiler-error-highlight
90
-    ))
91
-
92
-(defun set-color-theme (theme-name)
93
-  (destructuring-bind (&rest color-theme-args
94
-		       &key foreground background &allow-other-keys)
95
-      (color-theme-args theme-name)
96
-    
97
-    (setf *foreground-color* (or foreground :color_windowtext))
98
-    (setf *background-color* (or background :color_window))
99
-  
100
-    (dolist (name *editor-face-names*)
101
-      (let* ((color-theme-args-for-face (getf color-theme-args name))
102
-	     (face-name (intern (string name) '#:editor))
103
-	     (face (editor:make-face face-name :if-exists t)))
104
-	(apply 'editor:make-face face-name :if-exists :overwrite
105
-	       :documentation (or (getf color-theme-args-for-face :documentation)
106
-				  (slot-value face 'documentation))
107
-	       color-theme-args-for-face))))
108
-  
109
-  theme-name)
110
-
111
-(defun color-theme (theme-name)
112
-  (mapc 'set-color-theme (color-theme-super-theme-names theme-name))
113
-  (set-color-theme theme-name)
114
-  
115
-  (update-editor-panes)
116
-  
117
-  theme-name)
118
-
119
-(defun define-color-theme (theme-name super-theme-names
120
-			   &rest color-theme-args &key &allow-other-keys)
121
-  (dolist (super-theme-name super-theme-names)
122
-    (multiple-value-bind (color-theme-data found?)
123
-	(gethash super-theme-name *all-color-themes*)
124
-      (declare (ignore color-theme-data))
125
-      (unless found?
126
-	(warn "Inherited color theme ~s not defined." super-theme-name))))
127
-  
128
-  (setf (gethash theme-name *all-color-themes*) (list* super-theme-names color-theme-args))
129
-  
130
-  theme-name)
131
-
132
-(defun remove-color-theme (theme-name)
133
-  (remhash theme-name *all-color-themes*))
134
-
135
-(sys::without-warning-on-redefinition
136
-  (defmethod initialize-instance :around ((pane capi:editor-pane) &key &allow-other-keys)
137
-    (multiple-value-prog1
138
-	(call-next-method)
139
-      
140
-      (setf (gethash pane *all-editor-panes*) pane)
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
-  )
147
-
148
-;; This makes it "work" after the podium is launched
149
-(defun is-editor-pane-p (obj)
150
-  (and (typep obj 'capi:editor-pane)
151
-       (not (eq obj (hcl:class-prototype (class-of obj))))))
152
-
153
-(defun cache-existing-pane (pane)
154
-  (setf (gethash pane *all-editor-panes*) pane))
155
-
156
-(defun cache-if-pane (obj)
157
-  (when (is-editor-pane-p obj)
158
-    (cache-existing-pane obj)))
159
-
160
-#+:lispworks-personal-edition
161
-(hcl:sweep-all-objects #'cache-if-pane)
162
-
163
-
164
-;;; Initial color themes
165
-
166
-(define-color-theme "default" ()
167
-  :foreground nil :background nil
168
-  :region '(:foreground :color_highlighttext
169
-	    :background :color_highlight)
170
-  :show-point-face '(:background :green)
171
-  :interactive-input-face '(:foreground :red3)
172
-  :highlight '(:bold-p t)
173
-  :non-focus-complete-face '(:background :tweak_background)
174
-  :font-lock-function-name-face '(:foreground :blue)
175
-  :font-lock-comment-face '(:foreground :firebrick)
176
-  :font-lock-type-face '(:foreground :forestgreen)
177
-  :font-lock-variable-name-face '(:foreground :darkgoldenrod)
178
-  :font-lock-string-face '(:foreground :rosybrown)
179
-  :font-lock-keyword-face '(:foreground :purple)
180
-  :font-lock-builtin-face '(:foreground :orchid)
181
-  :compiler-note-highlight '(:foreground :magenta)
182
-  :compiler-warning-highlight '(:foreground :orange3)
183
-  :compiler-error-highlight '(:foreground :red))
184
-
185
-(define-color-theme "plain" ()
186
-  :foreground nil :background nil
187
-  :region '(:foreground :color_highlighttext
188
-	    :background :color_highlight)
189
-  :show-point-face '()
190
-  :interactive-input-face '()
191
-  :highlight '(:bold-p t)
192
-  :non-focus-complete-face '(:background :tweak_background)
193
-  :font-lock-function-name-face '()
194
-  :font-lock-comment-face '()
195
-  :font-lock-type-face '()
196
-  :font-lock-variable-name-face '()
197
-  :font-lock-string-face '()
198
-  :font-lock-keyword-face '()
199
-  :font-lock-builtin-face '()
200
-  :compiler-note-highlight '()
201
-  :compiler-warning-highlight '()
202
-  :compiler-error-highlight '())
203
-
204
-(define-color-theme "emacs" ()
205
-  :foreground nil :background nil
206
-  :region '(:foreground :color_highlighttext
207
-	    :background :color_highlight)
208
-  :show-point-face '(:background :green)
209
-  :interactive-input-face '(:foreground :red3)
210
-  :highlight '(:bold-p t)
211
-  :non-focus-complete-face '(:background :tweak_background)
212
-  :font-lock-function-name-face '(:foreground :blue)
213
-  :font-lock-comment-face '(:foreground :gray40)
214
-  :font-lock-type-face '(:foreground :forestgreen)
215
-  :font-lock-variable-name-face '(:foreground :darkgoldenrod)
216
-  :font-lock-string-face '(:foreground :rosybrown)
217
-  :font-lock-keyword-face '(:foreground :purple)
218
-  :font-lock-builtin-face '(:foreground :orchid)
219
-  :compiler-note-highlight '(:foreground :magenta)
220
-  :compiler-warning-highlight '(:foreground :orange3)
221
-  :compiler-error-highlight '(:foreground :red))
222
-
223
-(define-color-theme "torte" ()
224
-  :foreground (color:make-rgb 0.8s0 0.8s0 0.8s0)
225
-  :background (color:make-rgb 0.0s0 0.0s0 0.0s0)
226
-  :region '(:foreground :color_highlighttext
227
-	    :background :color_highlight)
228
-  :show-point-face `(:background ,(color:make-rgb 0.6275s0 0.1255s0 0.9412s0))
229
-  :interactive-input-face '(:foreground :pink)
230
-  :highlight '(:bold-p t)
231
-  :non-focus-complete-face '(:background :tweak_background)
232
-  :font-lock-function-name-face `(:foreground ,(color:make-rgb 0.0s0 1.0s0 1.0s0))
233
-  :font-lock-comment-face `(:foreground ,(color:make-rgb 0.5s0 0.6275s0 1.0s0))
234
-  :font-lock-type-face `(:foreground ,(color:make-rgb 0.5s0 1.0s0 0.5s0))
235
-  :font-lock-variable-name-face `(:foreground ,(color:make-rgb 1.0s0 1.0s0 1.0s0))
236
-  :font-lock-string-face `(:foreground ,(color:make-rgb 1.0s0 0.6275s0 0.6275s0))
237
-  :font-lock-keyword-face `(:foreground ,(color:make-rgb 1.0s0 1.0s0 0.0s0))
238
-  :font-lock-builtin-face `(:foreground ,(color:make-rgb 1.0s0 1.0s0 0.0s0))
239
-  :compiler-note-highlight '(:foreground :magenta)
240
-  :compiler-warning-highlight '(:foreground :orange)
241
-  :compiler-error-highlight '(:foreground :red))
242
-
243
-
244
-;;; Show presence when loaded
245
-(pushnew :editor-color-theme *features*)
1
+;;;; Copyright (C) 2013 Paulo Madeira
2
+;;;;
3
+;;;; This Source Code Form is subject to the terms of the Mozilla Public
4
+;;;; License, v. 2.0. If a copy of the MPL was not distributed with this
5
+;;;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
+
7
+;;; Interface
8
+
9
+(cl:in-package #:cl-user)
10
+
11
+(defpackage #:editor-color-theme
12
+  (:use #:cl)
13
+  (:export #:*foreground-color*
14
+	   #:*background-color*
15
+	   #:all-color-themes
16
+	   #:color-theme-args
17
+	   #:color-theme
18
+	   #:define-color-theme
19
+	   #:remove-color-theme
20
+	   ))
21
+
22
+(in-package #:editor-color-theme)
23
+
24
+
25
+;;; Configuration
26
+
27
+(defvar *foreground-color* nil)
28
+
29
+(defvar *background-color* nil)
30
+
31
+(defconstant +default-foreground-color :black)
32
+(defconstant +default-background-color :white)
33
+
34
+
35
+;;; Implementation
36
+
37
+(defvar *all-color-themes* (make-hash-table :test 'string=))
38
+
39
+(defun all-color-themes ()
40
+  (maphash #'(lambda (key value)
41
+	       (declare (ignore value))
42
+	       key)
43
+	   *all-color-themes*))
44
+
45
+(defun color-theme-data (theme-name)
46
+  (multiple-value-bind (color-theme-data found?)
47
+      (gethash theme-name *all-color-themes*)
48
+    (if found?
49
+	color-theme-data
50
+	(error "No color theme named ~s found." theme-name))))
51
+
52
+(defun color-theme-super-theme-names (theme-name)
53
+  (first (color-theme-data theme-name)))
54
+
55
+(defun color-theme-args (theme-name)
56
+  (rest (color-theme-data theme-name)))
57
+
58
+(defvar *all-editor-panes* (make-hash-table :test 'eq
59
+					    :weak-kind :key))
60
+
61
+(defun get-background-color ()
62
+  (or *background-color* +default-background-color))
63
+
64
+(defun get-foreground-color ()
65
+  (or *foreground-color* +default-foreground-color))
66
+
67
+
68
+(defun update-editor-pane (pane)
69
+  (setf (capi:simple-pane-foreground pane) (get-foreground-color))
70
+  (setf (capi:simple-pane-background pane) (get-background-color))
71
+  
72
+  (let ((recolorize-p (editor::buffer-font-lock-mode-p (capi:editor-pane-buffer pane))))
73
+    (when recolorize-p
74
+      (gp:invalidate-rectangle pane)))
75
+  (values))
76
+
77
+(defun update-editor-panes ()
78
+  (maphash #'(lambda (pane value)
79
+	       (declare (ignore value))
80
+	       (update-editor-pane pane))
81
+	   *all-editor-panes*)
82
+  (values))
83
+
84
+(defvar *editor-face-names*
85
+  '(:region
86
+    :show-point-face
87
+    :interactive-input-face
88
+    :highlight
89
+    :non-focus-complete-face
90
+    :font-lock-function-name-face
91
+    :font-lock-comment-face
92
+    :font-lock-type-face
93
+    :font-lock-variable-name-face
94
+    :font-lock-string-face
95
+    :font-lock-keyword-face
96
+    :font-lock-builtin-face
97
+    :compiler-note-highlight
98
+    :compiler-warning-highlight
99
+    :compiler-error-highlight
100
+    :incremental-search-face
101
+    :incremental-search-other-matches-face
102
+    ))
103
+
104
+(defun set-color-theme (theme-name)
105
+  (destructuring-bind (&rest color-theme-args
106
+		       &key foreground background &allow-other-keys)
107
+      (color-theme-args theme-name)
108
+    
109
+    (setf *foreground-color* (or foreground +default-foreground-color))
110
+    (setf *background-color* (or background +default-background-color))
111
+  
112
+    (dolist (name *editor-face-names*)
113
+      (let* ((color-theme-args-for-face (getf color-theme-args name))
114
+	     (face-name (intern (string name) '#:editor))
115
+	     (face (editor:make-face face-name :if-exists t)))
116
+	(apply 'editor:make-face face-name :if-exists :overwrite
117
+	       :documentation (or (getf color-theme-args-for-face :documentation)
118
+				  (slot-value face 'documentation))
119
+	       color-theme-args-for-face))))
120
+  
121
+  theme-name)
122
+
123
+(defun color-theme (theme-name)
124
+  (mapc 'set-color-theme (color-theme-super-theme-names theme-name))
125
+  (set-color-theme theme-name)
126
+  
127
+  (update-editor-panes)
128
+  
129
+  theme-name)
130
+
131
+(defun define-color-theme (theme-name super-theme-names
132
+			   &rest color-theme-args &key &allow-other-keys)
133
+  (dolist (super-theme-name super-theme-names)
134
+    (multiple-value-bind (color-theme-data found?)
135
+	(gethash super-theme-name *all-color-themes*)
136
+      (declare (ignore color-theme-data))
137
+      (unless found?
138
+	(warn "Inherited color theme ~s not defined." super-theme-name))))
139
+  
140
+  (setf (gethash theme-name *all-color-themes*) (list* super-theme-names color-theme-args))
141
+  
142
+  theme-name)
143
+
144
+(defun remove-color-theme (theme-name)
145
+  (remhash theme-name *all-color-themes*))
146
+
147
+(defun set-editor-pane-colors (pane)
148
+  (typecase pane
149
+    (capi:editor-pane
150
+     (progn
151
+       (setf (gethash pane *all-editor-panes*) pane)
152
+       (when *foreground-color*
153
+         (setf (capi:simple-pane-foreground pane) *foreground-color*))
154
+       (when *background-color*
155
+         (setf (capi:simple-pane-background pane) *background-color*))))))
156
+
157
+
158
+(lispworks:defadvice ((method capi:interface-display :before (lw-tools:editor))
159
+                      change-editor-colors
160
+                      :before
161
+                      :documentation "Change editor colors.")
162
+    (interface)
163
+  (capi:map-pane-descendant-children interface 'set-editor-pane-colors))
164
+
165
+
166
+;; This makes it "work" after the podium is launched
167
+(defun is-editor-pane-p (obj)
168
+  (and (typep obj 'capi:editor-pane)
169
+       (not (eq obj (hcl:class-prototype (class-of obj))))))
170
+
171
+(defun cache-existing-pane (pane)
172
+  (setf (gethash pane *all-editor-panes*) pane))
173
+
174
+(defun cache-if-pane (obj)
175
+  (when (is-editor-pane-p obj)
176
+    (cache-existing-pane obj)))
177
+
178
+#+:lispworks-personal-edition
179
+(hcl:sweep-all-objects #'cache-if-pane)
180
+
181
+
182
+;;; Initial color themes
183
+
184
+(define-color-theme "default" ()
185
+  :foreground nil
186
+  :background nil
187
+  :region '(:foreground :color_highlighttext
188
+	    :background :color_highlight)
189
+  :show-point-face '(:background :green)
190
+  :interactive-input-face '(:foreground :red3)
191
+  :highlight '(:bold-p t)
192
+  :non-focus-complete-face '(:background :tweak_background)
193
+  :font-lock-function-name-face '(:foreground :blue)
194
+  :font-lock-comment-face '(:foreground :firebrick)
195
+  :font-lock-type-face '(:foreground :forestgreen)
196
+  :font-lock-variable-name-face '(:foreground :darkgoldenrod)
197
+  :font-lock-string-face '(:foreground :rosybrown)
198
+  :font-lock-keyword-face '(:foreground :purple)
199
+  :font-lock-builtin-face '(:foreground :orchid)
200
+  :compiler-note-highlight '(:foreground :magenta)
201
+  :compiler-warning-highlight '(:foreground :orange3)
202
+  :compiler-error-highlight '(:foreground :red)
203
+  :incremental-search-face '(:background :tweak_background)
204
+  :incremental-search-other-matches-face '(:underline-p t))
205
+
206
+(define-color-theme "plain" ()
207
+  :foreground nil :background nil
208
+  :region '(:foreground :color_highlighttext
209
+	    :background :color_highlight)
210
+  :show-point-face '()
211
+  :interactive-input-face '()
212
+  :highlight '(:bold-p t)
213
+  :non-focus-complete-face '(:background :tweak_background)
214
+  :font-lock-function-name-face '()
215
+  :font-lock-comment-face '()
216
+  :font-lock-type-face '()
217
+  :font-lock-variable-name-face '()
218
+  :font-lock-string-face '()
219
+  :font-lock-keyword-face '()
220
+  :font-lock-builtin-face '()
221
+  :compiler-note-highlight '()
222
+  :compiler-warning-highlight '()
223
+  :compiler-error-highlight '()
224
+  :incremental-search-face '(:background :tweak_background)
225
+  :incremental-search-other-matches-face '(:underline-p t))
226
+
227
+
228
+(define-color-theme "emacs" ()
229
+  :foreground nil :background nil
230
+  :region '(:foreground :color_highlighttext
231
+	    :background :color_highlight)
232
+  :show-point-face '(:background :green)
233
+  :interactive-input-face '(:foreground :red3)
234
+  :highlight '(:bold-p t)
235
+  :non-focus-complete-face '(:background :tweak_background)
236
+  :font-lock-function-name-face '(:foreground :blue)
237
+  :font-lock-comment-face '(:foreground :gray40)
238
+  :font-lock-type-face '(:foreground :forestgreen)
239
+  :font-lock-variable-name-face '(:foreground :darkgoldenrod)
240
+  :font-lock-string-face '(:foreground :rosybrown)
241
+  :font-lock-keyword-face '(:foreground :purple)
242
+  :font-lock-builtin-face '(:foreground :orchid)
243
+  :compiler-note-highlight '(:foreground :magenta)
244
+  :compiler-warning-highlight '(:foreground :orange3)
245
+  :compiler-error-highlight '(:foreground :red)
246
+  :incremental-search-face '(:background :tweak_background)
247
+  :incremental-search-other-matches-face '(:underline-p t))
248
+
249
+
250
+(define-color-theme "torte" ()
251
+  :foreground (color:make-rgb 0.8s0 0.8s0 0.8s0)
252
+  :background (color:make-rgb 0.0s0 0.0s0 0.0s0)
253
+  :region '(:foreground :color_highlighttext
254
+	    :background :color_highlight)
255
+  :show-point-face `(:background ,(color:make-rgb 0.6275s0 0.1255s0 0.9412s0))
256
+  :interactive-input-face '(:foreground :pink)
257
+  :highlight '(:bold-p t)
258
+  :non-focus-complete-face '(:background :tweak_background)
259
+  :font-lock-function-name-face `(:foreground ,(color:make-rgb 0.0s0 1.0s0 1.0s0))
260
+  :font-lock-comment-face `(:foreground ,(color:make-rgb 0.5s0 0.6275s0 1.0s0))
261
+  :font-lock-type-face `(:foreground ,(color:make-rgb 0.5s0 1.0s0 0.5s0))
262
+  :font-lock-variable-name-face `(:foreground ,(color:make-rgb 1.0s0 1.0s0 1.0s0))
263
+  :font-lock-string-face `(:foreground ,(color:make-rgb 1.0s0 0.6275s0 0.6275s0))
264
+  :font-lock-keyword-face `(:foreground ,(color:make-rgb 1.0s0 1.0s0 0.0s0))
265
+  :font-lock-builtin-face `(:foreground ,(color:make-rgb 1.0s0 1.0s0 0.0s0))
266
+  :compiler-note-highlight '(:foreground :magenta)
267
+  :compiler-warning-highlight '(:foreground :orange)
268
+  :compiler-error-highlight '(:foreground :red)
269
+  :incremental-search-face '(:background :tweak_background)
270
+  :incremental-search-other-matches-face '(:underline-p t))
271
+
272
+
273
+
274
+;;; Show presence when loaded
275
+(pushnew :editor-color-theme *features*)