Mercurial > hg > xemacs-beta
annotate lisp/cus-face.el @ 4967:0d4c9d0f6a8d
rewrite dynarr code
-------------------- ChangeLog entries follow: --------------------
src/ChangeLog addition:
2010-02-03 Ben Wing <ben@xemacs.org>
* device-x.c (x_get_resource_prefix):
* device-x.c (Fx_get_resource):
* device-x.c (Fx_get_resource_prefix):
* device-x.c (Fx_put_resource):
* dialog-msw.c:
* dialog-msw.c (handle_question_dialog_box):
* dired-msw.c (mswindows_sort_files):
* dired-msw.c (mswindows_get_files):
* extents.c (extent_fragment_sort_by_priority):
* extents.c (Fset_extent_parent):
* file-coding.c (coding_reader):
* file-coding.c (coding_writer):
* file-coding.c (gzip_convert):
* frame.c (generate_title_string):
* gutter.c (calculate_gutter_size_from_display_lines):
* indent.c (vmotion_1):
* lread.c (read_bit_vector):
* mule-coding.c (iso2022_decode):
* rangetab.c:
* rangetab.c (Fcopy_range_table):
* rangetab.c (Fget_range_table):
* rangetab.c (unified_range_table_copy_data):
* redisplay-msw.c (mswindows_output_string):
* redisplay-output.c (output_display_line):
* redisplay-output.c (redisplay_move_cursor):
* redisplay-output.c (redisplay_clear_bottom_of_window):
* redisplay-tty.c (tty_output_ichar_dynarr):
* redisplay-tty.c (set_foreground_to):
* redisplay-tty.c (set_background_to):
* redisplay-xlike-inc.c (XLIKE_output_string):
* redisplay.c (redisplay_window_text_width_string):
* redisplay.c (redisplay_text_width_string):
* redisplay.c (create_text_block):
* redisplay.c (SET_CURRENT_MODE_CHARS_PIXSIZE):
* redisplay.c (generate_fstring_runes):
* redisplay.c (regenerate_modeline):
* redisplay.c (ensure_modeline_generated):
* redisplay.c (real_current_modeline_height):
* redisplay.c (create_string_text_block):
* redisplay.c (regenerate_window):
* redisplay.c (REGEN_INC_FIND_START_END):
* redisplay.c (point_visible):
* redisplay.c (redisplay_window):
* redisplay.c (mark_glyph_block_dynarr):
* redisplay.c (line_start_cache_start):
* redisplay.c (start_with_line_at_pixpos):
* redisplay.c (update_line_start_cache):
* redisplay.c (glyph_to_pixel_translation):
* redisplay.c (pixel_to_glyph_translation):
* sysdep.c (qxe_readdir):
* text.c (dfc_convert_to_external_format):
* text.c (dfc_convert_to_internal_format):
* toolbar-common.c (common_output_toolbar_button):
* window.c (window_modeline_height):
* window.c (Fwindow_last_line_visible_height):
* window.c (window_displayed_height):
* window.c (window_scroll):
* window.c (get_current_pixel_pos):
Use Dynarr_begin() in place of Dynarr_atp (foo, 0).
* dynarr.c (Dynarr_realloc):
* dynarr.c (Dynarr_lisp_realloc):
* dynarr.c (Dynarr_resize):
* dynarr.c (Dynarr_insert_many):
* dynarr.c (Dynarr_delete_many):
* dynarr.c (Dynarr_memory_usage):
* dynarr.c (stack_like_malloc):
* dynarr.c (stack_like_free):
* lisp.h:
* lisp.h (DECLARE_DYNARR_LISP_IMP):
* lisp.h (XD_DYNARR_DESC):
* lisp.h (Dynarr_pop):
* gutter.c (output_gutter):
* redisplay-output.c (sync_rune_structs):
* redisplay-output.c (redisplay_output_window):
Redo the dynarr code, add greater checks.
Rename the `len', `largest' and `max' members to `len_',
`largest_' and `max_' to try and catch existing places that might
directly modify these values. Make new accessors Dynarr_largest()
and Dynarr_max() and make them and existing Dynarr_length() be
non-lvalues by adding '+ 0' to them; fix a couple of places in the
redisplay code that tried to modify the length directly by setting
Dynarr_length(). Use the accessors whenever possible even in the
dynarr code itself. The accessors also verify that 0 <= len <=
largest <= max. Rename settor function Dynarr_set_size() to
Dynarr_set_length() and use it more consistently; also create
lower-level Dynarr_set_length_1(). This latter function should be
the only function that directly modifies the `len_' member of a
Dynarr, and in the process makes sure that the `largest' value is
kept correct.
Consistently use ERROR_CHECK_STRUCTURES instead of
ERROR_CHECK_TYPES for error-checking code. Reintroduce the
temporarily disabled verification code on the positions of
Dynarr_at(), Dynarr_atp() and Dynarr_atp_past_end().
Also create Dynarr_resize_if() in place of a repeated
code fragment. Clean up all the functions that modify Dynarrs to
use the new macros and functions and verify the correctness of the
Dynarr both before and after the change.
Note that there are two kinds of verification -- one for accessing
and one for modifying. The difference is that the modify
verification additionally checks to make sure that the Dynarr
isn't locked. (This is used in redisplay to check for problems
with reentrancy.)
* lrecord.h: Move XD_DYNARR_DESC to lisp.h, grouping with the dynarr code.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Wed, 03 Feb 2010 20:51:18 -0600 |
parents | 69a1eda3da06 |
children | 5502045ec510 |
rev | line source |
---|---|
428 | 1 ;;; cus-face.el -- Support for Custom faces. |
2 ;; | |
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc. | |
4 ;; | |
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk> | |
6 ;; Maintainer: Hrvoje Niksic <hniksic@xemacs.org> | |
7 ;; Keywords: help, faces | |
8 ;; Version: 1.9960-x | |
9 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/ | |
10 | |
3027 | 11 ;;; Synched with: Not synched. |
12 | |
428 | 13 ;;; Commentary: |
14 ;; | |
15 ;; See `custom.el'. | |
16 | |
17 ;;; Code: | |
18 | |
771 | 19 ;; it is now safe to put the `provide' anywhere. if an error occurs while |
20 ;; loading, all provides (and fsets) will be undone. put it first to | |
21 ;; prevent require/provide loop with custom and cus-face. | |
22 (provide 'cus-face) | |
428 | 23 (require 'custom) |
24 | |
25 ;; To elude the warnings for font functions. | |
26 (eval-when-compile | |
27 (require 'font)) | |
28 | |
29 ;;; Declaring a face. | |
30 | |
31 ;;;###autoload | |
32 (defun custom-declare-face (face spec doc &rest args) | |
33 "Like `defface', but FACE is evaluated as a normal argument." | |
34 ;; (when (fboundp 'pureload) | |
35 ;; (error "Attempt to declare a face during dump")) | |
36 ;; #### should we possibly reset force-face here? | |
37 (unless (get face 'face-defface-spec) | |
38 (put face 'face-defface-spec spec) | |
39 (unless (find-face face) | |
40 ;; If the user has already created the face, respect that. | |
41 (let ((value (or (get face 'saved-face) spec)) | |
42 (frames (relevant-custom-frames)) | |
43 frame) | |
44 ;; Create global face. | |
45 (make-empty-face face) | |
46 (face-display-set face value nil '(custom)) | |
47 ;; Create frame local faces | |
48 (while frames | |
49 (setq frame (car frames) | |
50 frames (cdr frames)) | |
51 (face-display-set face value frame '(custom))) | |
52 (init-face-from-resources face))) | |
4535
69a1eda3da06
Distinguish vars and functions in #'symbol-file, #'describe-{function,variable}
Aidan Kehoe <kehoea@parhasard.net>
parents:
3918
diff
changeset
|
53 ;; Don't record SPEC until we see it causes no errors. |
69a1eda3da06
Distinguish vars and functions in #'symbol-file, #'describe-{function,variable}
Aidan Kehoe <kehoea@parhasard.net>
parents:
3918
diff
changeset
|
54 (put face 'face-defface-spec spec) |
69a1eda3da06
Distinguish vars and functions in #'symbol-file, #'describe-{function,variable}
Aidan Kehoe <kehoea@parhasard.net>
parents:
3918
diff
changeset
|
55 (push (cons 'defface face) current-load-list) |
428 | 56 (when (and doc (null (face-doc-string face))) |
57 (set-face-doc-string face doc)) | |
58 (custom-handle-all-keywords face args 'custom-face) | |
59 (run-hooks 'custom-define-hook)) | |
60 face) | |
61 | |
62 ;;; Font Attributes. | |
63 | |
444 | 64 ;; Consider adding the stuff in the XML font model here. |
428 | 65 (defconst custom-face-attributes |
66 '((:foreground (color :tag "Foreground" | |
67 :value "" | |
68 :help-echo "Set foreground color.") | |
69 set-face-foreground face-foreground-name) | |
70 (:background (color :tag "Background" | |
71 :value "" | |
72 :help-echo "Set background color.") | |
73 set-face-background face-background-name) | |
74 (:size (editable-field :format "Size: %v" | |
75 :help-echo "\ | |
76 Text size (e.g. 9pt or 2mm).") | |
77 custom-set-face-font-size custom-face-font-size) | |
78 (:family (editable-field :format "Font Family: %v" | |
79 :help-echo "\ | |
80 Name of font family to use (e.g. times).") | |
81 custom-set-face-font-family custom-face-font-family) | |
82 (:background-pixmap (editable-field :format "Background pixmap: %v" | |
83 :help-echo "\ | |
84 Name of background pixmap file.") | |
85 set-face-background-pixmap custom-face-background-pixmap) | |
86 (:dim (toggle :format "%[Dim%]: %v\n" | |
87 :help-echo "Control whether the text should be dimmed.") | |
88 set-face-dim-p face-dim-p) | |
89 (:bold (toggle :format "%[Bold%]: %v\n" | |
90 :help-echo "Control whether a bold font should be used.") | |
91 custom-set-face-bold custom-face-bold) | |
92 (:italic (toggle :format "%[Italic%]: %v\n" | |
93 :help-echo "\ | |
94 Control whether an italic font should be used.") | |
95 custom-set-face-italic custom-face-italic) | |
96 (:underline (toggle :format "%[Underline%]: %v\n" | |
97 :help-echo "\ | |
98 Control whether the text should be underlined.") | |
99 set-face-underline-p face-underline-p) | |
100 (:strikethru (toggle :format "%[Strikethru%]: %v\n" | |
101 :help-echo "\ | |
102 Control whether the text should be strikethru.") | |
103 set-face-strikethru-p face-strikethru-p) | |
104 (:inverse-video (toggle :format "%[Inverse Video%]: %v\n" | |
105 :help-echo "\ | |
106 Control whether the text should be inverted. Works only on TTY-s") | |
3027 | 107 set-face-reverse-p face-reverse-p) |
108 (:inherit | |
109 (repeat :tag "Inherit" | |
110 :help-echo "List of faces to inherit attributes from." | |
111 (face :Tag "Face" default)) | |
112 ;; FSF 21.3 | |
113 ; ;; filter to make value suitable for customize | |
114 ; (lambda (real-value) | |
115 ; (cond ((or (null real-value) (eq real-value 'unspecified)) | |
116 ; nil) | |
117 ; ((symbolp real-value) | |
118 ; (list real-value)) | |
119 ; (t | |
120 ; real-value))) | |
121 ; ;; filter to make customized-value suitable for storing | |
122 ; (lambda (cus-value) | |
123 ; (if (and (consp cus-value) (null (cdr cus-value))) | |
124 ; (car cus-value) | |
125 ; cus-value)) | |
126 custom-set-face-inherit custom-face-inherit)) | |
444 | 127 "Alist of face attributes. |
428 | 128 |
444 | 129 The elements are lists of the form (KEY TYPE SET GET) where: |
130 KEY is a symbol identifying the attribute. | |
131 TYPE is a widget type for editing the attribute. | |
132 SET is a function for setting the attribute value. | |
133 GET is a function for getting the attribute value. | |
428 | 134 |
444 | 135 The SET function should take three arguments: the face to modify, the |
428 | 136 value of the attribute, and optionally the frame where the face should |
137 be changed. | |
138 | |
139 The GET function should take two arguments, the face to examine, and | |
444 | 140 optionally the frame where the face should be examined.") |
428 | 141 |
142 (defun face-custom-attributes-set (face frame tags &rest atts) | |
143 "For FACE on FRAME set the attributes [KEYWORD VALUE].... | |
144 Each keyword should be listed in `custom-face-attributes'. | |
145 | |
146 If FRAME is nil, set the default face." | |
147 (while atts | |
148 (let* ((name (nth 0 atts)) | |
149 (value (nth 1 atts)) | |
150 (fun (nth 2 (assq name custom-face-attributes)))) | |
151 (setq atts (cdr (cdr atts))) | |
152 (condition-case nil | |
153 (funcall fun face value frame tags) | |
154 (error nil))))) | |
155 | |
156 (defun face-custom-attributes-get (face frame) | |
157 "For FACE on FRAME get the attributes [KEYWORD VALUE].... | |
158 Each keyword should be listed in `custom-face-attributes'. | |
159 | |
160 If FRAME is nil, use the default face." | |
161 (condition-case nil | |
162 ;; Attempt to get `font.el' from w3. | |
163 (require 'font) | |
164 (error nil)) | |
165 (let ((atts custom-face-attributes) | |
166 att result get) | |
167 (while atts | |
168 (setq att (car atts) | |
169 atts (cdr atts) | |
170 get (nth 3 att)) | |
171 (condition-case nil | |
172 ;; This may fail if w3 doesn't exist. | |
173 (when get | |
174 (let ((answer (funcall get face frame))) | |
175 (unless (equal answer (funcall get 'default frame)) | |
176 (when (widget-apply (nth 1 att) :match answer) | |
177 (setq result (cons (nth 0 att) (cons answer result))))))) | |
178 (error nil))) | |
179 result)) | |
180 | |
181 (defsubst custom-face-get-spec (symbol) | |
182 (or (get symbol 'customized-face) | |
183 (get symbol 'saved-face) | |
184 (get symbol 'face-defface-spec) | |
185 ;; Attempt to construct it. | |
186 (list (list t (face-custom-attributes-get | |
187 symbol (selected-frame)))))) | |
188 | |
189 (defun custom-set-face-bold (face value &optional frame tags) | |
190 "Set the bold property of FACE to VALUE." | |
191 (if value | |
192 (make-face-bold face frame tags) | |
193 (make-face-unbold face frame tags))) | |
194 | |
195 ;; Really, we should get rid of these font.el dependencies... They | |
196 ;; are still presenting a problem with dumping the faces (font.el is | |
197 ;; too bloated for us to dump). I am thinking about hacking up | |
198 ;; font-like functionality myself for the sake of this file. It will | |
199 ;; probably be to-the-point and more efficient. | |
200 | |
201 (defun custom-face-bold (face &rest args) | |
202 "Return non-nil if the font of FACE is bold." | |
203 (let* ((font (apply 'face-font-name face args)) | |
204 ;; Gag | |
205 (fontobj (font-create-object font))) | |
206 (font-bold-p fontobj))) | |
207 | |
208 (defun custom-set-face-italic (face value &optional frame tags) | |
209 "Set the italic property of FACE to VALUE." | |
210 (if value | |
211 (make-face-italic face frame tags) | |
212 (make-face-unitalic face frame tags))) | |
213 | |
214 (defun custom-face-italic (face &rest args) | |
215 "Return non-nil if the font of FACE is italic." | |
216 (let* ((font (apply 'face-font-name face args)) | |
217 ;; Gag | |
218 (fontobj (font-create-object font))) | |
219 (font-italic-p fontobj))) | |
220 | |
221 (defun custom-face-background-pixmap (face &rest args) | |
222 "Return the name of the background pixmap file used for FACE." | |
3027 | 223 (let ((image (apply 'specifier-instance |
224 (face-background-pixmap face) args))) | |
444 | 225 (and image |
428 | 226 (image-instance-file-name image)))) |
227 | |
3027 | 228 (defun custom-set-face-inherit (face value &optional frame tags) |
229 "Set FACE to inherit its properties from another face." | |
230 (if (listp value) (setq value (car value))) ;; #### Temporary hack! | |
231 (if (find-face value) | |
232 (set-face-parent face value frame tags))) | |
233 | |
234 (defun custom-face-inherit (face &rest args) | |
235 "Return the value (instance) of the `inherit' property for FACE." | |
236 ;; #### Major, temporary hack! | |
237 (let ((spec (apply 'specifier-instantiator | |
238 (face-font face) args))) | |
239 (and spec (vector spec) (aref spec 0)))) | |
240 | |
707 | 241 ;; This consistently fails to dtrt |
242 ;;(defun custom-set-face-font-size (face size &optional locale tags) | |
243 ;; "Set the font of FACE to SIZE." | |
244 ;; ;; #### should this call have tags in it? | |
245 ;; (let* ((font (apply 'face-font-name face (list locale))) | |
246 ;; ;; Gag | |
247 ;; (fontobj (font-create-object font))) | |
248 ;; (set-font-size fontobj size) | |
249 ;; (apply 'font-set-face-font face fontobj locale tags))) | |
250 | |
251 ;; From Jan Vroonhof -- see faces.el | |
428 | 252 (defun custom-set-face-font-size (face size &optional locale tags) |
444 | 253 "Set the font of FACE to SIZE." |
707 | 254 (make-face-size face size locale tags)) |
428 | 255 |
256 (defun custom-face-font-size (face &rest args) | |
257 "Return the size of the font of FACE as a string." | |
258 (let* ((font (apply 'face-font-name face args)) | |
259 ;; Gag | |
260 (fontobj (font-create-object font))) | |
261 (format "%s" (font-size fontobj)))) | |
262 | |
707 | 263 ;; Jan suggests this may not dtrt |
264 ;;(defun custom-set-face-font-family (face family &optional locale tags) | |
265 ;; "Set the font of FACE to FAMILY." | |
266 ;; ;; #### should this call have tags in it? | |
267 ;; (let* ((font (apply 'face-font-name face (list locale))) | |
268 ;; ;; Gag | |
269 ;; (fontobj (font-create-object font))) | |
270 ;; (set-font-family fontobj family) | |
271 ;; (apply 'font-set-face-font face fontobj locale tags))) | |
272 | |
273 ;; From Jan Vroonhof -- see faces.el | |
428 | 274 (defun custom-set-face-font-family (face family &optional locale tags) |
275 "Set the font of FACE to FAMILY." | |
707 | 276 (make-face-family face family locale tags)) |
428 | 277 |
278 (defun custom-face-font-family (face &rest args) | |
279 "Return the name of the font family of FACE." | |
280 (let* ((font (apply 'face-font-name face args)) | |
281 ;; Gag | |
282 (fontobj (font-create-object font))) | |
283 (font-family fontobj))) | |
284 | |
285 ;;;###autoload | |
286 (defun custom-set-face-update-spec (face display plist) | |
287 "Customize the FACE for display types matching DISPLAY, merging | |
3918 | 288 in the new items from PLIST." |
428 | 289 (let ((spec (face-spec-update-all-matching (custom-face-get-spec face) |
290 display plist))) | |
291 (put face 'customized-face spec) | |
292 (face-spec-set face spec nil '(custom)))) | |
293 | |
294 ;;; Initializing. | |
295 | |
296 ;;;###autoload | |
297 (defun custom-set-faces (&rest args) | |
298 "Initialize faces according to user preferences. | |
299 This asociates the setting with the USER theme. | |
300 The arguments should be a list where each entry has the form: | |
301 | |
302 (FACE SPEC [NOW [COMMENT]]) | |
303 | |
304 SPEC will be stored as the saved value for FACE. If NOW is present | |
305 and non-nil, FACE will also be created according to SPEC. | |
306 COMMENT is a string comment about FACE. | |
307 | |
308 See `defface' for the format of SPEC." | |
309 (apply #'custom-theme-set-faces 'user args)) | |
310 | |
311 ;;;###autoload | |
312 (defun custom-theme-set-faces (theme &rest args) | |
313 "Initialize faces according to settings specified by args. | |
314 Records the settings as belonging to THEME. | |
315 | |
316 See `custom-set-faces' for a description of the arguments ARGS." | |
317 (custom-check-theme theme) | |
318 (let ((immediate (get theme 'theme-immediate))) | |
319 (while args | |
320 (let ((entry (car args))) | |
321 (if (listp entry) | |
322 (let ((face (nth 0 entry)) | |
323 (spec (nth 1 entry)) | |
324 (now (nth 2 entry)) | |
325 (comment (nth 3 entry))) | |
326 (put face 'saved-face spec) | |
327 (custom-push-theme 'theme-face face theme 'set spec) | |
328 (put face 'saved-face-comment comment) | |
329 (when (or now immediate) | |
330 (put face 'force-face (if now 'rogue 'immediate))) | |
331 (when (or now immediate (find-face face)) | |
332 (put face 'face-comment comment) | |
333 (unless (find-face face) | |
334 (make-empty-face face)) | |
335 (face-spec-set face spec nil '(custom))) | |
336 (setq args (cdr args))) | |
337 ;; Old format, a plist of FACE SPEC pairs. | |
338 (let ((face (nth 0 args)) | |
339 (spec (nth 1 args))) | |
340 (put face 'saved-face spec) | |
341 (custom-push-theme 'theme-face face theme 'set spec)) | |
342 (setq args (cdr (cdr args)))))))) | |
343 | |
344 ;;;###autoload | |
345 (defun custom-theme-face-value (face theme) | |
346 "Return spec of FACE in THEME if the THEME modifies the | |
347 FACE. Nil otherwise." | |
348 (car-safe (custom-theme-value theme (get face 'theme-face)))) | |
349 | |
350 (defun custom-theme-reset-internal-face (face to-theme) | |
351 (let ((spec (custom-theme-face-value face to-theme)) | |
352 was-in-theme) | |
353 (setq was-in-theme spec) | |
354 (setq spec (or spec (get face 'standard-value))) | |
355 (when spec | |
356 (put face 'save-face was-in-theme) | |
357 (when (or (get face 'force-face) (find-face face)) | |
358 (unless (find-face face) | |
359 (make-empty-face face)) | |
360 (face-spec-set face spec))) | |
361 spec)) | |
362 | |
363 ;;;###autoload | |
364 (defun custom-theme-reset-faces (theme &rest args) | |
365 "Reset the value of the face to values previously defined. | |
442 | 366 Associate this setting with THEME. |
428 | 367 |
368 ARGS is a list of lists of the form | |
369 | |
370 (face to-theme) | |
371 | |
372 This means reset face to its value in to-theme." | |
3842 | 373 (custom-check-theme theme) |
428 | 374 (mapc #'(lambda (arg) |
375 (apply #'custom-theme-reset-internal-face arg) | |
376 (custom-push-theme (car arg) 'theme-face theme 'reset (cadr arg))) | |
377 args)) | |
378 | |
379 ;;;###autoload | |
380 (defun custom-reset-faces (&rest args) | |
381 "Reset the value of the face to values previously defined. | |
442 | 382 Associate this setting with the 'user' theme. |
428 | 383 |
444 | 384 ARGS is defined as for `custom-theme-reset-faces'." |
428 | 385 (apply #'custom-theme-reset-faces 'user args)) |
386 | |
387 | |
388 ;;; The End. | |
389 | |
390 ;; cus-face.el ends here |