428
|
1 ;;; faces.el --- Lisp interface to the C "face" structure
|
|
2
|
|
3 ;; Copyright (C) 1992-4, 1997 Free Software Foundation, Inc.
|
|
4 ;; Copyright (C) 1995 Board of Trustees, University of Illinois
|
3027
|
5 ;; Copyright (C) 1995, 1996, 2002, 2005 Ben Wing
|
428
|
6
|
|
7 ;; Author: Ben Wing <ben@xemacs.org>
|
|
8 ;; Keywords: faces, internal, dumped
|
|
9
|
|
10 ;; This file is part of XEmacs.
|
|
11
|
|
12 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
13 ;; under the terms of the GNU General Public License as published by
|
|
14 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;; any later version.
|
|
16
|
|
17 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
20 ;; General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
|
23 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
25 ;; Boston, MA 02111-1307, USA.
|
|
26
|
|
27 ;;; Synched up with: Not synched with FSF. Almost completely divergent.
|
|
28
|
|
29 ;;; Commentary:
|
|
30
|
|
31 ;; This file is dumped with XEmacs.
|
|
32
|
|
33 ;; face implementation #1 (used Lisp vectors and parallel C vectors;
|
|
34 ;; FSFmacs still uses this) authored by Jamie Zawinski <jwz@jwz.org>
|
|
35 ;; pre Lucid-Emacs 19.0.
|
|
36
|
|
37 ;; face implementation #2 (used one face object per frame per face)
|
|
38 ;; authored by Jamie Zawinski for 19.9.
|
|
39
|
|
40 ;; face implementation #3 (use one face object per face) originally
|
|
41 ;; authored for 19.12 by Chuck Thompson <cthomp@cs.uiuc.edu>,
|
|
42 ;; rewritten by Ben Wing with the advent of specifiers.
|
|
43
|
|
44
|
|
45 ;;; Some stuff in FSF's faces.el is in our x-faces.el.
|
|
46
|
|
47 ;;; Code:
|
|
48
|
771
|
49 ;; To elude the warnings for font functions. (Normally autoloaded when
|
|
50 ;; font-create-object is called)
|
|
51 (eval-when-compile
|
|
52 (require 'font))
|
|
53
|
428
|
54 (defgroup faces nil
|
|
55 "Support for multiple text attributes (fonts, colors, ...)
|
|
56 Such a collection of attributes is called a \"face\"."
|
|
57 :group 'emacs)
|
|
58
|
|
59
|
|
60 (defun read-face-name (prompt)
|
|
61 (let (face)
|
|
62 (while (= (length face) 0) ; nil or ""
|
|
63 (setq face (completing-read prompt
|
|
64 (mapcar (lambda (x) (list (symbol-name x)))
|
|
65 (face-list))
|
|
66 nil t)))
|
|
67 (intern face)))
|
|
68
|
|
69 (defun face-interactive (what &optional bool)
|
|
70 (let* ((fn (intern (concat "face-" what "-instance")))
|
|
71 (face (read-face-name (format "Set %s of face: " what)))
|
|
72 (default (if (fboundp fn)
|
|
73 ;; #### we should distinguish here between
|
|
74 ;; explicitly setting the value to be the
|
|
75 ;; same as the default face's value, and
|
|
76 ;; not setting a value at all.
|
|
77 (funcall fn face)))
|
|
78 (value (if bool
|
|
79 (y-or-n-p (format "Should face %s be %s? "
|
|
80 (symbol-name face) bool))
|
|
81 (read-string (format "Set %s of face %s to: "
|
|
82 what (symbol-name face))
|
|
83 (cond ((font-instance-p default)
|
|
84 (font-instance-name default))
|
|
85 ((color-instance-p default)
|
|
86 (color-instance-name default))
|
|
87 ((image-instance-p default)
|
|
88 (image-instance-file-name default))
|
|
89 (t default))))))
|
|
90 (list face (if (equal value "") nil value))))
|
|
91
|
|
92 (defconst built-in-face-specifiers
|
|
93 (built-in-face-specifiers)
|
|
94 "A list of the built-in face properties that are specifiers.")
|
|
95
|
|
96 (defun face-property (face property &optional locale tag-set exact-p)
|
|
97 "Return FACE's value of the given PROPERTY.
|
|
98
|
3027
|
99 NOTE: If you are looking for the \"value\" of a built-in face property
|
|
100 (`foreground', `background', `font', `background-pixmap', etc.), you
|
|
101 are probably better off calling `face-property-instance'. The return
|
|
102 value of `face-property' for built-in properties describes the original
|
|
103 specification used to determine the face property, which may be nil,
|
|
104 a list of instantiators, or something else that is unexpected. For
|
|
105 example, if you ask for a face property in a particular buffer (by
|
|
106 specifying a buffer for LOCALE), you will get a non-nil return value
|
|
107 only if a buffer-local specification for that particular buffer had
|
|
108 previously been given.
|
|
109
|
|
110 For a full list of built-in property names and their semantics, see
|
|
111 `set-face-property'.
|
428
|
112
|
3027
|
113 If LOCALE is omitted, the FACE's actual value for PROPERTY will be
|
|
114 returned. In this case, this function appears to behave rather
|
|
115 differently depending on whether PROPERTY is a built-in face property of
|
|
116 a user-defined face property. This is because the most basic value of a
|
|
117 user-defined property is simply whatever was set using
|
|
118 `set-face-property', but for a built-in property it's always a specifier,
|
|
119 which is an abstract object encapsulating all the specifications for that
|
|
120 particular property.
|
|
121
|
|
122 LOCALE, if supplied, will generally be a buffer, frame or
|
|
123 `global' (for the global value), but there are other possibilities -- see
|
|
124 the following paragraph. This mostly applies to built-in properties. In
|
|
125 this case, the return value will not be a specifier object but the
|
|
126 specification(s) for the given locale or locale type will be returned
|
|
127 (equivalent to calling `specifier-specs' on the specifier).
|
|
128 (Technically, the same thing happens if the basic value of a user-
|
|
129 defined property is a specifier, although this usage is rare.)
|
428
|
130
|
|
131 The return value will be a list of instantiators (e.g. strings
|
|
132 specifying a font or color name), or a list of specifications, each
|
|
133 of which is a cons of a locale and a list of instantiators.
|
|
134 Specifically, if LOCALE is a particular locale (a buffer, window,
|
3027
|
135 frame, device, or `global'), a list of instantiators for that locale
|
428
|
136 will be returned. Otherwise, if LOCALE is a locale type (one of
|
3027
|
137 the symbols `buffer', `window', `frame', or `device'), the specifications
|
428
|
138 for all locales of that type will be returned. Finally, if LOCALE is
|
3027
|
139 `all', the specifications for all locales of all types will be returned.
|
428
|
140
|
|
141 The specifications in a specifier determine what the value of
|
|
142 PROPERTY will be in a particular \"domain\" or set of circumstances,
|
3027
|
143 which is typically a particular Emacs window -- which in turn defines
|
|
144 a buffer (the buffer in the window), a frame (the frame that the window
|
|
145 is in), and a device (the device that the frame is in). The value is
|
442
|
146 derived from the instantiator associated with the most specific
|
3027
|
147 locale (in the order buffer, window, frame, device, and `global')
|
428
|
148 that matches the domain in question. In other words, given a domain
|
442
|
149 (i.e. an Emacs window, usually), the specifier for PROPERTY will
|
|
150 first be searched for a specification whose locale is the buffer
|
|
151 contained within that window; then for a specification whose locale
|
|
152 is the window itself; then for a specification whose locale is the
|
|
153 frame that the window is contained within; etc. The first
|
|
154 instantiator that is valid for the domain (usually this means that
|
|
155 the instantiator is recognized by the device [i.e. MS Windows, the X
|
3027
|
156 server or TTY device]) will be \"instantiated\", which generates
|
|
157 a Lisp object encapsulating the original instantiator and the underlying
|
|
158 window-system object describing the property. The function
|
|
159 `face-property-instance' actually does all this."
|
428
|
160
|
|
161 (setq face (get-face face))
|
|
162 (let ((value (get face property)))
|
|
163 (if (and locale
|
|
164 (or (memq property built-in-face-specifiers)
|
|
165 (specifierp value)))
|
|
166 (setq value (specifier-specs value locale tag-set exact-p)))
|
|
167 value))
|
|
168
|
|
169 (defun convert-face-property-into-specifier (face property)
|
|
170 "Convert PROPERTY on FACE into a specifier, if it's not already."
|
|
171 (setq face (get-face face))
|
|
172 (let ((specifier (get face property)))
|
|
173 ;; if a user-property does not have a specifier but a
|
|
174 ;; locale was specified, put a specifier there.
|
|
175 ;; If there was already a value there, convert it to a
|
3027
|
176 ;; specifier with the value as its `global' instantiator.
|
428
|
177 (unless (specifierp specifier)
|
|
178 (let ((new-specifier (make-specifier 'generic)))
|
|
179 (if (or (not (null specifier))
|
|
180 ;; make sure the nil returned from `get' wasn't
|
|
181 ;; actually the value of the property
|
|
182 (null (get face property t)))
|
|
183 (add-spec-to-specifier new-specifier specifier))
|
|
184 (setq specifier new-specifier)
|
|
185 (put face property specifier)))))
|
|
186
|
|
187 (defun face-property-instance (face property
|
872
|
188 &optional domain default no-fallback)
|
428
|
189 "Return the instance of FACE's PROPERTY in the specified DOMAIN.
|
|
190
|
|
191 Under most circumstances, DOMAIN will be a particular window,
|
|
192 and the returned instance describes how the specified property
|
|
193 actually is displayed for that window and the particular buffer
|
|
194 in it. Note that this may not be the same as how the property
|
|
195 appears when the buffer is displayed in a different window or
|
|
196 frame, or how the property appears in the same window if you
|
|
197 switch to another buffer in that window; and in those cases,
|
|
198 the returned instance would be different.
|
|
199
|
|
200 The returned instance will typically be a color-instance,
|
3027
|
201 font-instance, or image-instance object, and you can query
|
428
|
202 it using the appropriate object-specific functions. For example,
|
|
203 you could use `color-instance-rgb-components' to find out the
|
3027
|
204 RGB (red, green, and blue) components of how the `background'
|
|
205 property of the `highlight' face is displayed in a particular
|
428
|
206 window. The results might be different from the results
|
|
207 you would get for another window (perhaps the user
|
|
208 specified a different color for the frame that window is on;
|
|
209 or perhaps the same color was specified but the window is
|
|
210 on a different X server, and that X server has different RGB
|
|
211 values for the color from this one).
|
|
212
|
|
213 DOMAIN defaults to the selected window if omitted.
|
|
214
|
|
215 DOMAIN can be a frame or device, instead of a window. The value
|
|
216 returned for a such a domain is used in special circumstances
|
|
217 when a more specific domain does not apply; for example, a frame
|
|
218 value might be used for coloring a toolbar, which is conceptually
|
|
219 attached to a frame rather than a particular window. The value
|
|
220 is also useful in determining what the value would be for a
|
|
221 particular window within the frame or device, if it is not
|
|
222 overridden by a more specific specification.
|
|
223
|
|
224 If PROPERTY does not name a built-in property, its value will
|
|
225 simply be returned unless it is a specifier object, in which case
|
|
226 it will be instanced using `specifier-instance'.
|
|
227
|
|
228 Optional arguments DEFAULT and NO-FALLBACK are the same as in
|
|
229 `specifier-instance'."
|
|
230
|
|
231 (setq face (get-face face))
|
|
232 (let ((value (get face property)))
|
|
233 (if (specifierp value)
|
|
234 (setq value (specifier-instance value domain default no-fallback)))
|
|
235 value))
|
|
236
|
|
237 (defun face-property-matching-instance (face property matchspec
|
872
|
238 &optional domain default
|
|
239 no-fallback)
|
428
|
240 "Return the instance of FACE's PROPERTY matching MATCHSPEC in DOMAIN.
|
|
241 Currently the only useful value for MATCHSPEC is a charset, when used
|
|
242 in conjunction with the face's font; this allows you to retrieve a
|
|
243 font that can be used to display a particular charset, rather than just
|
|
244 any font.
|
|
245
|
|
246 Other than MATCHSPEC, this function is identical to `face-property-instance'.
|
|
247 See also `specifier-matching-instance' for a fuller description of the
|
|
248 matching process."
|
|
249
|
|
250 (setq face (get-face face))
|
|
251 (let ((value (get face property)))
|
|
252 (if (specifierp value)
|
872
|
253 (setq value (if (or (charsetp matchspec)
|
|
254 (and (symbolp matchspec)
|
|
255 (find-charset matchspec)))
|
1137
|
256 (or
|
872
|
257 (specifier-matching-instance
|
|
258 value (cons matchspec nil) domain default
|
|
259 no-fallback)
|
|
260 (specifier-matching-instance
|
|
261 value (cons matchspec t) domain default
|
|
262 no-fallback))
|
|
263 (specifier-matching-instance value matchspec domain
|
|
264 default no-fallback))))
|
428
|
265 value))
|
|
266
|
|
267 (defun set-face-property (face property value &optional locale tag-set
|
872
|
268 how-to-add)
|
428
|
269 "Change a property of FACE.
|
|
270
|
|
271 NOTE: If you want to remove a property from a face, use `remove-face-property'
|
|
272 rather than attempting to set a value of nil for the property.
|
|
273
|
|
274 For built-in properties, the actual value of the property is a
|
|
275 specifier and you cannot change this; but you can change the
|
|
276 specifications within the specifier, and that is what this function
|
|
277 will do. For user-defined properties, you can use this function
|
|
278 to either change the actual value of the property or, if this value
|
|
279 is a specifier, change the specifications within it.
|
|
280
|
|
281 If PROPERTY is a built-in property, the specifications to be added to
|
|
282 this property can be supplied in many different ways:
|
|
283
|
|
284 -- If VALUE is a simple instantiator (e.g. a string naming a font or
|
|
285 color) or a list of instantiators, then the instantiator(s) will
|
|
286 be added as a specification of the property for the given LOCALE
|
3027
|
287 (which defaults to `global' if omitted).
|
428
|
288 -- If VALUE is a list of specifications (each of which is a cons of
|
|
289 a locale and a list of instantiators), then LOCALE must be nil
|
|
290 (it does not make sense to explicitly specify a locale in this
|
|
291 case), and specifications will be added as given.
|
|
292 -- If VALUE is a specifier (as would be returned by `face-property'
|
|
293 if no LOCALE argument is given), then some or all of the
|
|
294 specifications in the specifier will be added to the property.
|
|
295 In this case, the function is really equivalent to
|
|
296 `copy-specifier' and LOCALE has the same semantics (if it is
|
|
297 a particular locale, the specification for the locale will be
|
|
298 copied; if a locale type, specifications for all locales of
|
3027
|
299 that type will be copied; if nil or `all', then all
|
428
|
300 specifications will be copied).
|
|
301
|
3027
|
302 HOW-TO-ADD should be either nil or one of the symbols `prepend',
|
|
303 `append', `remove-tag-set-prepend', `remove-tag-set-append', `remove-locale',
|
|
304 `remove-locale-type', or `remove-all'. See `copy-specifier' and
|
428
|
305 `add-spec-to-specifier' for a description of what each of
|
|
306 these means. Most of the time, you do not need to worry about
|
|
307 this argument; the default behavior usually is fine.
|
|
308
|
|
309 In general, it is OK to pass an instance object (e.g. as returned
|
|
310 by `face-property-instance') as an instantiator in place of
|
|
311 an actual instantiator. In such a case, the instantiator used
|
|
312 to create that instance object will be used (for example, if
|
3027
|
313 you set a font-instance object as the value of the `font'
|
428
|
314 property, then the font name used to create that object will
|
|
315 be used instead). If some cases, however, doing this
|
|
316 conversion does not make sense, and this will be noted in
|
|
317 the documentation for particular types of instance objects.
|
|
318
|
|
319 If PROPERTY is not a built-in property, then this function will
|
|
320 simply set its value if LOCALE is nil. However, if LOCALE is
|
|
321 given, then this function will attempt to add VALUE as the
|
|
322 instantiator for the given LOCALE, using `add-spec-to-specifier'.
|
|
323 If the value of the property is not a specifier, it will
|
3027
|
324 automatically be converted into a `generic' specifier.
|
428
|
325
|
|
326
|
|
327 The following symbols have predefined meanings:
|
|
328
|
|
329 foreground The foreground color of the face.
|
442
|
330 For valid instantiators, see `make-color-specifier'.
|
428
|
331
|
|
332 background The background color of the face.
|
442
|
333 For valid instantiators, see `make-color-specifier'.
|
428
|
334
|
|
335 font The font used to display text covered by this face.
|
442
|
336 For valid instantiators, see `make-font-specifier'.
|
428
|
337
|
|
338 display-table The display table of the face.
|
|
339 This should be a vector of 256 elements.
|
|
340
|
|
341 background-pixmap The pixmap displayed in the background of the face.
|
442
|
342 Only used by faces on X and MS Windows devices.
|
|
343 For valid instantiators, see `make-image-specifier'.
|
428
|
344
|
|
345 underline Underline all text covered by this face.
|
442
|
346 For valid instantiators, see `make-face-boolean-specifier'.
|
428
|
347
|
|
348 strikethru Draw a line through all text covered by this face.
|
442
|
349 For valid instantiators, see `make-face-boolean-specifier'.
|
428
|
350
|
|
351 highlight Highlight all text covered by this face.
|
|
352 Only used by faces on TTY devices.
|
442
|
353 For valid instantiators, see `make-face-boolean-specifier'.
|
428
|
354
|
|
355 dim Dim all text covered by this face.
|
442
|
356 For valid instantiators, see `make-face-boolean-specifier'.
|
428
|
357
|
|
358 blinking Blink all text covered by this face.
|
|
359 Only used by faces on TTY devices.
|
442
|
360 For valid instantiators, see `make-face-boolean-specifier'.
|
428
|
361
|
|
362 reverse Reverse the foreground and background colors.
|
|
363 Only used by faces on TTY devices.
|
442
|
364 For valid instantiators, see `make-face-boolean-specifier'.
|
428
|
365
|
3027
|
366 inherit Face name or face object from which to inherit attributes,
|
|
367 or a list of such elements. Attributes from inherited
|
|
368 faces are merged into the face like an underlying face
|
|
369 would be, with higher priority than underlying faces.
|
|
370
|
428
|
371 doc-string Description of what the face's normal use is.
|
|
372 NOTE: This is not a specifier, unlike all
|
|
373 the other built-in properties, and cannot
|
|
374 contain locale-specific values."
|
|
375
|
|
376 (setq face (get-face face))
|
|
377 (if (memq property built-in-face-specifiers)
|
|
378 (set-specifier (get face property) value locale tag-set how-to-add)
|
|
379
|
|
380 ;; This section adds user defined properties.
|
|
381 (if (not locale)
|
|
382 (put face property value)
|
|
383 (convert-face-property-into-specifier face property)
|
|
384 (add-spec-to-specifier (get face property) value locale tag-set
|
|
385 how-to-add)))
|
|
386 value)
|
|
387
|
|
388 (defun remove-face-property (face property &optional locale tag-set exact-p)
|
|
389 "Remove a property from FACE.
|
|
390 For built-in properties, this is analogous to `remove-specifier'.
|
|
391 See `remove-specifier' for the meaning of the LOCALE, TAG-SET, and EXACT-P
|
|
392 arguments."
|
|
393 (or locale (setq locale 'all))
|
|
394 (if (memq property built-in-face-specifiers)
|
|
395 (remove-specifier (face-property face property) locale tag-set exact-p)
|
|
396 (if (eq locale 'all)
|
|
397 (remprop (get-face face) property)
|
|
398 (convert-face-property-into-specifier face property)
|
|
399 (remove-specifier (face-property face property) locale tag-set
|
|
400 exact-p))))
|
|
401
|
|
402 (defun reset-face (face &optional locale tag-set exact-p)
|
|
403 "Clear all existing built-in specifications from FACE.
|
3027
|
404 This makes FACE inherit all its display properties from `default'.
|
428
|
405 WARNING: Be absolutely sure you want to do this!!! It is a dangerous
|
|
406 operation and is not undoable.
|
|
407
|
|
408 The arguments LOCALE, TAG-SET and EXACT-P are the same as for
|
|
409 `remove-specifier'."
|
|
410 (mapc (lambda (x)
|
|
411 (remove-specifier (face-property face x) locale tag-set exact-p))
|
|
412 built-in-face-specifiers)
|
|
413 nil)
|
|
414
|
|
415 (defun set-face-parent (face parent &optional locale tag-set how-to-add)
|
|
416 "Set the parent of FACE to PARENT, for all properties.
|
|
417 This makes all properties of FACE inherit from PARENT."
|
|
418 (setq parent (get-face parent))
|
|
419 (mapcar (lambda (x)
|
|
420 (set-face-property face x (vector parent) locale tag-set
|
|
421 how-to-add))
|
3027
|
422 (set-difference built-in-face-specifiers
|
|
423 '(display-table background-pixmap inherit)))
|
428
|
424 (set-face-background-pixmap face (vector 'inherit ':face parent)
|
|
425 locale tag-set how-to-add)
|
|
426 nil)
|
|
427
|
|
428 (defun face-doc-string (face)
|
|
429 "Return the documentation string for FACE."
|
|
430 (face-property face 'doc-string))
|
|
431
|
|
432 (defun set-face-doc-string (face doc-string)
|
|
433 "Change the documentation string of FACE to DOC-STRING."
|
|
434 (interactive (face-interactive "doc-string"))
|
|
435 (set-face-property face 'doc-string doc-string))
|
|
436
|
|
437 (defun face-font-name (face &optional domain charset)
|
|
438 "Return the font name of FACE in DOMAIN, or nil if it is unspecified.
|
3027
|
439 DOMAIN is as in `face-font-instance'.
|
|
440
|
|
441 Font names are strings, as described in `make-font-specifier'."
|
428
|
442 (let ((f (face-font-instance face domain charset)))
|
|
443 (and f (font-instance-name f))))
|
|
444
|
|
445 (defun face-font (face &optional locale tag-set exact-p)
|
3027
|
446 "Return the font spec of FACE in LOCALE, or nil if it is unspecified.
|
|
447
|
|
448 NOTE: This returns a locale-specific specification, not any sort of value
|
|
449 corresponding to the actual font being used. If you want to know the
|
|
450 actual font used in a particular domain, use `face-font-instance', or
|
|
451 `face-font-name' for its name (i.e. the instantiator used to create it).
|
428
|
452
|
|
453 FACE may be either a face object or a symbol representing a face.
|
|
454
|
|
455 LOCALE may be a locale (the instantiators for that particular locale
|
|
456 will be returned), a locale type (the specifications for all locales
|
3027
|
457 of that type will be returned), `all' (all specifications will be
|
428
|
458 returned), or nil (the actual specifier object will be returned).
|
|
459
|
|
460 See `face-property' for more information."
|
|
461 (face-property face 'font locale tag-set exact-p))
|
|
462
|
|
463 (defun face-font-instance (face &optional domain charset)
|
|
464 "Return the instance of FACE's font in DOMAIN.
|
|
465
|
3027
|
466 Return value will be a font instance object; query its properties using
|
|
467 `font-instance-name', `font-instance-height', `font-instance-width', etc.
|
|
468
|
428
|
469 FACE may be either a face object or a symbol representing a face.
|
|
470
|
|
471 Normally DOMAIN will be a window or nil (meaning the selected window),
|
|
472 and an instance object describing how the font appears in that
|
|
473 particular window and buffer will be returned.
|
|
474
|
|
475 See `face-property-instance' for more information."
|
|
476 (if charset
|
|
477 (face-property-matching-instance face 'font charset domain)
|
|
478 (face-property-instance face 'font domain)))
|
|
479
|
|
480 (defun set-face-font (face font &optional locale tag-set how-to-add)
|
|
481 "Change the font of FACE to FONT in LOCALE.
|
|
482
|
|
483 FACE may be either a face object or a symbol representing a face.
|
|
484
|
442
|
485 FONT should be an instantiator (see `make-font-specifier'), a list of
|
428
|
486 instantiators, an alist of specifications (each mapping a
|
|
487 locale to an instantiator list), or a font specifier object.
|
|
488
|
|
489 If FONT is an alist, LOCALE must be omitted. If FONT is a
|
3027
|
490 specifier object, LOCALE can be a locale, a locale type, `all',
|
428
|
491 or nil; see `copy-specifier' for its semantics. Otherwise LOCALE
|
|
492 specifies the locale under which the specified instantiator(s)
|
3027
|
493 will be added, and defaults to `global'.
|
428
|
494
|
|
495 See `set-face-property' for more information."
|
|
496 (interactive (face-interactive "font"))
|
|
497 (set-face-property face 'font font locale tag-set how-to-add))
|
|
498
|
|
499 (defun face-foreground (face &optional locale tag-set exact-p)
|
3027
|
500 "Return the foreground spec of FACE in LOCALE, or nil if it is unspecified.
|
|
501
|
|
502 NOTE: This returns a locale-specific specification, not any sort of value
|
|
503 corresponding to the actual foreground being used. If you want to know the
|
|
504 actual foreground color used in a particular domain, use
|
|
505 `face-foreground-instance', or `face-foreground-name' for its name
|
|
506 \(i.e. the instantiator used to create it).
|
428
|
507
|
|
508 FACE may be either a face object or a symbol representing a face.
|
|
509
|
|
510 LOCALE may be a locale (the instantiators for that particular locale
|
|
511 will be returned), a locale type (the specifications for all locales
|
3027
|
512 of that type will be returned), `all' (all specifications will be
|
428
|
513 returned), or nil (the actual specifier object will be returned).
|
|
514
|
|
515 See `face-property' for more information."
|
|
516 (face-property face 'foreground locale tag-set exact-p))
|
|
517
|
|
518 (defun face-foreground-instance (face &optional domain default no-fallback)
|
|
519 "Return the instance of FACE's foreground in DOMAIN.
|
|
520
|
3027
|
521 Return value will be a color instance object; query its properties using
|
|
522 `color-instance-name' or `color-instance-rgb-properties'.
|
|
523
|
428
|
524 FACE may be either a face object or a symbol representing a face.
|
|
525
|
|
526 Normally DOMAIN will be a window or nil (meaning the selected window),
|
|
527 and an instance object describing how the foreground appears in that
|
|
528 particular window and buffer will be returned.
|
|
529
|
|
530 See `face-property-instance' for more information."
|
|
531 (face-property-instance face 'foreground domain default no-fallback))
|
|
532
|
|
533 (defun face-foreground-name (face &optional domain default no-fallback)
|
|
534 "Return the name of FACE's foreground color in DOMAIN.
|
|
535
|
|
536 FACE may be either a face object or a symbol representing a face.
|
|
537
|
|
538 Normally DOMAIN will be a window or nil (meaning the selected window),
|
|
539 and an instance object describing how the background appears in that
|
|
540 particular window and buffer will be returned.
|
|
541
|
|
542 See `face-property-instance' for more information."
|
|
543 (color-instance-name (face-foreground-instance
|
|
544 face domain default no-fallback)))
|
|
545
|
|
546 (defun set-face-foreground (face color &optional locale tag-set how-to-add)
|
|
547 "Change the foreground color of FACE to COLOR in LOCALE.
|
|
548
|
|
549 FACE may be either a face object or a symbol representing a face.
|
|
550
|
442
|
551 COLOR should be an instantiator (see `make-color-specifier'), a list of
|
428
|
552 instantiators, an alist of specifications (each mapping a locale to
|
|
553 an instantiator list), or a color specifier object.
|
|
554
|
|
555 If COLOR is an alist, LOCALE must be omitted. If COLOR is a
|
3027
|
556 specifier object, LOCALE can be a locale, a locale type, `all',
|
428
|
557 or nil; see `copy-specifier' for its semantics. Otherwise LOCALE
|
|
558 specifies the locale under which the specified instantiator(s)
|
3027
|
559 will be added, and defaults to `global'.
|
428
|
560
|
|
561 See `set-face-property' for more information."
|
|
562 (interactive (face-interactive "foreground"))
|
|
563 (set-face-property face 'foreground color locale tag-set how-to-add))
|
|
564
|
|
565 (defun face-background (face &optional locale tag-set exact-p)
|
|
566 "Return the background color of FACE in LOCALE, or nil if it is unspecified.
|
|
567
|
3027
|
568 NOTE: This returns a locale-specific specification, not any sort of value
|
|
569 corresponding to the actual background being used. If you want to know the
|
|
570 actual background color used in a particular domain, use
|
|
571 `face-background-instance', or `face-background-name' for its name
|
|
572 \(i.e. the instantiator used to create it).
|
|
573
|
428
|
574 FACE may be either a face object or a symbol representing a face.
|
|
575
|
|
576 LOCALE may be a locale (the instantiators for that particular locale
|
|
577 will be returned), a locale type (the specifications for all locales
|
3027
|
578 of that type will be returned), `all' (all specifications will be
|
428
|
579 returned), or nil (the actual specifier object will be returned).
|
|
580
|
|
581 See `face-property' for more information."
|
|
582 (face-property face 'background locale tag-set exact-p))
|
|
583
|
|
584 (defun face-background-instance (face &optional domain default no-fallback)
|
|
585 "Return the instance of FACE's background in DOMAIN.
|
|
586
|
3027
|
587 Return value will be a color instance object; query its properties using
|
|
588 `color-instance-name' or `color-instance-rgb-properties'.
|
|
589
|
428
|
590 FACE may be either a face object or a symbol representing a face.
|
|
591
|
|
592 Normally DOMAIN will be a window or nil (meaning the selected window),
|
|
593 and an instance object describing how the background appears in that
|
|
594 particular window and buffer will be returned.
|
|
595
|
|
596 See `face-property-instance' for more information."
|
|
597 (face-property-instance face 'background domain default no-fallback))
|
|
598
|
|
599 (defun face-background-name (face &optional domain default no-fallback)
|
|
600 "Return the name of FACE's background color in DOMAIN.
|
|
601
|
|
602 FACE may be either a face object or a symbol representing a face.
|
|
603
|
|
604 Normally DOMAIN will be a window or nil (meaning the selected window),
|
|
605 and an instance object describing how the background appears in that
|
|
606 particular window and buffer will be returned.
|
|
607
|
|
608 See `face-property-instance' for more information."
|
|
609 (color-instance-name (face-background-instance
|
|
610 face domain default no-fallback)))
|
|
611
|
|
612 (defun set-face-background (face color &optional locale tag-set how-to-add)
|
|
613 "Change the background color of FACE to COLOR in LOCALE.
|
|
614
|
|
615 FACE may be either a face object or a symbol representing a face.
|
|
616
|
442
|
617 COLOR should be an instantiator (see `make-color-specifier'), a list of
|
428
|
618 instantiators, an alist of specifications (each mapping a locale to
|
|
619 an instantiator list), or a color specifier object.
|
|
620
|
|
621 If COLOR is an alist, LOCALE must be omitted. If COLOR is a
|
3027
|
622 specifier object, LOCALE can be a locale, a locale type, `all',
|
428
|
623 or nil; see `copy-specifier' for its semantics. Otherwise LOCALE
|
|
624 specifies the locale under which the specified instantiator(s)
|
3027
|
625 will be added, and defaults to `global'.
|
428
|
626
|
|
627 See `set-face-property' for more information."
|
|
628 (interactive (face-interactive "background"))
|
|
629 (set-face-property face 'background color locale tag-set how-to-add))
|
|
630
|
|
631 (defun face-background-pixmap (face &optional locale tag-set exact-p)
|
3027
|
632 "Return the background pixmap spec of FACE in LOCALE, or nil if unspecified.
|
428
|
633 This property is only used on window system devices.
|
|
634
|
3027
|
635 NOTE: This returns a locale-specific specification, not any sort of value
|
|
636 corresponding to the actual background pixmap being used. If you want to
|
|
637 know the actual background pixmap used in a particular domain, use
|
|
638 `face-background-pixmap-instance'.
|
|
639
|
428
|
640 FACE may be either a face object or a symbol representing a face.
|
|
641
|
|
642 LOCALE may be a locale (the instantiators for that particular locale
|
|
643 will be returned), a locale type (the specifications for all locales
|
3027
|
644 of that type will be returned), `all' (all specifications will be
|
428
|
645 returned), or nil (the actual specifier object will be returned).
|
|
646
|
|
647 See `face-property' for more information."
|
|
648 (face-property face 'background-pixmap locale tag-set exact-p))
|
|
649
|
|
650 (defun face-background-pixmap-instance (face &optional domain default
|
|
651 no-fallback)
|
|
652 "Return the instance of FACE's background pixmap in DOMAIN.
|
|
653
|
3027
|
654 Return value will be an image instance object; query its properties using
|
|
655 `image-instance-instantiator' (the original instantiator used to create
|
|
656 the image, which may be a complex beast -- see `make-image-specifier'),
|
|
657 `image-instance-file-name' (the file, if any, from which the image was
|
|
658 created), `image-instance-height', etc.
|
|
659
|
428
|
660 FACE may be either a face object or a symbol representing a face.
|
|
661
|
|
662 Normally DOMAIN will be a window or nil (meaning the selected window),
|
|
663 and an instance object describing how the background appears in that
|
|
664 particular window and buffer will be returned.
|
|
665
|
|
666 See `face-property-instance' for more information."
|
|
667 (face-property-instance face 'background-pixmap domain default no-fallback))
|
|
668
|
|
669 (defun set-face-background-pixmap (face pixmap &optional locale tag-set
|
|
670 how-to-add)
|
|
671 "Change the background pixmap of FACE to PIXMAP in LOCALE.
|
|
672 This property is only used on window system devices.
|
|
673
|
|
674 FACE may be either a face object or a symbol representing a face.
|
|
675
|
442
|
676 PIXMAP should be an instantiator (see `make-image-specifier'), a list
|
428
|
677 of instantiators, an alist of specifications (each mapping a locale
|
|
678 to an instantiator list), or an image specifier object.
|
|
679
|
|
680 If PIXMAP is an alist, LOCALE must be omitted. If PIXMAP is a
|
3027
|
681 specifier object, LOCALE can be a locale, a locale type, `all',
|
428
|
682 or nil; see `copy-specifier' for its semantics. Otherwise LOCALE
|
|
683 specifies the locale under which the specified instantiator(s)
|
3027
|
684 will be added, and defaults to `global'.
|
428
|
685
|
|
686 See `set-face-property' for more information."
|
|
687 (interactive (face-interactive "background-pixmap"))
|
|
688 (set-face-property face 'background-pixmap pixmap locale tag-set how-to-add))
|
|
689
|
1137
|
690 (defvar background-pixmap-file-history nil
|
|
691 ;; History for `set-face-background-pixmap-file'
|
|
692 )
|
|
693
|
|
694 (defun set-face-background-pixmap-file (face file)
|
|
695 "Read (and set) the background pixmap of FACE from FILE.
|
|
696 This function is a simplified version of `set-face-background-pixmap',
|
|
697 designed for interactive use."
|
|
698 (interactive
|
|
699 (let* ((face (read-face-name "Set background pixmap of face: "))
|
1139
|
700 (default (and (face-background-pixmap-instance face)
|
|
701 ((image-instance-file-name
|
|
702 (face-background-pixmap-instance face)))))
|
1137
|
703 (file (read-file-name
|
|
704 (format "Set background pixmap of face %s to: "
|
|
705 (symbol-name face))
|
1139
|
706 nil default t nil
|
1137
|
707 'background-pixmap-file-history)))
|
|
708 (list face (if (equal file "") nil file))))
|
|
709 (set-face-property face 'background-pixmap file))
|
|
710
|
428
|
711 (defun face-display-table (face &optional locale tag-set exact-p)
|
3027
|
712 "Return the display table spec of FACE in LOCALE, or nil if unspecified..
|
428
|
713
|
3027
|
714 NOTE: This returns a locale-specific specification, not any sort of value
|
|
715 corresponding to the actual display table being used. If you want to
|
|
716 know the actual display table used in a particular domain, use
|
|
717 `face-display-table-instance'.
|
|
718
|
|
719 FACE may be either a face object or a symbol representing a face.
|
428
|
720
|
|
721 LOCALE may be a locale (the instantiators for that particular locale
|
|
722 will be returned), a locale type (the specifications for all locales
|
3027
|
723 of that type will be returned), `all' (all specifications will be
|
428
|
724 returned), or nil (the actual specifier object will be returned).
|
|
725
|
|
726 See `face-property' for more information."
|
|
727 (face-property face 'display-table locale tag-set exact-p))
|
|
728
|
|
729 (defun face-display-table-instance (face &optional domain default no-fallback)
|
|
730 "Return the instance of FACE's display table in DOMAIN.
|
3027
|
731
|
|
732 Return value will be a vector, char table or range table; see
|
|
733 `current-display-table'.
|
|
734
|
|
735 FACE may be either a face object or a symbol representing a face.
|
428
|
736
|
3027
|
737 Normally DOMAIN will be a window or nil (meaning the selected window),
|
|
738 and the actual display table used in that particular window and buffer
|
|
739 will be returned.
|
|
740
|
|
741 See `face-property-instance' for more information."
|
428
|
742 (face-property-instance face 'display-table domain default no-fallback))
|
|
743
|
|
744 (defun set-face-display-table (face display-table &optional locale tag-set
|
872
|
745 how-to-add)
|
428
|
746 "Change the display table of FACE to DISPLAY-TABLE in LOCALE.
|
|
747 DISPLAY-TABLE should be a vector as returned by `make-display-table'.
|
|
748
|
|
749 See `set-face-property' for the semantics of the LOCALE, TAG-SET, and
|
|
750 HOW-TO-ADD arguments."
|
|
751 (interactive (face-interactive "display-table"))
|
|
752 (set-face-property face 'display-table display-table locale tag-set
|
|
753 how-to-add))
|
|
754
|
|
755 ;; The following accessors and mutators are, IMHO, good
|
|
756 ;; implementation. Cf. with `make-face-bold'.
|
|
757
|
|
758 (defun face-underline-p (face &optional domain default no-fallback)
|
|
759 "Return t if FACE is underlined in DOMAIN.
|
|
760 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
761 (face-property-instance face 'underline domain default no-fallback))
|
|
762
|
|
763 (defun set-face-underline-p (face underline-p &optional locale tag-set
|
872
|
764 how-to-add)
|
428
|
765 "Change the underline property of FACE to UNDERLINE-P.
|
|
766 UNDERLINE-P is normally a face-boolean instantiator; see
|
442
|
767 `make-face-boolean-specifier'.
|
428
|
768 See `set-face-property' for the semantics of the LOCALE, TAG-SET, and
|
|
769 HOW-TO-ADD arguments."
|
|
770 (interactive (face-interactive "underline-p" "underlined"))
|
|
771 (set-face-property face 'underline underline-p locale tag-set how-to-add))
|
|
772
|
|
773 (defun face-strikethru-p (face &optional domain default no-fallback)
|
|
774 "Return t if FACE is strikethru-d (i.e. struck through) in DOMAIN.
|
|
775 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
776 (face-property-instance face 'strikethru domain default no-fallback))
|
|
777
|
|
778 (defun set-face-strikethru-p (face strikethru-p &optional locale tag-set
|
872
|
779 how-to-add)
|
428
|
780 "Change whether FACE is strikethru-d (i.e. struck through) in LOCALE.
|
|
781 STRIKETHRU-P is normally a face-boolean instantiator; see
|
442
|
782 `make-face-boolean-specifier'.
|
428
|
783 See `set-face-property' for the semantics of the LOCALE, TAG-SET, and
|
|
784 HOW-TO-ADD arguments."
|
|
785 (interactive (face-interactive "strikethru-p" "strikethru-d"))
|
|
786 (set-face-property face 'strikethru strikethru-p locale tag-set how-to-add))
|
|
787
|
|
788 (defun face-highlight-p (face &optional domain default no-fallback)
|
|
789 "Return t if FACE is highlighted in DOMAIN (TTY domains only).
|
|
790 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
791 (face-property-instance face 'highlight domain default no-fallback))
|
|
792
|
|
793 (defun set-face-highlight-p (face highlight-p &optional locale tag-set
|
872
|
794 how-to-add)
|
428
|
795 "Change whether FACE is highlighted in LOCALE (TTY locales only).
|
|
796 HIGHLIGHT-P is normally a face-boolean instantiator; see
|
442
|
797 `make-face-boolean-specifier'.
|
428
|
798 See `set-face-property' for the semantics of the LOCALE, TAG-SET, and
|
|
799 HOW-TO-ADD arguments."
|
|
800 (interactive (face-interactive "highlight-p" "highlighted"))
|
|
801 (set-face-property face 'highlight highlight-p locale tag-set how-to-add))
|
|
802
|
|
803 (defun face-dim-p (face &optional domain default no-fallback)
|
|
804 "Return t if FACE is dimmed in DOMAIN.
|
|
805 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
806 (face-property-instance face 'dim domain default no-fallback))
|
|
807
|
|
808 (defun set-face-dim-p (face dim-p &optional locale tag-set how-to-add)
|
|
809 "Change whether FACE is dimmed in LOCALE.
|
|
810 DIM-P is normally a face-boolean instantiator; see
|
442
|
811 `make-face-boolean-specifier'.
|
428
|
812 See `set-face-property' for the semantics of the LOCALE, TAG-SET, and
|
|
813 HOW-TO-ADD arguments."
|
|
814 (interactive (face-interactive "dim-p" "dimmed"))
|
|
815 (set-face-property face 'dim dim-p locale tag-set how-to-add))
|
|
816
|
|
817 (defun face-blinking-p (face &optional domain default no-fallback)
|
|
818 "Return t if FACE is blinking in DOMAIN (TTY domains only).
|
|
819 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
820 (face-property-instance face 'blinking domain default no-fallback))
|
|
821
|
|
822 (defun set-face-blinking-p (face blinking-p &optional locale tag-set
|
872
|
823 how-to-add)
|
428
|
824 "Change whether FACE is blinking in LOCALE (TTY locales only).
|
|
825 BLINKING-P is normally a face-boolean instantiator; see
|
442
|
826 `make-face-boolean-specifier'.
|
428
|
827 See `set-face-property' for the semantics of the LOCALE, TAG-SET, and
|
|
828 HOW-TO-ADD arguments."
|
|
829 (interactive (face-interactive "blinking-p" "blinking"))
|
|
830 (set-face-property face 'blinking blinking-p locale tag-set how-to-add))
|
|
831
|
|
832 (defun face-reverse-p (face &optional domain default no-fallback)
|
|
833 "Return t if FACE is reversed in DOMAIN (TTY domains only).
|
|
834 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
835 (face-property-instance face 'reverse domain default no-fallback))
|
|
836
|
|
837 (defun set-face-reverse-p (face reverse-p &optional locale tag-set how-to-add)
|
|
838 "Change whether FACE is reversed in LOCALE (TTY locales only).
|
|
839 REVERSE-P is normally a face-boolean instantiator; see
|
442
|
840 `make-face-boolean-specifier'.
|
428
|
841 See `set-face-property' for the semantics of the LOCALE, TAG-SET, and
|
|
842 HOW-TO-ADD arguments."
|
|
843 (interactive (face-interactive "reverse-p" "reversed"))
|
|
844 (set-face-property face 'reverse reverse-p locale tag-set how-to-add))
|
|
845
|
|
846
|
|
847 (defun face-property-equal (face1 face2 prop domain)
|
|
848 (equal (face-property-instance face1 prop domain)
|
|
849 (face-property-instance face2 prop domain)))
|
|
850
|
|
851 (defun face-equal-loop (props face1 face2 domain)
|
|
852 (while (and props
|
|
853 (face-property-equal face1 face2 (car props) domain))
|
|
854 (setq props (cdr props)))
|
|
855 (null props))
|
|
856
|
|
857 (defun face-equal (face1 face2 &optional domain)
|
|
858 "Return t if FACE1 and FACE2 will display in the same way in DOMAIN.
|
|
859 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
860 (if (null domain) (setq domain (selected-window)))
|
|
861 (if (not (valid-specifier-domain-p domain))
|
|
862 (error "Invalid specifier domain"))
|
|
863 (let ((device (dfw-device domain))
|
|
864 (common-props '(foreground background font display-table underline
|
3027
|
865 dim inherit))
|
428
|
866 (win-props '(background-pixmap strikethru))
|
|
867 (tty-props '(highlight blinking reverse)))
|
|
868
|
|
869 ;; First check the properties which are used in common between the
|
|
870 ;; x and tty devices. Then, check those properties specific to
|
|
871 ;; the particular device type.
|
|
872 (and (face-equal-loop common-props face1 face2 domain)
|
|
873 (cond ((eq 'tty (device-type device))
|
|
874 (face-equal-loop tty-props face1 face2 domain))
|
872
|
875 ((console-on-window-system-p (device-console device))
|
428
|
876 (face-equal-loop win-props face1 face2 domain))
|
|
877 (t t)))))
|
|
878
|
|
879 (defun face-differs-from-default-p (face &optional domain)
|
|
880 "Return t if FACE will display differently from the default face in DOMAIN.
|
|
881 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
882 (not (face-equal face 'default domain)))
|
|
883
|
|
884 (defun try-font-name (name &optional device)
|
872
|
885 "Return NAME if it's a valid font name on DEVICE, else nil."
|
428
|
886 ;; yes, name really should be here twice.
|
|
887 (and name (make-font-instance name device t) name))
|
|
888
|
|
889
|
872
|
890
|
|
891 (defcustom face-frob-from-locale-first nil
|
|
892 "*If non nil, use kludgy way of frobbing fonts suitable for non-mule
|
|
893 multi-charset environments."
|
|
894 :group 'faces
|
|
895 :type 'boolean)
|
|
896
|
428
|
897 ;; This function is a terrible, disgusting hack!!!! Need to
|
|
898 ;; separate out the font elements as separate face properties!
|
|
899
|
|
900 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
901 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
902 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
903 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
904 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
905 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
906 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
907 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
908 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
909 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
910 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
911 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
912 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
913 ;; WE DEMAND LEXICAL SCOPING!!!
|
|
914 ;; WE DEMAND LEXICAL SCOPING!!!
|
872
|
915
|
|
916 ;; When we are initializing a device, it won't be selected; we communicate
|
|
917 ;; the device to consider as selected using this variable.
|
|
918 (defvar Face-frob-property-device-considered-current nil)
|
428
|
919
|
872
|
920 (defun Face-frob-property (face locale tag-set exact-p
|
|
921 unfrobbed-face frobbed-face
|
|
922 win-prop tty-props
|
|
923 frob-mapping standard-face-mapping)
|
|
924 ;; implement the semantics of `make-face-bold' et al. FACE, LOCALE, TAG-SET
|
|
925 ;; and EXACT-P are as in that call. UNFROBBED-FACE and FROBBED-FACE are
|
|
926 ;; what we expect the original face and the result to look like,
|
|
927 ;; respectively. TTY-PROPS is a list of face properties to frob in place
|
|
928 ;; of `font' for TTY's. FROB-MAPPING is either a plist mapping device
|
|
929 ;; types to functions of two args (NAME DEVICE) that will frob the
|
|
930 ;; instantiator as appropriate for the device type (this includes TTY's),
|
|
931 ;; or a function to handle the mapping for all device types.
|
|
932 ;; STANDARD-FACE-MAPPING is an alist of mappings of inheritance
|
|
933 ;; instantiators to be replaced with other inheritance instantiators, meant
|
|
934 ;; for e.g. converting [bold] into [bold-italic].
|
|
935
|
|
936 ;; #### it would be nice if this function could be generalized to be
|
|
937 ;; a general specifier frobber. but so much of what it does is specific
|
|
938 ;; to faces -- e.g. handling of inheritance, standard faces,
|
|
939 ;; special-casing in various ways for tty's, etc. i've already extracted
|
|
940 ;; as much of the functionality as i can into subfunctions in the
|
|
941 ;; heuristic section of specifier.el.
|
442
|
942
|
872
|
943 ;; #### Note: The old code was totally different (and there was much less
|
|
944 ;; of it). It didn't bother with trying to frob all the instantiators,
|
|
945 ;; or handle inheritance vectors as instantiators, or do something
|
|
946 ;; sensible with buffer locales, or many other things. (It always, or
|
|
947 ;; usually, did a specifier-instance and frobbed the result.) But it did
|
|
948 ;; do three things we don't:
|
|
949 ;;
|
|
950 ;; (1) Map over all devices when processing global or buffer locales.
|
|
951 ;; Should we be doing this in stages 2 and/or 3? The fact that we
|
|
952 ;; now process all fallback instantiators seems to make this less
|
|
953 ;; necessary, at least for global locales.
|
|
954 ;;
|
|
955 ;; (2) Remove all instantiators tagged with `default' when putting the
|
|
956 ;; instantiators back. I don't see why this is necessary, but maybe
|
|
957 ;; it is.
|
|
958 ;;
|
|
959 ;; (3) Pay attention to the face-frob-from-locale-first variable. ####
|
|
960 ;; I don't understand its purpose. Undocumented hacks like this,
|
|
961 ;; clearly added after-the-fact, don't deserve to live. DOCUMENT
|
|
962 ;; THIS SHIT!
|
428
|
963
|
872
|
964 (flet
|
|
965 (
|
|
966
|
|
967 ;; non-nil if either instantiator non-nil, or nil instantiators allowed.
|
|
968 (nil-instantiator-ok (inst devtype-spec)
|
|
969 (or inst (eq devtype-spec 'tty)))
|
|
970
|
|
971 ;; if LOCALE is a global locale (all, nil, global), return 'global,
|
|
972 ;; else nil.
|
|
973 (global-locale (locale)
|
|
974 (and (memq locale '(all nil global)) 'global))
|
444
|
975
|
872
|
976 ;; Given a locale and the inst-list from that locale, frob the
|
|
977 ;; instantiators according to FROB-MAPPING, a plist mapping device
|
|
978 ;; types to functions that frob instantiators of that device type.
|
|
979 ;; NOTE: TAG-SET and FROB-MAPPING from environment.
|
|
980 (frob-face-inst-list (locale inst-list prop devtype-spec)
|
|
981 (let* ((ffpdev Face-frob-property-device-considered-current)
|
|
982 (results
|
|
983 ;; for each inst-pair, frob it (the result will be 0 or
|
|
984 ;; more inst-pairs; we may get more than one if, e.g. the
|
|
985 ;; instantiator specifies inheritance and we expand the
|
|
986 ;; inheritance); then nconc the results together
|
|
987 (loop for (tag-set . x) in inst-list
|
|
988 for devtype = (derive-device-type-from-locale-and-tag-set
|
|
989 locale tag-set devtype-spec ffpdev)
|
|
990 ;; devtype may be nil if it fails to match DEVTYPE-SPEC
|
|
991 if devtype
|
|
992 if (let* ((mapper (if (functionp frob-mapping) frob-mapping
|
|
993 (plist-get frob-mapping devtype)))
|
|
994 (result
|
|
995 (cond
|
|
996 ;; if a vector ...
|
|
997 ((vectorp x)
|
|
998 (let ((change-to
|
|
999 (cdr (assoc x standard-face-mapping))))
|
|
1000 (cond
|
|
1001 ;; (1) handle standard mappings/null vectors
|
|
1002 ((or change-to (null (length x)))
|
|
1003 (list (cons tag-set
|
|
1004 (cond ((eq change-to t) x)
|
|
1005 (change-to)
|
|
1006 (t x)))))
|
|
1007 ;; (2) inheritance vectors. retrieve the
|
|
1008 ;; inherited value and recursively frob.
|
|
1009 ;; stick the tag-set into the result.
|
|
1010 (t (let*
|
|
1011 ((subprop
|
|
1012 (if (> (length x) 1) (elt x 1)
|
|
1013 prop))
|
|
1014 (subinsts
|
|
1015 (frob-face-inst-list
|
|
1016 locale
|
|
1017 (cdar
|
|
1018 (specifier-spec-list
|
|
1019 (face-property (elt x 0)
|
|
1020 subprop)))
|
|
1021 subprop devtype-spec)))
|
|
1022 ;; #### we don't currently handle
|
|
1023 ;; the "reverse the sense" flag on
|
|
1024 ;; tty inheritance vectors.
|
|
1025 (add-tag-to-inst-list subinsts
|
|
1026 tag-set))))))
|
|
1027 ;; (3) not a vector. just process it.
|
|
1028 (t
|
|
1029 (let ((value
|
|
1030 (if (eq devtype-spec 'tty)
|
|
1031 (funcall mapper x)
|
|
1032 (funcall mapper x
|
|
1033 (derive-domain-from-locale
|
|
1034 locale devtype-spec
|
|
1035 ffpdev)))))
|
|
1036 (and (nil-instantiator-ok value devtype-spec)
|
|
1037 (list (cons tag-set value))))))))
|
|
1038 ;; if we're adding to a tty, we need to tag our
|
|
1039 ;; additions with `tty'; see [note 1] below. we leave
|
|
1040 ;; the old spec in place, however -- if e.g. we're
|
|
1041 ;; italicizing a font that was always set to be
|
|
1042 ;; underlined, even on window systems, then we still
|
|
1043 ;; want the underline there. unless we put the old
|
|
1044 ;; spec back, the underline will disappear, since
|
|
1045 ;; the new specs are all tagged with `tty'. this
|
|
1046 ;; doesn't apply to the [note 1] situations below
|
|
1047 ;; because there we're just adding, not substituting.
|
|
1048 (if (and (eq 'tty devtype-spec)
|
|
1049 (not (or (eq 'tty tag-set)
|
|
1050 (memq 'tty tag-set))))
|
|
1051 (nconc (add-tag-to-inst-list result 'tty)
|
|
1052 (list (cons tag-set x)))
|
|
1053 result))
|
|
1054 nconc it)))
|
|
1055 (delete-duplicates results :test #'equal)))
|
428
|
1056
|
872
|
1057 ;; Frob INST-LIST, which came from LOCALE, and put the new value back
|
|
1058 ;; into SP at LOCALE. THUNK is a cons of (PROP . DEVTYPE-SPEC), the
|
|
1059 ;; property being processed and whether this is a TTY property or a
|
|
1060 ;; win property.
|
|
1061 (frob-locale (sp locale inst-list thunk)
|
|
1062 (let ((newinst (frob-face-inst-list locale inst-list
|
|
1063 (car thunk) (cdr thunk))))
|
|
1064 (remove-specifier sp locale tag-set exact-p)
|
|
1065 (add-spec-list-to-specifier sp (list (cons locale newinst))))
|
|
1066 ;; map-specifier should keep going
|
|
1067 nil)
|
428
|
1068
|
872
|
1069 ;; map over all specified locales in LOCALE; for each locale,
|
|
1070 ;; frob the instantiators in that locale in the specifier in both
|
|
1071 ;; WIN-PROP and TTY-PROPS in FACE. Takes values from environment.
|
|
1072 (map-over-locales (locale)
|
|
1073 (map-specifier (get face win-prop) #'frob-locale locale
|
|
1074 (cons win-prop 'window-system)
|
|
1075 tag-set exact-p)
|
|
1076 (loop for prop in tty-props do
|
|
1077 (map-specifier (get face prop) #'frob-locale locale
|
|
1078 (cons prop 'tty)
|
|
1079 tag-set exact-p)))
|
|
1080
|
|
1081 ;; end of flets
|
|
1082 )
|
|
1083
|
|
1084 ;; the function itself
|
452
|
1085
|
872
|
1086 (let* ((ffpdev Face-frob-property-device-considered-current)
|
|
1087 (do-later-stages
|
|
1088 (or (global-locale locale)
|
|
1089 (valid-specifier-domain-p locale)
|
|
1090 (bufferp locale)))
|
|
1091 (domain (and do-later-stages
|
|
1092 (derive-domain-from-locale locale 'window-system
|
|
1093 ffpdev)))
|
|
1094 (check-differences
|
|
1095 (and unfrobbed-face frobbed-face domain
|
|
1096 (not (memq (face-name face)
|
|
1097 '(default bold italic bold-italic)))))
|
|
1098 (orig-instance
|
|
1099 (and check-differences
|
|
1100 (face-property-instance face win-prop domain))))
|
|
1101
|
|
1102 ;; first do the frobbing
|
|
1103 (setq face (get-face face))
|
|
1104 (map-over-locales locale)
|
|
1105
|
|
1106 (when do-later-stages
|
|
1107
|
|
1108 (if (global-locale locale) (setq locale 'global))
|
428
|
1109
|
872
|
1110 ;; now do the second stage -- if there's nothing there, try
|
|
1111 ;; harder to find an instantiator, and frob it.
|
|
1112 (let (do-something)
|
|
1113 (loop for prop in (cons win-prop tty-props)
|
|
1114 for propspec = (get face prop)
|
|
1115 for devtype-spec = (if (eq prop win-prop) 'window-system 'tty)
|
|
1116 if propspec
|
|
1117 do
|
|
1118 (or (specifier-spec-list propspec locale)
|
|
1119 (let ((doit (derive-specifier-specs-from-locale
|
|
1120 propspec locale devtype-spec ffpdev
|
|
1121 ;; #### does this make sense? When no tags
|
|
1122 ;; given, frob the whole list of fallbacks when
|
|
1123 ;; global, else just retrieve a current-device
|
|
1124 ;; value. this tries to mirror normal practices,
|
|
1125 ;; where with no tags you want everything frobbed,
|
|
1126 ;; but with a tag you want only the tag frobbed
|
|
1127 ;; and hence you probably don't want lots and lots
|
|
1128 ;; of items there. (#### Perhaps the best way --
|
|
1129 ;; or at least a way with some theoretical
|
|
1130 ;; justifiability -- is to fetch the fallbacks
|
|
1131 ;; that match the TAG-SET/EXACT-P, and if none,
|
|
1132 ;; fall back onto doing the selected-device
|
|
1133 ;; trick.)
|
|
1134 (and (not tag-set) (not exact-p)))))
|
|
1135 (if (and (not doit) (eq locale 'global))
|
|
1136 (error
|
|
1137 "No fallback for specifier property %s in face %s???"
|
|
1138 prop face))
|
|
1139 ;; [note 1] whenever we add to a tty property,
|
|
1140 ;; make sure we tag our additions with `tty' to
|
|
1141 ;; avoid accidentally messing things up on window
|
|
1142 ;; systems (e.g. when making things italic we
|
|
1143 ;; don't want to set the underline property on
|
|
1144 ;; window systems)
|
|
1145 (when doit
|
|
1146 (add-spec-list-to-specifier
|
|
1147 propspec
|
|
1148 (list (cons locale
|
|
1149 (add-tag-to-inst-list
|
|
1150 doit
|
|
1151 (append (if (listp tag-set) tag-set
|
|
1152 (list tag-set))
|
|
1153 (if (eq devtype-spec 'tty) '(tty)))
|
|
1154 ))))
|
|
1155 (setq do-something t)))))
|
|
1156 (when do-something
|
|
1157 (map-over-locales (or (global-locale locale) locale))))
|
|
1158
|
|
1159 ;; then do the third stage -- check for whether we have to do
|
|
1160 ;; the inheritance trick.
|
|
1161
|
|
1162 (when (and check-differences
|
|
1163 (let ((new-instance
|
|
1164 (face-property-instance face win-prop domain)))
|
|
1165 (and
|
|
1166 (equal orig-instance new-instance)
|
|
1167 (equal orig-instance
|
|
1168 (face-property-instance unfrobbed-face win-prop
|
|
1169 domain)))))
|
|
1170 (set-face-property face win-prop (vector frobbed-face)
|
|
1171 (or (global-locale locale) locale) tag-set))))))
|
428
|
1172
|
707
|
1173 ;; WE DEMAND FOUNDRY FROBBING!
|
|
1174
|
|
1175 ;; Family frobbing
|
|
1176 ;; Thx Jan Vroonhof, Ref xemacs-beta <87oflypbum.fsf@petteflet.ntlworld.com>
|
|
1177 ;; Brainlessly derived from make-face-size by Stephen; don't blame Jan.
|
|
1178 ;; I'm long since flown to Rio, it does you little good to blame me, either.
|
872
|
1179 (defun make-face-family (face family &optional locale tags exact-p)
|
|
1180 "Set FACE's family to FAMILY in LOCALE, if possible."
|
|
1181 (interactive (list (read-face-name "Set family of which face: ")
|
|
1182 (read-string "Family to set: ")))
|
707
|
1183
|
872
|
1184 (Face-frob-property face locale tags exact-p
|
|
1185 nil nil 'font nil
|
|
1186 `(lambda (f d)
|
707
|
1187 ;; keep the dependency on font.el for now
|
872
|
1188 (let ((fo (font-create-object f d)))
|
|
1189 (set-font-family fo ,family)
|
707
|
1190 (font-create-name fo d)))
|
872
|
1191 nil))
|
707
|
1192
|
|
1193 ;; Style (ie, typographical face) frobbing
|
872
|
1194 (defun make-face-bold (face &optional locale tags exact-p)
|
428
|
1195 "Make FACE bold in LOCALE, if possible.
|
872
|
1196 This will attempt to make the font bold for window-system locales and will
|
|
1197 set the highlight flag for TTY locales.
|
|
1198
|
|
1199 The actual behavior of this function is somewhat messy, in an attempt to
|
|
1200 get more intuitive behavior in quite a lot of different circumstances. (You
|
|
1201 might view this as indicative of design failures with specifiers, but in
|
|
1202 fact almost all code that attempts to interface to humans and produce
|
|
1203 \"intuitive\" results gets messy, particularly with a system as complicated
|
|
1204 as specifiers, whose complexity results from an attempt to work well in
|
|
1205 many different circumstances.)
|
|
1206
|
|
1207 The meaning of LOCALE is the same as for `specifier-spec-list', i.e.:
|
|
1208
|
|
1209 -- If LOCALE is nil, omitted, or `all', this will attempt to \"frob\" all
|
|
1210 font specifications for FACE to make them appear bold (i.e. the
|
|
1211 specifications are replaced with equivalent specifications, where the
|
|
1212 font names have been changed to the closest bold font).
|
|
1213
|
|
1214 -- If LOCALE is a locale type \(`buffer', `window', etc.), this frobs all
|
|
1215 font specifications for locales of that type.
|
|
1216
|
|
1217 -- If LOCALE is a particular locale, this frobs all font specifications for
|
|
1218 that locale.
|
428
|
1219
|
872
|
1220 If TAGS is given, this only processes instantiators whose tag set includes
|
|
1221 all tags mentioned in TAGS. In addition, if EXACT-P is non-nil, only
|
|
1222 instantiators whose tag set exactly matches TAGS are processed; otherwise,
|
|
1223 additional tags may be present in the instantiator's tag set.
|
|
1224
|
|
1225 This function proceeeds in three stages.
|
|
1226
|
|
1227 STAGE 1: Frob the settings that are already present.
|
|
1228 STAGE 2: (if called for) Ensure that *some* setting exists in the locale
|
|
1229 that was given, finding it in various ways and frobbing it as in
|
|
1230 stage 1. This ensures that there is an actual setting for
|
|
1231 the locale, so you will get the expected buffer-local/frame-local
|
|
1232 behavior -- changes to the global value, to other locales, won't
|
|
1233 affect this locale, (b) the face will actually look bold in
|
|
1234 the locale.
|
1137
|
1235 STAGE 3: (if called for)
|
872
|
1236
|
|
1237 The way the frobbing works depends on the device type -- first on whether
|
|
1238 or not it's TTY, and second, if it's a window-system device type, on which
|
|
1239 particular window-system device type. For locales with a specific device
|
|
1240 type, we do the frobbing in the context of that device type -- this means
|
|
1241 that for TTY device types we set the highlight flag, and for window-system
|
|
1242 device types we modify the font spec according to the rules for font specs
|
|
1243 of that device type. For global locales, we may process both the highlight
|
|
1244 flag and the font specs (depending on the device types compiled into this
|
|
1245 XEmacs). When processing font specs, we check the tag set associated with
|
|
1246 each font spec to see if it's specific to a particular device type; if so,
|
|
1247 we frob it in the context of that type, else we use the type of the current
|
|
1248 device. (A hack, but works well in practice -- and if a new device is
|
|
1249 created, we will automatically frob all the standard fonts to make sure
|
|
1250 they display OK on that device.)
|
|
1251
|
|
1252 If LOCALE is not a locale type, and both TAGS and EXACT-P are omitted, we
|
|
1253 do further frobbing in an attempt to give more intuitive behavior.
|
428
|
1254
|
872
|
1255 First, if there are no specifications in LOCALE (if LOCALE is `all', we act
|
|
1256 as if it were `global' for this step), we do our utmost to put a
|
|
1257 specification there; otherwise, this function will have no effect. For
|
|
1258 device, frame, or window locales, the face's font is instantiated using the
|
|
1259 locale as a domain, and the resulting font is frobbed and added back as a
|
|
1260 specification for this locale. If LOCALE is `global', we retrieve the
|
|
1261 fallback specs and frob them. If LOCALE is a buffer, things get tricky
|
|
1262 since you can't instantiate a specifier in a buffer domain \(the buffer can
|
|
1263 appear in multiple places, or in different places over time, so this
|
|
1264 operation is not well-defined). We used to signal an error in this case,
|
|
1265 but now we instead try to do something logical so that we work somewhat
|
|
1266 similarly to buffer-local variables. Specifically, we use
|
|
1267 `get-buffer-window' to find a window viewing the buffer, and if there is
|
|
1268 one, use this as a domain to instantiate the font, and frob the resulting
|
|
1269 value. Otherwise, we use the selected window for the same purpose.
|
|
1270
|
|
1271 Finally, if the frobbing didn't actually make the font look any different
|
|
1272 in whatever domain we instantiated the font in (this happens, for example,
|
|
1273 if your font specification is already bold or has no bold equivalent; note
|
|
1274 that in this step, we use the selected device in place of `global' or `all'
|
|
1275 -- another hack, but works well in practice since there's usually only one
|
|
1276 device), and the font currently looks like the font of the `default' face,
|
|
1277 it is set to inherit from the `bold' face.
|
|
1278
|
|
1279 NOTE: For the other functions defined below, the identity of these two
|
|
1280 standard faces mentioned in the previous paragraph, and the TTY properties
|
|
1281 that are modified, may be different, and whether the TTY property or
|
|
1282 properties are set or unset may be different. For example, for
|
|
1283 `make-face-unitalic', the last sentence in the previous paragraph would
|
|
1284 read \"... and the font currently looks like the font of the `italic' face,
|
|
1285 it is set to inherit from the `default' face.\", and the second sentence in
|
|
1286 the first paragraph would read \"This will attempt to make the font
|
|
1287 non-italic for window-system locales and will unset the underline flag for
|
|
1288 TTY locales.\"
|
|
1289
|
|
1290 Here's a table indicating the behavior differences with the different
|
|
1291 functions:
|
|
1292
|
|
1293 function face1 face2 tty-props tty-val
|
|
1294 ----------------------------------------------------------------------------
|
|
1295 make-face-bold default bold highlight t
|
|
1296 make-face-italic default italic underline t
|
|
1297 make-face-bold-italic default bold-italic highlight,underline t
|
|
1298 make-face-unbold bold default highlight nil
|
|
1299 make-face-unitalic italic default underline nil
|
|
1300 "
|
428
|
1301 (interactive (list (read-face-name "Make which face bold: ")))
|
872
|
1302 (Face-frob-property face locale tags exact-p
|
|
1303 'default 'bold 'font '(highlight)
|
|
1304 '(tty (lambda (x) t)
|
|
1305 x x-make-font-bold
|
|
1306 gtk gtk-make-font-bold
|
|
1307 mswindows mswindows-make-font-bold
|
|
1308 msprinter mswindows-make-font-bold)
|
|
1309 '(([default] . [bold])
|
|
1310 ([bold] . t)
|
|
1311 ([italic] . [bold-italic])
|
|
1312 ([bold-italic] . t))))
|
428
|
1313
|
872
|
1314 (defun make-face-italic (face &optional locale tags exact-p)
|
428
|
1315 "Make FACE italic in LOCALE, if possible.
|
442
|
1316 This will attempt to make the font italic for X/MS Windows locales and
|
|
1317 will set the underline flag for TTY locales. See `make-face-bold' for
|
|
1318 the semantics of the LOCALE argument and for more specifics on exactly
|
|
1319 how this function works."
|
428
|
1320 (interactive (list (read-face-name "Make which face italic: ")))
|
872
|
1321 (Face-frob-property face locale tags exact-p
|
|
1322 'default 'italic 'font '(underline)
|
|
1323 '(tty (lambda (x) t)
|
|
1324 x x-make-font-italic
|
|
1325 gtk gtk-make-font-italic
|
|
1326 mswindows mswindows-make-font-italic
|
|
1327 msprinter mswindows-make-font-italic)
|
|
1328 '(([default] . [italic])
|
|
1329 ([bold] . [bold-italic])
|
|
1330 ([italic] . t)
|
|
1331 ([bold-italic] . t))))
|
428
|
1332
|
872
|
1333 (defun make-face-bold-italic (face &optional locale tags exact-p)
|
428
|
1334 "Make FACE bold and italic in LOCALE, if possible.
|
442
|
1335 This will attempt to make the font bold-italic for X/MS Windows
|
|
1336 locales and will set the highlight and underline flags for TTY
|
|
1337 locales. See `make-face-bold' for the semantics of the LOCALE
|
|
1338 argument and for more specifics on exactly how this function works."
|
428
|
1339 (interactive (list (read-face-name "Make which face bold-italic: ")))
|
872
|
1340 (Face-frob-property face locale tags exact-p
|
|
1341 'default 'bold-italic 'font '(underline highlight)
|
|
1342 '(tty (lambda (x) t)
|
|
1343 x x-make-font-bold-italic
|
|
1344 gtk gtk-make-font-bold-italic
|
|
1345 mswindows mswindows-make-font-bold-italic
|
|
1346 msprinter mswindows-make-font-bold-italic)
|
|
1347 '(([default] . [italic])
|
|
1348 ([bold] . [bold-italic])
|
|
1349 ([italic] . [bold-italic])
|
|
1350 ([bold-italic] . t))))
|
428
|
1351
|
872
|
1352
|
|
1353 (defun make-face-unbold (face &optional locale tags exact-p)
|
428
|
1354 "Make FACE non-bold in LOCALE, if possible.
|
442
|
1355 This will attempt to make the font non-bold for X/MS Windows locales
|
|
1356 and will unset the highlight flag for TTY locales. See
|
|
1357 `make-face-bold' for the semantics of the LOCALE argument and for more
|
|
1358 specifics on exactly how this function works."
|
428
|
1359 (interactive (list (read-face-name "Make which face non-bold: ")))
|
872
|
1360 (Face-frob-property face locale tags exact-p
|
|
1361 'bold 'default 'font '(highlight)
|
|
1362 '(tty (lambda (x) nil)
|
|
1363 x x-make-font-unbold
|
|
1364 gtk gtk-make-font-unbold
|
|
1365 mswindows mswindows-make-font-unbold
|
|
1366 msprinter mswindows-make-font-unbold)
|
|
1367 '(([default] . t)
|
|
1368 ([bold] . [default])
|
|
1369 ([italic] . t)
|
|
1370 ([bold-italic] . [italic]))))
|
428
|
1371
|
872
|
1372 (defun make-face-unitalic (face &optional locale tags exact-p)
|
428
|
1373 "Make FACE non-italic in LOCALE, if possible.
|
442
|
1374 This will attempt to make the font non-italic for X/MS Windows locales
|
|
1375 and will unset the underline flag for TTY locales. See
|
|
1376 `make-face-bold' for the semantics of the LOCALE argument and for more
|
|
1377 specifics on exactly how this function works."
|
428
|
1378 (interactive (list (read-face-name "Make which face non-italic: ")))
|
872
|
1379 (Face-frob-property face locale tags exact-p
|
|
1380 'italic 'default 'font '(underline)
|
|
1381 '(tty (lambda (x) nil)
|
|
1382 x x-make-font-unitalic
|
|
1383 gtk gtk-make-font-unitalic
|
|
1384 mswindows mswindows-make-font-unitalic
|
|
1385 msprinter mswindows-make-font-unitalic)
|
|
1386 '(([default] . t)
|
|
1387 ([bold] . t)
|
|
1388 ([italic] . [default])
|
|
1389 ([bold-italic] . [bold]))))
|
428
|
1390
|
|
1391
|
707
|
1392 ;; Size frobbing
|
|
1393 ;; Thx Jan Vroonhof, Ref xemacs-beta <87oflypbum.fsf@petteflet.ntlworld.com>
|
1137
|
1394 ;; Jan had a separate helper function
|
872
|
1395 (defun make-face-size (face size &optional locale tags exact-p)
|
|
1396 "Adjust FACE to SIZE in LOCALE, if possible."
|
|
1397 (interactive (list (read-face-name "Set size of which face: ")
|
|
1398 (read-number "Size to set: " t 10)))
|
|
1399 (Face-frob-property face locale tags exact-p
|
|
1400 nil nil 'font nil
|
|
1401 `(lambda (f d)
|
|
1402 ;; keep the dependency on font.el for now
|
|
1403 (let ((fo (font-create-object f d)))
|
|
1404 (set-font-size fo ,size)
|
|
1405 (font-create-name fo d)))
|
|
1406 nil))
|
707
|
1407
|
428
|
1408 ;; Why do the following two functions lose so badly in so many
|
|
1409 ;; circumstances?
|
|
1410
|
872
|
1411 (defun make-face-smaller (face &optional locale tags exact-p)
|
428
|
1412 "Make the font of FACE be smaller, if possible.
|
|
1413 LOCALE works as in `make-face-bold' et al., but the ``inheriting-
|
|
1414 from-the-bold-face'' operations described there are not done
|
|
1415 because they don't make sense in this context."
|
|
1416 (interactive (list (read-face-name "Shrink which face: ")))
|
872
|
1417 (Face-frob-property face locale tags exact-p
|
|
1418 nil nil 'font nil
|
|
1419 '(x x-find-smaller-font
|
|
1420 gtk gtk-find-smaller-font
|
|
1421 mswindows mswindows-find-smaller-font
|
|
1422 msprinter mswindows-find-smaller-font)
|
|
1423 nil))
|
428
|
1424
|
872
|
1425 (defun make-face-larger (face &optional locale tags exact-p)
|
428
|
1426 "Make the font of FACE be larger, if possible.
|
|
1427 See `make-face-smaller' for the semantics of the LOCALE argument."
|
|
1428 (interactive (list (read-face-name "Enlarge which face: ")))
|
872
|
1429 (Face-frob-property face locale tags exact-p
|
|
1430 nil nil 'font nil
|
|
1431 '(x x-find-larger-font
|
|
1432 gtk gtk-find-larger-font
|
|
1433 mswindows mswindows-find-larger-font
|
|
1434 msprinter mswindows-find-larger-font)
|
|
1435 nil))
|
428
|
1436
|
|
1437 (defun invert-face (face &optional locale)
|
|
1438 "Swap the foreground and background colors of the face."
|
|
1439 (interactive (list (read-face-name "Invert face: ")))
|
|
1440 (if (valid-specifier-domain-p locale)
|
|
1441 (let ((foreface (face-foreground-instance face locale)))
|
|
1442 (set-face-foreground face (face-background-instance face locale)
|
|
1443 locale)
|
|
1444 (set-face-background face foreface locale))
|
|
1445 (let ((forespec (copy-specifier (face-foreground face) nil locale)))
|
|
1446 (copy-specifier (face-background face) (face-foreground face) locale)
|
|
1447 (copy-specifier forespec (face-background face) locale))))
|
|
1448
|
|
1449
|
|
1450 ;;; Convenience functions
|
|
1451
|
|
1452 (defun face-ascent (face &optional domain charset)
|
|
1453 "Return the ascent of FACE in DOMAIN.
|
|
1454 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
1455 (font-ascent (face-font face) domain charset))
|
|
1456
|
|
1457 (defun face-descent (face &optional domain charset)
|
|
1458 "Return the descent of FACE in DOMAIN.
|
|
1459 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
1460 (font-descent (face-font face) domain charset))
|
|
1461
|
|
1462 (defun face-width (face &optional domain charset)
|
|
1463 "Return the width of FACE in DOMAIN.
|
|
1464 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
1465 (font-width (face-font face) domain charset))
|
|
1466
|
|
1467 (defun face-height (face &optional domain charset)
|
|
1468 "Return the height of FACE in DOMAIN.
|
|
1469 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
1470 (+ (face-ascent face domain charset) (face-descent face domain charset)))
|
|
1471
|
|
1472 (defun face-proportional-p (face &optional domain charset)
|
|
1473 "Return t if FACE is proportional in DOMAIN.
|
|
1474 See `face-property-instance' for the semantics of the DOMAIN argument."
|
|
1475 (font-proportional-p (face-font face) domain charset))
|
|
1476
|
|
1477
|
|
1478 ;; Functions that used to be in cus-face.el, but logically go here.
|
|
1479
|
|
1480 (defcustom frame-background-mode nil
|
|
1481 "*The brightness of the background.
|
|
1482 Set this to the symbol dark if your background color is dark, light if
|
|
1483 your background is light, or nil (default) if you want Emacs to
|
|
1484 examine the brightness for you."
|
|
1485 :group 'faces
|
|
1486 :type '(choice (choice-item dark)
|
|
1487 (choice-item light)
|
|
1488 (choice-item :tag "Auto" nil)))
|
|
1489
|
|
1490 ;; The old variable that many people still have in .emacs files.
|
|
1491 (define-obsolete-variable-alias 'custom-background-mode
|
|
1492 'frame-background-mode)
|
|
1493
|
|
1494 (defun get-frame-background-mode (frame)
|
|
1495 "Detect background mode for FRAME."
|
|
1496 (let* ((color-instance (face-background-instance 'default frame))
|
|
1497 (mode (condition-case nil
|
|
1498 (if (< (apply '+ (color-instance-rgb-components
|
|
1499 color-instance)) 65536)
|
|
1500 'dark 'light)
|
872
|
1501 ;; Here, we get an error on a TTY (Return value from
|
|
1502 ;; color-instance-rgb-components is nil), and on the
|
|
1503 ;; initial stream device (Return value from
|
|
1504 ;; face-background-instance is nil). As we don't have a
|
|
1505 ;; good way of detecting whether a TTY is light or dark,
|
|
1506 ;; we'll guess it's dark.
|
428
|
1507 (error 'dark))))
|
|
1508 (set-frame-property frame 'background-mode mode)
|
|
1509 mode))
|
|
1510
|
|
1511 (defun extract-custom-frame-properties (frame)
|
|
1512 "Return a plist with the frame properties of FRAME used by custom."
|
|
1513 (list 'type (or (frame-property frame 'display-type)
|
|
1514 (device-type (frame-device frame)))
|
|
1515 'class (device-class (frame-device frame))
|
|
1516 'background (or frame-background-mode
|
|
1517 (frame-property frame 'background-mode)
|
|
1518 (get-frame-background-mode frame))))
|
|
1519
|
|
1520 (defcustom init-face-from-resources t
|
|
1521 "If non nil, attempt to initialize faces from the resource database."
|
|
1522 :group 'faces
|
|
1523 :type 'boolean)
|
|
1524
|
|
1525 ;; Old name, used by custom. Also, FSFmacs name.
|
|
1526 (defvaralias 'initialize-face-resources 'init-face-from-resources)
|
|
1527
|
|
1528 ;; Make sure all custom setting are added with this tag so we can
|
|
1529 ;; identify-them
|
|
1530 (define-specifier-tag 'custom)
|
|
1531
|
|
1532 (defun face-spec-set (face spec &optional frame tags)
|
|
1533 "Set FACE's face attributes according to the first matching entry in SPEC.
|
|
1534 If optional FRAME is non-nil, set it for that frame only.
|
|
1535 If it is nil, then apply SPEC to each frame individually.
|
|
1536 See `defface' for information about SPEC."
|
|
1537 (if frame
|
|
1538 (progn
|
|
1539 (reset-face face frame tags)
|
|
1540 (face-display-set face spec frame tags)
|
|
1541 (init-face-from-resources face frame))
|
|
1542 (let ((frames (relevant-custom-frames)))
|
|
1543 (reset-face face nil tags)
|
|
1544 ;; This should not be needed. We only remove our own specifiers
|
|
1545 ;; (if (and (eq 'default face) (featurep 'x))
|
|
1546 ;; (x-init-global-faces))
|
|
1547 (face-display-set face spec nil tags)
|
|
1548 (while frames
|
|
1549 (face-display-set face spec (car frames) tags)
|
|
1550 (pop frames))
|
|
1551 (init-face-from-resources face))))
|
|
1552
|
|
1553 (defun face-display-set (face spec &optional frame tags)
|
|
1554 "Set FACE to the attributes to the first matching entry in SPEC.
|
|
1555 Iff optional FRAME is non-nil, set it for that frame only.
|
|
1556 See `defface' for information about SPEC."
|
|
1557 (while spec
|
|
1558 (let ((display (caar spec))
|
|
1559 (atts (cadar spec)))
|
|
1560 (pop spec)
|
|
1561 (when (face-spec-set-match-display display frame)
|
|
1562 ;; Avoid creating frame local duplicates of the global face.
|
|
1563 (unless (and frame (eq display (get face 'custom-face-display)))
|
|
1564 (apply 'face-custom-attributes-set face frame tags atts))
|
|
1565 (unless frame
|
|
1566 (put face 'custom-face-display display))
|
|
1567 (setq spec nil)))))
|
|
1568
|
|
1569 (defvar default-custom-frame-properties nil
|
|
1570 "The frame properties used for the global faces.
|
442
|
1571 Frames not matching these properties should have frame local faces.
|
428
|
1572 The value should be nil, if uninitialized, or a plist otherwise.
|
|
1573 See `defface' for a list of valid keys and values for the plist.")
|
|
1574
|
|
1575 (defun get-custom-frame-properties (&optional frame)
|
|
1576 "Return a plist with the frame properties of FRAME used by custom.
|
|
1577 If FRAME is nil, return the default frame properties."
|
|
1578 (cond (frame
|
|
1579 ;; Try to get from cache.
|
|
1580 (let ((cache (frame-property frame 'custom-properties)))
|
|
1581 (unless cache
|
|
1582 ;; Oh well, get it then.
|
|
1583 (setq cache (extract-custom-frame-properties frame))
|
|
1584 ;; and cache it...
|
|
1585 (set-frame-property frame 'custom-properties cache))
|
|
1586 cache))
|
|
1587 (default-custom-frame-properties)
|
|
1588 (t
|
|
1589 (setq default-custom-frame-properties
|
|
1590 (extract-custom-frame-properties (selected-frame))))))
|
|
1591
|
|
1592 (defun face-spec-update-all-matching (spec display plist)
|
|
1593 "Update all entries in the face spec that could match display to
|
444
|
1594 have the entries from the new plist and return the new spec."
|
428
|
1595 (mapcar
|
|
1596 (lambda (e)
|
|
1597 (let ((entries (car e))
|
|
1598 (options (cadr e))
|
|
1599 (match t)
|
|
1600 dplist
|
|
1601 (new-options plist)
|
|
1602 )
|
|
1603 (unless (eq display t)
|
|
1604 (mapc (lambda (arg)
|
|
1605 (setq dplist (plist-put dplist (car arg) (cadr arg))))
|
|
1606 display))
|
|
1607 (unless (eq entries t)
|
|
1608 (mapc (lambda (arg)
|
|
1609 (setq match (and match (eq (cadr arg)
|
|
1610 (plist-get
|
|
1611 dplist (car arg)
|
|
1612 (cadr arg))))))
|
|
1613 entries))
|
|
1614 (if (not match)
|
|
1615 e
|
|
1616 (while new-options
|
|
1617 (setq options
|
|
1618 (plist-put options (car new-options) (cadr new-options)))
|
|
1619 (setq new-options (cddr new-options)))
|
|
1620 (list entries options))))
|
|
1621 (copy-sequence spec)))
|
444
|
1622
|
|
1623
|
428
|
1624
|
|
1625 (defun face-spec-set-match-display (display &optional frame)
|
|
1626 "Return non-nil if DISPLAY matches FRAME.
|
|
1627 DISPLAY is part of a spec such as can be used in `defface'.
|
|
1628 If FRAME is nil or omitted, the selected frame is used."
|
|
1629 (if (eq display t)
|
|
1630 t
|
|
1631 (let* ((props (get-custom-frame-properties frame))
|
|
1632 (type (plist-get props 'type))
|
|
1633 (class (plist-get props 'class))
|
|
1634 (background (plist-get props 'background))
|
|
1635 (match t)
|
|
1636 (entries display)
|
|
1637 entry req options)
|
|
1638 (while (and entries match)
|
|
1639 (setq entry (car entries)
|
|
1640 entries (cdr entries)
|
|
1641 req (car entry)
|
|
1642 options (cdr entry)
|
|
1643 match (case req
|
|
1644 (type (memq type options))
|
|
1645 (class (memq class options))
|
|
1646 (background (memq background options))
|
|
1647 (t (warn "Unknown req `%S' with options `%S'"
|
|
1648 req options)
|
|
1649 nil))))
|
|
1650 match)))
|
|
1651
|
|
1652 (defun relevant-custom-frames ()
|
|
1653 "List of frames whose custom properties differ from the default."
|
|
1654 (let ((relevant nil)
|
|
1655 (default (get-custom-frame-properties))
|
|
1656 (frames (frame-list))
|
|
1657 frame)
|
|
1658 (while frames
|
|
1659 (setq frame (car frames)
|
|
1660 frames (cdr frames))
|
|
1661 (unless (equal default (get-custom-frame-properties frame))
|
|
1662 (push frame relevant)))
|
|
1663 relevant))
|
|
1664
|
|
1665 (defun initialize-custom-faces (&optional frame)
|
|
1666 "Initialize all custom faces for FRAME.
|
|
1667 If FRAME is nil or omitted, initialize them for all frames."
|
|
1668 (mapc (lambda (symbol)
|
|
1669 (let ((spec (or (get symbol 'saved-face)
|
|
1670 (get symbol 'face-defface-spec))))
|
|
1671 (when spec
|
|
1672 ;; No need to init-face-from-resources -- code in
|
|
1673 ;; `init-frame-faces' does it already.
|
|
1674 (face-display-set symbol spec frame))))
|
|
1675 (face-list)))
|
|
1676
|
|
1677 (defun custom-initialize-frame (frame)
|
|
1678 "Initialize frame-local custom faces for FRAME if necessary."
|
|
1679 (unless (equal (get-custom-frame-properties)
|
|
1680 (get-custom-frame-properties frame))
|
|
1681 (initialize-custom-faces frame)))
|
|
1682
|
440
|
1683 (defun startup-initialize-custom-faces ()
|
|
1684 "Reset faces created by defface. Only called at startup.
|
|
1685 Don't use this function in your program."
|
|
1686 (when default-custom-frame-properties
|
|
1687 ;; Reset default value to the actual frame, not stream.
|
|
1688 (setq default-custom-frame-properties
|
|
1689 (extract-custom-frame-properties (selected-frame)))
|
|
1690 ;; like initialize-custom-faces but removes property first.
|
|
1691 (mapc (lambda (symbol)
|
|
1692 (let ((spec (or (get symbol 'saved-face)
|
|
1693 (get symbol 'face-defface-spec))))
|
|
1694 (when spec
|
|
1695 ;; Reset faces created during auto-autoloads loading.
|
|
1696 (reset-face symbol)
|
|
1697 ;; And set it according to the spec.
|
|
1698 (face-display-set symbol spec nil))))
|
|
1699 (face-list))))
|
|
1700
|
428
|
1701
|
|
1702 (defun make-empty-face (name &optional doc-string temporary)
|
|
1703 "Like `make-face', but doesn't query the resource database."
|
|
1704 (let ((init-face-from-resources nil))
|
|
1705 (make-face name doc-string temporary)))
|
|
1706
|
|
1707 (defun init-face-from-resources (face &optional locale)
|
|
1708 "Initialize FACE from the resource database.
|
3027
|
1709 If LOCALE is specified, it should be a frame, device, or `global', and
|
428
|
1710 the face will be resourced over that locale. Otherwise, the face will
|
|
1711 be resourced over all possible locales (i.e. all frames, all devices,
|
3027
|
1712 and `global')."
|
428
|
1713 (cond ((null init-face-from-resources)
|
|
1714 ;; Do nothing.
|
|
1715 )
|
|
1716 ((not locale)
|
|
1717 ;; Global, set for all frames.
|
|
1718 (progn
|
|
1719 (init-face-from-resources face 'global)
|
|
1720 (let ((devices (device-list)))
|
|
1721 (while devices
|
|
1722 (init-face-from-resources face (car devices))
|
|
1723 (setq devices (cdr devices))))
|
|
1724 (let ((frames (frame-list)))
|
|
1725 (while frames
|
|
1726 (init-face-from-resources face (car frames))
|
|
1727 (setq frames (cdr frames))))))
|
|
1728 (t
|
|
1729 ;; Specific.
|
|
1730 (let ((devtype (cond ((devicep locale) (device-type locale))
|
|
1731 ((framep locale) (frame-type locale))
|
|
1732 (t nil))))
|
|
1733 (cond ((or (and (not devtype) (featurep 'x)) (eq 'x devtype))
|
502
|
1734 (declare-fboundp (x-init-face-from-resources face locale)))
|
428
|
1735 ((or (not devtype) (eq 'tty devtype))
|
|
1736 ;; Nothing to do for TTYs?
|
|
1737 ))))))
|
|
1738
|
|
1739 (defun init-device-faces (device)
|
|
1740 ;; First, add any device-local face resources.
|
|
1741 (when init-face-from-resources
|
|
1742 (loop for face in (face-list) do
|
|
1743 (init-face-from-resources face device))
|
|
1744 ;; Then do any device-specific initialization.
|
|
1745 (cond ((eq 'x (device-type device))
|
502
|
1746 (declare-fboundp (x-init-device-faces device)))
|
462
|
1747 ((eq 'gtk (device-type device))
|
502
|
1748 (declare-fboundp (gtk-init-device-faces device)))
|
428
|
1749 ((eq 'mswindows (device-type device))
|
502
|
1750 (declare-fboundp (mswindows-init-device-faces device)))
|
428
|
1751 ;; Nothing to do for TTYs?
|
|
1752 )
|
|
1753 (or (eq 'stream (device-type device))
|
|
1754 (init-other-random-faces device))))
|
|
1755
|
|
1756 (defun init-frame-faces (frame)
|
|
1757 (when init-face-from-resources
|
|
1758 ;; First, add any frame-local face resources.
|
|
1759 (loop for face in (face-list) do
|
|
1760 (init-face-from-resources face frame))
|
|
1761 ;; Then do any frame-specific initialization.
|
|
1762 (cond ((eq 'x (frame-type frame))
|
502
|
1763 (declare-fboundp (x-init-frame-faces frame)))
|
462
|
1764 ((eq 'gtk (frame-type frame))
|
502
|
1765 (declare-fboundp (gtk-init-frame-faces frame)))
|
428
|
1766 ((eq 'mswindows (frame-type frame))
|
502
|
1767 (declare-fboundp (mswindows-init-frame-faces frame)))
|
428
|
1768 ;; Is there anything which should be done for TTY's?
|
|
1769 )))
|
|
1770
|
872
|
1771 ;; Called when the first device created.
|
428
|
1772
|
872
|
1773 (defun init-global-faces (device)
|
|
1774 (let ((Face-frob-property-device-considered-current device))
|
|
1775 ;; Look for global face resources.
|
|
1776 (loop for face in (face-list) do
|
|
1777 (init-face-from-resources face 'global))
|
|
1778 ;; Further frobbing.
|
|
1779 (and (featurep 'x) (declare-fboundp (x-init-global-faces)))
|
|
1780 (and (featurep 'gtk) (declare-fboundp (gtk-init-global-faces)))
|
|
1781 (and (featurep 'mswindows) (declare-fboundp (mswindows-init-global-faces)))
|
462
|
1782
|
872
|
1783 ;; for bold and the like, make the global specification be bold etc.
|
|
1784 ;; if the user didn't already specify a value. These will also be
|
|
1785 ;; frobbed further in init-other-random-faces.
|
|
1786 (unless (face-font 'bold 'global)
|
|
1787 (make-face-bold 'bold 'global))
|
|
1788 ;;
|
|
1789 (unless (face-font 'italic 'global)
|
|
1790 (make-face-italic 'italic 'global))
|
|
1791 ;;
|
428
|
1792 (unless (face-font 'bold-italic 'global)
|
872
|
1793 (make-face-bold-italic 'bold-italic 'global)
|
|
1794 (unless (face-font 'bold-italic 'global)
|
|
1795 (copy-face 'bold 'bold-italic)
|
|
1796 (make-face-italic 'bold-italic)))
|
428
|
1797
|
872
|
1798 (when (face-equal 'bold 'bold-italic device)
|
|
1799 (copy-face 'italic 'bold-italic)
|
|
1800 (make-face-bold 'bold-italic))))
|
428
|
1801
|
|
1802
|
|
1803 ;; These warnings are there for a reason. Just specify your fonts
|
|
1804 ;; correctly. Deal with it. Additionally, one can use
|
|
1805 ;; `log-warning-minimum-level' instead of this.
|
|
1806 ;(defvar inhibit-font-complaints nil
|
|
1807 ; "Whether to suppress complaints about incomplete sets of fonts.")
|
|
1808
|
|
1809 (defun face-complain-about-font (face device)
|
|
1810 (if (symbolp face) (setq face (symbol-name face)))
|
|
1811 ;; (if (not inhibit-font-complaints)
|
707
|
1812 ;; complaining for printers is generally annoying.
|
|
1813 (unless (device-printer-p device)
|
|
1814 (display-warning
|
|
1815 'font
|
|
1816 (let ((default-name (face-font-name 'default device)))
|
|
1817 (format "%s: couldn't deduce %s %s version of the font
|
428
|
1818 %S.
|
|
1819
|
|
1820 Please specify X resources to make the %s face
|
|
1821 visually distinguishable from the default face.
|
|
1822 For example, you could add one of the following to $HOME/Emacs:
|
|
1823
|
2703
|
1824 XEmacs.%s.attributeFont: -dt-*-medium-i-*
|
428
|
1825 or
|
2703
|
1826 XEmacs.%s.attributeForeground: hotpink\n"
|
707
|
1827 invocation-name
|
|
1828 (if (string-match "\\`[aeiouAEIOU]" face) "an" "a")
|
|
1829 face
|
|
1830 default-name
|
|
1831 face
|
|
1832 face
|
|
1833 face
|
|
1834 )))))
|
428
|
1835
|
|
1836
|
|
1837 ;; #### This is quite a mess. We should use the custom mechanism for
|
|
1838 ;; most of this stuff. Currently we don't do it, because Custom
|
|
1839 ;; doesn't use specifiers (yet.) FSF does it the Right Way.
|
|
1840
|
|
1841 ;; For instance, the definition of `bold' should be something like
|
|
1842 ;; (defface bold ((t (:bold t))) "Bold text.") -- and `:bold t' should
|
|
1843 ;; make sure that everything works properly.
|
|
1844
|
|
1845 (defun init-other-random-faces (device)
|
|
1846 "Initialize the colors and fonts of the bold, italic, bold-italic,
|
|
1847 zmacs-region, list-mode-item-selected, highlight, primary-selection,
|
|
1848 secondary-selection, and isearch faces when each device is created. If
|
|
1849 you want to add code to do stuff like this, use the create-device-hook."
|
|
1850
|
|
1851 ;; try to make 'bold look different from the default on this device.
|
|
1852 ;; If that doesn't work at all, then issue a warning.
|
|
1853 (unless (face-differs-from-default-p 'bold device)
|
|
1854 (make-face-bold 'bold device)
|
|
1855 (unless (face-differs-from-default-p 'bold device)
|
|
1856 (make-face-unbold 'bold device)
|
|
1857 (unless (face-differs-from-default-p 'bold device)
|
|
1858 ;; the luser specified one of the bogus font names
|
|
1859 (face-complain-about-font 'bold device))))
|
|
1860
|
|
1861 ;; Similar for italic.
|
|
1862 ;; It's unreasonable to expect to be able to make a font italic all
|
|
1863 ;; the time. For many languages, italic is an alien concept.
|
|
1864 ;; Basically, because italic is not a globally meaningful concept,
|
440
|
1865 ;; the use of the italic face should really be obsoleted.
|
428
|
1866
|
|
1867 ;; I disagree with above. In many languages, the concept of capital
|
|
1868 ;; letters is just as alien, and yet we use them. Italic is here to
|
|
1869 ;; stay. -hniksic
|
|
1870
|
|
1871 ;; In a Solaris Japanese environment, there just aren't any italic
|
|
1872 ;; fonts - period. CDE recognizes this reality, and fonts
|
|
1873 ;; -dt-interface user-medium-r-normal-*-*-*-*-*-*-*-*-* don't come
|
|
1874 ;; in italic versions. So we first try to make the font bold before
|
|
1875 ;; complaining.
|
|
1876 (unless (face-differs-from-default-p 'italic device)
|
|
1877 (make-face-italic 'italic device)
|
|
1878 (unless (face-differs-from-default-p 'italic device)
|
|
1879 (make-face-bold 'italic device)
|
|
1880 (unless (face-differs-from-default-p 'italic device)
|
|
1881 (face-complain-about-font 'italic device))))
|
|
1882
|
|
1883 ;; similar for bold-italic.
|
|
1884 (unless (face-differs-from-default-p 'bold-italic device)
|
|
1885 (make-face-bold-italic 'bold-italic device)
|
|
1886 ;; if we couldn't get a bold-italic version, try just bold.
|
|
1887 (unless (face-differs-from-default-p 'bold-italic device)
|
|
1888 (make-face-bold 'bold-italic device)
|
|
1889 ;; if we couldn't get bold or bold-italic, then that's probably because
|
|
1890 ;; the default font is bold, so make the `bold-italic' face be unbold.
|
|
1891 (unless (face-differs-from-default-p 'bold-italic device)
|
|
1892 (make-face-unbold 'bold-italic device)
|
|
1893 (make-face-italic 'bold-italic device)
|
|
1894 (unless (face-differs-from-default-p 'bold-italic device)
|
|
1895 ;; if that didn't work, try plain italic
|
|
1896 ;; (can this ever happen? what the hell.)
|
|
1897 (make-face-italic 'bold-italic device)
|
|
1898 (unless (face-differs-from-default-p 'bold-italic device)
|
|
1899 ;; then bitch and moan.
|
|
1900 (face-complain-about-font 'bold-italic device))))))
|
|
1901
|
|
1902 ;; Set the text-cursor colors unless already specified.
|
|
1903 (when (and (not (eq 'tty (device-type device)))
|
|
1904 (not (face-background 'text-cursor 'global))
|
|
1905 (face-property-equal 'text-cursor 'default 'background device))
|
|
1906 (set-face-background 'text-cursor [default foreground] 'global
|
|
1907 nil 'append))
|
|
1908 (when (and (not (eq 'tty (device-type device)))
|
|
1909 (not (face-foreground 'text-cursor 'global))
|
|
1910 (face-property-equal 'text-cursor 'default 'foreground device))
|
|
1911 (set-face-foreground 'text-cursor [default background] 'global
|
|
1912 nil 'append))
|
|
1913 )
|
|
1914
|
442
|
1915 ;; New function with 20.1, suggested by Per Abrahamsen, coded by Kyle
|
|
1916 ;; Jones and Hrvoje Niksic.
|
428
|
1917 (defun set-face-stipple (face pixmap &optional frame)
|
|
1918 "Change the stipple pixmap of FACE to PIXMAP.
|
|
1919 This is an Emacs compatibility function; consider using
|
|
1920 set-face-background-pixmap instead.
|
|
1921
|
|
1922 PIXMAP should be a string, the name of a file of pixmap data.
|
442
|
1923 The directories listed in the variables `x-bitmap-file-path' and
|
|
1924 `mswindows-bitmap-file-path' under X and MS Windows respectively
|
|
1925 are searched.
|
428
|
1926
|
|
1927 Alternatively, PIXMAP may be a list of the form (WIDTH HEIGHT
|
|
1928 DATA) where WIDTH and HEIGHT are the size in pixels, and DATA is
|
|
1929 a string, containing the raw bits of the bitmap. XBM data is
|
|
1930 expected in this case, other types of image data will not work.
|
|
1931
|
|
1932 If the optional FRAME argument is provided, change only
|
|
1933 in that frame; otherwise change each frame."
|
|
1934 (while (not (find-face face))
|
446
|
1935 (setq face (wrong-type-argument 'facep face)))
|
502
|
1936 (let ((bitmap-path
|
|
1937 (ecase (console-type)
|
|
1938 (x (declare-boundp x-bitmap-file-path))
|
|
1939 (mswindows (declare-boundp mswindows-bitmap-file-path))))
|
442
|
1940 instantiator)
|
|
1941 (while
|
|
1942 (null
|
|
1943 (setq instantiator
|
|
1944 (cond ((stringp pixmap)
|
|
1945 (let ((file (if (file-name-absolute-p pixmap)
|
|
1946 pixmap
|
|
1947 (locate-file pixmap bitmap-path
|
|
1948 '(".xbm" "")))))
|
|
1949 (and file
|
|
1950 `[xbm :file ,file])))
|
|
1951 ((and (listp pixmap) (= (length pixmap) 3))
|
|
1952 `[xbm :data ,pixmap])
|
|
1953 (t nil))))
|
|
1954 ;; We're signaling a continuable error; let's make sure the
|
|
1955 ;; function `stipple-pixmap-p' at least exists.
|
|
1956 (flet ((stipple-pixmap-p (pixmap)
|
|
1957 (or (stringp pixmap)
|
|
1958 (and (listp pixmap) (= (length pixmap) 3)))))
|
|
1959 (setq pixmap (signal 'wrong-type-argument
|
|
1960 (list 'stipple-pixmap-p pixmap)))))
|
446
|
1961 (check-type frame (or null frame))
|
442
|
1962 (set-face-background-pixmap face instantiator frame)))
|
428
|
1963
|
|
1964
|
|
1965 ;; Create the remaining standard faces now. This way, packages that we dump
|
|
1966 ;; can reference these faces as parents.
|
|
1967 ;;
|
|
1968 ;; The default, modeline, left-margin, right-margin, text-cursor,
|
|
1969 ;; and pointer faces are created in C.
|
|
1970
|
|
1971 (make-face 'bold "Bold text.")
|
|
1972 (make-face 'italic "Italic text.")
|
|
1973 (make-face 'bold-italic "Bold-italic text.")
|
|
1974 (make-face 'underline "Underlined text.")
|
|
1975 (or (face-differs-from-default-p 'underline)
|
|
1976 (set-face-underline-p 'underline t 'global '(default)))
|
735
|
1977 (make-face 'zmacs-region "Used on highlighted region between point and mark.")
|
428
|
1978 (make-face 'isearch "Used on region matched by isearch.")
|
|
1979 (make-face 'isearch-secondary "Face to use for highlighting all matches.")
|
|
1980 (make-face 'list-mode-item-selected
|
|
1981 "Face for the selected list item in list-mode.")
|
|
1982 (make-face 'highlight "Highlight face.")
|
|
1983 (make-face 'primary-selection "Primary selection face.")
|
|
1984 (make-face 'secondary-selection "Secondary selection face.")
|
|
1985
|
|
1986 ;; Several useful color faces.
|
|
1987 (dolist (color '(red green blue yellow))
|
|
1988 (make-face color (concat (symbol-name color) " text."))
|
|
1989 (set-face-foreground color (symbol-name color) nil 'color))
|
|
1990
|
|
1991 ;; Make some useful faces. This happens very early, before creating
|
|
1992 ;; the first non-stream device.
|
|
1993
|
|
1994 (set-face-background 'text-cursor
|
711
|
1995 '(((win default) . "Red3"))
|
428
|
1996 'global)
|
|
1997
|
|
1998 ;; some older X servers don't recognize "darkseagreen2"
|
|
1999 (set-face-background 'highlight
|
711
|
2000 '(((win default color) . "darkseagreen2")
|
|
2001 ((win default color) . "green")
|
|
2002 ((win default grayscale) . "gray53"))
|
428
|
2003 'global)
|
|
2004 (set-face-background-pixmap 'highlight
|
711
|
2005 '(((win default mono) . "gray1"))
|
428
|
2006 'global)
|
|
2007
|
|
2008 (set-face-background 'zmacs-region
|
711
|
2009 '(((win default color) . "gray65")
|
|
2010 ((win default grayscale) . "gray65"))
|
428
|
2011 'global)
|
|
2012 (set-face-background-pixmap 'zmacs-region
|
711
|
2013 '(((win default mono) . "gray3"))
|
428
|
2014 'global)
|
|
2015
|
|
2016 (set-face-background 'list-mode-item-selected
|
711
|
2017 '(((win default color) . "gray68")
|
|
2018 ((win default grayscale) . "gray68")
|
|
2019 ((win default mono) . [default foreground]))
|
428
|
2020 'global)
|
|
2021 (set-face-foreground 'list-mode-item-selected
|
711
|
2022 '(((win default mono) . [default background]))
|
428
|
2023 'global)
|
|
2024
|
|
2025 (set-face-background 'primary-selection
|
711
|
2026 '(((win default color) . "gray65")
|
|
2027 ((win default grayscale) . "gray65"))
|
428
|
2028 'global)
|
|
2029 (set-face-background-pixmap 'primary-selection
|
711
|
2030 '(((win default mono) . "gray3"))
|
428
|
2031 'global)
|
|
2032
|
|
2033 (set-face-background 'secondary-selection
|
711
|
2034 '(((win default color) . "paleturquoise")
|
|
2035 ((win default color) . "green")
|
|
2036 ((win default grayscale) . "gray53"))
|
428
|
2037 'global)
|
|
2038 (set-face-background-pixmap 'secondary-selection
|
711
|
2039 '(((win default mono) . "gray1"))
|
428
|
2040 'global)
|
|
2041
|
|
2042 (set-face-background 'isearch
|
711
|
2043 '(((win default color) . "paleturquoise")
|
|
2044 ((win default color) . "green"))
|
428
|
2045 'global)
|
|
2046
|
|
2047 ;; #### This should really, I mean *really*, be converted to some form
|
|
2048 ;; of `defface' one day.
|
|
2049 (set-face-foreground 'isearch-secondary
|
711
|
2050 '(((win default color) . "red3"))
|
428
|
2051 'global)
|
|
2052
|
|
2053 ;; Define some logical color names to be used when reading the pixmap files.
|
|
2054 (if (featurep 'xpm)
|
|
2055 (setq xpm-color-symbols
|
|
2056 (list
|
444
|
2057 '("foreground" (face-foreground 'default))
|
|
2058 '("background" (face-background 'default))
|
|
2059 '("backgroundToolBarColor"
|
|
2060 (or
|
|
2061 (and
|
|
2062 (featurep 'x)
|
|
2063 (x-get-resource "backgroundToolBarColor"
|
|
2064 "BackgroundToolBarColor" 'string
|
|
2065 nil nil 'warn))
|
428
|
2066
|
444
|
2067 (face-background 'toolbar)))
|
|
2068 '("foregroundToolBarColor"
|
|
2069 (or
|
|
2070 (and
|
|
2071 (featurep 'x)
|
|
2072 (x-get-resource "foregroundToolBarColor"
|
|
2073 "ForegroundToolBarColor" 'string
|
|
2074 nil nil 'warn))
|
|
2075 (face-foreground 'toolbar)))
|
428
|
2076 )))
|
|
2077
|
|
2078 (when (featurep 'tty)
|
|
2079 (set-face-highlight-p 'bold t 'global '(default tty))
|
|
2080 (set-face-underline-p 'italic t 'global '(default tty))
|
|
2081 (set-face-highlight-p 'bold-italic t 'global '(default tty))
|
|
2082 (set-face-underline-p 'bold-italic t 'global '(default tty))
|
|
2083 (set-face-highlight-p 'highlight t 'global '(default tty))
|
|
2084 (set-face-reverse-p 'text-cursor t 'global '(default tty))
|
|
2085 (set-face-reverse-p 'modeline t 'global '(default tty))
|
|
2086 (set-face-reverse-p 'zmacs-region t 'global '(default tty))
|
|
2087 (set-face-reverse-p 'primary-selection t 'global '(default tty))
|
|
2088 (set-face-underline-p 'secondary-selection t 'global '(default tty))
|
|
2089 (set-face-reverse-p 'list-mode-item-selected t 'global '(default tty))
|
|
2090 (set-face-reverse-p 'isearch t 'global '(default tty))
|
|
2091 )
|
|
2092
|
|
2093 ;;; faces.el ends here
|