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