0
|
1 /* "Face" primitives
|
|
2 Copyright (C) 1994 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Board of Trustees, University of Illinois.
|
|
4 Copyright (C) 1995, 1996 Ben Wing.
|
|
5 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: Not in FSF. */
|
|
25
|
|
26 /* Written by Chuck Thompson and Ben Wing,
|
|
27 based loosely on old face code by Jamie Zawinski. */
|
|
28
|
|
29 #include <config.h>
|
|
30 #include "lisp.h"
|
|
31
|
|
32 #include "buffer.h"
|
|
33 #include "device.h"
|
|
34 #include "elhash.h"
|
|
35 #include "extents.h"
|
|
36 #include "faces.h"
|
|
37 #include "frame.h"
|
|
38 #include "glyphs.h"
|
|
39 #include "hash.h"
|
|
40 #include "objects.h"
|
|
41 #include "specifier.h"
|
|
42 #include "window.h"
|
|
43
|
|
44 #ifdef HAVE_X_WINDOWS
|
|
45 #include "console-x.h"
|
|
46 #include "objects-x.h"
|
|
47 #include "EmacsFrame.h"
|
|
48 #endif /* HAVE_X_WINDOWS */
|
|
49
|
|
50 /* Qfont, Qdoc_string, Qface defined in general.c */
|
|
51 Lisp_Object Qfacep;
|
|
52 Lisp_Object Qforeground, Qbackground, Qdisplay_table;
|
|
53 /* Qhighlight, Qreverse defined in general.c */
|
|
54 Lisp_Object Qbackground_pixmap, Qunderline, Qdim;
|
|
55 Lisp_Object Qblinking, Qstrikethru;
|
|
56
|
|
57 Lisp_Object Qinit_face_from_resources;
|
|
58 Lisp_Object Qinit_frame_faces;
|
|
59 Lisp_Object Qinit_device_faces;
|
|
60 Lisp_Object Qinit_global_faces;
|
|
61
|
|
62 /* These faces are used directly internally. We use these variables
|
|
63 to be able to reference them directly and save the overhead of
|
|
64 calling Ffind_face. */
|
|
65 Lisp_Object Vdefault_face, Vmodeline_face;
|
|
66 Lisp_Object Vleft_margin_face, Vright_margin_face, Vtext_cursor_face;
|
|
67 Lisp_Object Vpointer_face;
|
|
68
|
|
69 /* Qdefault, Qhighlight defined in general.c */
|
|
70 Lisp_Object Qmodeline, Qleft_margin, Qright_margin, Qtext_cursor;
|
|
71
|
|
72 /* In the old implementation Vface_list was a list of the face names,
|
|
73 not the faces themselves. We now distinguish between permanent and
|
|
74 temporary faces. Permanent faces are kept in a regular hash table,
|
|
75 temporary faces in a weak hash table. */
|
|
76 Lisp_Object Vpermanent_faces_cache;
|
|
77 Lisp_Object Vtemporary_faces_cache;
|
|
78
|
|
79 Lisp_Object Vbuilt_in_face_specifiers;
|
|
80
|
|
81
|
|
82 static Lisp_Object mark_face (Lisp_Object, void (*) (Lisp_Object));
|
|
83 static void print_face (Lisp_Object, Lisp_Object, int);
|
|
84 static int face_equal (Lisp_Object, Lisp_Object, int depth);
|
|
85 static unsigned long face_hash (Lisp_Object obj, int depth);
|
|
86 static Lisp_Object face_getprop (Lisp_Object obj, Lisp_Object prop);
|
|
87 static int face_putprop (Lisp_Object obj, Lisp_Object prop, Lisp_Object value);
|
|
88 static int face_remprop (Lisp_Object obj, Lisp_Object prop);
|
|
89 static Lisp_Object face_plist (Lisp_Object obj);
|
|
90 DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS ("face", face,
|
|
91 mark_face, print_face, 0, face_equal,
|
|
92 face_hash, face_getprop,
|
|
93 face_putprop, face_remprop,
|
|
94 face_plist, struct Lisp_Face);
|
|
95
|
|
96 static Lisp_Object
|
|
97 mark_face (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
98 {
|
|
99 struct Lisp_Face *face = XFACE (obj);
|
|
100
|
|
101 ((markobj) (face->name));
|
|
102 ((markobj) (face->doc_string));
|
|
103
|
|
104 ((markobj) (face->foreground));
|
|
105 ((markobj) (face->background));
|
|
106 ((markobj) (face->font));
|
|
107 ((markobj) (face->display_table));
|
|
108 ((markobj) (face->background_pixmap));
|
|
109 ((markobj) (face->underline));
|
|
110 ((markobj) (face->strikethru));
|
|
111 ((markobj) (face->highlight));
|
|
112 ((markobj) (face->dim));
|
|
113 ((markobj) (face->blinking));
|
|
114 ((markobj) (face->reverse));
|
|
115
|
|
116 ((markobj) (face->charsets_warned_about));
|
|
117
|
173
|
118 return face->plist;
|
0
|
119 }
|
|
120
|
|
121 static void
|
|
122 print_face (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
123 {
|
|
124 struct Lisp_Face *face = XFACE (obj);
|
|
125
|
|
126 if (print_readably)
|
|
127 {
|
|
128 write_c_string ("#s(face name ", printcharfun);
|
|
129 print_internal (face->name, printcharfun, 1);
|
|
130 write_c_string (")", printcharfun);
|
|
131 }
|
|
132 else
|
|
133 {
|
|
134 write_c_string ("#<face ", printcharfun);
|
|
135 print_internal (face->name, printcharfun, 1);
|
|
136 if (!NILP (face->doc_string))
|
|
137 {
|
|
138 write_c_string (" ", printcharfun);
|
|
139 print_internal (face->doc_string, printcharfun, 1);
|
|
140 }
|
|
141 write_c_string (">", printcharfun);
|
|
142 }
|
|
143 }
|
|
144
|
|
145 /* Faces are equal if all of their display attributes are equal. We
|
|
146 don't compare names or doc-strings, because that would make equal
|
|
147 be eq.
|
|
148
|
|
149 This isn't concerned with "unspecified" attributes, that's what
|
|
150 #'face-differs-from-default-p is for. */
|
|
151 static int
|
|
152 face_equal (Lisp_Object o1, Lisp_Object o2, int depth)
|
|
153 {
|
|
154 struct Lisp_Face *f1 = XFACE (o1);
|
|
155 struct Lisp_Face *f2 = XFACE (o2);
|
|
156
|
|
157 depth++;
|
|
158
|
|
159 if (!internal_equal (f1->foreground, f2->foreground, depth) ||
|
|
160 !internal_equal (f1->background, f2->background, depth) ||
|
|
161 !internal_equal (f1->font, f2->font, depth) ||
|
|
162 !internal_equal (f1->display_table, f2->display_table, depth) ||
|
|
163 !internal_equal (f1->background_pixmap, f2->background_pixmap, depth) ||
|
|
164 !internal_equal (f1->underline, f2->underline, depth) ||
|
|
165 !internal_equal (f1->strikethru, f2->strikethru, depth) ||
|
|
166 !internal_equal (f1->highlight, f2->highlight, depth) ||
|
|
167 !internal_equal (f1->dim, f2->dim, depth) ||
|
|
168 !internal_equal (f1->blinking, f2->blinking, depth) ||
|
|
169 !internal_equal (f1->reverse, f2->reverse, depth) ||
|
|
170 plists_differ (f1->plist, f2->plist, 0, 0, depth + 1))
|
|
171 return 0;
|
|
172
|
|
173 return 1;
|
|
174 }
|
|
175
|
|
176 static unsigned long
|
|
177 face_hash (Lisp_Object obj, int depth)
|
|
178 {
|
|
179 struct Lisp_Face *f = XFACE (obj);
|
|
180
|
|
181 depth++;
|
|
182
|
|
183 /* No need to hash all of the elements; that would take too long.
|
|
184 Just hash the most common ones. */
|
|
185 return HASH3 (internal_hash (f->foreground, depth),
|
|
186 internal_hash (f->background, depth),
|
|
187 internal_hash (f->font, depth));
|
|
188 }
|
|
189
|
|
190 static Lisp_Object
|
|
191 face_getprop (Lisp_Object obj, Lisp_Object prop)
|
|
192 {
|
|
193 struct Lisp_Face *f = XFACE (obj);
|
|
194
|
|
195 #define FROB(propprop) \
|
|
196 do { \
|
|
197 if (EQ (prop, Q##propprop)) \
|
|
198 { \
|
|
199 return f->propprop; \
|
|
200 } \
|
|
201 } while (0)
|
|
202
|
|
203 FROB (foreground);
|
|
204 FROB (background);
|
|
205 FROB (font);
|
|
206 FROB (display_table);
|
|
207 FROB (background_pixmap);
|
|
208 FROB (underline);
|
|
209 FROB (strikethru);
|
|
210 FROB (highlight);
|
|
211 FROB (dim);
|
|
212 FROB (blinking);
|
|
213 FROB (reverse);
|
|
214 FROB (doc_string);
|
|
215
|
|
216 #undef FROB
|
|
217
|
|
218 return external_plist_get (&f->plist, prop, 0, ERROR_ME);
|
|
219 }
|
|
220
|
|
221 static int
|
|
222 face_putprop (Lisp_Object obj, Lisp_Object prop, Lisp_Object value)
|
|
223 {
|
|
224 struct Lisp_Face *f = XFACE (obj);
|
|
225
|
|
226 #define FROB(propprop) \
|
|
227 do { \
|
|
228 if (EQ (prop, Q##propprop)) \
|
|
229 return 0; \
|
|
230 } while (0)
|
|
231
|
|
232 FROB (foreground);
|
|
233 FROB (background);
|
|
234 FROB (font);
|
|
235 FROB (display_table);
|
|
236 FROB (background_pixmap);
|
|
237 FROB (underline);
|
|
238 FROB (strikethru);
|
|
239 FROB (highlight);
|
|
240 FROB (dim);
|
|
241 FROB (blinking);
|
|
242 FROB (reverse);
|
|
243
|
|
244 #undef FROB
|
|
245
|
|
246 if (EQ (prop, Qdoc_string))
|
|
247 {
|
|
248 if (!NILP (value))
|
|
249 CHECK_STRING (value);
|
|
250 f->doc_string = value;
|
|
251 return 1;
|
|
252 }
|
|
253
|
|
254 external_plist_put (&f->plist, prop, value, 0, ERROR_ME);
|
|
255 return 1;
|
|
256 }
|
|
257
|
|
258 static int
|
|
259 face_remprop (Lisp_Object obj, Lisp_Object prop)
|
|
260 {
|
|
261 struct Lisp_Face *f = XFACE (obj);
|
|
262
|
|
263 #define FROB(propprop) \
|
|
264 do { \
|
|
265 if (EQ (prop, Q##propprop)) \
|
|
266 return -1; \
|
|
267 } while (0)
|
|
268
|
|
269 FROB (foreground);
|
|
270 FROB (background);
|
|
271 FROB (font);
|
|
272 FROB (display_table);
|
|
273 FROB (background_pixmap);
|
|
274 FROB (underline);
|
|
275 FROB (strikethru);
|
|
276 FROB (highlight);
|
|
277 FROB (dim);
|
|
278 FROB (blinking);
|
|
279 FROB (reverse);
|
|
280
|
|
281 #undef FROB
|
|
282
|
|
283 if (EQ (prop, Qdoc_string))
|
|
284 {
|
|
285 f->doc_string = Qnil;
|
|
286 return 1;
|
|
287 }
|
|
288
|
|
289 return external_remprop (&f->plist, prop, 0, ERROR_ME);
|
|
290 }
|
|
291
|
|
292 static Lisp_Object
|
|
293 face_plist (Lisp_Object obj)
|
|
294 {
|
|
295 struct Lisp_Face *f = XFACE (obj);
|
|
296 Lisp_Object result = Qnil;
|
|
297
|
|
298 #define FROB(propprop) \
|
|
299 do { \
|
|
300 /* backwards order; we reverse it below */ \
|
|
301 result = Fcons (f->propprop, Fcons (Q##propprop, result)); \
|
|
302 } while (0)
|
|
303
|
|
304 FROB (foreground);
|
|
305 FROB (background);
|
|
306 FROB (font);
|
|
307 FROB (display_table);
|
|
308 FROB (background_pixmap);
|
|
309 FROB (underline);
|
|
310 FROB (strikethru);
|
|
311 FROB (highlight);
|
|
312 FROB (dim);
|
|
313 FROB (blinking);
|
|
314 FROB (reverse);
|
|
315
|
|
316 #undef FROB
|
|
317 return nconc2 (Fnreverse (result), f->plist);
|
|
318 }
|
|
319
|
|
320
|
|
321 /************************************************************************/
|
|
322 /* face read syntax */
|
|
323 /************************************************************************/
|
|
324
|
|
325 static int
|
|
326 face_name_validate (Lisp_Object keyword, Lisp_Object value,
|
|
327 Error_behavior errb)
|
|
328 {
|
|
329 if (ERRB_EQ (errb, ERROR_ME))
|
|
330 {
|
|
331 CHECK_SYMBOL (value);
|
|
332 return 1;
|
|
333 }
|
|
334
|
|
335 return SYMBOLP (value);
|
|
336 }
|
|
337
|
|
338 static int
|
|
339 face_validate (Lisp_Object data, Error_behavior errb)
|
|
340 {
|
|
341 int name_seen = 0;
|
173
|
342 Lisp_Object valw = Qnil;
|
0
|
343
|
|
344 data = Fcdr (data); /* skip over Qface */
|
|
345 while (!NILP (data))
|
|
346 {
|
|
347 Lisp_Object keyw = Fcar (data);
|
|
348
|
|
349 data = Fcdr (data);
|
|
350 valw = Fcar (data);
|
|
351 data = Fcdr (data);
|
|
352 if (EQ (keyw, Qname))
|
|
353 {
|
|
354 if (name_seen)
|
|
355 {
|
|
356 maybe_signal_simple_error ("Duplicate face name given", valw,
|
|
357 Qface, errb);
|
|
358 return 0;
|
|
359 }
|
|
360 name_seen = 1;
|
|
361 }
|
|
362 else
|
|
363 abort ();
|
|
364 }
|
|
365
|
|
366 if (!name_seen)
|
|
367 {
|
|
368 maybe_error (Qface, errb, "No face name given");
|
|
369 return 0;
|
|
370 }
|
|
371
|
|
372 if (NILP (Ffind_face (valw)))
|
|
373 {
|
|
374 maybe_signal_simple_error ("No such face", valw, Qface, errb);
|
|
375 return 0;
|
|
376 }
|
|
377
|
|
378 return 1;
|
|
379 }
|
|
380
|
|
381 static Lisp_Object
|
|
382 face_instantiate (Lisp_Object data)
|
|
383 {
|
|
384 return Fget_face (Fcar (Fcdr (data)));
|
|
385 }
|
|
386
|
|
387
|
|
388 /****************************************************************************
|
|
389 * utility functions *
|
|
390 ****************************************************************************/
|
|
391
|
|
392 static void
|
|
393 reset_face (struct Lisp_Face *f)
|
|
394 {
|
|
395 f->name = Qnil;
|
|
396 f->doc_string = Qnil;
|
|
397 f->dirty = 0;
|
|
398 f->foreground = Qnil;
|
|
399 f->background = Qnil;
|
|
400 f->font = Qnil;
|
|
401 f->display_table = Qnil;
|
|
402 f->background_pixmap = Qnil;
|
|
403 f->underline = Qnil;
|
|
404 f->strikethru = Qnil;
|
|
405 f->highlight = Qnil;
|
|
406 f->dim = Qnil;
|
|
407 f->blinking = Qnil;
|
|
408 f->reverse = Qnil;
|
|
409 f->plist = Qnil;
|
|
410 f->charsets_warned_about = Qnil;
|
|
411 }
|
|
412
|
|
413 static struct Lisp_Face *
|
|
414 allocate_face (void)
|
|
415 {
|
|
416 struct Lisp_Face *result =
|
|
417 alloc_lcrecord (sizeof (struct Lisp_Face), lrecord_face);
|
|
418
|
|
419 reset_face (result);
|
|
420 return result;
|
|
421 }
|
|
422
|
|
423
|
|
424 /* We store the faces in hash tables with the names as the key and the
|
|
425 actual face object as the value. Occasionally we need to use them
|
|
426 in a list format. These routines provide us with that. */
|
|
427 struct face_list_closure
|
|
428 {
|
|
429 Lisp_Object *face_list;
|
|
430 };
|
|
431
|
|
432 static void
|
|
433 add_face_to_list_mapper (CONST void *hash_key, void *hash_contents,
|
|
434 void *face_list_closure)
|
|
435 {
|
|
436 /* This function can GC */
|
|
437 Lisp_Object key, contents;
|
|
438 Lisp_Object *face_list;
|
|
439 struct face_list_closure *fcl = face_list_closure;
|
|
440 CVOID_TO_LISP (key, hash_key);
|
|
441 VOID_TO_LISP (contents, hash_contents);
|
|
442 face_list = fcl->face_list;
|
|
443
|
|
444 *face_list = Fcons (XFACE (contents)->name, *face_list);
|
|
445 }
|
|
446
|
|
447 static Lisp_Object
|
|
448 faces_list_internal (Lisp_Object list)
|
|
449 {
|
|
450 Lisp_Object face_list = Qnil;
|
|
451 struct gcpro gcpro1;
|
|
452 struct face_list_closure face_list_closure;
|
|
453
|
|
454 GCPRO1 (face_list);
|
|
455 face_list_closure.face_list = &face_list;
|
|
456 elisp_maphash (add_face_to_list_mapper, list, &face_list_closure);
|
|
457 UNGCPRO;
|
|
458
|
|
459 return face_list;
|
|
460 }
|
|
461
|
|
462 static Lisp_Object
|
|
463 permanent_faces_list (void)
|
|
464 {
|
|
465 return faces_list_internal (Vpermanent_faces_cache);
|
|
466 }
|
|
467
|
|
468 static Lisp_Object
|
|
469 temporary_faces_list (void)
|
|
470 {
|
|
471 return faces_list_internal (Vtemporary_faces_cache);
|
|
472 }
|
|
473
|
|
474
|
|
475 static void
|
|
476 mark_face_as_clean_mapper (CONST void *hash_key, void *hash_contents,
|
|
477 void *flag_closure)
|
|
478 {
|
|
479 /* This function can GC */
|
|
480 Lisp_Object key, contents;
|
|
481 int *flag = flag_closure;
|
|
482 CVOID_TO_LISP (key, hash_key);
|
|
483 VOID_TO_LISP (contents, hash_contents);
|
|
484 XFACE (contents)->dirty = *flag;
|
|
485 }
|
|
486
|
|
487 static void
|
|
488 mark_all_faces_internal (int flag)
|
|
489 {
|
|
490 elisp_maphash (mark_face_as_clean_mapper, Vpermanent_faces_cache, &flag);
|
|
491 elisp_maphash (mark_face_as_clean_mapper, Vtemporary_faces_cache, &flag);
|
|
492 }
|
|
493
|
|
494 void
|
|
495 mark_all_faces_as_clean (void)
|
|
496 {
|
|
497 mark_all_faces_internal (0);
|
|
498 }
|
|
499
|
|
500 /* #### OBSOLETE ME, PLEASE. Maybe. Maybe this is just as good as
|
|
501 any other solution. */
|
|
502 struct face_inheritance_closure
|
|
503 {
|
|
504 Lisp_Object face;
|
|
505 Lisp_Object property;
|
|
506 };
|
|
507
|
|
508 static void
|
|
509 update_inheritance_mapper_internal (Lisp_Object cur_face,
|
|
510 Lisp_Object inh_face,
|
|
511 Lisp_Object property)
|
|
512 {
|
|
513 /* #### fix this function */
|
|
514 Lisp_Object elt = Qnil;
|
|
515 struct gcpro gcpro1;
|
|
516
|
|
517 GCPRO1 (elt);
|
|
518
|
|
519 for (elt = FACE_PROPERTY_SPEC_LIST (cur_face, property, Qall);
|
|
520 !NILP (elt);
|
|
521 elt = XCDR (elt))
|
|
522 {
|
|
523 Lisp_Object locale, values;
|
|
524
|
|
525 locale = XCAR (XCAR (elt));
|
|
526 values = XCDR (XCAR (elt));
|
|
527
|
|
528 for (; !NILP (values); values = XCDR (values))
|
|
529 {
|
|
530 Lisp_Object value = XCDR (XCAR (values));
|
173
|
531 if (VECTORP (value) && XVECTOR_LENGTH (value))
|
0
|
532 {
|
173
|
533 if (EQ (Ffind_face (XVECTOR_DATA (value)[0]), inh_face))
|
0
|
534 Fset_specifier_dirty_flag
|
|
535 (FACE_PROPERTY_SPECIFIER (inh_face, property));
|
|
536 }
|
|
537 }
|
|
538 }
|
|
539
|
|
540 UNGCPRO;
|
|
541 }
|
|
542
|
|
543 static void
|
|
544 update_face_inheritance_mapper (CONST void *hash_key, void *hash_contents,
|
|
545 void *face_inheritance_closure)
|
|
546 {
|
|
547 Lisp_Object key, contents;
|
|
548 struct face_inheritance_closure *fcl = face_inheritance_closure;
|
|
549
|
|
550 CVOID_TO_LISP (key, hash_key);
|
|
551 VOID_TO_LISP (contents, hash_contents);
|
|
552
|
|
553 if (EQ (fcl->property, Qfont))
|
|
554 {
|
|
555 update_inheritance_mapper_internal (contents, fcl->face, Qfont);
|
|
556 }
|
|
557 else if (EQ (fcl->property, Qforeground)
|
|
558 || EQ (fcl->property, Qbackground))
|
|
559 {
|
|
560 update_inheritance_mapper_internal (contents, fcl->face, Qforeground);
|
|
561 update_inheritance_mapper_internal (contents, fcl->face, Qbackground);
|
|
562 }
|
|
563 else if (EQ (fcl->property, Qunderline)
|
|
564 || EQ (fcl->property, Qstrikethru)
|
|
565 || EQ (fcl->property, Qhighlight)
|
|
566 || EQ (fcl->property, Qdim)
|
|
567 || EQ (fcl->property, Qblinking)
|
|
568 || EQ (fcl->property, Qreverse))
|
|
569 {
|
|
570 update_inheritance_mapper_internal (contents, fcl->face, Qunderline);
|
|
571 update_inheritance_mapper_internal (contents, fcl->face, Qstrikethru);
|
|
572 update_inheritance_mapper_internal (contents, fcl->face, Qhighlight);
|
|
573 update_inheritance_mapper_internal (contents, fcl->face, Qdim);
|
|
574 update_inheritance_mapper_internal (contents, fcl->face, Qblinking);
|
|
575 update_inheritance_mapper_internal (contents, fcl->face, Qreverse);
|
|
576 }
|
|
577 }
|
|
578
|
|
579 static void
|
|
580 update_faces_inheritance (Lisp_Object face, Lisp_Object property)
|
|
581 {
|
|
582 struct face_inheritance_closure face_inheritance_closure;
|
|
583 struct gcpro gcpro1, gcpro2;
|
|
584
|
|
585 GCPRO2 (face, property);
|
|
586 face_inheritance_closure.face = face;
|
|
587 face_inheritance_closure.property = property;
|
|
588
|
|
589 elisp_maphash (update_face_inheritance_mapper, Vpermanent_faces_cache,
|
|
590 &face_inheritance_closure);
|
|
591 elisp_maphash (update_face_inheritance_mapper, Vtemporary_faces_cache,
|
|
592 &face_inheritance_closure);
|
|
593
|
|
594 UNGCPRO;
|
|
595 }
|
|
596
|
|
597 Lisp_Object
|
|
598 face_property_matching_instance (Lisp_Object face, Lisp_Object property,
|
|
599 Lisp_Object charset, Lisp_Object domain,
|
|
600 Error_behavior errb, int no_fallback,
|
|
601 Lisp_Object depth)
|
|
602 {
|
|
603 Lisp_Object retval =
|
|
604 specifier_instance_no_quit (Fget (face, property, Qnil), charset,
|
|
605 domain, errb, no_fallback, depth);
|
|
606
|
|
607 if (UNBOUNDP (retval) && !no_fallback)
|
|
608 {
|
|
609 if (EQ (property, Qfont))
|
|
610 {
|
|
611 if (NILP (memq_no_quit (charset,
|
|
612 XFACE (face)->charsets_warned_about)))
|
|
613 {
|
70
|
614 #ifdef MULE
|
|
615 warn_when_safe
|
|
616 (Qfont, Qwarning,
|
|
617 "Unable to instantiate font for face %s, charset %s",
|
|
618 string_data (symbol_name
|
|
619 (XSYMBOL (XFACE (face)->name))),
|
|
620 string_data (symbol_name
|
|
621 (XSYMBOL (XCHARSET_NAME (charset)))));
|
|
622 #else
|
0
|
623 warn_when_safe (Qfont, Qwarning,
|
|
624 "Unable to instantiate font for face %s",
|
|
625 string_data (symbol_name
|
|
626 (XSYMBOL (XFACE (face)->name))));
|
70
|
627 #endif
|
0
|
628 XFACE (face)->charsets_warned_about =
|
|
629 Fcons (charset, XFACE (face)->charsets_warned_about);
|
|
630 }
|
|
631 retval = Vthe_null_font_instance;
|
|
632 }
|
|
633 }
|
|
634
|
|
635 return retval;
|
|
636 }
|
|
637
|
|
638
|
20
|
639 DEFUN ("facep", Ffacep, 1, 1, 0, /*
|
0
|
640 Return non-nil if OBJECT is a face.
|
20
|
641 */
|
|
642 (object))
|
0
|
643 {
|
173
|
644 return FACEP (object) ? Qt : Qnil;
|
0
|
645 }
|
|
646
|
20
|
647 DEFUN ("find-face", Ffind_face, 1, 1, 0, /*
|
0
|
648 Retrieve the face of the given name.
|
|
649 If FACE-OR-NAME is a face object, it is simply returned.
|
|
650 Otherwise, FACE-OR-NAME should be a symbol. If there is no such face,
|
|
651 nil is returned. Otherwise the associated face object is returned.
|
20
|
652 */
|
|
653 (face_or_name))
|
0
|
654 {
|
|
655 Lisp_Object retval;
|
|
656
|
|
657 if (FACEP (face_or_name))
|
|
658 return face_or_name;
|
|
659 CHECK_SYMBOL (face_or_name);
|
|
660
|
|
661 /* Check if the name represents a permanent face. */
|
|
662 retval = Fgethash (face_or_name, Vpermanent_faces_cache, Qnil);
|
|
663 if (!NILP (retval))
|
|
664 return retval;
|
|
665
|
|
666 /* Check if the name represents a temporary face. */
|
|
667 return Fgethash (face_or_name, Vtemporary_faces_cache, Qnil);
|
|
668 }
|
|
669
|
20
|
670 DEFUN ("get-face", Fget_face, 1, 1, 0, /*
|
0
|
671 Retrieve the face of the given name.
|
|
672 Same as `find-face' except an error is signalled if there is no such
|
|
673 face instead of returning nil.
|
20
|
674 */
|
|
675 (name))
|
0
|
676 {
|
|
677 Lisp_Object face = Ffind_face (name);
|
|
678
|
|
679 if (NILP (face))
|
|
680 signal_simple_error ("No such face", name);
|
|
681 return face;
|
|
682 }
|
|
683
|
20
|
684 DEFUN ("face-name", Fface_name, 1, 1, 0, /*
|
0
|
685 Return the name of the given face.
|
20
|
686 */
|
|
687 (face))
|
0
|
688 {
|
173
|
689 return XFACE (Fget_face (face))->name;
|
0
|
690 }
|
|
691
|
20
|
692 DEFUN ("built-in-face-specifiers", Fbuilt_in_face_specifiers, 0, 0, 0, /*
|
0
|
693 Return a list of all built-in face specifier properties.
|
|
694 Don't modify this list!
|
20
|
695 */
|
|
696 ())
|
0
|
697 {
|
|
698 return Vbuilt_in_face_specifiers;
|
|
699 }
|
|
700
|
|
701 /* These values are retrieved so often that we make a special
|
|
702 function.
|
|
703 */
|
|
704
|
|
705 void
|
|
706 default_face_font_info (Lisp_Object domain, int *ascent, int *descent,
|
|
707 int *height, int *width, int *proportional_p)
|
|
708 {
|
|
709 Lisp_Object font_instance;
|
|
710
|
|
711 if (noninteractive)
|
|
712 {
|
|
713 if (ascent)
|
|
714 *ascent = 1;
|
|
715 if (descent)
|
|
716 *descent = 0;
|
|
717 if (height)
|
|
718 *height = 1;
|
|
719 if (width)
|
|
720 *width = 1;
|
|
721 if (proportional_p)
|
|
722 *proportional_p = 0;
|
|
723 return;
|
|
724 }
|
|
725
|
|
726 /* We use ASCII here. This is probably reasonable because the
|
|
727 people calling this function are using the resulting values to
|
|
728 come up with overall sizes for windows and frames. */
|
|
729 if (WINDOWP (domain))
|
|
730 {
|
|
731 struct face_cachel *cachel;
|
|
732 struct window *w = XWINDOW (domain);
|
|
733
|
|
734 /* #### It's possible for this function to get called when the
|
|
735 face cachels have not been initialized. I don't know why. */
|
|
736 if (!Dynarr_length (w->face_cachels))
|
|
737 reset_face_cachels (w);
|
|
738 cachel = WINDOW_FACE_CACHEL (w, DEFAULT_INDEX);
|
|
739 font_instance = FACE_CACHEL_FONT (cachel, Vcharset_ascii);
|
|
740 }
|
|
741 else
|
|
742 {
|
|
743 font_instance = FACE_FONT (Vdefault_face, domain, Vcharset_ascii);
|
|
744 }
|
|
745
|
|
746 if (height)
|
|
747 *height = XFONT_INSTANCE (font_instance)->height;
|
|
748 if (width)
|
|
749 *width = XFONT_INSTANCE (font_instance)->width;
|
|
750 if (ascent)
|
|
751 *ascent = XFONT_INSTANCE (font_instance)->ascent;
|
|
752 if (descent)
|
|
753 *descent = XFONT_INSTANCE (font_instance)->descent;
|
|
754 if (proportional_p)
|
|
755 *proportional_p = XFONT_INSTANCE (font_instance)->proportional_p;
|
|
756 }
|
|
757
|
|
758 void
|
|
759 default_face_height_and_width (Lisp_Object domain,
|
|
760 int *height, int *width)
|
|
761 {
|
|
762 default_face_font_info (domain, 0, 0, height, width, 0);
|
|
763 }
|
|
764
|
20
|
765 DEFUN ("face-list", Fface_list, 0, 1, 0, /*
|
0
|
766 Return a list of the names of all defined faces.
|
|
767 If TEMPORARY is nil, only the permanent faces are included.
|
|
768 If it is t, only the temporary faces are included. If it is any
|
|
769 other non-nil value both permanent and temporary are included.
|
20
|
770 */
|
|
771 (temporary))
|
0
|
772 {
|
|
773 Lisp_Object face_list = Qnil;
|
|
774
|
|
775 /* Added the permanent faces, if requested. */
|
|
776 if (NILP (temporary) || !EQ (Qt, temporary))
|
|
777 face_list = permanent_faces_list ();
|
|
778
|
|
779 if (!NILP (temporary))
|
|
780 {
|
|
781 struct gcpro gcpro1;
|
|
782 GCPRO1 (face_list);
|
|
783 face_list = nconc2 (face_list, temporary_faces_list ());
|
|
784 UNGCPRO;
|
|
785 }
|
|
786
|
|
787 return face_list;
|
|
788 }
|
|
789
|
20
|
790 DEFUN ("make-face", Fmake_face, 1, 3, 0, /*
|
0
|
791 Defines and returns a new FACE described by DOC-STRING.
|
|
792 You can modify the font, color, etc of a face with the set-face- functions.
|
|
793 If the face already exists, it is unmodified.
|
|
794 If TEMPORARY is non-nil, this face will cease to exist if not in use.
|
20
|
795 */
|
|
796 (name, doc_string, temporary))
|
0
|
797 {
|
|
798 /* This function can GC if initialized is non-zero */
|
|
799 struct Lisp_Face *f;
|
|
800 Lisp_Object face;
|
|
801
|
|
802 CHECK_SYMBOL (name);
|
|
803 if (!NILP (doc_string))
|
|
804 CHECK_STRING (doc_string);
|
|
805
|
|
806 face = Ffind_face (name);
|
|
807 if (!NILP (face))
|
|
808 return face;
|
|
809
|
|
810 f = allocate_face ();
|
|
811 XSETFACE (face, f);
|
|
812
|
|
813 f->name = name;
|
|
814 f->doc_string = doc_string;
|
|
815 f->foreground = Fmake_specifier (Qcolor);
|
|
816 set_color_attached_to (f->foreground, face, Qforeground);
|
|
817 f->background = Fmake_specifier (Qcolor);
|
|
818 set_color_attached_to (f->background, face, Qbackground);
|
|
819 f->font = Fmake_specifier (Qfont);
|
|
820 set_font_attached_to (f->font, face, Qfont);
|
|
821 f->background_pixmap = Fmake_specifier (Qimage);
|
|
822 set_image_attached_to (f->background_pixmap, face, Qbackground_pixmap);
|
116
|
823 f->display_table = Fmake_specifier (Qdisplay_table);
|
0
|
824 f->underline = Fmake_specifier (Qface_boolean);
|
|
825 set_face_boolean_attached_to (f->underline, face, Qunderline);
|
|
826 f->strikethru = Fmake_specifier (Qface_boolean);
|
|
827 set_face_boolean_attached_to (f->strikethru, face, Qstrikethru);
|
|
828 f->highlight = Fmake_specifier (Qface_boolean);
|
|
829 set_face_boolean_attached_to (f->highlight, face, Qhighlight);
|
|
830 f->dim = Fmake_specifier (Qface_boolean);
|
|
831 set_face_boolean_attached_to (f->dim, face, Qdim);
|
|
832 f->blinking = Fmake_specifier (Qface_boolean);
|
|
833 set_face_boolean_attached_to (f->blinking, face, Qblinking);
|
|
834 f->reverse = Fmake_specifier (Qface_boolean);
|
|
835 set_face_boolean_attached_to (f->reverse, face, Qreverse);
|
|
836 if (!NILP (Vdefault_face))
|
|
837 {
|
|
838 /* If the default face has already been created, set it as
|
|
839 the default fallback specifier for all the specifiers we
|
|
840 just created. This implements the standard "all faces
|
|
841 inherit from default" behavior. */
|
|
842 set_specifier_fallback (f->foreground,
|
|
843 Fget (Vdefault_face, Qforeground, Qunbound));
|
|
844 set_specifier_fallback (f->background,
|
|
845 Fget (Vdefault_face, Qbackground, Qunbound));
|
|
846 set_specifier_fallback (f->font,
|
|
847 Fget (Vdefault_face, Qfont, Qunbound));
|
|
848 set_specifier_fallback (f->background_pixmap,
|
|
849 Fget (Vdefault_face, Qbackground_pixmap,
|
|
850 Qunbound));
|
|
851 set_specifier_fallback (f->display_table,
|
|
852 Fget (Vdefault_face, Qdisplay_table, Qunbound));
|
|
853 set_specifier_fallback (f->underline,
|
|
854 Fget (Vdefault_face, Qunderline, Qunbound));
|
|
855 set_specifier_fallback (f->strikethru,
|
|
856 Fget (Vdefault_face, Qstrikethru, Qunbound));
|
|
857 set_specifier_fallback (f->highlight,
|
|
858 Fget (Vdefault_face, Qhighlight, Qunbound));
|
|
859 set_specifier_fallback (f->dim,
|
|
860 Fget (Vdefault_face, Qdim, Qunbound));
|
|
861 set_specifier_fallback (f->blinking,
|
|
862 Fget (Vdefault_face, Qblinking, Qunbound));
|
|
863 set_specifier_fallback (f->reverse,
|
|
864 Fget (Vdefault_face, Qreverse, Qunbound));
|
|
865 }
|
|
866
|
|
867 /* Add the face to the appropriate list. */
|
|
868 if (NILP (temporary))
|
|
869 Fputhash (name, face, Vpermanent_faces_cache);
|
|
870 else
|
|
871 Fputhash (name, face, Vtemporary_faces_cache);
|
|
872
|
|
873 /* Note that it's OK if we dump faces.
|
|
874 When we start up again when we're not noninteractive,
|
|
875 `init-global-faces' is called and it resources all
|
|
876 existing faces. */
|
|
877 if (initialized && !noninteractive)
|
|
878 {
|
|
879 struct gcpro gcpro1, gcpro2;
|
|
880
|
|
881 GCPRO2 (name, face);
|
|
882 call1 (Qinit_face_from_resources, name);
|
|
883 UNGCPRO;
|
|
884 }
|
|
885
|
|
886 return face;
|
|
887 }
|
|
888
|
|
889
|
|
890 /*****************************************************************************
|
|
891 initialization code
|
|
892 ****************************************************************************/
|
|
893
|
|
894 void
|
|
895 init_global_faces (struct device *d)
|
|
896 {
|
|
897 /* When making the initial terminal device, there is no Lisp code
|
|
898 loaded, so we can't do this. */
|
|
899 if (initialized && !noninteractive)
|
|
900 {
|
|
901 call_critical_lisp_code (d, Qinit_global_faces, Qnil);
|
|
902 }
|
|
903 }
|
|
904
|
|
905 void
|
|
906 init_device_faces (struct device *d)
|
|
907 {
|
|
908 /* When making the initial terminal device, there is no Lisp code
|
|
909 loaded, so we can't do this. */
|
|
910 if (initialized)
|
|
911 {
|
|
912 Lisp_Object tdevice;
|
|
913 XSETDEVICE (tdevice, d);
|
|
914 call_critical_lisp_code (d, Qinit_device_faces, tdevice);
|
|
915 }
|
|
916 }
|
|
917
|
|
918 void
|
|
919 init_frame_faces (struct frame *frm)
|
|
920 {
|
|
921 /* When making the initial terminal device, there is no Lisp code
|
|
922 loaded, so we can't do this. */
|
|
923 if (initialized)
|
|
924 {
|
|
925 Lisp_Object tframe;
|
|
926 XSETFRAME (tframe, frm);
|
|
927
|
|
928 /* DO NOT change the selected frame here. If the debugger goes off
|
|
929 it will try and display on the frame being created, but it is not
|
|
930 ready for that yet and a horrible death will occur. Any random
|
|
931 code depending on the selected-frame as an implicit arg should be
|
|
932 tracked down and shot. For the benefit of the one known,
|
|
933 xpm-color-symbols, make-frame sets the variable
|
|
934 Vframe_being_created to the frame it is making and sets it to nil
|
|
935 when done. Internal functions that this could trigger which are
|
|
936 currently depending on selected-frame should use this instead. It
|
|
937 is not currently visible at the lisp level. */
|
|
938 call_critical_lisp_code (XDEVICE (FRAME_DEVICE (frm)),
|
|
939 Qinit_frame_faces, tframe);
|
|
940 }
|
|
941 }
|
|
942
|
|
943
|
|
944 /****************************************************************************
|
|
945 * face cache element functions *
|
|
946 ****************************************************************************/
|
|
947
|
|
948 /*
|
|
949
|
|
950 #### Here is a description of how the face cache elements ought
|
|
951 to be redone. It is *NOT* how they work currently:
|
|
952
|
|
953 However, when I started to go about implementing this, I realized
|
|
954 that there are all sorts of subtle problems with cache coherency
|
|
955 that are coming up. As it turns out, these problems don't
|
|
956 manifest themselves now due to the brute-force "kill 'em all"
|
|
957 approach to cache invalidation when faces change; but if this
|
|
958 is ever made smarter, these problems are going to come up, and
|
|
959 some of them are very non-obvious.
|
|
960
|
|
961 I'm thinking of redoing the cache code a bit to avoid these
|
|
962 coherency problems. The bulk of the problems will arise because
|
|
963 the current display structures have simple indices into the
|
|
964 face cache, but the cache can be changed at various times,
|
|
965 which could make the current display structures incorrect.
|
|
966 I guess the dirty and updated flags are an attempt to fix
|
|
967 this, but this approach doesn't really work.
|
|
968
|
|
969 Here's an approach that should keep things clean and unconfused:
|
|
970
|
|
971 1) Imagine a "virtual face cache" that can grow arbitrarily
|
|
972 big and for which the only thing allowed is to add new
|
|
973 elements. Existing elements cannot be removed or changed.
|
|
974 This way, any pointers in the existing redisplay structure
|
|
975 into the cache never get screwed up. (This is important
|
|
976 because even if a cache element is out of date, if there's
|
|
977 a pointer to it then its contents still accurately describe
|
|
978 the way the text currently looks on the screen.)
|
|
979 2) Each element in the virtual cache either describes exactly
|
|
980 one face, or describes the merger of a number of faces
|
|
981 by some process. In order to simplify things, for mergers
|
|
982 we do not record which faces or ordering was used, but
|
|
983 simply that this cache element is the result of merging.
|
|
984 Unlike the current implementation, it's important that a
|
|
985 single cache element not be used to both describe a
|
|
986 single face and describe a merger, even if all the property
|
|
987 values are the same.
|
|
988 3) Each cache element can be clean or dirty. "Dirty" means
|
|
989 that the face that the element points to has been changed;
|
|
990 this gets set at the time the face is changed. This
|
|
991 way, when looking up a value in the cache, you can determine
|
|
992 whether it's out of date or not. For merged faces it
|
|
993 does not matter -- we don't record the faces or priority
|
|
994 used to create the merger, so it's impossible to look up
|
|
995 one of these faces. We have to recompute it each time.
|
|
996 Luckily, this is fine -- doing the merge is much
|
|
997 less expensive than recomputing the properties of a
|
|
998 single face.
|
|
999 4) For each cache element, we keep a hash value. (In order
|
|
1000 to hash the boolean properties, we convert each of them
|
|
1001 into a different large prime number so that the hashing works
|
|
1002 well.) This allows us, when comparing runes, to properly
|
|
1003 determine whether the face for that rune has changed.
|
|
1004 This will be especially important for TTY's, where there
|
|
1005 aren't that many faces and minimizing redraw is very
|
|
1006 important.
|
|
1007 5) We can't actually keep an infinite cache, but that doesn't
|
|
1008 really matter that much. The only elements we care about
|
|
1009 are those that are used by either the current or desired
|
|
1010 display structs. Therefore, we keep a per-window
|
|
1011 redisplay iteration number, and mark each element with
|
|
1012 that number as we use it. Just after outputting the
|
|
1013 window and synching the redisplay structs, we go through
|
|
1014 the cache and invalidate all elements that are not clean
|
|
1015 elements referring to a particular face and that do not
|
|
1016 have an iteration number equal to the current one. We
|
|
1017 keep them in a chain, and use them to allocate new
|
|
1018 elements when possible instead of increasing the Dynarr.
|
|
1019
|
|
1020 */
|
|
1021
|
|
1022 /* mark for GC a dynarr of face cachels. */
|
|
1023
|
|
1024 void
|
|
1025 mark_face_cachels (face_cachel_dynarr *elements,
|
|
1026 void (*markobj) (Lisp_Object))
|
|
1027 {
|
|
1028 int elt;
|
|
1029
|
|
1030 if (!elements)
|
|
1031 return;
|
|
1032
|
|
1033 for (elt = 0; elt < Dynarr_length (elements); elt++)
|
|
1034 {
|
|
1035 struct face_cachel *cachel = Dynarr_atp (elements, elt);
|
|
1036
|
|
1037 {
|
|
1038 int i;
|
|
1039
|
|
1040 for (i = 0; i < NUM_LEADING_BYTES; i++)
|
|
1041 if (!NILP (cachel->font[i]) && !UNBOUNDP (cachel->font[i]))
|
|
1042 ((markobj) (cachel->font[i]));
|
|
1043 }
|
|
1044 ((markobj) (cachel->face));
|
|
1045 ((markobj) (cachel->foreground));
|
|
1046 ((markobj) (cachel->background));
|
|
1047 ((markobj) (cachel->display_table));
|
|
1048 ((markobj) (cachel->background_pixmap));
|
|
1049 }
|
|
1050 }
|
|
1051
|
|
1052 /* ensure that the given cachel contains an updated font value for
|
|
1053 the given charset. Return the updated font value. */
|
|
1054
|
|
1055 Lisp_Object
|
|
1056 ensure_face_cachel_contains_charset (struct face_cachel *cachel,
|
|
1057 Lisp_Object domain, Lisp_Object charset)
|
|
1058 {
|
|
1059 Lisp_Object new_val;
|
|
1060 Lisp_Object face = cachel->face;
|
|
1061 int bound = 1;
|
|
1062 int offs = XCHARSET_LEADING_BYTE (charset) - MIN_LEADING_BYTE;
|
|
1063
|
|
1064 if (!UNBOUNDP (cachel->font[offs])
|
|
1065 && cachel->font_updated[offs])
|
|
1066 return cachel->font[offs];
|
|
1067
|
|
1068 if (UNBOUNDP (face))
|
|
1069 {
|
|
1070 /* a merged face. */
|
|
1071 int i;
|
|
1072 struct window *w = XWINDOW (domain);
|
|
1073
|
|
1074 new_val = Qunbound;
|
|
1075 cachel->font_specified[offs] = 0;
|
|
1076 for (i = 0; i < cachel->nfaces; i++)
|
|
1077 {
|
|
1078 struct face_cachel *oth;
|
173
|
1079
|
0
|
1080 oth = Dynarr_atp (w->face_cachels,
|
|
1081 FACE_CACHEL_FINDEX_UNSAFE (cachel, i));
|
|
1082 /* Tout le monde aime la recursion */
|
|
1083 ensure_face_cachel_contains_charset (oth, domain, charset);
|
173
|
1084
|
0
|
1085 if (oth->font_specified[offs])
|
|
1086 {
|
|
1087 new_val = oth->font[offs];
|
|
1088 cachel->font_specified[offs] = 1;
|
|
1089 break;
|
|
1090 }
|
|
1091 }
|
|
1092
|
|
1093 if (!cachel->font_specified[offs])
|
|
1094 /* need to do the default face. */
|
|
1095 {
|
|
1096 struct face_cachel *oth =
|
|
1097 Dynarr_atp (w->face_cachels, DEFAULT_INDEX);
|
|
1098 ensure_face_cachel_contains_charset (oth, domain, charset);
|
|
1099
|
|
1100 new_val = oth->font[offs];
|
|
1101 }
|
|
1102
|
|
1103 if (!UNBOUNDP (cachel->font[offs]) && !EQ (cachel->font[offs], new_val))
|
|
1104 cachel->dirty = 1;
|
|
1105 cachel->font_updated[offs] = 1;
|
|
1106 cachel->font[offs] = new_val;
|
|
1107 return new_val;
|
|
1108 }
|
|
1109
|
|
1110 new_val = face_property_matching_instance (face, Qfont, charset, domain,
|
|
1111 /* #### look into ERROR_ME_NOT */
|
|
1112 ERROR_ME_NOT, 1, Qzero);
|
|
1113 if (UNBOUNDP (new_val))
|
|
1114 {
|
|
1115 bound = 0;
|
|
1116 new_val = face_property_matching_instance (face, Qfont,
|
|
1117 charset, domain,
|
|
1118 /* #### look into
|
|
1119 ERROR_ME_NOT */
|
|
1120 ERROR_ME_NOT, 0, Qzero);
|
|
1121 }
|
|
1122 if (!UNBOUNDP (cachel->font[offs]) && !EQ (new_val, cachel->font[offs]))
|
|
1123 cachel->dirty = 1;
|
|
1124 cachel->font_updated[offs] = 1;
|
|
1125 cachel->font[offs] = new_val;
|
|
1126 cachel->font_specified[offs] = (bound || EQ (face, Vdefault_face));
|
|
1127 return new_val;
|
|
1128 }
|
|
1129
|
|
1130 /* Ensure that the given cachel contains updated fonts for all
|
|
1131 the charsets specified. */
|
|
1132
|
|
1133 void
|
|
1134 ensure_face_cachel_complete (struct face_cachel *cachel,
|
|
1135 Lisp_Object domain, unsigned char *charsets)
|
|
1136 {
|
|
1137 int i;
|
173
|
1138
|
0
|
1139 for (i = 0; i < NUM_LEADING_BYTES; i++)
|
|
1140 if (charsets[i])
|
|
1141 {
|
181
|
1142 Lisp_Object charset = CHARSET_BY_LEADING_BYTE (i + MIN_LEADING_BYTE);
|
0
|
1143 assert (CHARSETP (charset));
|
|
1144 ensure_face_cachel_contains_charset (cachel, domain, charset);
|
|
1145 }
|
|
1146 }
|
|
1147
|
|
1148 void
|
|
1149 face_cachel_charset_font_metric_info (struct face_cachel *cachel,
|
|
1150 unsigned char *charsets,
|
|
1151 struct font_metric_info *fm)
|
|
1152 {
|
|
1153 int i;
|
173
|
1154
|
0
|
1155 fm->width = 1;
|
|
1156 fm->height = fm->ascent = 1;
|
|
1157 fm->descent = 0;
|
|
1158 fm->proportional_p = 0;
|
|
1159
|
|
1160 for (i = 0; i < NUM_LEADING_BYTES; i++)
|
|
1161 {
|
|
1162 if (charsets[i])
|
|
1163 {
|
|
1164 Lisp_Object charset;
|
|
1165 Lisp_Object font_instance;
|
|
1166 struct Lisp_Font_Instance *fi;
|
173
|
1167
|
0
|
1168 charset = CHARSET_BY_LEADING_BYTE (i + MIN_LEADING_BYTE);
|
|
1169 assert (CHARSETP (charset));
|
|
1170 font_instance = FACE_CACHEL_FONT (cachel, charset);
|
|
1171 assert (FONT_INSTANCEP (font_instance));
|
|
1172 fi = XFONT_INSTANCE (font_instance);
|
|
1173 fm->ascent = max ((int) fi->ascent, (int) fm->ascent);
|
|
1174 fm->descent = max ((int) fi->descent, (int) fm->descent);
|
|
1175 fm->height = fm->ascent + fm->descent;
|
|
1176 if (fi->proportional_p)
|
|
1177 fm->proportional_p = 1;
|
|
1178 if (EQ (charset, Vcharset_ascii))
|
|
1179 fm->width = fi->width;
|
|
1180 }
|
|
1181 }
|
|
1182 }
|
|
1183
|
|
1184 /* Called when the updated flag has been cleared on a cachel. */
|
|
1185
|
|
1186 void
|
|
1187 update_face_cachel_data (struct face_cachel *cachel,
|
|
1188 Lisp_Object domain,
|
|
1189 Lisp_Object face)
|
|
1190 {
|
|
1191 if (XFACE (face)->dirty || UNBOUNDP (cachel->face))
|
|
1192 {
|
|
1193 int default_face = EQ (face, Vdefault_face);
|
|
1194 cachel->face = face;
|
|
1195
|
|
1196 /* We normally only set the _specified flags if the value was
|
|
1197 actually bound. The exception is for the default face where
|
|
1198 we always set it since it is the ultimate fallback. */
|
|
1199
|
|
1200 #define FROB(field) \
|
|
1201 do { \
|
|
1202 Lisp_Object new_val = \
|
|
1203 FACE_PROPERTY_INSTANCE (face, Q##field, domain, 1, Qzero); \
|
|
1204 int bound = 1; \
|
|
1205 if (UNBOUNDP (new_val)) \
|
|
1206 { \
|
|
1207 bound = 0; \
|
|
1208 new_val = FACE_PROPERTY_INSTANCE (face, Q##field, domain, 0, Qzero); \
|
|
1209 } \
|
|
1210 if (!EQ (new_val, cachel->field)) \
|
|
1211 { \
|
|
1212 cachel->field = new_val; \
|
|
1213 cachel->dirty = 1; \
|
|
1214 } \
|
|
1215 cachel->field##_specified = (bound || default_face); \
|
|
1216 } while (0)
|
173
|
1217
|
0
|
1218 FROB (foreground);
|
|
1219 FROB (background);
|
|
1220 FROB (display_table);
|
|
1221 FROB (background_pixmap);
|
|
1222 #undef FROB
|
|
1223
|
|
1224 ensure_face_cachel_contains_charset (cachel, domain, Vcharset_ascii);
|
|
1225
|
|
1226 #define FROB(field) \
|
|
1227 do { \
|
|
1228 Lisp_Object new_val = \
|
|
1229 FACE_PROPERTY_INSTANCE (face, Q##field, domain, 1, Qzero); \
|
|
1230 int bound = 1; \
|
|
1231 int new_val_int; \
|
|
1232 if (UNBOUNDP (new_val)) \
|
|
1233 { \
|
|
1234 bound = 0; \
|
|
1235 new_val = FACE_PROPERTY_INSTANCE (face, Q##field, domain, 0, Qzero); \
|
|
1236 } \
|
|
1237 new_val_int = EQ (new_val, Qt); \
|
|
1238 if (cachel->field != new_val_int) \
|
|
1239 { \
|
|
1240 cachel->field = new_val_int; \
|
|
1241 cachel->dirty = 1; \
|
|
1242 } \
|
|
1243 cachel->field##_specified = bound; \
|
|
1244 } while (0)
|
|
1245
|
|
1246 FROB (underline);
|
|
1247 FROB (strikethru);
|
|
1248 FROB (highlight);
|
|
1249 FROB (dim);
|
|
1250 FROB (reverse);
|
|
1251 FROB (blinking);
|
|
1252 #undef FROB
|
|
1253 }
|
|
1254
|
|
1255 cachel->updated = 1;
|
|
1256 }
|
|
1257
|
|
1258 /* Merge the cachel identified by FINDEX in window W into the given
|
|
1259 cachel. */
|
|
1260
|
|
1261 static void
|
|
1262 merge_face_cachel_data (struct window *w, face_index findex,
|
|
1263 struct face_cachel *cachel)
|
|
1264 {
|
|
1265 #define FINDEX_FIELD(field) \
|
|
1266 Dynarr_atp (w->face_cachels, findex)->field
|
|
1267
|
|
1268 #define FROB(field) \
|
|
1269 do { \
|
|
1270 if (!cachel->field##_specified && FINDEX_FIELD (field##_specified)) \
|
|
1271 { \
|
|
1272 cachel->field = FINDEX_FIELD (field); \
|
|
1273 cachel->field##_specified = 1; \
|
|
1274 cachel->dirty = 1; \
|
|
1275 } \
|
|
1276 } while (0)
|
|
1277
|
|
1278 FROB (foreground);
|
|
1279 FROB (background);
|
|
1280 FROB (display_table);
|
|
1281 FROB (background_pixmap);
|
|
1282 FROB (underline);
|
|
1283 FROB (strikethru);
|
|
1284 FROB (highlight);
|
|
1285 FROB (dim);
|
|
1286 FROB (reverse);
|
|
1287 FROB (blinking);
|
|
1288 /* And do ASCII, of course. */
|
|
1289 {
|
|
1290 int offs = LEADING_BYTE_ASCII - MIN_LEADING_BYTE;
|
|
1291
|
|
1292 if (!cachel->font_specified[offs] && FINDEX_FIELD (font_specified[offs]))
|
|
1293 {
|
|
1294 cachel->font[offs] = FINDEX_FIELD (font[offs]);
|
|
1295 cachel->font_specified[offs] = 1;
|
|
1296 cachel->dirty = 1;
|
|
1297 }
|
|
1298 }
|
|
1299
|
|
1300 #undef FROB
|
|
1301 #undef FINDEX_FIELD
|
|
1302
|
|
1303 cachel->updated = 1;
|
|
1304 }
|
|
1305
|
|
1306 /* Initialize a cachel. */
|
|
1307
|
|
1308 void
|
|
1309 reset_face_cachel (struct face_cachel *cachel)
|
|
1310 {
|
|
1311 memset (cachel, 0, sizeof (struct face_cachel));
|
|
1312 cachel->face = Qunbound;
|
|
1313 cachel->nfaces = 0;
|
|
1314 cachel->merged_faces = 0;
|
|
1315 cachel->foreground = Qunbound;
|
|
1316 cachel->background = Qunbound;
|
|
1317 {
|
|
1318 int i;
|
|
1319
|
|
1320 for (i = 0; i < NUM_LEADING_BYTES; i++)
|
|
1321 cachel->font[i] = Qunbound;
|
|
1322 }
|
|
1323 cachel->display_table = Qunbound;
|
|
1324 cachel->background_pixmap = Qunbound;
|
|
1325 }
|
|
1326
|
|
1327 /* Add a cachel for the given face to the given window's cache. */
|
|
1328
|
|
1329 static void
|
|
1330 add_face_cachel (struct window *w, Lisp_Object face)
|
|
1331 {
|
|
1332 struct face_cachel new_cachel;
|
|
1333 Lisp_Object window;
|
|
1334
|
|
1335 reset_face_cachel (&new_cachel);
|
|
1336 XSETWINDOW (window, w);
|
|
1337 update_face_cachel_data (&new_cachel, window, face);
|
|
1338 Dynarr_add (w->face_cachels, new_cachel);
|
|
1339 }
|
|
1340
|
|
1341 /* Retrieve the index to a cachel for window W that corresponds to
|
|
1342 the specified face. If necessary, add a new element to the
|
|
1343 cache. */
|
|
1344
|
|
1345 face_index
|
|
1346 get_builtin_face_cache_index (struct window *w, Lisp_Object face)
|
|
1347 {
|
|
1348 int elt;
|
|
1349
|
|
1350 if (noninteractive)
|
|
1351 return 0;
|
|
1352
|
|
1353 for (elt = 0; elt < Dynarr_length (w->face_cachels); elt++)
|
|
1354 {
|
|
1355 struct face_cachel *cachel = WINDOW_FACE_CACHEL (w, elt);
|
|
1356
|
|
1357 if (EQ (cachel->face, face))
|
|
1358 {
|
|
1359 Lisp_Object window = Qnil;
|
|
1360 XSETWINDOW (window, w);
|
|
1361 if (!cachel->updated)
|
|
1362 update_face_cachel_data (cachel, window, face);
|
|
1363 return elt;
|
|
1364 }
|
|
1365 }
|
|
1366
|
|
1367 /* If we didn't find the face, add it and then return its index. */
|
|
1368 add_face_cachel (w, face);
|
|
1369 return elt;
|
|
1370 }
|
|
1371
|
|
1372 void
|
|
1373 reset_face_cachels (struct window *w)
|
|
1374 {
|
|
1375 /* #### Not initialized in batch mode for the stream device. */
|
|
1376 if (w->face_cachels)
|
|
1377 {
|
|
1378 int i;
|
|
1379
|
|
1380 for (i = 0; i < Dynarr_length (w->face_cachels); i++)
|
|
1381 {
|
|
1382 struct face_cachel *cachel = Dynarr_atp (w->face_cachels, i);
|
|
1383 if (cachel->merged_faces)
|
|
1384 Dynarr_free (cachel->merged_faces);
|
|
1385 }
|
|
1386 Dynarr_reset (w->face_cachels);
|
|
1387 get_builtin_face_cache_index (w, Vdefault_face);
|
|
1388 get_builtin_face_cache_index (w, Vmodeline_face);
|
|
1389 XFRAME (w->frame)->window_face_cache_reset = 1;
|
|
1390 }
|
|
1391 }
|
|
1392
|
|
1393 void
|
|
1394 mark_face_cachels_as_clean (struct window *w)
|
|
1395 {
|
|
1396 int elt;
|
|
1397
|
|
1398 for (elt = 0; elt < Dynarr_length (w->face_cachels); elt++)
|
|
1399 Dynarr_atp (w->face_cachels, elt)->dirty = 0;
|
|
1400 }
|
|
1401
|
|
1402 void
|
|
1403 mark_face_cachels_as_not_updated (struct window *w)
|
|
1404 {
|
|
1405 int elt;
|
|
1406
|
|
1407 for (elt = 0; elt < Dynarr_length (w->face_cachels); elt++)
|
|
1408 {
|
|
1409 struct face_cachel *cachel = Dynarr_atp (w->face_cachels, elt);
|
|
1410 int i;
|
|
1411
|
|
1412 cachel->updated = 0;
|
|
1413 for (i = 0; i < NUM_LEADING_BYTES; i++)
|
|
1414 cachel->font_updated[i] = 0;
|
|
1415 }
|
|
1416 }
|
|
1417
|
|
1418 #ifdef MEMORY_USAGE_STATS
|
|
1419
|
|
1420 int
|
|
1421 compute_face_cachel_usage (face_cachel_dynarr *face_cachels,
|
|
1422 struct overhead_stats *ovstats)
|
|
1423 {
|
|
1424 int total = 0;
|
|
1425
|
|
1426 if (face_cachels)
|
|
1427 {
|
|
1428 int i;
|
|
1429
|
|
1430 total += Dynarr_memory_usage (face_cachels, ovstats);
|
|
1431 for (i = 0; i < Dynarr_length (face_cachels); i++)
|
|
1432 {
|
|
1433 int_dynarr *merged = Dynarr_at (face_cachels, i).merged_faces;
|
|
1434 if (merged)
|
|
1435 total += Dynarr_memory_usage (merged, ovstats);
|
|
1436 }
|
|
1437 }
|
|
1438
|
|
1439 return total;
|
|
1440 }
|
|
1441
|
|
1442 #endif /* MEMORY_USAGE_STATS */
|
|
1443
|
|
1444
|
|
1445 /*****************************************************************************
|
|
1446 * merged face functions *
|
|
1447 *****************************************************************************/
|
|
1448
|
|
1449 /* Compare two merged face cachels to determine whether we have to add
|
|
1450 a new entry to the face cache.
|
|
1451
|
|
1452 Note that we do not compare the attributes, but just the faces the
|
|
1453 cachels are based on. If they are the same, then the cachels certainly
|
|
1454 ought to have the same attributes, except in the case where fonts
|
|
1455 for different charsets have been determined in the two -- and in that
|
|
1456 case this difference is fine. */
|
|
1457
|
|
1458 static int
|
|
1459 compare_merged_face_cachels (struct face_cachel *cachel1,
|
|
1460 struct face_cachel *cachel2)
|
|
1461 {
|
|
1462 int i;
|
|
1463
|
|
1464 if (!EQ (cachel1->face, cachel2->face)
|
|
1465 || cachel1->nfaces != cachel2->nfaces)
|
|
1466 return 0;
|
|
1467
|
|
1468 for (i = 0; i < cachel1->nfaces; i++)
|
|
1469 if (FACE_CACHEL_FINDEX_UNSAFE (cachel1, i)
|
|
1470 != FACE_CACHEL_FINDEX_UNSAFE (cachel2, i))
|
|
1471 return 0;
|
|
1472
|
|
1473 return 1;
|
|
1474 }
|
|
1475
|
|
1476 /* Retrieve the index to a cachel for window W that corresponds to
|
|
1477 the specified cachel. If necessary, add a new element to the
|
|
1478 cache. This is similar to get_builtin_face_cache_index() but
|
|
1479 is intended for merged cachels rather than for cachels representing
|
|
1480 just a face.
|
|
1481
|
|
1482 Note that a merged cachel for just one face is not the same as
|
|
1483 the simple cachel for that face, because it is also merged with
|
|
1484 the default face. */
|
|
1485
|
|
1486 static face_index
|
|
1487 get_merged_face_cache_index (struct window *w,
|
|
1488 struct face_cachel *merged_cachel)
|
|
1489 {
|
|
1490 int elt;
|
|
1491 int cache_size = Dynarr_length (w->face_cachels);
|
|
1492
|
|
1493 for (elt = 0; elt < cache_size; elt++)
|
|
1494 {
|
|
1495 struct face_cachel *cachel =
|
|
1496 Dynarr_atp (w->face_cachels, elt);
|
|
1497
|
|
1498 if (compare_merged_face_cachels (cachel, merged_cachel))
|
|
1499 return elt;
|
|
1500 }
|
|
1501
|
|
1502 /* We didn't find it so add this instance to the cache. */
|
|
1503 merged_cachel->updated = 1;
|
|
1504 merged_cachel->dirty = 1;
|
|
1505 Dynarr_add (w->face_cachels, *merged_cachel);
|
|
1506 return cache_size;
|
|
1507 }
|
|
1508
|
|
1509 face_index
|
|
1510 get_extent_fragment_face_cache_index (struct window *w,
|
|
1511 struct extent_fragment *ef)
|
|
1512 {
|
|
1513 struct face_cachel cachel;
|
|
1514 int len = Dynarr_length (ef->extents);
|
173
|
1515 face_index findex = 0;
|
0
|
1516 Lisp_Object window = Qnil;
|
|
1517 XSETWINDOW (window, w);
|
|
1518
|
|
1519 /* Optimize the default case. */
|
|
1520 if (len == 0)
|
|
1521 return DEFAULT_INDEX;
|
|
1522 else
|
|
1523 {
|
|
1524 int i;
|
|
1525
|
|
1526 /* Merge the faces of the extents together in order. */
|
|
1527
|
|
1528 reset_face_cachel (&cachel);
|
|
1529
|
|
1530 for (i = len - 1; i >= 0; i--)
|
|
1531 {
|
|
1532 EXTENT current = Dynarr_at (ef->extents, i);
|
|
1533 int has_findex = 0;
|
|
1534 Lisp_Object face = extent_face (current);
|
|
1535
|
|
1536 if (FACEP (face))
|
|
1537 {
|
|
1538 findex = get_builtin_face_cache_index (w, face);
|
|
1539 has_findex = 1;
|
|
1540 merge_face_cachel_data (w, findex, &cachel);
|
|
1541 }
|
|
1542 /* remember, we're called from within redisplay
|
|
1543 so we can't error. */
|
|
1544 else while (CONSP (face))
|
|
1545 {
|
|
1546 Lisp_Object one_face = XCAR (face);
|
|
1547 if (FACEP (one_face))
|
|
1548 {
|
|
1549 findex = get_builtin_face_cache_index (w, one_face);
|
|
1550 merge_face_cachel_data (w, findex, &cachel);
|
173
|
1551
|
0
|
1552 /* code duplication here but there's no clean
|
|
1553 way to avoid it. */
|
|
1554 if (cachel.nfaces >= NUM_STATIC_CACHEL_FACES)
|
|
1555 {
|
|
1556 if (!cachel.merged_faces)
|
|
1557 cachel.merged_faces = Dynarr_new (int);
|
|
1558 Dynarr_add (cachel.merged_faces, findex);
|
|
1559 }
|
|
1560 else
|
|
1561 cachel.merged_faces_static[cachel.nfaces] = findex;
|
|
1562 cachel.nfaces++;
|
|
1563 }
|
|
1564 face = XCDR (face);
|
|
1565 }
|
173
|
1566
|
0
|
1567 if (has_findex)
|
|
1568 {
|
|
1569 if (cachel.nfaces >= NUM_STATIC_CACHEL_FACES)
|
|
1570 {
|
|
1571 if (!cachel.merged_faces)
|
|
1572 cachel.merged_faces = Dynarr_new (int);
|
|
1573 Dynarr_add (cachel.merged_faces, findex);
|
|
1574 }
|
|
1575 else
|
|
1576 cachel.merged_faces_static[cachel.nfaces] = findex;
|
|
1577 cachel.nfaces++;
|
|
1578 }
|
|
1579 }
|
|
1580
|
|
1581 /* Now finally merge in the default face. */
|
|
1582 findex = get_builtin_face_cache_index (w, Vdefault_face);
|
|
1583 merge_face_cachel_data (w, findex, &cachel);
|
|
1584
|
|
1585 return get_merged_face_cache_index (w, &cachel);
|
|
1586 }
|
|
1587 }
|
|
1588
|
|
1589
|
|
1590 /*****************************************************************************
|
|
1591 interface functions
|
|
1592 ****************************************************************************/
|
|
1593
|
|
1594 /* #### This function should be converted into appropriate device methods. */
|
|
1595 static void
|
|
1596 update_EmacsFrame (Lisp_Object frame, Lisp_Object name)
|
|
1597 {
|
|
1598 struct frame *frm = XFRAME (frame);
|
|
1599
|
|
1600 #ifdef HAVE_X_WINDOWS
|
|
1601 if (FRAME_X_P (frm))
|
|
1602 {
|
|
1603 Arg av[10];
|
|
1604 int ac = 0;
|
173
|
1605
|
0
|
1606 if (EQ (name, Qforeground))
|
|
1607 {
|
|
1608 Lisp_Object color = FACE_FOREGROUND (Vdefault_face, frame);
|
|
1609 XColor fgc;
|
|
1610
|
|
1611 if (!EQ (color, Vthe_null_color_instance))
|
|
1612 {
|
|
1613 fgc = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (color));
|
|
1614 XtSetArg (av[ac], XtNforeground, (void *) fgc.pixel); ac++;
|
|
1615 }
|
|
1616 }
|
|
1617 else if (EQ (name, Qbackground))
|
|
1618 {
|
|
1619 Lisp_Object color = FACE_BACKGROUND (Vdefault_face, frame);
|
|
1620 XColor bgc;
|
|
1621
|
|
1622 if (!EQ (color, Vthe_null_color_instance))
|
|
1623 {
|
|
1624 bgc = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (color));
|
|
1625 XtSetArg (av[ac], XtNbackground, (void *) bgc.pixel); ac++;
|
|
1626 }
|
|
1627
|
|
1628 /* Really crappy way to force the modeline shadows to be
|
|
1629 redrawn. But effective. */
|
|
1630 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (frm);
|
|
1631 MARK_FRAME_CHANGED (frm);
|
|
1632 }
|
|
1633 else if (EQ (name, Qfont))
|
|
1634 {
|
|
1635 Lisp_Object font = FACE_FONT (Vdefault_face, frame, Vcharset_ascii);
|
|
1636
|
|
1637 if (!EQ (font, Vthe_null_font_instance))
|
|
1638 XtSetArg (av[ac], XtNfont,
|
|
1639 (void *) FONT_INSTANCE_X_FONT (XFONT_INSTANCE (font)));
|
|
1640 ac++;
|
|
1641 }
|
|
1642 else
|
|
1643 abort ();
|
|
1644
|
|
1645 XtSetValues (FRAME_X_TEXT_WIDGET (frm), av, ac);
|
|
1646
|
|
1647 #ifdef HAVE_TOOLBARS
|
|
1648 /* Setting the background clears the entire frame area
|
|
1649 including the toolbar so we force an immediate redraw of
|
|
1650 it. */
|
|
1651 if (EQ (name, Qbackground))
|
|
1652 MAYBE_DEVMETH (XDEVICE (frm->device), redraw_frame_toolbars, (frm));
|
|
1653 #endif
|
|
1654
|
|
1655 /* The intent of this code is to cause the frame size in
|
|
1656 characters to remain the same when the font changes, at the
|
|
1657 expense of changing the frame size in pixels. It's not
|
|
1658 totally clear that this is the right thing to do, but it's
|
|
1659 not clearly wrong either. */
|
|
1660 if (EQ (name, Qfont))
|
|
1661 {
|
|
1662 EmacsFrameRecomputeCellSize (FRAME_X_TEXT_WIDGET (frm));
|
|
1663 Fset_frame_size (frame,
|
|
1664 make_int (frm->width),
|
|
1665 make_int (frm->height),
|
|
1666 Qnil);
|
|
1667 }
|
|
1668 }
|
|
1669 #endif /* HAVE_X_WINDOWS */
|
|
1670 }
|
|
1671
|
|
1672 static void
|
|
1673 update_EmacsFrames (Lisp_Object locale, Lisp_Object name)
|
|
1674 {
|
|
1675 if (FRAMEP (locale))
|
|
1676 {
|
|
1677 update_EmacsFrame (locale, name);
|
|
1678 }
|
|
1679 else if (DEVICEP (locale))
|
|
1680 {
|
|
1681 Lisp_Object frmcons;
|
|
1682
|
|
1683 DEVICE_FRAME_LOOP (frmcons, XDEVICE (locale))
|
|
1684 update_EmacsFrame (XCAR (frmcons), name);
|
|
1685 }
|
|
1686 else if (EQ (locale, Qglobal) || EQ (locale, Qfallback))
|
|
1687 {
|
|
1688 Lisp_Object frmcons, devcons, concons;
|
173
|
1689
|
0
|
1690 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
|
|
1691 update_EmacsFrame (XCAR (frmcons), name);
|
|
1692 }
|
|
1693 }
|
|
1694
|
|
1695 void
|
|
1696 update_frame_face_values (struct frame *f)
|
|
1697 {
|
|
1698 Lisp_Object frm = Qnil;
|
|
1699
|
|
1700 XSETFRAME (frm, f);
|
|
1701 update_EmacsFrame (frm, Qforeground);
|
|
1702 update_EmacsFrame (frm, Qbackground);
|
|
1703 update_EmacsFrame (frm, Qfont);
|
|
1704 }
|
|
1705
|
|
1706 void
|
|
1707 face_property_was_changed (Lisp_Object face, Lisp_Object property,
|
|
1708 Lisp_Object locale)
|
|
1709 {
|
|
1710 int default_face = EQ (face, Vdefault_face);
|
|
1711
|
|
1712 /* If the locale could affect the frame value, then call
|
|
1713 update_EmacsFrames just in case. */
|
|
1714 if (default_face &&
|
|
1715 (EQ (property, Qforeground) ||
|
|
1716 EQ (property, Qbackground) ||
|
|
1717 EQ (property, Qfont)))
|
|
1718 update_EmacsFrames (locale, property);
|
|
1719
|
|
1720 if (WINDOWP (locale))
|
|
1721 {
|
|
1722 MARK_FRAME_FACES_CHANGED (XFRAME (XWINDOW (locale)->frame));
|
|
1723 }
|
|
1724 else if (FRAMEP (locale))
|
|
1725 {
|
|
1726 MARK_FRAME_FACES_CHANGED (XFRAME (locale));
|
|
1727 }
|
|
1728 else if (DEVICEP (locale))
|
|
1729 {
|
|
1730 MARK_DEVICE_FRAMES_FACES_CHANGED (XDEVICE (locale));
|
|
1731 }
|
|
1732 else
|
|
1733 {
|
|
1734 Lisp_Object devcons, concons;
|
173
|
1735
|
0
|
1736 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
1737 MARK_DEVICE_FRAMES_FACES_CHANGED (XDEVICE (XCAR (devcons)));
|
|
1738 }
|
173
|
1739
|
0
|
1740 update_faces_inheritance (face, property);
|
|
1741 XFACE (face)->dirty = 1;
|
|
1742 }
|
|
1743
|
20
|
1744 DEFUN ("copy-face", Fcopy_face, 2, 6, 0, /*
|
0
|
1745 Defines and returns a new face which is a copy of an existing one,
|
|
1746 or makes an already-existing face be exactly like another. LOCALE,
|
|
1747 TAG-SET, EXACT-P, and HOW-TO-ADD are as in `copy-specifier'.
|
20
|
1748 */
|
|
1749 (old_face, new_name, locale, tag_set, exact_p, how_to_add))
|
0
|
1750 {
|
|
1751 struct Lisp_Face *fold, *fnew;
|
|
1752 Lisp_Object new_face = Qnil;
|
|
1753 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
1754
|
|
1755 old_face = Fget_face (old_face);
|
|
1756
|
|
1757 /* We GCPRO old_face because it might be temporary, and GCing could
|
|
1758 occur in various places below. */
|
|
1759 GCPRO4 (tag_set, locale, old_face, new_face);
|
|
1760 /* check validity of how_to_add now. */
|
|
1761 (void) decode_how_to_add_specification (how_to_add);
|
|
1762 /* and of tag_set. */
|
|
1763 tag_set = decode_specifier_tag_set (tag_set);
|
|
1764 /* and of locale. */
|
|
1765 locale = decode_locale_list (locale);
|
|
1766
|
|
1767 new_face = Ffind_face (new_name);
|
|
1768 if (NILP (new_face))
|
|
1769 {
|
|
1770 Lisp_Object temp;
|
|
1771
|
|
1772 CHECK_SYMBOL (new_name);
|
|
1773
|
|
1774 /* Create the new face with the same status as the old face. */
|
|
1775 temp = (NILP (Fgethash (old_face, Vtemporary_faces_cache, Qnil))
|
|
1776 ? Qnil
|
|
1777 : Qt);
|
|
1778
|
|
1779 new_face = Fmake_face (new_name, Qnil, temp);
|
|
1780 }
|
|
1781
|
|
1782 fold = XFACE (old_face);
|
|
1783 fnew = XFACE (new_face);
|
|
1784
|
2
|
1785 #define COPY_PROPERTY(property) \
|
|
1786 Fcopy_specifier (fold->property, fnew->property, \
|
|
1787 locale, tag_set, exact_p, how_to_add);
|
|
1788
|
|
1789 COPY_PROPERTY (foreground);
|
|
1790 COPY_PROPERTY (background);
|
|
1791 COPY_PROPERTY (font);
|
|
1792 COPY_PROPERTY (display_table);
|
|
1793 COPY_PROPERTY (background_pixmap);
|
|
1794 COPY_PROPERTY (underline);
|
|
1795 COPY_PROPERTY (strikethru);
|
|
1796 COPY_PROPERTY (highlight);
|
|
1797 COPY_PROPERTY (dim);
|
|
1798 COPY_PROPERTY (blinking);
|
|
1799 COPY_PROPERTY (reverse);
|
|
1800 #undef COPY_PROPERTY
|
0
|
1801 /* #### should it copy the individual specifiers, if they exist? */
|
|
1802 fnew->plist = Fcopy_sequence (fold->plist);
|
|
1803
|
|
1804 UNGCPRO;
|
|
1805
|
|
1806 return new_name;
|
|
1807 }
|
|
1808
|
|
1809
|
|
1810 void
|
|
1811 syms_of_faces (void)
|
|
1812 {
|
|
1813 /* Qdefault defined in general.c */
|
|
1814 defsymbol (&Qmodeline, "modeline");
|
|
1815 defsymbol (&Qleft_margin, "left-margin");
|
|
1816 defsymbol (&Qright_margin, "right-margin");
|
|
1817 defsymbol (&Qtext_cursor, "text-cursor");
|
|
1818
|
20
|
1819 DEFSUBR (Ffacep);
|
|
1820 DEFSUBR (Ffind_face);
|
|
1821 DEFSUBR (Fget_face);
|
|
1822 DEFSUBR (Fface_name);
|
|
1823 DEFSUBR (Fbuilt_in_face_specifiers);
|
|
1824 DEFSUBR (Fface_list);
|
|
1825 DEFSUBR (Fmake_face);
|
|
1826 DEFSUBR (Fcopy_face);
|
0
|
1827
|
|
1828 defsymbol (&Qfacep, "facep");
|
|
1829 defsymbol (&Qforeground, "foreground");
|
|
1830 defsymbol (&Qbackground, "background");
|
|
1831 /* Qfont defined in general.c */
|
|
1832 defsymbol (&Qdisplay_table, "display-table");
|
|
1833 defsymbol (&Qbackground_pixmap, "background-pixmap");
|
|
1834 defsymbol (&Qunderline, "underline");
|
|
1835 defsymbol (&Qstrikethru, "strikethru");
|
|
1836 /* Qhighlight, Qreverse defined in general.c */
|
|
1837 defsymbol (&Qdim, "dim");
|
|
1838 defsymbol (&Qblinking, "blinking");
|
|
1839
|
|
1840 defsymbol (&Qinit_face_from_resources, "init-face-from-resources");
|
|
1841 defsymbol (&Qinit_global_faces, "init-global-faces");
|
|
1842 defsymbol (&Qinit_device_faces, "init-device-faces");
|
|
1843 defsymbol (&Qinit_frame_faces, "init-frame-faces");
|
|
1844 }
|
|
1845
|
|
1846 void
|
|
1847 structure_type_create_faces (void)
|
|
1848 {
|
|
1849 struct structure_type *st;
|
|
1850
|
|
1851 st = define_structure_type (Qface, face_validate, face_instantiate);
|
|
1852
|
|
1853 define_structure_type_keyword (st, Qname, face_name_validate);
|
|
1854 }
|
|
1855
|
|
1856 void
|
|
1857 vars_of_faces (void)
|
|
1858 {
|
|
1859 staticpro (&Vpermanent_faces_cache);
|
|
1860 Vpermanent_faces_cache = Qnil;
|
|
1861 staticpro (&Vtemporary_faces_cache);
|
|
1862 Vtemporary_faces_cache = Qnil;
|
|
1863
|
|
1864 staticpro (&Vdefault_face);
|
|
1865 Vdefault_face = Qnil;
|
|
1866 staticpro (&Vmodeline_face);
|
|
1867 Vmodeline_face = Qnil;
|
|
1868
|
|
1869 staticpro (&Vleft_margin_face);
|
|
1870 Vleft_margin_face = Qnil;
|
|
1871 staticpro (&Vright_margin_face);
|
|
1872 Vright_margin_face = Qnil;
|
|
1873 staticpro (&Vtext_cursor_face);
|
|
1874 Vtext_cursor_face = Qnil;
|
|
1875 staticpro (&Vpointer_face);
|
|
1876 Vpointer_face = Qnil;
|
|
1877
|
|
1878 {
|
|
1879 Lisp_Object syms[20];
|
|
1880 int n = 0;
|
|
1881
|
|
1882 syms[n++] = Qforeground;
|
|
1883 syms[n++] = Qbackground;
|
|
1884 syms[n++] = Qfont;
|
|
1885 syms[n++] = Qdisplay_table;
|
|
1886 syms[n++] = Qbackground_pixmap;
|
|
1887 syms[n++] = Qunderline;
|
|
1888 syms[n++] = Qstrikethru;
|
|
1889 syms[n++] = Qhighlight;
|
|
1890 syms[n++] = Qdim;
|
|
1891 syms[n++] = Qblinking;
|
|
1892 syms[n++] = Qreverse;
|
|
1893
|
|
1894 Vbuilt_in_face_specifiers = pure_list (n, syms);
|
|
1895 staticpro (&Vbuilt_in_face_specifiers);
|
|
1896 }
|
|
1897 }
|
|
1898
|
|
1899 void
|
|
1900 complex_vars_of_faces (void)
|
|
1901 {
|
|
1902 Vpermanent_faces_cache = make_lisp_hashtable (10, HASHTABLE_NONWEAK,
|
|
1903 HASHTABLE_EQ);
|
|
1904 Vtemporary_faces_cache = make_lisp_hashtable (0, HASHTABLE_WEAK,
|
|
1905 HASHTABLE_EQ);
|
|
1906
|
|
1907 /* Create the default face now so we know what it is immediately. */
|
|
1908
|
|
1909 Vdefault_face = Qnil; /* so that Fmake_face() doesn't set up a bogus
|
|
1910 default value */
|
|
1911 Vdefault_face = Fmake_face (Qdefault, build_string ("default face"),
|
|
1912 Qnil);
|
|
1913
|
|
1914 /* Provide some last-resort fallbacks to avoid utter fuckage if
|
|
1915 someone provides invalid values for the global specifications. */
|
|
1916
|
|
1917 {
|
|
1918 Lisp_Object fg_inst_list = Qnil, bg_inst_list = Qnil;
|
|
1919
|
|
1920 #ifdef HAVE_X_WINDOWS
|
|
1921 fg_inst_list = Fcons (Fcons (list1 (Qx), build_string ("black")),
|
|
1922 fg_inst_list);
|
|
1923 bg_inst_list = Fcons (Fcons (list1 (Qx), build_string ("white")),
|
|
1924 bg_inst_list);
|
|
1925 #endif
|
|
1926 #ifdef HAVE_TTY
|
|
1927 fg_inst_list = Fcons (Fcons (list1 (Qtty), Fvector (0, 0)),
|
|
1928 fg_inst_list);
|
|
1929 bg_inst_list = Fcons (Fcons (list1 (Qtty), Fvector (0, 0)),
|
|
1930 bg_inst_list);
|
|
1931 #endif
|
|
1932 set_specifier_fallback (Fget (Vdefault_face, Qforeground, Qnil),
|
|
1933 fg_inst_list);
|
|
1934 set_specifier_fallback (Fget (Vdefault_face, Qbackground, Qnil),
|
|
1935 bg_inst_list);
|
|
1936 }
|
|
1937
|
|
1938 /* #### We may want to have different fallback values if NeXTstep
|
|
1939 support is compiled in. */
|
|
1940 {
|
|
1941 Lisp_Object inst_list = Qnil;
|
|
1942 #ifdef HAVE_X_WINDOWS
|
|
1943 CONST char *fonts[30];
|
|
1944 int n = 0;
|
|
1945
|
|
1946 /* The same gory list from x-faces.el.
|
|
1947 (#### Perhaps we should remove the stuff from x-faces.el
|
|
1948 and only depend on this stuff here? That should work.)
|
|
1949 */
|
|
1950 fonts[n++] = "-*-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-*";
|
|
1951 fonts[n++] = "-*-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-*";
|
|
1952 fonts[n++] = "-*-courier-*-r-*-*-*-120-*-*-*-*-iso8859-*";
|
|
1953 fonts[n++] = "-*-*-medium-r-*-*-*-120-*-*-m-*-iso8859-*";
|
|
1954 fonts[n++] = "-*-*-medium-r-*-*-*-120-*-*-c-*-iso8859-*";
|
|
1955 fonts[n++] = "-*-*-*-r-*-*-*-120-*-*-m-*-iso8859-*";
|
|
1956 fonts[n++] = "-*-*-*-r-*-*-*-120-*-*-c-*-iso8859-*";
|
|
1957 fonts[n++] = "-*-*-*-r-*-*-*-120-*-*-*-*-iso8859-*";
|
|
1958 fonts[n++] = "-*-*-medium-r-*-*-*-120-*-*-m-*-*-*";
|
|
1959 fonts[n++] = "-*-*-medium-r-*-*-*-120-*-*-c-*-*-*";
|
|
1960 fonts[n++] = "-*-*-*-r-*-*-*-120-*-*-m-*-*-*";
|
|
1961 fonts[n++] = "-*-*-*-r-*-*-*-120-*-*-c-*-*-*";
|
|
1962 fonts[n++] = "-*-*-*-r-*-*-*-120-*-*-*-*-*-*";
|
|
1963 fonts[n++] = "-*-*-*-*-*-*-*-120-*-*-*-*-*-*";
|
|
1964 fonts[n++] = "*";
|
|
1965
|
|
1966 for (--n; n >= 0; --n)
|
|
1967 inst_list = Fcons (Fcons (list1 (Qx), build_string (fonts[n])),
|
|
1968 inst_list);
|
|
1969 #endif
|
|
1970 #ifdef HAVE_TTY
|
|
1971 inst_list = Fcons (Fcons (list1 (Qtty), build_string ("normal")),
|
|
1972 inst_list);
|
|
1973 #endif
|
|
1974 set_specifier_fallback (Fget (Vdefault_face, Qfont, Qnil), inst_list);
|
|
1975 }
|
173
|
1976
|
0
|
1977 set_specifier_fallback (Fget (Vdefault_face, Qunderline, Qnil),
|
|
1978 list1 (Fcons (Qnil, Qnil)));
|
|
1979 set_specifier_fallback (Fget (Vdefault_face, Qstrikethru, Qnil),
|
|
1980 list1 (Fcons (Qnil, Qnil)));
|
|
1981 set_specifier_fallback (Fget (Vdefault_face, Qhighlight, Qnil),
|
|
1982 list1 (Fcons (Qnil, Qnil)));
|
|
1983 set_specifier_fallback (Fget (Vdefault_face, Qdim, Qnil),
|
|
1984 list1 (Fcons (Qnil, Qnil)));
|
|
1985 set_specifier_fallback (Fget (Vdefault_face, Qblinking, Qnil),
|
|
1986 list1 (Fcons (Qnil, Qnil)));
|
|
1987 set_specifier_fallback (Fget (Vdefault_face, Qreverse, Qnil),
|
|
1988 list1 (Fcons (Qnil, Qnil)));
|
|
1989
|
|
1990 /* Now create the other faces that redisplay needs to refer to
|
|
1991 directly. We could create them in Lisp but it's simpler this
|
|
1992 way since we need to get them anyway. */
|
|
1993 Vmodeline_face = Fmake_face (Qmodeline, build_string ("modeline face"),
|
|
1994 Qnil);
|
|
1995 Vleft_margin_face = Fmake_face (Qleft_margin,
|
|
1996 build_string ("left margin face"),
|
|
1997 Qnil);
|
|
1998 Vright_margin_face = Fmake_face (Qright_margin,
|
|
1999 build_string ("right margin face"),
|
|
2000 Qnil);
|
|
2001 Vtext_cursor_face = Fmake_face (Qtext_cursor,
|
|
2002 build_string ("face for text cursor"),
|
|
2003 Qnil);
|
|
2004 Vpointer_face =
|
|
2005 Fmake_face (Qpointer,
|
|
2006 build_string
|
|
2007 ("face for foreground/background colors of mouse pointer"),
|
|
2008 Qnil);
|
|
2009 }
|