Commit | Line | Data |
---|---|---|
5f5c8ee5 | 1 | ;;; faces.el --- Lisp faces |
465fceed | 2 | |
ba318903 | 3 | ;; Copyright (C) 1992-1996, 1998-2014 Free Software Foundation, Inc. |
465fceed | 4 | |
34dc21db | 5 | ;; Maintainer: emacs-devel@gnu.org |
30764597 | 6 | ;; Keywords: internal |
bd78fa1d | 7 | ;; Package: emacs |
6228c05b | 8 | |
465fceed ER |
9 | ;; This file is part of GNU Emacs. |
10 | ||
eb3fa2cf | 11 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
465fceed | 12 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
13 | ;; the Free Software Foundation, either version 3 of the License, or |
14 | ;; (at your option) any later version. | |
465fceed ER |
15 | |
16 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 22 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
465fceed ER |
23 | |
24 | ;;; Commentary: | |
25 | ||
465fceed ER |
26 | ;;; Code: |
27 | ||
f18b81e6 GM |
28 | (defcustom term-file-prefix (purecopy "term/") |
29 | "If non-nil, Emacs startup performs terminal-specific initialization. | |
30 | It does this by: (load (concat term-file-prefix (getenv \"TERM\"))) | |
31 | ||
32 | You may set this variable to nil in your init file if you do not wish | |
33 | the terminal-initialization file to be loaded." | |
34 | :type '(choice (const :tag "No terminal-specific initialization" nil) | |
35 | (string :tag "Name of directory with term files")) | |
36 | :group 'terminals) | |
37 | ||
c8ccffb1 | 38 | (declare-function xw-defined-colors "term/common-win" (&optional frame)) |
5f5c8ee5 | 39 | |
b782a458 | 40 | (defvar help-xref-stack-item) |
2aef0850 JL |
41 | |
42 | (defvar face-name-history nil | |
43 | "History list for some commands that read face names. | |
44 | Maximum length of the history list is determined by the value | |
45 | of `history-length', which see.") | |
46 | ||
5f5c8ee5 GM |
47 | \f |
48 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
49 | ;;; Font selection. | |
50 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
51 | ||
52 | (defgroup font-selection nil | |
53 | "Influencing face font selection." | |
54 | :group 'faces) | |
55 | ||
56 | ||
57 | (defcustom face-font-selection-order | |
58 | '(:width :height :weight :slant) | |
9201cc28 | 59 | "A list specifying how face font selection chooses fonts. |
5f5c8ee5 GM |
60 | Each of the four symbols `:width', `:height', `:weight', and `:slant' |
61 | must appear once in the list, and the list must not contain any other | |
7c626e9d | 62 | elements. Font selection first tries to find a best matching font |
b73f65b6 | 63 | for those face attributes that appear before in the list. For |
5f5c8ee5 GM |
64 | example, if `:slant' appears before `:height', font selection first |
65 | tries to find a font with a suitable slant, even if this results in | |
66 | a font height that isn't optimal." | |
239ad97f | 67 | :tag "Font selection order" |
94354bdd | 68 | :type '(list symbol symbol symbol symbol) |
5f5c8ee5 GM |
69 | :group 'font-selection |
70 | :set #'(lambda (symbol value) | |
71 | (set-default symbol value) | |
72 | (internal-set-font-selection-order value))) | |
73 | ||
18f1dcb4 | 74 | |
ed008205 | 75 | ;; In the absence of Fontconfig support, Monospace and Sans Serif are |
80073c33 CY |
76 | ;; unavailable, and we fall back on the courier and helv families, |
77 | ;; which are generally available. | |
5f5c8ee5 | 78 | (defcustom face-font-family-alternatives |
1e8780b1 | 79 | (mapcar (lambda (arg) (mapcar 'purecopy arg)) |
d5f57335 | 80 | '(("Monospace" "courier" "fixed") |
f37a389e | 81 | ("courier" "CMU Typewriter Text" "fixed") |
ed008205 | 82 | ("Sans Serif" "helv" "helvetica" "arial" "fixed") |
1e8780b1 | 83 | ("helv" "helvetica" "arial" "fixed"))) |
9201cc28 | 84 | "Alist of alternative font family names. |
86886bce | 85 | Each element has the form (FAMILY ALTERNATIVE1 ALTERNATIVE2 ...). |
5f5c8ee5 GM |
86 | If fonts of family FAMILY can't be loaded, try ALTERNATIVE1, then |
87 | ALTERNATIVE2 etc." | |
239ad97f | 88 | :tag "Alternative font families to try" |
94354bdd | 89 | :type '(repeat (repeat string)) |
5f5c8ee5 GM |
90 | :group 'font-selection |
91 | :set #'(lambda (symbol value) | |
92 | (set-default symbol value) | |
93 | (internal-set-alternative-font-family-alist value))) | |
94 | ||
95 | ||
18f1dcb4 GM |
96 | ;; This is defined originally in xfaces.c. |
97 | (defcustom face-font-registry-alternatives | |
1e8780b1 | 98 | (mapcar (lambda (arg) (mapcar 'purecopy arg)) |
0fda9b75 | 99 | (if (featurep 'w32) |
990d68dd | 100 | '(("iso8859-1" "ms-oemlatin") |
e38c812e | 101 | ("gb2312.1980" "gb2312" "gbk" "gb18030") |
c97db4e4 AI |
102 | ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978") |
103 | ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987") | |
104 | ("muletibetan-2" "muletibetan-0")) | |
e38c812e | 105 | '(("gb2312.1980" "gb2312.80&gb8565.88" "gbk" "gb18030") |
c97db4e4 AI |
106 | ("jisx0208.1990" "jisx0208.1983" "jisx0208.1978") |
107 | ("ksc5601.1989" "ksx1001.1992" "ksc5601.1987") | |
1e8780b1 | 108 | ("muletibetan-2" "muletibetan-0")))) |
9201cc28 | 109 | "Alist of alternative font registry names. |
86886bce | 110 | Each element has the form (REGISTRY ALTERNATIVE1 ALTERNATIVE2 ...). |
8ac2d32f KH |
111 | If fonts of registry REGISTRY can be loaded, font selection |
112 | tries to find a best matching font among all fonts of registry | |
113 | REGISTRY, ALTERNATIVE1, ALTERNATIVE2, and etc." | |
239ad97f | 114 | :tag "Alternative font registries to try" |
18f1dcb4 | 115 | :type '(repeat (repeat string)) |
f676894c | 116 | :version "21.1" |
18f1dcb4 GM |
117 | :group 'font-selection |
118 | :set #'(lambda (symbol value) | |
119 | (set-default symbol value) | |
120 | (internal-set-alternative-font-registry-alist value))) | |
121 | ||
bdda3754 | 122 | \f |
5f5c8ee5 GM |
123 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
124 | ;;; Creation, copying. | |
125 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
126 | ||
127 | ||
128 | (defun face-list () | |
94ab793f | 129 | "Return a list of all defined faces." |
5f5c8ee5 GM |
130 | (mapcar #'car face-new-frame-defaults)) |
131 | ||
5f5c8ee5 GM |
132 | (defun make-face (face &optional no-init-from-resources) |
133 | "Define a new face with name FACE, a symbol. | |
fb5b8aca CY |
134 | Do not call this directly from Lisp code; use `defface' instead. |
135 | ||
5f91455c MD |
136 | If FACE is already known as a face, leave it unmodified. Return FACE. |
137 | ||
138 | NO-INIT-FROM-RESOURCES has been deprecated and is no longer used | |
139 | and will go away. Handling of conditional X resources application | |
140 | has been pushed down to make-x-resource-internal itself." | |
2aef0850 JL |
141 | (interactive (list (read-from-minibuffer |
142 | "Make face: " nil nil t 'face-name-history))) | |
5f5c8ee5 GM |
143 | (unless (facep face) |
144 | ;; Make frame-local faces (this also makes the global one). | |
145 | (dolist (frame (frame-list)) | |
146 | (internal-make-lisp-face face frame)) | |
147 | ;; Add the face to the face menu. | |
148 | (when (fboundp 'facemenu-add-new-face) | |
149 | (facemenu-add-new-face face)) | |
150 | ;; Define frame-local faces for all frames from X resources. | |
5f91455c | 151 | (make-face-x-resource-internal face)) |
5f5c8ee5 GM |
152 | face) |
153 | ||
5f91455c MD |
154 | ;; Handling of whether to apply X resources or not, has been pushed down |
155 | ;; to make-face-x-resource-internal itself, thus the optional arg is no | |
156 | ;; longer evaluated at all and going away. | |
157 | (set-advertised-calling-convention 'make-face '(face) "24.4") | |
158 | ||
5f5c8ee5 GM |
159 | (defun make-empty-face (face) |
160 | "Define a new, empty face with name FACE. | |
fb5b8aca | 161 | Do not call this directly from Lisp code; use `defface' instead." |
2aef0850 JL |
162 | (interactive (list (read-from-minibuffer |
163 | "Make empty face: " nil nil t 'face-name-history))) | |
5f91455c | 164 | (make-face face)) |
5f5c8ee5 | 165 | |
5f5c8ee5 | 166 | (defun copy-face (old-face new-face &optional frame new-frame) |
fb5b8aca CY |
167 | "Define a face named NEW-FACE, which is a copy of OLD-FACE. |
168 | This function does not copy face customization data, so NEW-FACE | |
169 | will not be made customizable. Most Lisp code should not call | |
170 | this function; use `defface' with :inherit instead. | |
171 | ||
172 | If NEW-FACE already exists as a face, modify it to be like | |
173 | OLD-FACE. If NEW-FACE doesn't already exist, create it. | |
174 | ||
175 | If the optional argument FRAME is a frame, change NEW-FACE on | |
176 | FRAME only. If FRAME is t, copy the frame-independent default | |
177 | specification for OLD-FACE to NEW-FACE. If FRAME is nil, copy | |
178 | the defaults as well as the faces on each existing frame. | |
179 | ||
180 | If the optional fourth argument NEW-FRAME is given, copy the | |
181 | information from face OLD-FACE on frame FRAME to NEW-FACE on | |
182 | frame NEW-FRAME. In this case, FRAME must not be nil." | |
5f5c8ee5 GM |
183 | (let ((inhibit-quit t)) |
184 | (if (null frame) | |
185 | (progn | |
341a1bfb RS |
186 | (when new-frame |
187 | (error "Copying face %s from all frames to one frame" | |
188 | old-face)) | |
189 | (make-empty-face new-face) | |
5f5c8ee5 GM |
190 | (dolist (frame (frame-list)) |
191 | (copy-face old-face new-face frame)) | |
192 | (copy-face old-face new-face t)) | |
341a1bfb | 193 | (make-empty-face new-face) |
5f5c8ee5 GM |
194 | (internal-copy-lisp-face old-face new-face frame new-frame)) |
195 | new-face)) | |
196 | ||
5f5c8ee5 GM |
197 | \f |
198 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
199 | ;;; Predicates, type checks. | |
200 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
201 | ||
202 | (defun facep (face) | |
20d29b0b RS |
203 | "Return non-nil if FACE is a face name; nil otherwise. |
204 | A face name can be a string or a symbol." | |
5f5c8ee5 GM |
205 | (internal-lisp-face-p face)) |
206 | ||
207 | ||
208 | (defun check-face (face) | |
209 | "Signal an error if FACE doesn't name a face. | |
210 | Value is FACE." | |
211 | (unless (facep face) | |
212 | (error "Not a face: %s" face)) | |
213 | face) | |
214 | ||
215 | ||
216 | ;; The ID returned is not to be confused with the internally used IDs | |
217 | ;; of realized faces. The ID assigned to Lisp faces is used to | |
218 | ;; support faces in display table entries. | |
219 | ||
06b60517 | 220 | (defun face-id (face &optional _frame) |
2df447f2 | 221 | "Return the internal ID of face with name FACE. |
b2d5aa46 | 222 | If FACE is a face-alias, return the ID of the target face. |
9ae89a1a RS |
223 | The optional argument FRAME is ignored, since the internal face ID |
224 | of a face name is the same for all frames." | |
5f5c8ee5 | 225 | (check-face face) |
b2d5aa46 JB |
226 | (or (get face 'face) |
227 | (face-id (get face 'face-alias)))) | |
5f5c8ee5 GM |
228 | |
229 | (defun face-equal (face1 face2 &optional frame) | |
230 | "Non-nil if faces FACE1 and FACE2 are equal. | |
231 | Faces are considered equal if all their attributes are equal. | |
a09be93a JB |
232 | If the optional argument FRAME is given, report on FACE1 and FACE2 in that frame. |
233 | If FRAME is t, report on the defaults for FACE1 and FACE2 (for new frames). | |
5f5c8ee5 GM |
234 | If FRAME is omitted or nil, use the selected frame." |
235 | (internal-lisp-face-equal-p face1 face2 frame)) | |
236 | ||
237 | ||
238 | (defun face-differs-from-default-p (face &optional frame) | |
7e07a66d | 239 | "Return non-nil if FACE displays differently from the default face. |
5f5c8ee5 GM |
240 | If the optional argument FRAME is given, report on face FACE in that frame. |
241 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
7e07a66d | 242 | If FRAME is omitted or nil, use the selected frame." |
1151d617 | 243 | (let ((attrs |
833547aa | 244 | (delq :inherit (mapcar 'car face-attribute-name-alist))) |
1151d617 MB |
245 | (differs nil)) |
246 | (while (and attrs (not differs)) | |
247 | (let* ((attr (pop attrs)) | |
248 | (attr-val (face-attribute face attr frame t))) | |
249 | (when (and | |
250 | (not (eq attr-val 'unspecified)) | |
251 | (display-supports-face-attributes-p (list attr attr-val) | |
252 | frame)) | |
253 | (setq differs attr)))) | |
254 | differs)) | |
5f5c8ee5 GM |
255 | |
256 | ||
257 | (defun face-nontrivial-p (face &optional frame) | |
258 | "True if face FACE has some non-nil attribute. | |
259 | If the optional argument FRAME is given, report on face FACE in that frame. | |
260 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
261 | If FRAME is omitted or nil, use the selected frame." | |
262 | (not (internal-lisp-face-empty-p face frame))) | |
263 | ||
264 | ||
265 | \f | |
266 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
267 | ;;; Setting face attributes from X resources. | |
268 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
269 | ||
270 | (defcustom face-x-resources | |
1e8780b1 DN |
271 | (mapcar |
272 | (lambda (arg) | |
273 | ;; FIXME; can we purecopy some of the conses too? | |
e8e4d5c8 SS |
274 | (cons (car arg) |
275 | (cons (purecopy (car (cdr arg))) (purecopy (cdr (cdr arg)))))) | |
5f5c8ee5 | 276 | '((:family (".attributeFamily" . "Face.AttributeFamily")) |
fcea6e23 | 277 | (:foundry (".attributeFoundry" . "Face.AttributeFoundry")) |
5f5c8ee5 GM |
278 | (:width (".attributeWidth" . "Face.AttributeWidth")) |
279 | (:height (".attributeHeight" . "Face.AttributeHeight")) | |
280 | (:weight (".attributeWeight" . "Face.AttributeWeight")) | |
281 | (:slant (".attributeSlant" . "Face.AttributeSlant")) | |
282 | (:foreground (".attributeForeground" . "Face.AttributeForeground")) | |
3c334c14 JD |
283 | (:distant-foreground |
284 | (".attributeDistantForeground" . "Face.AttributeDistantForeground")) | |
5f5c8ee5 GM |
285 | (:background (".attributeBackground" . "Face.AttributeBackground")) |
286 | (:overline (".attributeOverline" . "Face.AttributeOverline")) | |
287 | (:strike-through (".attributeStrikeThrough" . "Face.AttributeStrikeThrough")) | |
288 | (:box (".attributeBox" . "Face.AttributeBox")) | |
289 | (:underline (".attributeUnderline" . "Face.AttributeUnderline")) | |
290 | (:inverse-video (".attributeInverse" . "Face.AttributeInverse")) | |
291 | (:stipple | |
292 | (".attributeStipple" . "Face.AttributeStipple") | |
293 | (".attributeBackgroundPixmap" . "Face.AttributeBackgroundPixmap")) | |
5f5c8ee5 GM |
294 | (:bold (".attributeBold" . "Face.AttributeBold")) |
295 | (:italic (".attributeItalic" . "Face.AttributeItalic")) | |
a0e5a5a4 | 296 | (:font (".attributeFont" . "Face.AttributeFont")) |
1e8780b1 | 297 | (:inherit (".attributeInherit" . "Face.AttributeInherit")))) |
9201cc28 | 298 | "List of X resources and classes for face attributes. |
5f5c8ee5 GM |
299 | Each element has the form (ATTRIBUTE ENTRY1 ENTRY2...) where ATTRIBUTE is |
300 | the name of a face attribute, and each ENTRY is a cons of the form | |
2cb95d1b | 301 | \(RESOURCE . CLASS) with RESOURCE being the resource and CLASS being the |
5f5c8ee5 | 302 | X resource class for the attribute." |
b5325e78 | 303 | :type '(repeat (cons symbol (repeat (cons string string)))) |
5f5c8ee5 GM |
304 | :group 'faces) |
305 | ||
306 | ||
aa360da1 | 307 | (declare-function internal-face-x-get-resource "xfaces.c" |
f20def1f | 308 | (resource class &optional frame)) |
aa360da1 GM |
309 | |
310 | (declare-function internal-set-lisp-face-attribute-from-resource "xfaces.c" | |
311 | (face attr value &optional frame)) | |
312 | ||
5f5c8ee5 GM |
313 | (defun set-face-attribute-from-resource (face attribute resource class frame) |
314 | "Set FACE's ATTRIBUTE from X resource RESOURCE, class CLASS on FRAME. | |
315 | Value is the attribute value specified by the resource, or nil | |
316 | if not present. This function displays a message if the resource | |
317 | specifies an invalid attribute." | |
318 | (let* ((face-name (face-name face)) | |
319 | (value (internal-face-x-get-resource (concat face-name resource) | |
320 | class frame))) | |
321 | (when value | |
322 | (condition-case () | |
323 | (internal-set-lisp-face-attribute-from-resource | |
324 | face attribute (downcase value) frame) | |
325 | (error | |
326 | (message "Face %s, frame %s: invalid attribute %s %s from X resource" | |
327 | face-name frame attribute value)))) | |
328 | value)) | |
329 | ||
330 | ||
331 | (defun set-face-attributes-from-resources (face frame) | |
332 | "Set attributes of FACE from X resources for FRAME." | |
e51fe00a | 333 | (when (memq (framep frame) '(x w32)) |
5f5c8ee5 GM |
334 | (dolist (definition face-x-resources) |
335 | (let ((attribute (car definition))) | |
336 | (dolist (entry (cdr definition)) | |
337 | (set-face-attribute-from-resource face attribute (car entry) | |
338 | (cdr entry) frame)))))) | |
00f51890 SS |
339 | |
340 | ||
5f5c8ee5 GM |
341 | (defun make-face-x-resource-internal (face &optional frame) |
342 | "Fill frame-local FACE on FRAME from X resources. | |
f5e4494c MD |
343 | FRAME nil or not specified means do it for all frames. |
344 | ||
345 | If `inhibit-x-resources' is non-nil, this function does nothing." | |
346 | (unless inhibit-x-resources | |
347 | (dolist (frame (if (null frame) (frame-list) (list frame))) | |
348 | ;; `x-create-frame' already took care of correctly handling | |
349 | ;; the reverse video case-- do _not_ touch the default face | |
350 | (unless (and (eq face 'default) | |
351 | (frame-parameter frame 'reverse)) | |
352 | (set-face-attributes-from-resources face frame))))) | |
5f5c8ee5 GM |
353 | |
354 | ||
355 | \f | |
356 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
357 | ;;; Retrieving face attributes. | |
358 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
359 | ||
feaad827 | 360 | (defun face-name (face) |
465fceed | 361 | "Return the name of face FACE." |
5f5c8ee5 GM |
362 | (symbol-name (check-face face))) |
363 | ||
364 | ||
833547aa RS |
365 | (defun face-all-attributes (face &optional frame) |
366 | "Return an alist stating the attributes of FACE. | |
367 | Each element of the result has the form (ATTR-NAME . ATTR-VALUE). | |
37766706 | 368 | If FRAME is omitted or nil the value describes the default attributes, |
833547aa RS |
369 | but if you specify FRAME, the value describes the attributes |
370 | of FACE on FRAME." | |
606c9f59 RS |
371 | (mapcar (lambda (pair) |
372 | (let ((attr (car pair))) | |
373 | (cons attr (face-attribute face attr (or frame t))))) | |
833547aa RS |
374 | face-attribute-name-alist)) |
375 | ||
c7f814cb | 376 | (defun face-attribute (face attribute &optional frame inherit) |
5f5c8ee5 GM |
377 | "Return the value of FACE's ATTRIBUTE on FRAME. |
378 | If the optional argument FRAME is given, report on face FACE in that frame. | |
379 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
c7f814cb | 380 | If FRAME is omitted or nil, use the selected frame. |
5f5c8ee5 | 381 | |
c7f814cb MB |
382 | If INHERIT is nil, only attributes directly defined by FACE are considered, |
383 | so the return value may be `unspecified', or a relative value. | |
384 | If INHERIT is non-nil, FACE's definition of ATTRIBUTE is merged with the | |
385 | faces specified by its `:inherit' attribute; however the return value | |
386 | may still be `unspecified' or relative. | |
387 | If INHERIT is a face or a list of faces, then the result is further merged | |
388 | with that face (or faces), until it becomes specified and absolute. | |
389 | ||
390 | To ensure that the return value is always specified and absolute, use a | |
391 | value of `default' for INHERIT; this will resolve any unspecified or | |
392 | relative values by merging with the `default' face (which is always | |
393 | completely specified)." | |
394 | (let ((value (internal-get-lisp-face-attribute face attribute frame))) | |
395 | (when (and inherit (face-attribute-relative-p attribute value)) | |
396 | ;; VALUE is relative, so merge with inherited faces | |
397 | (let ((inh-from (face-attribute face :inherit frame))) | |
398 | (unless (or (null inh-from) (eq inh-from 'unspecified)) | |
621e71ee SM |
399 | (condition-case nil |
400 | (setq value | |
401 | (face-attribute-merged-with attribute value inh-from frame)) | |
402 | ;; The `inherit' attribute may point to non existent faces. | |
403 | (error nil))))) | |
c7f814cb MB |
404 | (when (and inherit |
405 | (not (eq inherit t)) | |
406 | (face-attribute-relative-p attribute value)) | |
b6b90dfc | 407 | ;; We should merge with INHERIT as well |
c7f814cb MB |
408 | (setq value (face-attribute-merged-with attribute value inherit frame))) |
409 | value)) | |
5f5c8ee5 | 410 | |
c7f814cb MB |
411 | (defun face-attribute-merged-with (attribute value faces &optional frame) |
412 | "Merges ATTRIBUTE, initially VALUE, with faces from FACES until absolute. | |
413 | FACES may be either a single face or a list of faces. | |
522fb950 | 414 | \[This is an internal function.]" |
c7f814cb MB |
415 | (cond ((not (face-attribute-relative-p attribute value)) |
416 | value) | |
417 | ((null faces) | |
418 | value) | |
419 | ((consp faces) | |
420 | (face-attribute-merged-with | |
421 | attribute | |
422 | (face-attribute-merged-with attribute value (car faces) frame) | |
423 | (cdr faces) | |
424 | frame)) | |
425 | (t | |
426 | (merge-face-attribute attribute | |
427 | value | |
428 | (face-attribute faces attribute frame t))))) | |
429 | ||
430 | ||
431 | (defmacro face-attribute-specified-or (value &rest body) | |
432 | "Return VALUE, unless it's `unspecified', in which case evaluate BODY and return the result." | |
433 | (let ((temp (make-symbol "value"))) | |
434 | `(let ((,temp ,value)) | |
435 | (if (not (eq ,temp 'unspecified)) | |
436 | ,temp | |
437 | ,@body)))) | |
438 | ||
439 | (defun face-foreground (face &optional frame inherit) | |
5f5c8ee5 GM |
440 | "Return the foreground color name of FACE, or nil if unspecified. |
441 | If the optional argument FRAME is given, report on face FACE in that frame. | |
442 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
c7f814cb | 443 | If FRAME is omitted or nil, use the selected frame. |
5f5c8ee5 | 444 | |
c7f814cb MB |
445 | If INHERIT is nil, only a foreground color directly defined by FACE is |
446 | considered, so the return value may be nil. | |
447 | If INHERIT is t, and FACE doesn't define a foreground color, then any | |
448 | foreground color that FACE inherits through its `:inherit' attribute | |
449 | is considered as well; however the return value may still be nil. | |
450 | If INHERIT is a face or a list of faces, then it is used to try to | |
451 | resolve an unspecified foreground color. | |
452 | ||
453 | To ensure that a valid color is always returned, use a value of | |
454 | `default' for INHERIT; this will resolve any unspecified values by | |
455 | merging with the `default' face (which is always completely specified)." | |
456 | (face-attribute-specified-or (face-attribute face :foreground frame inherit) | |
457 | nil)) | |
458 | ||
459 | (defun face-background (face &optional frame inherit) | |
5f5c8ee5 GM |
460 | "Return the background color name of FACE, or nil if unspecified. |
461 | If the optional argument FRAME is given, report on face FACE in that frame. | |
462 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
c7f814cb | 463 | If FRAME is omitted or nil, use the selected frame. |
5f5c8ee5 | 464 | |
c7f814cb MB |
465 | If INHERIT is nil, only a background color directly defined by FACE is |
466 | considered, so the return value may be nil. | |
467 | If INHERIT is t, and FACE doesn't define a background color, then any | |
468 | background color that FACE inherits through its `:inherit' attribute | |
469 | is considered as well; however the return value may still be nil. | |
470 | If INHERIT is a face or a list of faces, then it is used to try to | |
471 | resolve an unspecified background color. | |
472 | ||
473 | To ensure that a valid color is always returned, use a value of | |
474 | `default' for INHERIT; this will resolve any unspecified values by | |
475 | merging with the `default' face (which is always completely specified)." | |
476 | (face-attribute-specified-or (face-attribute face :background frame inherit) | |
477 | nil)) | |
478 | ||
479 | (defun face-stipple (face &optional frame inherit) | |
5f5c8ee5 GM |
480 | "Return the stipple pixmap name of FACE, or nil if unspecified. |
481 | If the optional argument FRAME is given, report on face FACE in that frame. | |
482 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
c7f814cb MB |
483 | If FRAME is omitted or nil, use the selected frame. |
484 | ||
485 | If INHERIT is nil, only a stipple directly defined by FACE is | |
486 | considered, so the return value may be nil. | |
487 | If INHERIT is t, and FACE doesn't define a stipple, then any stipple | |
488 | that FACE inherits through its `:inherit' attribute is considered as | |
489 | well; however the return value may still be nil. | |
490 | If INHERIT is a face or a list of faces, then it is used to try to | |
491 | resolve an unspecified stipple. | |
492 | ||
493 | To ensure that a valid stipple or nil is always returned, use a value of | |
494 | `default' for INHERIT; this will resolve any unspecified values by merging | |
495 | with the `default' face (which is always completely specified)." | |
496 | (face-attribute-specified-or (face-attribute face :stipple frame inherit) | |
497 | nil)) | |
5f5c8ee5 GM |
498 | |
499 | ||
500 | (defalias 'face-background-pixmap 'face-stipple) | |
501 | ||
502 | ||
1bf335cf | 503 | (defun face-underline-p (face &optional frame inherit) |
bde3c6c0 | 504 | "Return non-nil if FACE specifies a non-nil underlining. |
5f5c8ee5 GM |
505 | If the optional argument FRAME is given, report on face FACE in that frame. |
506 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
1bf335cf GM |
507 | If FRAME is omitted or nil, use the selected frame. |
508 | Optional argument INHERIT is passed to `face-attribute'." | |
509 | (face-attribute-specified-or | |
510 | (face-attribute face :underline frame inherit) nil)) | |
5f5c8ee5 GM |
511 | |
512 | ||
1bf335cf | 513 | (defun face-inverse-video-p (face &optional frame inherit) |
bde3c6c0 | 514 | "Return non-nil if FACE specifies a non-nil inverse-video. |
5f5c8ee5 GM |
515 | If the optional argument FRAME is given, report on face FACE in that frame. |
516 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
1bf335cf GM |
517 | If FRAME is omitted or nil, use the selected frame. |
518 | Optional argument INHERIT is passed to `face-attribute'." | |
519 | (eq (face-attribute face :inverse-video frame inherit) t)) | |
5f5c8ee5 GM |
520 | |
521 | ||
1bf335cf | 522 | (defun face-bold-p (face &optional frame inherit) |
5f5c8ee5 GM |
523 | "Return non-nil if the font of FACE is bold on FRAME. |
524 | If the optional argument FRAME is given, report on face FACE in that frame. | |
525 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
526 | If FRAME is omitted or nil, use the selected frame. | |
1bf335cf | 527 | Optional argument INHERIT is passed to `face-attribute'. |
5f5c8ee5 | 528 | Use `face-attribute' for finer control." |
1bf335cf | 529 | (let ((bold (face-attribute face :weight frame inherit))) |
da2c7b8c | 530 | (memq bold '(semi-bold bold extra-bold ultra-bold)))) |
5f5c8ee5 GM |
531 | |
532 | ||
1bf335cf | 533 | (defun face-italic-p (face &optional frame inherit) |
5f5c8ee5 GM |
534 | "Return non-nil if the font of FACE is italic on FRAME. |
535 | If the optional argument FRAME is given, report on face FACE in that frame. | |
536 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
537 | If FRAME is omitted or nil, use the selected frame. | |
1bf335cf | 538 | Optional argument INHERIT is passed to `face-attribute'. |
5f5c8ee5 | 539 | Use `face-attribute' for finer control." |
1bf335cf | 540 | (let ((italic (face-attribute face :slant frame inherit))) |
a48f6020 | 541 | (memq italic '(italic oblique)))) |
00f51890 | 542 | |
5f5c8ee5 | 543 | |
5f5c8ee5 GM |
544 | \f |
545 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
546 | ;;; Face documentation. | |
547 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
548 | ||
549 | (defun face-documentation (face) | |
9a558a07 GM |
550 | "Get the documentation string for FACE. |
551 | If FACE is a face-alias, get the documentation for the target face." | |
5e400cb3 | 552 | (let ((alias (get face 'face-alias))) |
9a558a07 | 553 | (if alias |
5e400cb3 | 554 | (let ((doc (get alias 'face-documentation))) |
3446bfc8 | 555 | (format "%s is an alias for the face `%s'.%s" face alias |
9a558a07 GM |
556 | (if doc (format "\n%s" doc) |
557 | ""))) | |
558 | (get face 'face-documentation)))) | |
5f5c8ee5 GM |
559 | |
560 | ||
561 | (defun set-face-documentation (face string) | |
562 | "Set the documentation string for FACE to STRING." | |
291cfb96 | 563 | ;; Perhaps the text should go in DOC. |
49435801 | 564 | (put face 'face-documentation (purecopy string))) |
5f5c8ee5 GM |
565 | |
566 | ||
567 | (defalias 'face-doc-string 'face-documentation) | |
568 | (defalias 'set-face-doc-string 'set-face-documentation) | |
569 | ||
570 | ||
571 | \f | |
572 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
573 | ;; Setting face attributes. | |
574 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
575 | ||
576 | ||
577 | (defun set-face-attribute (face frame &rest args) | |
578 | "Set attributes of FACE on FRAME from ARGS. | |
4b56d0fe CY |
579 | This function overrides the face attributes specified by FACE's |
580 | face spec. It is mostly intended for internal use only. | |
5f5c8ee5 | 581 | |
4b56d0fe CY |
582 | If FRAME is nil, set the attributes for all existing frames, as |
583 | well as the default for new frames. If FRAME is t, change the | |
584 | default for new frames only. | |
5f5c8ee5 | 585 | |
4b56d0fe CY |
586 | ARGS must come in pairs ATTRIBUTE VALUE. ATTRIBUTE must be a |
587 | valid face attribute name. All attributes can be set to | |
588 | `unspecified'; this fact is not further mentioned below. | |
5f5c8ee5 GM |
589 | |
590 | The following attributes are recognized: | |
591 | ||
592 | `:family' | |
593 | ||
4b56d0fe CY |
594 | VALUE must be a string specifying the font family |
595 | \(e.g. \"Monospace\") or a fontset. | |
5f5c8ee5 | 596 | |
fcea6e23 KH |
597 | `:foundry' |
598 | ||
599 | VALUE must be a string specifying the font foundry, | |
600 | e.g. ``adobe''. If a font foundry is specified, wild-cards `*' | |
601 | and `?' are allowed. | |
602 | ||
5f5c8ee5 GM |
603 | `:width' |
604 | ||
605 | VALUE specifies the relative proportionate width of the font to use. | |
606 | It must be one of the symbols `ultra-condensed', `extra-condensed', | |
607 | `condensed', `semi-condensed', `normal', `semi-expanded', `expanded', | |
608 | `extra-expanded', or `ultra-expanded'. | |
609 | ||
610 | `:height' | |
611 | ||
4b56d0fe CY |
612 | VALUE specifies the relative or absolute height of the font. An |
613 | absolute height is an integer, and specifies font height in units | |
614 | of 1/10 pt. A relative height is either a floating point number, | |
95838641 | 615 | which specifies a scaling factor for the underlying face height; |
4b56d0fe CY |
616 | or a function that takes a single argument (the underlying face |
617 | height) and returns the new height. Note that for the `default' | |
618 | face, you must specify an absolute height (since there is nothing | |
95838641 | 619 | for it to be relative to). |
5f5c8ee5 GM |
620 | |
621 | `:weight' | |
622 | ||
623 | VALUE specifies the weight of the font to use. It must be one of the | |
624 | symbols `ultra-bold', `extra-bold', `bold', `semi-bold', `normal', | |
625 | `semi-light', `light', `extra-light', `ultra-light'. | |
626 | ||
627 | `:slant' | |
628 | ||
629 | VALUE specifies the slant of the font to use. It must be one of the | |
630 | symbols `italic', `oblique', `normal', `reverse-italic', or | |
631 | `reverse-oblique'. | |
632 | ||
633 | `:foreground', `:background' | |
634 | ||
635 | VALUE must be a color name, a string. | |
636 | ||
637 | `:underline' | |
638 | ||
9b0e3eba AA |
639 | VALUE specifies whether characters in FACE should be underlined. |
640 | If VALUE is t, underline with foreground color of the face. | |
641 | If VALUE is a string, underline with that color. | |
642 | If VALUE is nil, explicitly don't underline. | |
643 | ||
644 | Otherwise, VALUE must be a property list of the form: | |
645 | ||
646 | `(:color COLOR :style STYLE)'. | |
647 | ||
648 | COLOR can be a either a color name string or `foreground-color'. | |
649 | STYLE can be either `line' or `wave'. | |
650 | If a keyword/value pair is missing from the property list, a | |
651 | default value will be used for the value. | |
652 | The default value of COLOR is the foreground color of the face. | |
653 | The default value of STYLE is `line'. | |
5f5c8ee5 GM |
654 | |
655 | `:overline' | |
656 | ||
657 | VALUE specifies whether characters in FACE should be overlined. If | |
658 | VALUE is t, overline with foreground color of the face. If VALUE is a | |
659 | string, overline with that color. If VALUE is nil, explicitly don't | |
660 | overline. | |
661 | ||
662 | `:strike-through' | |
663 | ||
664 | VALUE specifies whether characters in FACE should be drawn with a line | |
665 | striking through them. If VALUE is t, use the foreground color of the | |
666 | face. If VALUE is a string, strike-through with that color. If VALUE | |
667 | is nil, explicitly don't strike through. | |
668 | ||
669 | `:box' | |
670 | ||
671 | VALUE specifies whether characters in FACE should have a box drawn | |
672 | around them. If VALUE is nil, explicitly don't draw boxes. If | |
673 | VALUE is t, draw a box with lines of width 1 in the foreground color | |
674 | of the face. If VALUE is a string, the string must be a color name, | |
675 | and the box is drawn in that color with a line width of 1. Otherwise, | |
676 | VALUE must be a property list of the form `(:line-width WIDTH | |
677 | :color COLOR :style STYLE)'. If a keyword/value pair is missing from | |
678 | the property list, a default value will be used for the value, as | |
679 | specified below. WIDTH specifies the width of the lines to draw; it | |
0f937ebd KH |
680 | defaults to 1. If WIDTH is negative, the absolute value is the width |
681 | of the lines, and draw top/bottom lines inside the characters area, | |
682 | not around it. COLOR is the name of the color to draw in, default is | |
5f5c8ee5 GM |
683 | the foreground color of the face for simple boxes, and the background |
684 | color of the face for 3D boxes. STYLE specifies whether a 3D box | |
685 | should be draw. If STYLE is `released-button', draw a box looking | |
686 | like a released 3D button. If STYLE is `pressed-button' draw a box | |
687 | that appears like a pressed button. If STYLE is nil, the default if | |
688 | the property list doesn't contain a style specification, draw a 2D | |
689 | box. | |
690 | ||
691 | `:inverse-video' | |
692 | ||
693 | VALUE specifies whether characters in FACE should be displayed in | |
70d0c3b0 | 694 | inverse video. VALUE must be one of t or nil. |
5f5c8ee5 GM |
695 | |
696 | `:stipple' | |
697 | ||
698 | If VALUE is a string, it must be the name of a file of pixmap data. | |
699 | The directories listed in the `x-bitmap-file-path' variable are | |
700 | searched. Alternatively, VALUE may be a list of the form (WIDTH | |
701 | HEIGHT DATA) where WIDTH and HEIGHT are the size in pixels, and DATA | |
702 | is a string containing the raw bits of the bitmap. VALUE nil means | |
703 | explicitly don't use a stipple pattern. | |
704 | ||
fcea6e23 KH |
705 | For convenience, attributes `:family', `:foundry', `:width', |
706 | `:height', `:weight', and `:slant' may also be set in one step | |
707 | from an X font name: | |
5f5c8ee5 GM |
708 | |
709 | `:font' | |
710 | ||
4b56d0fe CY |
711 | Set font-related face attributes from VALUE. VALUE must be a |
712 | valid font name or font object. Setting this attribute will also | |
713 | set the `:family', `:foundry', `:width', `:height', `:weight', | |
714 | and `:slant' attributes. | |
19feb949 MB |
715 | |
716 | `:inherit' | |
717 | ||
4b56d0fe CY |
718 | VALUE is the name of a face from which to inherit attributes, or |
719 | a list of face names. Attributes from inherited faces are merged | |
720 | into the face like an underlying face would be, with higher | |
721 | priority than underlying faces. | |
722 | ||
723 | For backward compatibility, the keywords `:bold' and `:italic' | |
724 | can be used to specify weight and slant respectively. This usage | |
725 | is considered obsolete. For these two keywords, the VALUE must | |
726 | be either t or nil. A value of t for `:bold' is equivalent to | |
727 | setting `:weight' to `bold', and a value of t for `:italic' is | |
728 | equivalent to setting `:slant' to `italic'. But if `:weight' is | |
729 | specified in the face spec, `:bold' is ignored, and if `:slant' | |
730 | is specified, `:italic' is ignored." | |
61ab9392 CY |
731 | (setq args (purecopy args)) |
732 | (let ((where (if (null frame) 0 frame)) | |
733 | (spec args) | |
734 | family foundry) | |
680da3f8 RS |
735 | ;; If we set the new-frame defaults, this face is modified outside Custom. |
736 | (if (memq where '(0 t)) | |
9a558a07 | 737 | (put (or (get face 'face-alias) face) 'face-modified t)) |
61ab9392 CY |
738 | ;; If family and/or foundry are specified, set it first. Certain |
739 | ;; face attributes, e.g. :weight semi-condensed, are not supported | |
740 | ;; in every font. See bug#1127. | |
741 | (while spec | |
742 | (cond ((eq (car spec) :family) | |
743 | (setq family (cadr spec))) | |
744 | ((eq (car spec) :foundry) | |
745 | (setq foundry (cadr spec)))) | |
746 | (setq spec (cddr spec))) | |
747 | (when (or family foundry) | |
748 | (when (and (stringp family) | |
749 | (string-match "\\([^-]*\\)-\\([^-]*\\)" family)) | |
750 | (unless foundry | |
3a92c095 KH |
751 | (setq foundry (match-string 1 family))) |
752 | (setq family (match-string 2 family))) | |
c917476d | 753 | (when (or (stringp family) (eq family 'unspecified)) |
61ab9392 CY |
754 | (internal-set-lisp-face-attribute face :family (purecopy family) |
755 | where)) | |
c917476d | 756 | (when (or (stringp foundry) (eq foundry 'unspecified)) |
61ab9392 CY |
757 | (internal-set-lisp-face-attribute face :foundry (purecopy foundry) |
758 | where))) | |
70a267c9 | 759 | (while args |
61ab9392 | 760 | (unless (memq (car args) '(:family :foundry)) |
96c1a800 CY |
761 | (internal-set-lisp-face-attribute face (car args) |
762 | (purecopy (cadr args)) | |
763 | where)) | |
61ab9392 | 764 | (setq args (cddr args))))) |
5f5c8ee5 | 765 | |
06b60517 | 766 | (defun make-face-bold (face &optional frame _noerror) |
5f5c8ee5 GM |
767 | "Make the font of FACE be bold, if possible. |
768 | FRAME nil or not specified means change face on all frames. | |
39cac3e7 | 769 | Argument NOERROR is ignored and retained for compatibility. |
5f5c8ee5 | 770 | Use `set-face-attribute' for finer control of the font weight." |
011cddd6 RW |
771 | (interactive (list (read-face-name "Make which face bold" |
772 | (face-at-point t)))) | |
5f5c8ee5 GM |
773 | (set-face-attribute face frame :weight 'bold)) |
774 | ||
775 | ||
06b60517 | 776 | (defun make-face-unbold (face &optional frame _noerror) |
5f5c8ee5 | 777 | "Make the font of FACE be non-bold, if possible. |
39cac3e7 GM |
778 | FRAME nil or not specified means change face on all frames. |
779 | Argument NOERROR is ignored and retained for compatibility." | |
011cddd6 RW |
780 | (interactive (list (read-face-name "Make which face non-bold" |
781 | (face-at-point t)))) | |
5f5c8ee5 GM |
782 | (set-face-attribute face frame :weight 'normal)) |
783 | ||
00f51890 | 784 | |
06b60517 | 785 | (defun make-face-italic (face &optional frame _noerror) |
5f5c8ee5 GM |
786 | "Make the font of FACE be italic, if possible. |
787 | FRAME nil or not specified means change face on all frames. | |
39cac3e7 | 788 | Argument NOERROR is ignored and retained for compatibility. |
5f5c8ee5 | 789 | Use `set-face-attribute' for finer control of the font slant." |
011cddd6 RW |
790 | (interactive (list (read-face-name "Make which face italic" |
791 | (face-at-point t)))) | |
5f5c8ee5 GM |
792 | (set-face-attribute face frame :slant 'italic)) |
793 | ||
794 | ||
06b60517 | 795 | (defun make-face-unitalic (face &optional frame _noerror) |
5f5c8ee5 | 796 | "Make the font of FACE be non-italic, if possible. |
70d0c3b0 DL |
797 | FRAME nil or not specified means change face on all frames. |
798 | Argument NOERROR is ignored and retained for compatibility." | |
011cddd6 RW |
799 | (interactive (list (read-face-name "Make which face non-italic" |
800 | (face-at-point t)))) | |
5f5c8ee5 GM |
801 | (set-face-attribute face frame :slant 'normal)) |
802 | ||
00f51890 | 803 | |
06b60517 | 804 | (defun make-face-bold-italic (face &optional frame _noerror) |
5f5c8ee5 GM |
805 | "Make the font of FACE be bold and italic, if possible. |
806 | FRAME nil or not specified means change face on all frames. | |
39cac3e7 | 807 | Argument NOERROR is ignored and retained for compatibility. |
5f5c8ee5 | 808 | Use `set-face-attribute' for finer control of font weight and slant." |
011cddd6 RW |
809 | (interactive (list (read-face-name "Make which face bold-italic" |
810 | (face-at-point t)))) | |
5f5c8ee5 GM |
811 | (set-face-attribute face frame :weight 'bold :slant 'italic)) |
812 | ||
813 | ||
814 | (defun set-face-font (face font &optional frame) | |
815 | "Change font-related attributes of FACE to those of FONT (a string). | |
816 | FRAME nil or not specified means change face on all frames. | |
fcea6e23 KH |
817 | This sets the attributes `:family', `:foundry', `:width', |
818 | `:height', `:weight', and `:slant'. When called interactively, | |
819 | prompt for the face and font." | |
5f5c8ee5 GM |
820 | (interactive (read-face-and-attribute :font)) |
821 | (set-face-attribute face frame :font font)) | |
822 | ||
823 | ||
824 | ;; Implementation note: Emulating gray background colors with a | |
825 | ;; stipple pattern is now part of the face realization process, and is | |
826 | ;; done in C depending on the frame on which the face is realized. | |
827 | ||
828 | (defun set-face-background (face color &optional frame) | |
829 | "Change the background color of face FACE to COLOR (a string). | |
830 | FRAME nil or not specified means change face on all frames. | |
72e6f142 RS |
831 | COLOR can be a system-defined color name (see `list-colors-display') |
832 | or a hex spec of the form #RRGGBB. | |
833 | When called interactively, prompts for the face and color." | |
5f5c8ee5 | 834 | (interactive (read-face-and-attribute :background)) |
78ad1cd5 | 835 | (set-face-attribute face frame :background (or color 'unspecified))) |
5f5c8ee5 GM |
836 | |
837 | ||
838 | (defun set-face-foreground (face color &optional frame) | |
839 | "Change the foreground color of face FACE to COLOR (a string). | |
840 | FRAME nil or not specified means change face on all frames. | |
72e6f142 RS |
841 | COLOR can be a system-defined color name (see `list-colors-display') |
842 | or a hex spec of the form #RRGGBB. | |
843 | When called interactively, prompts for the face and color." | |
5f5c8ee5 | 844 | (interactive (read-face-and-attribute :foreground)) |
78ad1cd5 | 845 | (set-face-attribute face frame :foreground (or color 'unspecified))) |
5f5c8ee5 GM |
846 | |
847 | ||
848 | (defun set-face-stipple (face stipple &optional frame) | |
849 | "Change the stipple pixmap of face FACE to STIPPLE. | |
850 | FRAME nil or not specified means change face on all frames. | |
70d0c3b0 | 851 | STIPPLE should be a string, the name of a file of pixmap data. |
5f5c8ee5 GM |
852 | The directories listed in the `x-bitmap-file-path' variable are searched. |
853 | ||
854 | Alternatively, STIPPLE may be a list of the form (WIDTH HEIGHT DATA) | |
855 | where WIDTH and HEIGHT are the size in pixels, | |
856 | and DATA is a string, containing the raw bits of the bitmap." | |
857 | (interactive (read-face-and-attribute :stipple)) | |
78ad1cd5 | 858 | (set-face-attribute face frame :stipple (or stipple 'unspecified))) |
5f5c8ee5 GM |
859 | |
860 | ||
bde3c6c0 | 861 | (defun set-face-underline (face underline &optional frame) |
5f5c8ee5 GM |
862 | "Specify whether face FACE is underlined. |
863 | UNDERLINE nil means FACE explicitly doesn't underline. | |
bde3c6c0 GM |
864 | UNDERLINE t means FACE underlines with its foreground color. |
865 | If UNDERLINE is a string, underline with that color. | |
866 | ||
867 | UNDERLINE may also be a list of the form (:color COLOR :style STYLE), | |
868 | where COLOR is a string or `foreground-color', and STYLE is either | |
869 | `line' or `wave'. :color may be omitted, which means to use the | |
870 | foreground color. :style may be omitted, which means to use a line. | |
871 | ||
5f5c8ee5 | 872 | FRAME nil or not specified means change face on all frames. |
5f5c8ee5 | 873 | Use `set-face-attribute' to ``unspecify'' underlining." |
bde3c6c0 | 874 | (interactive (read-face-and-attribute :underline)) |
a61afeac | 875 | (set-face-attribute face frame :underline underline)) |
5f5c8ee5 | 876 | |
bde3c6c0 GM |
877 | (define-obsolete-function-alias 'set-face-underline-p |
878 | 'set-face-underline "24.3") | |
9b82fc01 | 879 | |
5f5c8ee5 | 880 | |
3ca2f1bf | 881 | (defun set-face-inverse-video (face inverse-video-p &optional frame) |
5f5c8ee5 GM |
882 | "Specify whether face FACE is in inverse video. |
883 | INVERSE-VIDEO-P non-nil means FACE displays explicitly in inverse video. | |
884 | INVERSE-VIDEO-P nil means FACE explicitly is not in inverse video. | |
885 | FRAME nil or not specified means change face on all frames. | |
886 | Use `set-face-attribute' to ``unspecify'' the inverse video attribute." | |
887 | (interactive | |
888 | (let ((list (read-face-and-attribute :inverse-video))) | |
3ca2f1bf | 889 | (list (car list) (if (cadr list) t)))) |
5f5c8ee5 GM |
890 | (set-face-attribute face frame :inverse-video inverse-video-p)) |
891 | ||
3ca2f1bf GM |
892 | (define-obsolete-function-alias 'set-face-inverse-video-p |
893 | 'set-face-inverse-video "24.4") | |
5f5c8ee5 | 894 | |
3ca2f1bf | 895 | (defun set-face-bold (face bold-p &optional frame) |
5f5c8ee5 GM |
896 | "Specify whether face FACE is bold. |
897 | BOLD-P non-nil means FACE should explicitly display bold. | |
898 | BOLD-P nil means FACE should explicitly display non-bold. | |
899 | FRAME nil or not specified means change face on all frames. | |
900 | Use `set-face-attribute' or `modify-face' for finer control." | |
901 | (if (null bold-p) | |
902 | (make-face-unbold face frame) | |
903 | (make-face-bold face frame))) | |
904 | ||
3ca2f1bf | 905 | (define-obsolete-function-alias 'set-face-bold-p 'set-face-bold "24.4") |
5f5c8ee5 | 906 | |
3ca2f1bf GM |
907 | |
908 | (defun set-face-italic (face italic-p &optional frame) | |
5f5c8ee5 GM |
909 | "Specify whether face FACE is italic. |
910 | ITALIC-P non-nil means FACE should explicitly display italic. | |
911 | ITALIC-P nil means FACE should explicitly display non-italic. | |
912 | FRAME nil or not specified means change face on all frames. | |
913 | Use `set-face-attribute' or `modify-face' for finer control." | |
914 | (if (null italic-p) | |
915 | (make-face-unitalic face frame) | |
916 | (make-face-italic face frame))) | |
917 | ||
3ca2f1bf GM |
918 | (define-obsolete-function-alias 'set-face-italic-p 'set-face-italic "24.4") |
919 | ||
5f5c8ee5 GM |
920 | |
921 | (defalias 'set-face-background-pixmap 'set-face-stipple) | |
922 | ||
923 | ||
924 | (defun invert-face (face &optional frame) | |
925 | "Swap the foreground and background colors of FACE. | |
e458cb49 | 926 | If FRAME is omitted or nil, it means change face on all frames. |
5f5c8ee5 GM |
927 | If FACE specifies neither foreground nor background color, |
928 | set its foreground and background to the background and foreground | |
929 | of the default face. Value is FACE." | |
011cddd6 | 930 | (interactive (list (read-face-name "Invert face" (face-at-point t)))) |
5f5c8ee5 GM |
931 | (let ((fg (face-attribute face :foreground frame)) |
932 | (bg (face-attribute face :background frame))) | |
e458cb49 | 933 | (if (not (and (eq fg 'unspecified) (eq bg 'unspecified))) |
5f5c8ee5 GM |
934 | (set-face-attribute face frame :foreground bg :background fg) |
935 | (set-face-attribute face frame | |
936 | :foreground | |
937 | (face-attribute 'default :background frame) | |
938 | :background | |
939 | (face-attribute 'default :foreground frame)))) | |
940 | face) | |
941 | ||
942 | \f | |
943 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
944 | ;;; Interactively modifying faces. | |
945 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
946 | ||
5cb15713 JB |
947 | (defvar crm-separator) ; from crm.el |
948 | ||
c91e692b | 949 | (defun read-face-name (prompt &optional default multiple) |
011cddd6 RW |
950 | "Read one or more face names, prompting with PROMPT. |
951 | PROMPT should not end in a space or a colon. | |
bccffa83 | 952 | |
011cddd6 | 953 | Return DEFAULT if the user enters the empty string. |
c46da669 RW |
954 | If DEFAULT is non-nil, it should be a single face or a list of face names |
955 | \(symbols or strings). In the latter case, return the `car' of DEFAULT | |
956 | \(if MULTIPLE is nil, see below), or DEFAULT (if MULTIPLE is non-nil). | |
957 | ||
958 | If MULTIPLE is non-nil, this function uses `completing-read-multiple' | |
959 | to read multiple faces with \"[ \\t]*,[ \\t]*\" as the separator regexp | |
960 | and it returns a list of face names. Otherwise, it reads and returns | |
961 | a single face name." | |
011cddd6 RW |
962 | (if (and default (not (stringp default))) |
963 | (setq default | |
964 | (cond ((symbolp default) | |
965 | (symbol-name default)) | |
966 | (multiple | |
967 | (mapconcat (lambda (f) (if (symbolp f) (symbol-name f) f)) | |
968 | default ", ")) | |
969 | ;; If we only want one, and the default is more than one, | |
970 | ;; discard the unwanted ones. | |
971 | (t (symbol-name (car default)))))) | |
e0eb0550 JB |
972 | (when (and default (not multiple)) |
973 | (require 'crm) | |
974 | ;; For compatibility with `completing-read-multiple' use `crm-separator' | |
975 | ;; to define DEFAULT if MULTIPLE is nil. | |
976 | (setq default (car (split-string default crm-separator t)))) | |
c46da669 RW |
977 | |
978 | (let ((prompt (if default | |
979 | (format "%s (default `%s'): " prompt default) | |
980 | (format "%s: " prompt))) | |
981 | aliasfaces nonaliasfaces faces) | |
011cddd6 | 982 | ;; Build up the completion tables. |
e3b5b35b | 983 | (mapatoms (lambda (s) |
011cddd6 | 984 | (if (facep s) |
e3b5b35b SM |
985 | (if (get s 'face-alias) |
986 | (push (symbol-name s) aliasfaces) | |
987 | (push (symbol-name s) nonaliasfaces))))) | |
c46da669 RW |
988 | (if multiple |
989 | (progn | |
990 | (dolist (face (completing-read-multiple | |
991 | prompt | |
992 | (completion-table-in-turn nonaliasfaces aliasfaces) | |
993 | nil t nil 'face-name-history default)) | |
994 | ;; Ignore elements that are not faces | |
995 | ;; (for example, because DEFAULT was "all faces") | |
996 | (if (facep face) (push (intern face) faces))) | |
997 | (nreverse faces)) | |
998 | (let ((face (completing-read | |
999 | prompt | |
011cddd6 | 1000 | (completion-table-in-turn nonaliasfaces aliasfaces) |
c46da669 RW |
1001 | nil t nil 'face-name-history default))) |
1002 | (if (facep face) (intern face)))))) | |
a482f364 | 1003 | |
aa360da1 GM |
1004 | ;; Not defined without X, but behind window-system test. |
1005 | (defvar x-bitmap-file-path) | |
a482f364 | 1006 | |
5f5c8ee5 GM |
1007 | (defun face-valid-attribute-values (attribute &optional frame) |
1008 | "Return valid values for face attribute ATTRIBUTE. | |
1009 | The optional argument FRAME is used to determine available fonts | |
c6f3804c JB |
1010 | and colors. If it is nil or not specified, the selected frame is used. |
1011 | Value is an alist of (NAME . VALUE) if ATTRIBUTE expects a value out | |
1012 | of a set of discrete values. Value is `integerp' if ATTRIBUTE expects | |
5f5c8ee5 | 1013 | an integer value." |
00f51890 | 1014 | (let ((valid |
36cec983 SM |
1015 | (pcase attribute |
1016 | (`:family | |
428a555e | 1017 | (if (window-system frame) |
95ac8fbd | 1018 | (mapcar (lambda (x) (cons x x)) |
6e783e91 | 1019 | (font-family-list)) |
00f51890 SS |
1020 | ;; Only one font on TTYs. |
1021 | (list (cons "default" "default")))) | |
36cec983 | 1022 | (`:foundry |
fcea6e23 | 1023 | (list nil)) |
36cec983 | 1024 | (`:width |
e83eedbf | 1025 | (mapcar #'(lambda (x) (cons (symbol-name (aref x 1)) (aref x 1))) |
6e783e91 | 1026 | font-width-table)) |
36cec983 | 1027 | (`:weight |
e83eedbf | 1028 | (mapcar #'(lambda (x) (cons (symbol-name (aref x 1)) (aref x 1))) |
6e783e91 | 1029 | font-weight-table)) |
36cec983 | 1030 | (`:slant |
e83eedbf | 1031 | (mapcar #'(lambda (x) (cons (symbol-name (aref x 1)) (aref x 1))) |
6e783e91 | 1032 | font-slant-table)) |
36cec983 | 1033 | (`:inverse-video |
6e783e91 KH |
1034 | (mapcar #'(lambda (x) (cons (symbol-name x) x)) |
1035 | (internal-lisp-face-attribute-values attribute))) | |
36cec983 | 1036 | ((or `:underline `:overline `:strike-through `:box) |
428a555e | 1037 | (if (window-system frame) |
00f51890 SS |
1038 | (nconc (mapcar #'(lambda (x) (cons (symbol-name x) x)) |
1039 | (internal-lisp-face-attribute-values attribute)) | |
1040 | (mapcar #'(lambda (c) (cons c c)) | |
b533d0ae | 1041 | (defined-colors frame))) |
00f51890 SS |
1042 | (mapcar #'(lambda (x) (cons (symbol-name x) x)) |
1043 | (internal-lisp-face-attribute-values attribute)))) | |
36cec983 | 1044 | ((or `:foreground `:background) |
00f51890 SS |
1045 | (mapcar #'(lambda (c) (cons c c)) |
1046 | (defined-colors frame))) | |
36cec983 | 1047 | (`:height |
00f51890 | 1048 | 'integerp) |
36cec983 | 1049 | (`:stipple |
0db2e6af | 1050 | (and (memq (window-system frame) '(x ns)) ; No stipple on w32 |
00f51890 SS |
1051 | (mapcar #'list |
1052 | (apply #'nconc | |
1053 | (mapcar (lambda (dir) | |
1054 | (and (file-readable-p dir) | |
1055 | (file-directory-p dir) | |
1056 | (directory-files dir))) | |
1057 | x-bitmap-file-path))))) | |
36cec983 | 1058 | (`:inherit |
00f51890 SS |
1059 | (cons '("none" . nil) |
1060 | (mapcar #'(lambda (c) (cons (symbol-name c) c)) | |
1061 | (face-list)))) | |
36cec983 | 1062 | (_ |
00f51890 | 1063 | (error "Internal error"))))) |
19feb949 | 1064 | (if (and (listp valid) (not (memq attribute '(:inherit)))) |
fbd5f1cc GM |
1065 | (nconc (list (cons "unspecified" 'unspecified)) valid) |
1066 | valid))) | |
5f5c8ee5 GM |
1067 | |
1068 | ||
2f7f4bee | 1069 | (defconst face-attribute-name-alist |
5f5c8ee5 | 1070 | '((:family . "font family") |
fcea6e23 | 1071 | (:foundry . "font foundry") |
5f5c8ee5 GM |
1072 | (:width . "character set width") |
1073 | (:height . "height in 1/10 pt") | |
1074 | (:weight . "weight") | |
1075 | (:slant . "slant") | |
1076 | (:underline . "underline") | |
1077 | (:overline . "overline") | |
1078 | (:strike-through . "strike-through") | |
1079 | (:box . "box") | |
1080 | (:inverse-video . "inverse-video display") | |
1081 | (:foreground . "foreground color") | |
1082 | (:background . "background color") | |
19feb949 MB |
1083 | (:stipple . "background stipple") |
1084 | (:inherit . "inheritance")) | |
5f5c8ee5 GM |
1085 | "An alist of descriptive names for face attributes. |
1086 | Each element has the form (ATTRIBUTE-NAME . DESCRIPTION) where | |
1087 | ATTRIBUTE-NAME is a face attribute name (a keyword symbol), and | |
1088 | DESCRIPTION is a descriptive name for ATTRIBUTE-NAME.") | |
1089 | ||
1090 | ||
1091 | (defun face-descriptive-attribute-name (attribute) | |
1092 | "Return a descriptive name for ATTRIBUTE." | |
1093 | (cdr (assq attribute face-attribute-name-alist))) | |
1094 | ||
1095 | ||
1096 | (defun face-read-string (face default name &optional completion-alist) | |
1097 | "Interactively read a face attribute string value. | |
19feb949 MB |
1098 | FACE is the face whose attribute is read. If non-nil, DEFAULT is the |
1099 | default string to return if no new value is entered. NAME is a | |
1100 | descriptive name of the attribute for prompting. COMPLETION-ALIST is an | |
1101 | alist of valid values, if non-nil. | |
5f5c8ee5 | 1102 | |
19feb949 | 1103 | Entering nothing accepts the default string DEFAULT. |
5f5c8ee5 | 1104 | Value is the new attribute value." |
19feb949 MB |
1105 | ;; Capitalize NAME (we don't use `capitalize' because that capitalizes |
1106 | ;; each word in a string separately). | |
1107 | (setq name (concat (upcase (substring name 0 1)) (substring name 1))) | |
5f5c8ee5 GM |
1108 | (let* ((completion-ignore-case t) |
1109 | (value (completing-read | |
1110 | (if default | |
19feb949 MB |
1111 | (format "%s for face `%s' (default %s): " |
1112 | name face default) | |
1113 | (format "%s for face `%s': " name face)) | |
d69ab4ba | 1114 | completion-alist nil nil nil nil default))) |
fbd5f1cc | 1115 | (if (equal value "") default value))) |
5f5c8ee5 GM |
1116 | |
1117 | ||
1118 | (defun face-read-integer (face default name) | |
1119 | "Interactively read an integer face attribute value. | |
1120 | FACE is the face whose attribute is read. DEFAULT is the default | |
1121 | value to return if no new value is entered. NAME is a descriptive | |
1122 | name of the attribute for prompting. Value is the new attribute value." | |
fbd5f1cc GM |
1123 | (let ((new-value |
1124 | (face-read-string face | |
19feb949 | 1125 | (format "%s" default) |
fbd5f1cc GM |
1126 | name |
1127 | (list (cons "unspecified" 'unspecified))))) | |
19feb949 MB |
1128 | (cond ((equal new-value "unspecified") |
1129 | 'unspecified) | |
1130 | ((member new-value '("unspecified-fg" "unspecified-bg")) | |
1131 | new-value) | |
1132 | (t | |
027a4b6b | 1133 | (string-to-number new-value))))) |
5f5c8ee5 GM |
1134 | |
1135 | ||
bde3c6c0 GM |
1136 | ;; FIXME this does allow you to enter the list forms of :box, |
1137 | ;; :stipple, or :underline, because face-valid-attribute-values does | |
1138 | ;; not return those forms. | |
5f5c8ee5 GM |
1139 | (defun read-face-attribute (face attribute &optional frame) |
1140 | "Interactively read a new value for FACE's ATTRIBUTE. | |
1141 | Optional argument FRAME nil or unspecified means read an attribute value | |
1142 | of a global face. Value is the new attribute value." | |
1143 | (let* ((old-value (face-attribute face attribute frame)) | |
1144 | (attribute-name (face-descriptive-attribute-name attribute)) | |
1145 | (valid (face-valid-attribute-values attribute frame)) | |
1146 | new-value) | |
1147 | ;; Represent complex attribute values as strings by printing them | |
1148 | ;; out. Stipple can be a vector; (WIDTH HEIGHT DATA). Box can be | |
1149 | ;; a list `(:width WIDTH :color COLOR)' or `(:width WIDTH :shadow | |
bde3c6c0 GM |
1150 | ;; SHADOW)'. Underline can be `(:color COLOR :style STYLE)'. |
1151 | (and (memq attribute '(:box :stipple :underline)) | |
1152 | (or (consp old-value) | |
1153 | (vectorp old-value)) | |
1154 | (setq old-value (prin1-to-string old-value))) | |
5f5c8ee5 | 1155 | (cond ((listp valid) |
19feb949 MB |
1156 | (let ((default |
1157 | (or (car (rassoc old-value valid)) | |
1158 | (format "%s" old-value)))) | |
1159 | (setq new-value | |
1160 | (face-read-string face default attribute-name valid)) | |
1161 | (if (equal new-value default) | |
1162 | ;; Nothing changed, so don't bother with all the stuff | |
1163 | ;; below. In particular, this avoids a non-tty color | |
1164 | ;; from being canonicalized for a tty when the user | |
1165 | ;; just uses the default. | |
1166 | (setq new-value old-value) | |
1167 | ;; Terminal frames can support colors that don't appear | |
1168 | ;; explicitly in VALID, using color approximation code | |
1169 | ;; in tty-colors.el. | |
f9056dd9 | 1170 | (when (and (memq attribute '(:foreground :background)) |
9e2a2647 | 1171 | (not (memq (window-system frame) '(x w32 ns))) |
f9056dd9 MB |
1172 | (not (member new-value |
1173 | '("unspecified" | |
1174 | "unspecified-fg" "unspecified-bg")))) | |
4385f1b0 | 1175 | (setq new-value (car (tty-color-desc new-value frame)))) |
f9056dd9 MB |
1176 | (when (assoc new-value valid) |
1177 | (setq new-value (cdr (assoc new-value valid))))))) | |
5f5c8ee5 GM |
1178 | ((eq valid 'integerp) |
1179 | (setq new-value (face-read-integer face old-value attribute-name))) | |
1180 | (t (error "Internal error"))) | |
1181 | ;; Convert stipple and box value text we read back to a list or | |
1182 | ;; vector if it looks like one. This makes the assumption that a | |
1183 | ;; pixmap file name won't start with an open-paren. | |
bde3c6c0 GM |
1184 | (and (memq attribute '(:stipple :box :underline)) |
1185 | (stringp new-value) | |
5e400cb3 | 1186 | (string-match-p "^[[(]" new-value) |
bde3c6c0 | 1187 | (setq new-value (read new-value))) |
5f5c8ee5 GM |
1188 | new-value)) |
1189 | ||
aa360da1 GM |
1190 | (declare-function fontset-list "fontset.c" ()) |
1191 | (declare-function x-list-fonts "xfaces.c" | |
1192 | (pattern &optional face frame maximum width)) | |
5f5c8ee5 GM |
1193 | |
1194 | (defun read-face-font (face &optional frame) | |
1195 | "Read the name of a font for FACE on FRAME. | |
522fb950 | 1196 | If optional argument FRAME is nil or omitted, use the selected frame." |
5f5c8ee5 | 1197 | (let ((completion-ignore-case t)) |
48ec9939 | 1198 | (completing-read (format "Set font attributes of face `%s' from font: " face) |
6b61353c | 1199 | (append (fontset-list) (x-list-fonts "*" nil frame))))) |
5f5c8ee5 GM |
1200 | |
1201 | ||
1202 | (defun read-all-face-attributes (face &optional frame) | |
1203 | "Interactively read all attributes for FACE. | |
522fb950 | 1204 | If optional argument FRAME is nil or omitted, use the selected frame. |
5f5c8ee5 GM |
1205 | Value is a property list of attribute names and new values." |
1206 | (let (result) | |
1207 | (dolist (attribute face-attribute-name-alist result) | |
1208 | (setq result (cons (car attribute) | |
1209 | (cons (read-face-attribute face (car attribute) frame) | |
1210 | result)))))) | |
1211 | ||
7cd512f2 | 1212 | (defun modify-face (&optional face foreground background stipple |
a61afeac | 1213 | bold-p italic-p underline inverse-p frame) |
5f5c8ee5 GM |
1214 | "Modify attributes of faces interactively. |
1215 | If optional argument FRAME is nil or omitted, modify the face used | |
7cd512f2 SM |
1216 | for newly created frame, i.e. the global face. |
1217 | For non-interactive use, `set-face-attribute' is preferred. | |
522fb950 | 1218 | When called from Lisp, if FACE is nil, all arguments but FRAME are ignored |
7cd512f2 | 1219 | and the face and its settings are obtained by querying the user." |
5f5c8ee5 | 1220 | (interactive) |
7cd512f2 SM |
1221 | (if face |
1222 | (set-face-attribute face frame | |
1223 | :foreground (or foreground 'unspecified) | |
1224 | :background (or background 'unspecified) | |
1225 | :stipple stipple | |
4b56d0fe CY |
1226 | :weight (if bold-p 'bold 'normal) |
1227 | :slant (if italic-p 'italic 'normal) | |
a61afeac | 1228 | :underline underline |
7cd512f2 | 1229 | :inverse-video inverse-p) |
011cddd6 | 1230 | (setq face (read-face-name "Modify face" (face-at-point t))) |
5f5c8ee5 GM |
1231 | (apply #'set-face-attribute face frame |
1232 | (read-all-face-attributes face frame)))) | |
1233 | ||
5f5c8ee5 GM |
1234 | (defun read-face-and-attribute (attribute &optional frame) |
1235 | "Read face name and face attribute value. | |
1236 | ATTRIBUTE is the attribute whose new value is read. | |
1237 | FRAME nil or unspecified means read attribute value of global face. | |
1238 | Value is a list (FACE NEW-VALUE) where FACE is the face read | |
7cd512f2 | 1239 | \(a symbol), and NEW-VALUE is value read." |
5f5c8ee5 | 1240 | (cond ((eq attribute :font) |
48ec9939 | 1241 | (let* ((prompt "Set font-related attributes of face") |
011cddd6 | 1242 | (face (read-face-name prompt (face-at-point t))) |
5f5c8ee5 GM |
1243 | (font (read-face-font face frame))) |
1244 | (list face font))) | |
1245 | (t | |
1246 | (let* ((attribute-name (face-descriptive-attribute-name attribute)) | |
19feb949 | 1247 | (prompt (format "Set %s of face" attribute-name)) |
011cddd6 | 1248 | (face (read-face-name prompt (face-at-point t))) |
5f5c8ee5 GM |
1249 | (new-value (read-face-attribute face attribute frame))) |
1250 | (list face new-value))))) | |
1251 | ||
1252 | ||
1253 | \f | |
1254 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1255 | ;;; Listing faces. | |
1256 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1257 | ||
2f7f4bee | 1258 | (defconst list-faces-sample-text |
5f5c8ee5 | 1259 | "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
fb7ada5f | 1260 | "Text string to display as the sample text for `list-faces-display'.") |
5f5c8ee5 GM |
1261 | |
1262 | ||
1263 | ;; The name list-faces would be more consistent, but let's avoid a | |
1264 | ;; conflict with Lucid, which uses that name differently. | |
1265 | ||
645a1038 | 1266 | (defvar help-xref-stack) |
e2c11e3b | 1267 | (defun list-faces-display (&optional regexp) |
5f5c8ee5 GM |
1268 | "List all faces, using the same sample text in each. |
1269 | The sample text is a string that comes from the variable | |
e2c11e3b RS |
1270 | `list-faces-sample-text'. |
1271 | ||
1272 | If REGEXP is non-nil, list only those faces with names matching | |
1273 | this regular expression. When called interactively with a prefix | |
b2bf2a25 | 1274 | argument, prompt for a regular expression using `read-regexp'." |
e2c11e3b | 1275 | (interactive (list (and current-prefix-arg |
2aef0850 | 1276 | (read-regexp "List faces matching regexp")))) |
011131fd | 1277 | (let ((all-faces (zerop (length regexp))) |
5f5c8ee5 | 1278 | (frame (selected-frame)) |
011131fd JB |
1279 | (max-length 0) |
1280 | faces line-format | |
84fe35f0 | 1281 | disp-frame window face-name) |
011131fd JB |
1282 | ;; We filter and take the max length in one pass |
1283 | (setq faces | |
1284 | (delq nil | |
1285 | (mapcar (lambda (f) | |
1286 | (let ((s (symbol-name f))) | |
5e400cb3 | 1287 | (when (or all-faces (string-match-p regexp s)) |
011131fd JB |
1288 | (setq max-length (max (length s) max-length)) |
1289 | f))) | |
1290 | (sort (face-list) #'string-lessp)))) | |
1291 | (unless faces | |
1292 | (error "No faces matching \"%s\"" regexp)) | |
1293 | (setq max-length (1+ max-length) | |
1294 | line-format (format "%%-%ds" max-length)) | |
b766be6a | 1295 | (with-help-window "*Faces*" |
7fdbcd83 | 1296 | (with-current-buffer standard-output |
5f5c8ee5 | 1297 | (setq truncate-lines t) |
84fe35f0 DL |
1298 | (insert |
1299 | (substitute-command-keys | |
1300 | (concat | |
75bfc667 | 1301 | "\\<help-mode-map>Use " |
53c80cf6 | 1302 | (if (display-mouse-p) "\\[help-follow-mouse] or ") |
32e33f60 | 1303 | "\\[help-follow] on a face name to customize it\n" |
46057f5f | 1304 | "or on its sample text for a description of the face.\n\n"))) |
84fe35f0 | 1305 | (setq help-xref-stack nil) |
e2c11e3b | 1306 | (dolist (face faces) |
84fe35f0 | 1307 | (setq face-name (symbol-name face)) |
011131fd | 1308 | (insert (format line-format face-name)) |
84fe35f0 DL |
1309 | ;; Hyperlink to a customization buffer for the face. Using |
1310 | ;; the help xref mechanism may not be the best way. | |
1311 | (save-excursion | |
1312 | (save-match-data | |
1313 | (search-backward face-name) | |
35a0a8aa | 1314 | (setq help-xref-stack-item `(list-faces-display ,regexp)) |
a482f364 RS |
1315 | (help-xref-button 0 'help-customize-face face))) |
1316 | (let ((beg (point)) | |
1317 | (line-beg (line-beginning-position))) | |
5f5c8ee5 | 1318 | (insert list-faces-sample-text) |
84fe35f0 DL |
1319 | ;; Hyperlink to a help buffer for the face. |
1320 | (save-excursion | |
1321 | (save-match-data | |
1322 | (search-backward list-faces-sample-text) | |
8940232b | 1323 | (help-xref-button 0 'help-face face))) |
5f5c8ee5 GM |
1324 | (insert "\n") |
1325 | (put-text-property beg (1- (point)) 'face face) | |
a482f364 RS |
1326 | ;; Make all face commands default to the proper face |
1327 | ;; anywhere in the line. | |
1328 | (put-text-property line-beg (1- (point)) 'read-face-name face) | |
5f5c8ee5 GM |
1329 | ;; If the sample text has multiple lines, line up all of them. |
1330 | (goto-char beg) | |
1331 | (forward-line 1) | |
1332 | (while (not (eobp)) | |
011131fd | 1333 | (insert-char ?\s max-length) |
5f5c8ee5 | 1334 | (forward-line 1)))) |
b766be6a | 1335 | (goto-char (point-min)))) |
5f5c8ee5 GM |
1336 | ;; If the *Faces* buffer appears in a different frame, |
1337 | ;; copy all the face definitions from FRAME, | |
1338 | ;; so that the display will reflect the frame that was selected. | |
1339 | (setq window (get-buffer-window (get-buffer "*Faces*") t)) | |
1340 | (setq disp-frame (if window (window-frame window) | |
1341 | (car (frame-list)))) | |
1342 | (or (eq frame disp-frame) | |
5e400cb3 JB |
1343 | (dolist (face (face-list)) |
1344 | (copy-face face face frame disp-frame))))) | |
5f5c8ee5 | 1345 | |
e2c11e3b | 1346 | |
5f5c8ee5 GM |
1347 | (defun describe-face (face &optional frame) |
1348 | "Display the properties of face FACE on FRAME. | |
6afa5404 | 1349 | Interactively, FACE defaults to the faces of the character after point |
a482f364 RS |
1350 | and FRAME defaults to the selected frame. |
1351 | ||
5f5c8ee5 GM |
1352 | If the optional argument FRAME is given, report on face FACE in that frame. |
1353 | If FRAME is t, report on the defaults for face FACE (for new frames). | |
1354 | If FRAME is omitted or nil, use the selected frame." | |
f3d3eaf0 | 1355 | (interactive (list (read-face-name "Describe face" |
011cddd6 | 1356 | (or (face-at-point t) 'default) |
f3d3eaf0 | 1357 | t))) |
5f5c8ee5 | 1358 | (let* ((attrs '((:family . "Family") |
fcea6e23 | 1359 | (:foundry . "Foundry") |
5f5c8ee5 GM |
1360 | (:width . "Width") |
1361 | (:height . "Height") | |
1362 | (:weight . "Weight") | |
1363 | (:slant . "Slant") | |
1364 | (:foreground . "Foreground") | |
5b97b4c0 | 1365 | (:distant-foreground . "DistantForeground") |
5f5c8ee5 GM |
1366 | (:background . "Background") |
1367 | (:underline . "Underline") | |
1368 | (:overline . "Overline") | |
1369 | (:strike-through . "Strike-through") | |
1370 | (:box . "Box") | |
1371 | (:inverse-video . "Inverse") | |
b32631c8 | 1372 | (:stipple . "Stipple") |
0540dc5e KH |
1373 | (:font . "Font") |
1374 | (:fontset . "Fontset") | |
25ac7b52 | 1375 | (:inherit . "Inherit"))) |
5f5c8ee5 GM |
1376 | (max-width (apply #'max (mapcar #'(lambda (x) (length (cdr x))) |
1377 | attrs)))) | |
32226619 JB |
1378 | (help-setup-xref (list #'describe-face face) |
1379 | (called-interactively-p 'interactive)) | |
a482f364 RS |
1380 | (unless face |
1381 | (setq face 'default)) | |
1382 | (if (not (listp face)) | |
1383 | (setq face (list face))) | |
b766be6a | 1384 | (with-help-window (help-buffer) |
7fdbcd83 | 1385 | (with-current-buffer standard-output |
a482f364 | 1386 | (dolist (f face) |
faa3d27b | 1387 | (if (stringp f) (setq f (intern f))) |
0d3b1f4e CY |
1388 | ;; We may get called for anonymous faces (i.e., faces |
1389 | ;; expressed using prop-value plists). Those can't be | |
1390 | ;; usefully customized, so ignore them. | |
1391 | (when (symbolp f) | |
1392 | (insert "Face: " (symbol-name f)) | |
1393 | (if (not (facep f)) | |
1394 | (insert " undefined face.\n") | |
1395 | (let ((customize-label "customize this face") | |
1396 | file-name) | |
1397 | (insert (concat " (" (propertize "sample" 'font-lock-face f) ")")) | |
1398 | (princ (concat " (" customize-label ")\n")) | |
3446bfc8 GM |
1399 | ;; FIXME not sure how much of this belongs here, and |
1400 | ;; how much in `face-documentation'. The latter is | |
1401 | ;; not used much, but needs to return nil for | |
1402 | ;; undocumented faces. | |
1403 | (let ((alias (get f 'face-alias)) | |
1404 | (face f) | |
1405 | obsolete) | |
1406 | (when alias | |
1407 | (setq face alias) | |
1408 | (insert | |
1409 | (format "\n %s is an alias for the face `%s'.\n%s" | |
1410 | f alias | |
1411 | (if (setq obsolete (get f 'obsolete-face)) | |
1412 | (format " This face is obsolete%s; use `%s' instead.\n" | |
1413 | (if (stringp obsolete) | |
1414 | (format " since %s" obsolete) | |
1415 | "") | |
1416 | alias) | |
1417 | "")))) | |
1418 | (insert "\nDocumentation:\n" | |
1419 | (or (face-documentation face) | |
1420 | "Not documented as a face.") | |
1421 | "\n\n")) | |
0d3b1f4e CY |
1422 | (with-current-buffer standard-output |
1423 | (save-excursion | |
1424 | (re-search-backward | |
1425 | (concat "\\(" customize-label "\\)") nil t) | |
1426 | (help-xref-button 1 'help-customize-face f))) | |
1427 | (setq file-name (find-lisp-object-file-name f 'defface)) | |
1428 | (when file-name | |
1429 | (princ "Defined in `") | |
1430 | (princ (file-name-nondirectory file-name)) | |
1431 | (princ "'") | |
1432 | ;; Make a hyperlink to the library. | |
1433 | (save-excursion | |
1434 | (re-search-backward "`\\([^`']+\\)'" nil t) | |
1435 | (help-xref-button 1 'help-face-def f file-name)) | |
1436 | (princ ".") | |
1437 | (terpri) | |
1438 | (terpri)) | |
1439 | (dolist (a attrs) | |
1440 | (let ((attr (face-attribute f (car a) frame))) | |
1441 | (insert (make-string (- max-width (length (cdr a))) ?\s) | |
1442 | (cdr a) ": " (format "%s" attr)) | |
1443 | (if (and (eq (car a) :inherit) | |
1444 | (not (eq attr 'unspecified))) | |
1445 | ;; Make a hyperlink to the parent face. | |
1446 | (save-excursion | |
1447 | (re-search-backward ": \\([^:]+\\)" nil t) | |
1448 | (help-xref-button 1 'help-face attr))) | |
1449 | (insert "\n"))))) | |
1450 | (terpri))))))) | |
8940232b | 1451 | |
5f5c8ee5 GM |
1452 | \f |
1453 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1454 | ;;; Face specifications (defface). | |
1455 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1456 | ||
1457 | ;; Parameter FRAME Is kept for call compatibility to with previous | |
1458 | ;; face implementation. | |
1459 | ||
06b60517 JB |
1460 | (defun face-attr-construct (face &optional _frame) |
1461 | "Return a `defface'-style attribute list for FACE. | |
5f5c8ee5 GM |
1462 | Value is a property list of pairs ATTRIBUTE VALUE for all specified |
1463 | face attributes of FACE where ATTRIBUTE is the attribute name and | |
06b60517 JB |
1464 | VALUE is the specified value of that attribute. |
1465 | Argument FRAME is ignored and retained for compatibility." | |
5f5c8ee5 GM |
1466 | (let (result) |
1467 | (dolist (entry face-attribute-name-alist result) | |
1468 | (let* ((attribute (car entry)) | |
1469 | (value (face-attribute face attribute))) | |
1470 | (unless (eq value 'unspecified) | |
1471 | (setq result (nconc (list attribute value) result))))))) | |
00f51890 | 1472 | |
5f5c8ee5 GM |
1473 | |
1474 | (defun face-spec-set-match-display (display frame) | |
1475 | "Non-nil if DISPLAY matches FRAME. | |
1476 | DISPLAY is part of a spec such as can be used in `defface'. | |
1477 | If FRAME is nil, the current FRAME is used." | |
1478 | (let* ((conjuncts display) | |
1479 | conjunct req options | |
1480 | ;; t means we have succeeded against all the conjuncts in | |
1481 | ;; DISPLAY that have been tested so far. | |
1482 | (match t)) | |
1483 | (if (eq conjuncts t) | |
1484 | (setq conjuncts nil)) | |
1485 | (while (and conjuncts match) | |
1486 | (setq conjunct (car conjuncts) | |
1487 | conjuncts (cdr conjuncts) | |
1488 | req (car conjunct) | |
1489 | options (cdr conjunct) | |
1490 | match (cond ((eq req 'type) | |
428a555e | 1491 | (or (memq (window-system frame) options) |
ee0e9f11 LMI |
1492 | (and (memq 'graphic options) |
1493 | (memq (window-system frame) '(x w32 ns))) | |
1695ca2b EZ |
1494 | ;; FIXME: This should be revisited to use |
1495 | ;; display-graphic-p, provided that the | |
1496 | ;; color selection depends on the number | |
1497 | ;; of supported colors, and all defface's | |
1498 | ;; are changed to look at number of colors | |
1499 | ;; instead of (type graphic) etc. | |
dcb79f20 AS |
1500 | (if (null (window-system frame)) |
1501 | (memq 'tty options) | |
1502 | (or (and (memq 'motif options) | |
1503 | (featurep 'motif)) | |
1504 | (and (memq 'gtk options) | |
1505 | (featurep 'gtk)) | |
1506 | (and (memq 'lucid options) | |
1507 | (featurep 'x-toolkit) | |
1508 | (not (featurep 'motif)) | |
1509 | (not (featurep 'gtk))) | |
1510 | (and (memq 'x-toolkit options) | |
1511 | (featurep 'x-toolkit)))))) | |
6b61353c KH |
1512 | ((eq req 'min-colors) |
1513 | (>= (display-color-cells frame) (car options))) | |
5f5c8ee5 GM |
1514 | ((eq req 'class) |
1515 | (memq (frame-parameter frame 'display-type) options)) | |
1516 | ((eq req 'background) | |
1517 | (memq (frame-parameter frame 'background-mode) | |
1518 | options)) | |
16320ac7 MB |
1519 | ((eq req 'supports) |
1520 | (display-supports-face-attributes-p options frame)) | |
70d0c3b0 | 1521 | (t (error "Unknown req `%S' with options `%S'" |
5f5c8ee5 GM |
1522 | req options))))) |
1523 | match)) | |
1524 | ||
1525 | ||
fdafd487 MD |
1526 | (defun face-spec-choose (spec &optional frame no-match-retval) |
1527 | "Return the proper attributes for FRAME, out of SPEC. | |
1528 | ||
1529 | If no match is found or SPEC is nil, return nil, unless NO-MATCH-RETVAL | |
1530 | is given, in which case return its value instead." | |
5f5c8ee5 GM |
1531 | (unless frame |
1532 | (setq frame (selected-frame))) | |
1533 | (let ((tail spec) | |
fdafd487 | 1534 | result defaults match-found) |
5f5c8ee5 | 1535 | (while tail |
073f69e6 MB |
1536 | (let* ((entry (pop tail)) |
1537 | (display (car entry)) | |
cf459bb7 RS |
1538 | (attrs (cdr entry)) |
1539 | thisval) | |
1540 | ;; Get the attributes as actually specified by this alternative. | |
1541 | (setq thisval | |
1542 | (if (null (cdr attrs)) ;; was (listp (car attrs)) | |
1543 | ;; Old-style entry, the attribute list is the | |
1544 | ;; first element. | |
1545 | (car attrs) | |
1546 | attrs)) | |
1547 | ||
1548 | ;; If the condition is `default', that sets the default | |
1549 | ;; for following conditions. | |
1550 | (if (eq display 'default) | |
1551 | (setq defaults thisval) | |
1552 | ;; Otherwise, if it matches, use it. | |
1553 | (when (face-spec-set-match-display display frame) | |
fdafd487 MD |
1554 | (setq result thisval |
1555 | tail nil | |
1556 | match-found t))))) | |
1557 | ;; If defaults have been found, it's safe to just append those to the result | |
1558 | ;; list (which at this point will be either nil or contain actual specs) and | |
1559 | ;; return it to the caller. Since there will most definitely be something to | |
1560 | ;; return in this case, there's no need to know/check if a match was found. | |
1561 | (if defaults | |
1562 | (append result defaults) | |
1563 | (if match-found | |
1564 | result | |
1565 | no-match-retval)))) | |
5f5c8ee5 GM |
1566 | |
1567 | ||
1568 | (defun face-spec-reset-face (face &optional frame) | |
1569 | "Reset all attributes of FACE on FRAME to unspecified." | |
c349f4e6 CY |
1570 | (apply 'set-face-attribute face frame |
1571 | (if (eq face 'default) | |
1572 | ;; For the default face, avoid making any attribute | |
f003f294 | 1573 | ;; unspecified. Instead, set attributes to default values |
c349f4e6 CY |
1574 | ;; (see also realize_default_face in xfaces.c). |
1575 | (append | |
1576 | '(:underline nil :overline nil :strike-through nil | |
1577 | :box nil :inverse-video nil :stipple nil :inherit nil) | |
4c5779ab CY |
1578 | ;; `display-graphic-p' is unavailable when running |
1579 | ;; temacs, prior to loading frame.el. | |
aac2b673 CY |
1580 | (when (fboundp 'display-graphic-p) |
1581 | (unless (display-graphic-p frame) | |
1582 | `(:family "default" :foundry "default" :width normal | |
1583 | :height 1 :weight normal :slant normal | |
1584 | :foreground ,(if (frame-parameter nil 'reverse) | |
1585 | "unspecified-bg" | |
1586 | "unspecified-fg") | |
1587 | :background ,(if (frame-parameter nil 'reverse) | |
1588 | "unspecified-fg" | |
1589 | "unspecified-bg"))))) | |
c349f4e6 CY |
1590 | ;; For all other faces, unspecify all attributes. |
1591 | (apply 'append | |
1592 | (mapcar (lambda (x) (list (car x) 'unspecified)) | |
1593 | face-attribute-name-alist))))) | |
5f5c8ee5 | 1594 | |
1c4f115d CY |
1595 | (defun face-spec-set (face spec &optional spec-type) |
1596 | "Set the face spec SPEC for FACE. | |
1597 | See `defface' for the format of SPEC. | |
1598 | ||
aac2b673 CY |
1599 | The appearance of each face is controlled by its specs (set via |
1600 | this function), and by the internal frame-specific face | |
1601 | attributes (set via `set-face-attribute'). | |
bacb0e77 | 1602 | |
aac2b673 CY |
1603 | This function also defines FACE as a valid face name if it is not |
1604 | already one, and (re)calculates its attributes on existing | |
1605 | frames. | |
1c4f115d CY |
1606 | |
1607 | The argument SPEC-TYPE determines which spec to set: | |
1608 | nil or `face-override-spec' means the override spec (which is | |
1609 | usually what you want if calling this function outside of | |
1610 | Custom code); | |
1611 | `customized-face' or `saved-face' means the customized spec or | |
1612 | the saved custom spec; | |
1613 | `face-defface-spec' means the default spec | |
1614 | (usually set only via `defface'); | |
1615 | `reset' means to ignore SPEC, but clear the `customized-face' | |
1616 | and `face-override-spec' specs; | |
1617 | Any other value means not to set any spec, but to run the | |
bacb0e77 | 1618 | function for its other effects." |
1c4f115d CY |
1619 | (if (get face 'face-alias) |
1620 | (setq face (get face 'face-alias))) | |
1621 | ;; Save SPEC to the relevant symbol property. | |
1622 | (unless spec-type | |
1623 | (setq spec-type 'face-override-spec)) | |
1624 | (if (memq spec-type '(face-defface-spec face-override-spec | |
1625 | customized-face saved-face)) | |
1626 | (put face spec-type spec)) | |
1627 | (if (memq spec-type '(reset saved-face)) | |
1628 | (put face 'customized-face nil)) | |
1629 | ;; Setting the face spec via Custom empties out any override spec, | |
f24f2e22 | 1630 | ;; similar to how setting a variable via Custom changes its values. |
1c4f115d CY |
1631 | (if (memq spec-type '(customized-face saved-face reset)) |
1632 | (put face 'face-override-spec nil)) | |
1633 | ;; If we reset the face based on its custom spec, it is unmodified | |
1634 | ;; as far as Custom is concerned. | |
1635 | (unless (eq face 'face-override-spec) | |
1636 | (put face 'face-modified nil)) | |
aac2b673 CY |
1637 | ;; Initialize the face if it does not exist, then recalculate. |
1638 | (make-empty-face face) | |
1639 | (dolist (frame (frame-list)) | |
1640 | (face-spec-recalc face frame))) | |
24837f13 RS |
1641 | |
1642 | (defun face-spec-recalc (face frame) | |
1643 | "Reset the face attributes of FACE on FRAME according to its specs. | |
bc6953b3 MD |
1644 | The following sources are applied in this order: |
1645 | ||
1646 | face reset to default values if it's the default face, otherwise set | |
426b5daf | 1647 | to unspecified (through `face-spec-reset-face') |
eb7a03cc MD |
1648 | | |
1649 | (theme and user customization) | |
426b5daf PE |
1650 | or: if none of the above exist, and none match the current frame or |
1651 | inherited from the defface spec instead of overwriting it | |
bc6953b3 | 1652 | entirely, the following is applied instead: |
eb7a03cc | 1653 | (defface default spec) |
bc6953b3 | 1654 | (X resources (if applicable)) |
eb7a03cc MD |
1655 | | |
1656 | defface override spec" | |
1c4f115d CY |
1657 | (while (get face 'face-alias) |
1658 | (setq face (get face 'face-alias))) | |
24837f13 | 1659 | (face-spec-reset-face face frame) |
1c4f115d | 1660 | ;; If FACE is customized or themed, set the custom spec from |
dca38cf9 CY |
1661 | ;; `theme-face' records. |
1662 | (let ((theme-faces (get face 'theme-face)) | |
fdafd487 | 1663 | (no-match-found 0) |
dca38cf9 | 1664 | spec theme-face-applied) |
1c4f115d | 1665 | (if theme-faces |
dca38cf9 | 1666 | (dolist (elt (reverse theme-faces)) |
fdafd487 MD |
1667 | (setq spec (face-spec-choose (cadr elt) frame no-match-found)) |
1668 | (unless (eq spec no-match-found) | |
dca38cf9 CY |
1669 | (face-spec-set-2 face frame spec) |
1670 | (setq theme-face-applied t)))) | |
1671 | ;; If there was a spec applicable to FRAME, that overrides the | |
1672 | ;; defface spec entirely (rather than inheriting from it). If | |
bc6953b3 MD |
1673 | ;; there was no spec applicable to FRAME, apply the defface spec |
1674 | ;; as well as any applicable X resources. | |
dca38cf9 CY |
1675 | (unless theme-face-applied |
1676 | (setq spec (face-spec-choose (face-default-spec face) frame)) | |
bc6953b3 MD |
1677 | (face-spec-set-2 face frame spec) |
1678 | (make-face-x-resource-internal face frame)) | |
dca38cf9 | 1679 | (setq spec (face-spec-choose (get face 'face-override-spec) frame)) |
eb7a03cc | 1680 | (face-spec-set-2 face frame spec))) |
24837f13 RS |
1681 | |
1682 | (defun face-spec-set-2 (face frame spec) | |
1683 | "Set the face attributes of FACE on FRAME according to SPEC." | |
dca38cf9 | 1684 | (let (attrs) |
4f77c25d CY |
1685 | (while spec |
1686 | (when (assq (car spec) face-x-resources) | |
1687 | (push (car spec) attrs) | |
1688 | (push (cadr spec) attrs)) | |
1689 | (setq spec (cddr spec))) | |
1690 | (apply 'set-face-attribute face frame (nreverse attrs)))) | |
5f5c8ee5 GM |
1691 | |
1692 | (defun face-attr-match-p (face attrs &optional frame) | |
a9de7d29 | 1693 | "Return t if attributes of FACE match values in plist ATTRS. |
5f5c8ee5 GM |
1694 | Optional parameter FRAME is the frame whose definition of FACE |
1695 | is used. If nil or omitted, use the selected frame." | |
1696 | (unless frame | |
1697 | (setq frame (selected-frame))) | |
8a6f24e5 GM |
1698 | (let* ((list face-attribute-name-alist) |
1699 | (match t) | |
1700 | (bold (and (plist-member attrs :bold) | |
1701 | (not (plist-member attrs :weight)))) | |
1702 | (italic (and (plist-member attrs :italic) | |
1703 | (not (plist-member attrs :slant)))) | |
1704 | (plist (if (or bold italic) | |
1705 | (copy-sequence attrs) | |
1706 | attrs))) | |
1707 | ;; Handle the Emacs 20 :bold and :italic properties. | |
1708 | (if bold | |
1709 | (plist-put plist :weight (if bold 'bold 'normal))) | |
1710 | (if italic | |
1711 | (plist-put plist :slant (if italic 'italic 'normal))) | |
4983ddea CY |
1712 | (while (and match list) |
1713 | (let* ((attr (caar list)) | |
a9de7d29 | 1714 | (specified-value |
8a6f24e5 GM |
1715 | (if (plist-member plist attr) |
1716 | (plist-get plist attr) | |
a9de7d29 | 1717 | 'unspecified)) |
5f5c8ee5 | 1718 | (value-now (face-attribute face attr frame))) |
a9de7d29 | 1719 | (setq match (equal specified-value value-now)) |
5f5c8ee5 GM |
1720 | (setq list (cdr list)))) |
1721 | match)) | |
1722 | ||
4983ddea | 1723 | (defsubst face-spec-match-p (face spec &optional frame) |
5f5c8ee5 GM |
1724 | "Return t if FACE, on FRAME, matches what SPEC says it should look like." |
1725 | (face-attr-match-p face (face-spec-choose spec frame) frame)) | |
1726 | ||
94fe8a31 | 1727 | (defsubst face-default-spec (face) |
96c2938f MB |
1728 | "Return the default face-spec for FACE, ignoring any user customization. |
1729 | If there is no default for FACE, return nil." | |
1730 | (get face 'face-defface-spec)) | |
5f5c8ee5 | 1731 | |
94fe8a31 MB |
1732 | (defsubst face-user-default-spec (face) |
1733 | "Return the user's customized face-spec for FACE, or the default if none. | |
7cd512f2 | 1734 | If there is neither a user setting nor a default for FACE, return nil." |
e44d251c JL |
1735 | (or (get face 'customized-face) |
1736 | (get face 'saved-face) | |
94fe8a31 MB |
1737 | (face-default-spec face))) |
1738 | ||
5f5c8ee5 | 1739 | \f |
f795f633 EZ |
1740 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1741 | ;;; Frame-type independent color support. | |
1742 | ;;; We keep the old x-* names as aliases for back-compatibility. | |
1743 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1744 | ||
1745 | (defun defined-colors (&optional frame) | |
1746 | "Return a list of colors supported for a particular frame. | |
1747 | The argument FRAME specifies which frame to try. | |
1748 | The value may be different for frames on different display types. | |
43c58260 RS |
1749 | If FRAME doesn't support colors, the value is nil. |
1750 | If FRAME is nil, that stands for the selected frame." | |
9e2a2647 | 1751 | (if (memq (framep (or frame (selected-frame))) '(x w32 ns)) |
f795f633 | 1752 | (xw-defined-colors frame) |
37462f4c | 1753 | (mapcar 'car (tty-color-alist frame)))) |
f795f633 EZ |
1754 | (defalias 'x-defined-colors 'defined-colors) |
1755 | ||
aa360da1 GM |
1756 | (declare-function xw-color-defined-p "xfns.c" (color &optional frame)) |
1757 | ||
f795f633 | 1758 | (defun color-defined-p (color &optional frame) |
bccffa83 CY |
1759 | "Return non-nil if COLOR is supported on frame FRAME. |
1760 | COLOR should be a string naming a color (e.g. \"white\"), or a | |
1761 | string specifying a color's RGB components (e.g. \"#ff12ec\"), or | |
1762 | the symbol `unspecified'. | |
1763 | ||
1764 | This function returns nil if COLOR is the symbol `unspecified', | |
1765 | or one of the strings \"unspecified-fg\" or \"unspecified-bg\". | |
1766 | ||
1767 | If FRAME is omitted or nil, use the selected frame." | |
1768 | (unless (member color '(unspecified "unspecified-bg" "unspecified-fg")) | |
9e2a2647 | 1769 | (if (member (framep (or frame (selected-frame))) '(x w32 ns)) |
f795f633 | 1770 | (xw-color-defined-p color frame) |
37462f4c | 1771 | (numberp (tty-color-translate color frame))))) |
f795f633 EZ |
1772 | (defalias 'x-color-defined-p 'color-defined-p) |
1773 | ||
aa360da1 GM |
1774 | (declare-function xw-color-values "xfns.c" (color &optional frame)) |
1775 | ||
f795f633 EZ |
1776 | (defun color-values (color &optional frame) |
1777 | "Return a description of the color named COLOR on frame FRAME. | |
6d713256 CY |
1778 | COLOR should be a string naming a color (e.g. \"white\"), or a |
1779 | string specifying a color's RGB components (e.g. \"#ff12ec\"). | |
1780 | ||
1781 | Return a list of three integers, (RED GREEN BLUE), each between 0 | |
1782 | and either 65280 or 65535 (the maximum depends on the system). | |
1783 | Use `color-name-to-rgb' if you want RGB floating-point values | |
1784 | normalized to 1.0. | |
1785 | ||
f795f633 EZ |
1786 | If FRAME is omitted or nil, use the selected frame. |
1787 | If FRAME cannot display COLOR, the value is nil. | |
6d713256 CY |
1788 | |
1789 | COLOR can also be the symbol `unspecified' or one of the strings | |
1790 | \"unspecified-fg\" or \"unspecified-bg\", in which case the | |
1791 | return value is nil." | |
1792 | (cond | |
1793 | ((member color '(unspecified "unspecified-fg" "unspecified-bg")) | |
1794 | nil) | |
1795 | ((memq (framep (or frame (selected-frame))) '(x w32 ns)) | |
1796 | (xw-color-values color frame)) | |
1797 | (t | |
1798 | (tty-color-values color frame)))) | |
1799 | ||
f795f633 EZ |
1800 | (defalias 'x-color-values 'color-values) |
1801 | ||
aa360da1 GM |
1802 | (declare-function xw-display-color-p "xfns.c" (&optional terminal)) |
1803 | ||
f795f633 EZ |
1804 | (defun display-color-p (&optional display) |
1805 | "Return t if DISPLAY supports color. | |
1806 | The optional argument DISPLAY specifies which display to ask about. | |
1807 | DISPLAY should be either a frame or a display name (a string). | |
1808 | If omitted or nil, that stands for the selected frame's display." | |
9e2a2647 | 1809 | (if (memq (framep-on-display display) '(x w32 ns)) |
d5179a01 EZ |
1810 | (xw-display-color-p display) |
1811 | (tty-display-color-p display))) | |
f795f633 EZ |
1812 | (defalias 'x-display-color-p 'display-color-p) |
1813 | ||
aa360da1 GM |
1814 | (declare-function x-display-grayscale-p "xfns.c" (&optional terminal)) |
1815 | ||
d5179a01 EZ |
1816 | (defun display-grayscale-p (&optional display) |
1817 | "Return non-nil if frames on DISPLAY can display shades of gray." | |
1818 | (let ((frame-type (framep-on-display display))) | |
1819 | (cond | |
9e2a2647 | 1820 | ((memq frame-type '(x w32 ns)) |
d5179a01 EZ |
1821 | (x-display-grayscale-p display)) |
1822 | (t | |
1823 | (> (tty-color-gray-shades display) 2))))) | |
1824 | ||
9317e499 | 1825 | (defun read-color (&optional prompt convert-to-RGB allow-empty-name msg) |
315bc30d | 1826 | "Read a color name or RGB triplet. |
9317e499 CY |
1827 | Completion is available for color names, but not for RGB triplets. |
1828 | ||
315bc30d CY |
1829 | RGB triplets have the form \"#RRGGBB\". Each of the R, G, and B |
1830 | components can have one to four digits, but all three components | |
1831 | must have the same number of digits. Each digit is a hex value | |
1832 | between 0 and F; either upper case or lower case for A through F | |
1833 | are acceptable. | |
9317e499 CY |
1834 | |
1835 | In addition to standard color names and RGB hex values, the | |
1836 | following are available as color candidates. In each case, the | |
1837 | corresponding color is used. | |
26c07a69 RS |
1838 | |
1839 | * `foreground at point' - foreground under the cursor | |
1840 | * `background at point' - background under the cursor | |
1841 | ||
9317e499 | 1842 | Optional arg PROMPT is the prompt; if nil, use a default prompt. |
26c07a69 | 1843 | |
9317e499 CY |
1844 | Interactively, or with optional arg CONVERT-TO-RGB-P non-nil, |
1845 | convert an input color name to an RGB hex string. Return the RGB | |
1846 | hex string. | |
26c07a69 | 1847 | |
9317e499 CY |
1848 | If optional arg ALLOW-EMPTY-NAME is non-nil, the user is allowed |
1849 | to enter an empty color name (the empty string). | |
26c07a69 | 1850 | |
9317e499 CY |
1851 | Interactively, or with optional arg MSG non-nil, print the |
1852 | resulting color name in the echo area." | |
26c07a69 RS |
1853 | (interactive "i\np\ni\np") ; Always convert to RGB interactively. |
1854 | (let* ((completion-ignore-case t) | |
9317e499 CY |
1855 | (colors (or facemenu-color-alist |
1856 | (append '("foreground at point" "background at point") | |
1857 | (if allow-empty-name '("")) | |
1858 | (defined-colors)))) | |
1859 | (color (completing-read | |
1860 | (or prompt "Color (name or #RGB triplet): ") | |
1861 | ;; Completing function for reading colors, accepting | |
1862 | ;; both color names and RGB triplets. | |
1863 | (lambda (string pred flag) | |
1864 | (cond | |
1865 | ((null flag) ; Try completion. | |
1866 | (or (try-completion string colors pred) | |
1867 | (if (color-defined-p string) | |
1868 | string))) | |
1869 | ((eq flag t) ; List all completions. | |
1870 | (or (all-completions string colors pred) | |
1871 | (if (color-defined-p string) | |
1872 | (list string)))) | |
1873 | ((eq flag 'lambda) ; Test completion. | |
a9574eb7 | 1874 | (or (member string colors) |
9317e499 | 1875 | (color-defined-p string))))) |
06b60517 | 1876 | nil t))) |
9317e499 CY |
1877 | |
1878 | ;; Process named colors. | |
1879 | (when (member color colors) | |
1880 | (cond ((string-equal color "foreground at point") | |
1881 | (setq color (foreground-color-at-point))) | |
1882 | ((string-equal color "background at point") | |
1883 | (setq color (background-color-at-point)))) | |
1884 | (when (and convert-to-RGB | |
1885 | (not (string-equal color ""))) | |
1886 | (let ((components (x-color-values color))) | |
5e400cb3 | 1887 | (unless (string-match-p "^#\\(?:[a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color) |
9317e499 CY |
1888 | (setq color (format "#%04X%04X%04X" |
1889 | (logand 65535 (nth 0 components)) | |
1890 | (logand 65535 (nth 1 components)) | |
1891 | (logand 65535 (nth 2 components)))))))) | |
1892 | (when msg (message "Color: `%s'" color)) | |
1893 | color)) | |
1894 | ||
011cddd6 | 1895 | (defun face-at-point (&optional thing multiple) |
26c07a69 RS |
1896 | "Return the face of the character after point. |
1897 | If it has more than one face, return the first one. | |
011cddd6 RW |
1898 | If THING is non-nil try first to get a face name from the buffer. |
1899 | IF MULTIPLE is non-nil, return a list of all faces. | |
1900 | Return nil if there is no face." | |
1901 | (let (faces) | |
1902 | (if thing | |
1903 | ;; Try to get a face name from the buffer. | |
1904 | (let ((face (intern-soft (thing-at-point 'symbol)))) | |
1905 | (if (facep face) | |
1906 | (push face faces)))) | |
1907 | ;; Add the named faces that the `read-face-name' or `face' property uses. | |
1908 | (let ((faceprop (or (get-char-property (point) 'read-face-name) | |
1909 | (get-char-property (point) 'face)))) | |
1910 | (cond ((facep faceprop) | |
1911 | (push faceprop faces)) | |
1912 | ((and (listp faceprop) | |
1913 | ;; Don't treat an attribute spec as a list of faces. | |
1914 | (not (keywordp (car faceprop))) | |
1915 | (not (memq (car faceprop) | |
1916 | '(foreground-color background-color)))) | |
1917 | (dolist (face faceprop) | |
1918 | (if (facep face) | |
1919 | (push face faces)))))) | |
1920 | (setq faces (delete-dups (nreverse faces))) | |
1921 | (if multiple faces (car faces)))) | |
26c07a69 RS |
1922 | |
1923 | (defun foreground-color-at-point () | |
1924 | "Return the foreground color of the character after point." | |
1925 | ;; `face-at-point' alone is not sufficient. It only gets named faces. | |
1926 | ;; Need also pick up any face properties that are not associated with named faces. | |
1927 | (let ((face (or (face-at-point) | |
1928 | (get-char-property (point) 'read-face-name) | |
1929 | (get-char-property (point) 'face)))) | |
1930 | (cond ((and face (symbolp face)) | |
1931 | (let ((value (face-foreground face nil 'default))) | |
1932 | (if (member value '("unspecified-fg" "unspecified-bg")) | |
1933 | nil | |
1934 | value))) | |
1935 | ((consp face) | |
1936 | (cond ((memq 'foreground-color face) (cdr (memq 'foreground-color face))) | |
1937 | ((memq ':foreground face) (cadr (memq ':foreground face))))) | |
1938 | (t nil)))) ; Invalid face value. | |
1939 | ||
1940 | (defun background-color-at-point () | |
1941 | "Return the background color of the character after point." | |
1942 | ;; `face-at-point' alone is not sufficient. It only gets named faces. | |
1943 | ;; Need also pick up any face properties that are not associated with named faces. | |
1944 | (let ((face (or (face-at-point) | |
1945 | (get-char-property (point) 'read-face-name) | |
1946 | (get-char-property (point) 'face)))) | |
1947 | (cond ((and face (symbolp face)) | |
1948 | (let ((value (face-background face nil 'default))) | |
1949 | (if (member value '("unspecified-fg" "unspecified-bg")) | |
1950 | nil | |
1951 | value))) | |
1952 | ((consp face) | |
1953 | (cond ((memq 'background-color face) (cdr (memq 'background-color face))) | |
1954 | ((memq ':background face) (cadr (memq ':background face))))) | |
1955 | (t nil)))) ; Invalid face value. | |
5f5c8ee5 | 1956 | |
5f5c8ee5 GM |
1957 | \f |
1958 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1959 | ;;; Frame creation. | |
1960 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
1961 | ||
76e69577 GM |
1962 | (declare-function x-display-list "xfns.c" ()) |
1963 | (declare-function x-open-connection "xfns.c" | |
1964 | (display &optional xrm-string must-succeed)) | |
1965 | (declare-function x-get-resource "frame.c" | |
1966 | (attribute class &optional component subclass)) | |
aa360da1 | 1967 | (declare-function x-parse-geometry "frame.c" (string)) |
a88324d4 | 1968 | (defvar x-display-name) |
aa360da1 | 1969 | |
5f5c8ee5 GM |
1970 | (defun x-handle-named-frame-geometry (parameters) |
1971 | "Add geometry parameters for a named frame to parameter list PARAMETERS. | |
1972 | Value is the new parameter list." | |
e8a2b2da | 1973 | ;; Note that `x-resource-name' has a global meaning. |
c1ef4455 | 1974 | (let ((x-resource-name (cdr (assq 'name parameters)))) |
e8a2b2da CY |
1975 | (when x-resource-name |
1976 | ;; Before checking X resources, we must have an X connection. | |
1977 | (or (window-system) | |
1978 | (x-display-list) | |
1979 | (x-open-connection (or (cdr (assq 'display parameters)) | |
1980 | x-display-name))) | |
1981 | (let (res-geometry parsed) | |
1982 | (and (setq res-geometry (x-get-resource "geometry" "Geometry")) | |
1983 | (setq parsed (x-parse-geometry res-geometry)) | |
1984 | (setq parameters | |
c1ef4455 | 1985 | (append parameters parsed |
e8a2b2da CY |
1986 | ;; If the resource specifies a position, |
1987 | ;; take note of that. | |
1988 | (if (or (assq 'top parsed) (assq 'left parsed)) | |
1989 | '((user-position . t) (user-size . t))))))))) | |
1990 | parameters) | |
5f5c8ee5 GM |
1991 | |
1992 | ||
1993 | (defun x-handle-reverse-video (frame parameters) | |
1994 | "Handle the reverse-video frame parameter and X resource. | |
1995 | `x-create-frame' does not handle this one." | |
1996 | (when (cdr (or (assq 'reverse parameters) | |
5f5c8ee5 GM |
1997 | (let ((resource (x-get-resource "reverseVideo" |
1998 | "ReverseVideo"))) | |
1999 | (if resource | |
2000 | (cons nil (member (downcase resource) | |
2001 | '("on" "true"))))))) | |
2002 | (let* ((params (frame-parameters frame)) | |
2003 | (bg (cdr (assq 'foreground-color params))) | |
2004 | (fg (cdr (assq 'background-color params)))) | |
2005 | (modify-frame-parameters frame | |
2006 | (list (cons 'foreground-color fg) | |
2007 | (cons 'background-color bg))) | |
2008 | (if (equal bg (cdr (assq 'border-color params))) | |
2009 | (modify-frame-parameters frame | |
2010 | (list (cons 'border-color fg)))) | |
2011 | (if (equal bg (cdr (assq 'mouse-color params))) | |
2012 | (modify-frame-parameters frame | |
2013 | (list (cons 'mouse-color fg)))) | |
2014 | (if (equal bg (cdr (assq 'cursor-color params))) | |
2015 | (modify-frame-parameters frame | |
2016 | (list (cons 'cursor-color fg))))))) | |
2017 | ||
aa360da1 | 2018 | (declare-function x-create-frame "xfns.c" (parms)) |
c8ccffb1 | 2019 | (declare-function x-setup-function-keys "term/common-win" (frame)) |
5f5c8ee5 GM |
2020 | |
2021 | (defun x-create-frame-with-faces (&optional parameters) | |
c1ef4455 CY |
2022 | "Create and return a frame with frame parameters PARAMETERS. |
2023 | If PARAMETERS specify a frame name, handle X geometry resources | |
2024 | for that name. If PARAMETERS includes a `reverse' parameter, or | |
2025 | the X resource ``reverseVideo'' is present, handle that." | |
5f5c8ee5 | 2026 | (setq parameters (x-handle-named-frame-geometry parameters)) |
41e6403e CY |
2027 | (let* ((params (copy-tree parameters)) |
2028 | (visibility-spec (assq 'visibility parameters)) | |
2029 | (delayed-params '(foreground-color background-color font | |
2030 | border-color cursor-color mouse-color | |
2031 | visibility scroll-bar-foreground | |
2032 | scroll-bar-background)) | |
2033 | frame success) | |
2034 | (dolist (param delayed-params) | |
2035 | (setq params (assq-delete-all param params))) | |
2036 | (setq frame (x-create-frame `((visibility . nil) . ,params))) | |
5f5c8ee5 GM |
2037 | (unwind-protect |
2038 | (progn | |
2bb819d5 | 2039 | (x-setup-function-keys frame) |
5f5c8ee5 | 2040 | (x-handle-reverse-video frame parameters) |
4983ddea | 2041 | (frame-set-background-mode frame t) |
fa7015f4 | 2042 | (face-set-after-frame-default frame parameters) |
095fe281 | 2043 | (if (null visibility-spec) |
5f5c8ee5 GM |
2044 | (make-frame-visible frame) |
2045 | (modify-frame-parameters frame (list visibility-spec))) | |
2046 | (setq success t)) | |
2047 | (unless success | |
2048 | (delete-frame frame))) | |
2049 | frame)) | |
2050 | ||
fa7015f4 CY |
2051 | (defun face-set-after-frame-default (frame &optional parameters) |
2052 | "Initialize the frame-local faces of FRAME. | |
2053 | Calculate the face definitions using the face specs, custom theme | |
41e6403e | 2054 | settings, X resources, and `face-new-frame-defaults'. |
fa7015f4 | 2055 | Finally, apply any relevant face attributes found amongst the |
c1ef4455 | 2056 | frame parameters in PARAMETERS." |
4983ddea | 2057 | (let ((window-system-p (memq (window-system frame) '(x w32)))) |
1485f4c0 CY |
2058 | ;; The `reverse' is so that `default' goes first. |
2059 | (dolist (face (nreverse (face-list))) | |
4983ddea CY |
2060 | (condition-case () |
2061 | (progn | |
2062 | ;; Initialize faces from face spec and custom theme. | |
2063 | (face-spec-recalc face frame) | |
4983ddea CY |
2064 | ;; Apply attributes specified by face-new-frame-defaults |
2065 | (internal-merge-in-global-face face frame)) | |
2066 | ;; Don't let invalid specs prevent frame creation. | |
2067 | (error nil)))) | |
2068 | ||
fa7015f4 | 2069 | ;; Apply attributes specified by frame parameters. |
8db9c5ee | 2070 | (let ((face-params '((foreground-color default :foreground) |
fa7015f4 CY |
2071 | (background-color default :background) |
2072 | (font default :font) | |
2073 | (border-color border :background) | |
2074 | (cursor-color cursor :background) | |
2075 | (scroll-bar-foreground scroll-bar :foreground) | |
2076 | (scroll-bar-background scroll-bar :background) | |
2077 | (mouse-color mouse :background)))) | |
8db9c5ee | 2078 | (dolist (param face-params) |
fa7015f4 | 2079 | (let* ((param-name (nth 0 param)) |
c1ef4455 | 2080 | (value (cdr (assq param-name parameters)))) |
fa7015f4 CY |
2081 | (if value |
2082 | (set-face-attribute (nth 1 param) frame | |
2083 | (nth 2 param) value)))))) | |
5f5c8ee5 | 2084 | |
53990c84 EZ |
2085 | (defun tty-handle-reverse-video (frame parameters) |
2086 | "Handle the reverse-video frame parameter for terminal frames." | |
c1ef4455 | 2087 | (when (cdr (assq 'reverse parameters)) |
53990c84 EZ |
2088 | (let* ((params (frame-parameters frame)) |
2089 | (bg (cdr (assq 'foreground-color params))) | |
2090 | (fg (cdr (assq 'background-color params)))) | |
2091 | (modify-frame-parameters frame | |
2092 | (list (cons 'foreground-color fg) | |
2093 | (cons 'background-color bg))) | |
2094 | (if (equal bg (cdr (assq 'mouse-color params))) | |
2095 | (modify-frame-parameters frame | |
2096 | (list (cons 'mouse-color fg)))) | |
2097 | (if (equal bg (cdr (assq 'cursor-color params))) | |
2098 | (modify-frame-parameters frame | |
2099 | (list (cons 'cursor-color fg))))))) | |
2100 | ||
5f5c8ee5 GM |
2101 | |
2102 | (defun tty-create-frame-with-faces (&optional parameters) | |
c1ef4455 CY |
2103 | "Create and return a frame from optional frame parameters PARAMETERS. |
2104 | If PARAMETERS contains a `reverse' parameter, handle that." | |
5f5c8ee5 GM |
2105 | (let ((frame (make-terminal-frame parameters)) |
2106 | success) | |
2107 | (unwind-protect | |
061e4e7f | 2108 | (with-selected-frame frame |
53990c84 | 2109 | (tty-handle-reverse-video frame (frame-parameters frame)) |
cd85984a | 2110 | |
8782c744 SM |
2111 | (unless (terminal-parameter frame 'terminal-initted) |
2112 | (set-terminal-parameter frame 'terminal-initted t) | |
2113 | (set-locale-environment nil frame) | |
1d491ef2 | 2114 | (tty-run-terminal-initialization frame nil t)) |
4983ddea | 2115 | (frame-set-background-mode frame t) |
fa7015f4 | 2116 | (face-set-after-frame-default frame parameters) |
5f5c8ee5 GM |
2117 | (setq success t)) |
2118 | (unless success | |
2119 | (delete-frame frame))) | |
2120 | frame)) | |
465fceed | 2121 | |
b34c34da KL |
2122 | (defun tty-find-type (pred type) |
2123 | "Return the longest prefix of TYPE to which PRED returns non-nil. | |
2124 | TYPE should be a tty type name such as \"xterm-16color\". | |
2125 | ||
2126 | The function tries only those prefixes that are followed by a | |
2127 | dash or underscore in the original type name, like \"xterm\" in | |
2128 | the above example." | |
2129 | (let (hyphend) | |
2130 | (while (and type | |
2131 | (not (funcall pred type))) | |
2132 | ;; Strip off last hyphen and what follows, then try again | |
2133 | (setq type | |
5e400cb3 | 2134 | (if (setq hyphend (string-match-p "[-_][^-_]+$" type)) |
b34c34da KL |
2135 | (substring type 0 hyphend) |
2136 | nil)))) | |
2137 | type) | |
2138 | ||
7fd72e2c SM |
2139 | (defvar tty-setup-hook nil |
2140 | "Hook run after running the initialization function of a new text terminal. | |
98bd6b32 | 2141 | Specifically, `tty-run-terminal-initialization' runs this. |
7fd72e2c SM |
2142 | This can be used to fine tune the `input-decode-map', for example.") |
2143 | ||
1d491ef2 | 2144 | (defun tty-run-terminal-initialization (frame &optional type run-hook) |
8cbd7bed KL |
2145 | "Run the special initialization code for the terminal type of FRAME. |
2146 | The optional TYPE parameter may be used to override the autodetected | |
1d491ef2 GM |
2147 | terminal type to a different value. |
2148 | ||
2149 | If optional argument RUN-HOOK is non-nil, then as a final step, | |
2150 | this runs the hook `tty-setup-hook'. | |
98bd6b32 GM |
2151 | |
2152 | If you set `term-file-prefix' to nil, this function does nothing." | |
8cbd7bed | 2153 | (setq type (or type (tty-type frame))) |
cd85984a KL |
2154 | ;; Load library for our terminal type. |
2155 | ;; User init file can set term-file-prefix to nil to prevent this. | |
2156 | (with-selected-frame frame | |
8782c744 | 2157 | (unless (null term-file-prefix) |
b34c34da KL |
2158 | (let* (term-init-func) |
2159 | ;; First, load the terminal initialization file, if it is | |
2160 | ;; available and it hasn't been loaded already. | |
2161 | (tty-find-type #'(lambda (type) | |
2162 | (let ((file (locate-library (concat term-file-prefix type)))) | |
2163 | (and file | |
2164 | (or (assoc file load-history) | |
2165 | (load file t t))))) | |
8cbd7bed | 2166 | type) |
b34c34da KL |
2167 | ;; Next, try to find a matching initialization function, and call it. |
2168 | (tty-find-type #'(lambda (type) | |
2169 | (fboundp (setq term-init-func | |
2170 | (intern (concat "terminal-init-" type))))) | |
8cbd7bed | 2171 | type) |
567c8878 | 2172 | (when (fboundp term-init-func) |
b34c34da | 2173 | (funcall term-init-func)) |
f1e6674b | 2174 | (set-terminal-parameter frame 'terminal-initted term-init-func) |
1d491ef2 | 2175 | (if run-hook (run-hooks 'tty-setup-hook)))))) |
465fceed | 2176 | |
5f5c8ee5 GM |
2177 | ;; Called from C function init_display to initialize faces of the |
2178 | ;; dumped terminal frame on startup. | |
465fceed | 2179 | |
5f5c8ee5 GM |
2180 | (defun tty-set-up-initial-frame-faces () |
2181 | (let ((frame (selected-frame))) | |
4983ddea | 2182 | (frame-set-background-mode frame t) |
5f5c8ee5 | 2183 | (face-set-after-frame-default frame))) |
00f51890 | 2184 | |
bdda3754 | 2185 | \f |
5f5c8ee5 GM |
2186 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2187 | ;;; Standard faces. | |
2188 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
465fceed | 2189 | |
5f5c8ee5 GM |
2190 | (defgroup basic-faces nil |
2191 | "The standard faces of Emacs." | |
2192 | :group 'faces) | |
ef436392 | 2193 | |
bacbbe8f CY |
2194 | (defface default |
2195 | '((t nil)) ; If this were nil, face-defface-spec would not be set. | |
5f5c8ee5 GM |
2196 | "Basic default face." |
2197 | :group 'basic-faces) | |
465fceed | 2198 | |
51d44a36 JL |
2199 | (defface bold |
2200 | '((t :weight bold)) | |
2201 | "Basic bold face." | |
2202 | :group 'basic-faces) | |
2203 | ||
2204 | (defface italic | |
2205 | '((((supports :slant italic)) | |
2206 | :slant italic) | |
2207 | (((supports :underline t)) | |
2208 | :underline t) | |
2209 | (t | |
9aaf2b9c GM |
2210 | ;; Default to italic, even if it doesn't appear to be supported, |
2211 | ;; because in some cases the display engine will do its own | |
2212 | ;; workaround (to `dim' on ttys). | |
51d44a36 JL |
2213 | :slant italic)) |
2214 | "Basic italic face." | |
2215 | :group 'basic-faces) | |
2216 | ||
2217 | (defface bold-italic | |
2218 | '((t :weight bold :slant italic)) | |
2219 | "Basic bold-italic face." | |
2220 | :group 'basic-faces) | |
2221 | ||
2222 | (defface underline | |
2223 | '((((supports :underline t)) | |
2224 | :underline t) | |
2225 | (((supports :weight bold)) | |
2226 | :weight bold) | |
2227 | (t :underline t)) | |
2228 | "Basic underlined face." | |
2229 | :group 'basic-faces) | |
2230 | ||
2231 | (defface fixed-pitch | |
d5f57335 | 2232 | '((t :family "Monospace")) |
51d44a36 JL |
2233 | "The basic fixed-pitch face." |
2234 | :group 'basic-faces) | |
2235 | ||
2236 | (defface variable-pitch | |
ed008205 | 2237 | '((t :family "Sans Serif")) |
51d44a36 JL |
2238 | "The basic variable-pitch face." |
2239 | :group 'basic-faces) | |
2240 | ||
2241 | (defface shadow | |
2242 | '((((class color grayscale) (min-colors 88) (background light)) | |
2243 | :foreground "grey50") | |
2244 | (((class color grayscale) (min-colors 88) (background dark)) | |
2245 | :foreground "grey70") | |
2246 | (((class color) (min-colors 8) (background light)) | |
2247 | :foreground "green") | |
2248 | (((class color) (min-colors 8) (background dark)) | |
2249 | :foreground "yellow")) | |
2250 | "Basic face for shadowed text." | |
2251 | :group 'basic-faces | |
2252 | :version "22.1") | |
2253 | ||
59746720 JL |
2254 | (defface link |
2255 | '((((class color) (min-colors 88) (background light)) | |
fa7c3228 | 2256 | :foreground "RoyalBlue3" :underline t) |
59746720 JL |
2257 | (((class color) (background light)) |
2258 | :foreground "blue" :underline t) | |
2259 | (((class color) (min-colors 88) (background dark)) | |
2260 | :foreground "cyan1" :underline t) | |
2261 | (((class color) (background dark)) | |
2262 | :foreground "cyan" :underline t) | |
2263 | (t :inherit underline)) | |
2264 | "Basic face for unvisited links." | |
2265 | :group 'basic-faces | |
2266 | :version "22.1") | |
2267 | ||
2268 | (defface link-visited | |
2269 | '((default :inherit link) | |
2270 | (((class color) (background light)) :foreground "magenta4") | |
2271 | (((class color) (background dark)) :foreground "violet")) | |
2272 | "Basic face for visited links." | |
2273 | :group 'basic-faces | |
2274 | :version "22.1") | |
2275 | ||
51d44a36 JL |
2276 | (defface highlight |
2277 | '((((class color) (min-colors 88) (background light)) | |
2278 | :background "darkseagreen2") | |
2279 | (((class color) (min-colors 88) (background dark)) | |
2280 | :background "darkolivegreen") | |
2281 | (((class color) (min-colors 16) (background light)) | |
2282 | :background "darkseagreen2") | |
2283 | (((class color) (min-colors 16) (background dark)) | |
2284 | :background "darkolivegreen") | |
2285 | (((class color) (min-colors 8)) | |
2286 | :background "green" :foreground "black") | |
2287 | (t :inverse-video t)) | |
2288 | "Basic face for highlighting." | |
2289 | :group 'basic-faces) | |
2290 | ||
f3e848f4 AR |
2291 | ;; Region face: under NS, default to the system-defined selection |
2292 | ;; color (optimized for the fixed white background of other apps), | |
2293 | ;; if background is light. | |
51d44a36 JL |
2294 | (defface region |
2295 | '((((class color) (min-colors 88) (background dark)) | |
2296 | :background "blue3") | |
3a46642b | 2297 | (((class color) (min-colors 88) (background light) (type gtk)) |
3c334c14 | 2298 | :distant-foreground "gtk_selection_fg_color" |
3a46642b | 2299 | :background "gtk_selection_bg_color") |
f3e848f4 | 2300 | (((class color) (min-colors 88) (background light) (type ns)) |
3c334c14 | 2301 | :distant-foreground "ns_selection_fg_color" |
1610938f | 2302 | :background "ns_selection_bg_color") |
51d44a36 JL |
2303 | (((class color) (min-colors 88) (background light)) |
2304 | :background "lightgoldenrod2") | |
2305 | (((class color) (min-colors 16) (background dark)) | |
2306 | :background "blue3") | |
2307 | (((class color) (min-colors 16) (background light)) | |
2308 | :background "lightgoldenrod2") | |
2309 | (((class color) (min-colors 8)) | |
2310 | :background "blue" :foreground "white") | |
2311 | (((type tty) (class mono)) | |
2312 | :inverse-video t) | |
2313 | (t :background "gray")) | |
2314 | "Basic face for highlighting the region." | |
2315 | :version "21.1" | |
2316 | :group 'basic-faces) | |
2317 | ||
2318 | (defface secondary-selection | |
2319 | '((((class color) (min-colors 88) (background light)) | |
2320 | :background "yellow1") | |
2321 | (((class color) (min-colors 88) (background dark)) | |
2322 | :background "SkyBlue4") | |
2323 | (((class color) (min-colors 16) (background light)) | |
2324 | :background "yellow") | |
2325 | (((class color) (min-colors 16) (background dark)) | |
2326 | :background "SkyBlue4") | |
2327 | (((class color) (min-colors 8)) | |
2328 | :background "cyan" :foreground "black") | |
2329 | (t :inverse-video t)) | |
2330 | "Basic face for displaying the secondary selection." | |
2331 | :group 'basic-faces) | |
2332 | ||
2333 | (defface trailing-whitespace | |
2334 | '((((class color) (background light)) | |
2335 | :background "red1") | |
2336 | (((class color) (background dark)) | |
2337 | :background "red1") | |
2338 | (t :inverse-video t)) | |
2339 | "Basic face for highlighting trailing whitespace." | |
2340 | :version "21.1" | |
51d44a36 JL |
2341 | :group 'basic-faces) |
2342 | ||
2343 | (defface escape-glyph | |
2344 | '((((background dark)) :foreground "cyan") | |
2345 | ;; See the comment in minibuffer-prompt for | |
2346 | ;; the reason not to use blue on MS-DOS. | |
2347 | (((type pc)) :foreground "magenta") | |
2348 | ;; red4 is too dark, but some say blue is too loud. | |
2349 | ;; brown seems to work ok. -- rms. | |
2350 | (t :foreground "brown")) | |
1a77c985 | 2351 | "Face for characters displayed as sequences using `^' or `\\'." |
51d44a36 JL |
2352 | :group 'basic-faces |
2353 | :version "22.1") | |
2354 | ||
2355 | (defface nobreak-space | |
2356 | '((((class color) (min-colors 88)) :inherit escape-glyph :underline t) | |
2357 | (((class color) (min-colors 8)) :background "magenta") | |
2358 | (t :inverse-video t)) | |
2359 | "Face for displaying nobreak space." | |
2360 | :group 'basic-faces | |
2361 | :version "22.1") | |
72418504 | 2362 | |
97bca259 JL |
2363 | (defgroup mode-line-faces nil |
2364 | "Faces used in the mode line." | |
6d968826 | 2365 | :group 'mode-line |
97bca259 JL |
2366 | :group 'faces |
2367 | :version "22.1") | |
2368 | ||
3759f14b | 2369 | (defface mode-line |
11c2175c | 2370 | '((((class color) (min-colors 88)) |
b6b90dfc SM |
2371 | :box (:line-width -1 :style released-button) |
2372 | :background "grey75" :foreground "black") | |
5f5c8ee5 | 2373 | (t |
b6b90dfc | 2374 | :inverse-video t)) |
c5752dcb | 2375 | "Basic mode line face for selected window." |
a4391cf1 | 2376 | :version "21.1" |
97bca259 | 2377 | :group 'mode-line-faces |
5f5c8ee5 | 2378 | :group 'basic-faces) |
465fceed | 2379 | |
c5752dcb | 2380 | (defface mode-line-inactive |
cf459bb7 | 2381 | '((default |
b6b90dfc | 2382 | :inherit mode-line) |
11c2175c | 2383 | (((class color) (min-colors 88) (background light)) |
c5752dcb KS |
2384 | :weight light |
2385 | :box (:line-width -1 :color "grey75" :style nil) | |
2386 | :foreground "grey20" :background "grey90") | |
11c2175c | 2387 | (((class color) (min-colors 88) (background dark) ) |
53a2f6e1 MB |
2388 | :weight light |
2389 | :box (:line-width -1 :color "grey40" :style nil) | |
b6b90dfc | 2390 | :foreground "grey80" :background "grey30")) |
c5752dcb | 2391 | "Basic mode line face for non-selected windows." |
bf247b6e | 2392 | :version "22.1" |
97bca259 JL |
2393 | :group 'mode-line-faces |
2394 | :group 'basic-faces) | |
9f255bc3 | 2395 | (define-obsolete-face-alias 'modeline-inactive 'mode-line-inactive "22.1") |
97bca259 JL |
2396 | |
2397 | (defface mode-line-highlight | |
2398 | '((((class color) (min-colors 88)) | |
2399 | :box (:line-width 2 :color "grey40" :style released-button)) | |
2400 | (t | |
2401 | :inherit highlight)) | |
2402 | "Basic mode line face for highlighting." | |
2403 | :version "22.1" | |
2404 | :group 'mode-line-faces | |
2405 | :group 'basic-faces) | |
9f255bc3 | 2406 | (define-obsolete-face-alias 'modeline-highlight 'mode-line-highlight "22.1") |
97bca259 | 2407 | |
313e2fc4 GM |
2408 | (defface mode-line-emphasis |
2409 | '((t (:weight bold))) | |
2410 | "Face used to emphasize certain mode line features. | |
2411 | Use the face `mode-line-highlight' for features that can be selected." | |
2412 | :version "23.1" | |
2413 | :group 'mode-line-faces | |
2414 | :group 'basic-faces) | |
2415 | ||
97bca259 JL |
2416 | (defface mode-line-buffer-id |
2417 | '((t (:weight bold))) | |
2418 | "Face used for buffer identification parts of the mode line." | |
2419 | :version "22.1" | |
2420 | :group 'mode-line-faces | |
c5752dcb | 2421 | :group 'basic-faces) |
9f255bc3 | 2422 | (define-obsolete-face-alias 'modeline-buffer-id 'mode-line-buffer-id "22.1") |
d11fba25 | 2423 | |
e5e7779f | 2424 | (defface header-line |
cf459bb7 | 2425 | '((default |
6b61353c KH |
2426 | :inherit mode-line) |
2427 | (((type tty)) | |
1cb4393e MB |
2428 | ;; This used to be `:inverse-video t', but that doesn't look very |
2429 | ;; good when combined with inverse-video mode-lines and multiple | |
2430 | ;; windows. Underlining looks better, and is more consistent with | |
2431 | ;; the window-system face variants, which deemphasize the | |
2432 | ;; header-line in relation to the mode-line face. If a terminal | |
2433 | ;; can't underline, then the header-line will end up without any | |
2434 | ;; highlighting; this may be too confusing in general, although it | |
2435 | ;; happens to look good with the only current use of header-lines, | |
2436 | ;; the info browser. XXX | |
6b61353c | 2437 | :inverse-video nil ;Override the value inherited from mode-line. |
a7ac92b6 | 2438 | :underline t) |
98490598 | 2439 | (((class color grayscale) (background light)) |
bdab1d43 | 2440 | :background "grey90" :foreground "grey20" |
6b61353c | 2441 | :box nil) |
98490598 | 2442 | (((class color grayscale) (background dark)) |
bdab1d43 | 2443 | :background "grey20" :foreground "grey90" |
6b61353c | 2444 | :box nil) |
98490598 | 2445 | (((class mono) (background light)) |
bdab1d43 MB |
2446 | :background "white" :foreground "black" |
2447 | :inverse-video nil | |
2448 | :box nil | |
6b61353c | 2449 | :underline t) |
98490598 | 2450 | (((class mono) (background dark)) |
bdab1d43 MB |
2451 | :background "black" :foreground "white" |
2452 | :inverse-video nil | |
2453 | :box nil | |
6b61353c | 2454 | :underline t)) |
e5e7779f | 2455 | "Basic header-line face." |
a4391cf1 | 2456 | :version "21.1" |
5f5c8ee5 | 2457 | :group 'basic-faces) |
e8e4cda0 | 2458 | |
51d44a36 JL |
2459 | (defface vertical-border |
2460 | '((((type tty)) :inherit mode-line-inactive)) | |
2461 | "Face used for vertical window dividers on ttys." | |
2462 | :version "22.1" | |
5f5c8ee5 | 2463 | :group 'basic-faces) |
d11fba25 | 2464 | |
764ec9e5 MR |
2465 | (defface window-divider '((t :foreground "gray60")) |
2466 | "Basic face for window dividers. | |
2467 | When a divider is less than 3 pixels wide, it is drawn solidly | |
2468 | with the foreground of this face. For larger dividers this face | |
2469 | is used for the inner part while the first pixel line/column is | |
2470 | drawn with the `window-divider-first-pixel' face and the last | |
2471 | pixel line/column with the `window-divider-last-pixel' face." | |
2472 | :version "24.4" | |
2473 | :group 'frames | |
2474 | :group 'basic-faces) | |
2475 | ||
2476 | (defface window-divider-first-pixel | |
2477 | '((t :foreground "gray80")) | |
2478 | "Basic face for first pixel line/column of window dividers. | |
2479 | When a divider is at least 3 pixels wide, its first pixel | |
2480 | line/column is drawn with the foreground of this face. If you do | |
2481 | not want to accentuate the first pixel line/column, set this to | |
2482 | the same as `window-divider' face." | |
2483 | :version "24.4" | |
2484 | :group 'frames | |
2485 | :group 'basic-faces) | |
2486 | ||
2487 | (defface window-divider-last-pixel | |
2488 | '((t :foreground "gray40")) | |
2489 | "Basic face for last pixel line/column of window dividers. | |
2490 | When a divider is at least 3 pixels wide, its last pixel | |
2491 | line/column is drawn with the foreground of this face. If you do | |
2492 | not want to accentuate the last pixel line/column, set this to | |
2493 | the same as `window-divider' face." | |
2494 | :version "24.4" | |
2495 | :group 'frames | |
2496 | :group 'basic-faces) | |
2497 | ||
9ed779e8 JL |
2498 | (defface minibuffer-prompt |
2499 | '((((background dark)) :foreground "cyan") | |
2500 | ;; Don't use blue because many users of the MS-DOS port customize | |
2501 | ;; their foreground color to be blue. | |
2502 | (((type pc)) :foreground "magenta") | |
c57a1dc6 | 2503 | (t :foreground "medium blue")) |
9ed779e8 JL |
2504 | "Face for minibuffer prompts. |
2505 | By default, Emacs automatically adds this face to the value of | |
2506 | `minibuffer-prompt-properties', which is a list of text properties | |
2507 | used to display the prompt text." | |
bf247b6e | 2508 | :version "22.1" |
31cf46d3 RS |
2509 | :group 'basic-faces) |
2510 | ||
2511 | (setq minibuffer-prompt-properties | |
2512 | (append minibuffer-prompt-properties (list 'face 'minibuffer-prompt))) | |
2513 | ||
f1cae29e | 2514 | (defface fringe |
d6d59057 | 2515 | '((((class color) (background light)) |
b6b90dfc SM |
2516 | :background "grey95") |
2517 | (((class color) (background dark)) | |
2518 | :background "grey10") | |
2519 | (t | |
2520 | :background "gray")) | |
f1cae29e GM |
2521 | "Basic face for the fringes to the left and right of windows under X." |
2522 | :version "21.1" | |
84fe35f0 | 2523 | :group 'frames |
f1cae29e GM |
2524 | :group 'basic-faces) |
2525 | ||
d390b4d2 | 2526 | (defface scroll-bar '((t nil)) |
f1cae29e GM |
2527 | "Basic face for the scroll bar colors under X." |
2528 | :version "21.1" | |
84fe35f0 | 2529 | :group 'frames |
f1cae29e GM |
2530 | :group 'basic-faces) |
2531 | ||
d390b4d2 | 2532 | (defface border '((t nil)) |
f1cae29e GM |
2533 | "Basic face for the frame border under X." |
2534 | :version "21.1" | |
84fe35f0 | 2535 | :group 'frames |
f1cae29e GM |
2536 | :group 'basic-faces) |
2537 | ||
4983ddea CY |
2538 | (defface cursor |
2539 | '((((background light)) :background "black") | |
2540 | (((background dark)) :background "white")) | |
8d413c2b | 2541 | "Basic face for the cursor color under X. |
08b0fee8 CY |
2542 | Currently, only the `:background' attribute is meaningful; all |
2543 | other attributes are ignored. The cursor foreground color is | |
2544 | taken from the background color of the underlying text. | |
2545 | ||
8d413c2b | 2546 | Note: Other faces cannot inherit from the cursor face." |
f1cae29e | 2547 | :version "21.1" |
84fe35f0 | 2548 | :group 'cursor |
f1cae29e GM |
2549 | :group 'basic-faces) |
2550 | ||
8d413c2b | 2551 | (put 'cursor 'face-no-inherit t) |
f1cae29e | 2552 | |
d390b4d2 | 2553 | (defface mouse '((t nil)) |
f1cae29e | 2554 | "Basic face for the mouse color under X." |
e59176e2 | 2555 | :version "21.1" |
84fe35f0 | 2556 | :group 'mouse |
5f5c8ee5 | 2557 | :group 'basic-faces) |
bdda3754 | 2558 | |
51d44a36 JL |
2559 | (defface tool-bar |
2560 | '((default | |
2561 | :box (:line-width 1 :style released-button) | |
2562 | :foreground "black") | |
9e2a2647 | 2563 | (((type x w32 ns) (class color)) |
51d44a36 JL |
2564 | :background "grey75") |
2565 | (((type x) (class mono)) | |
2566 | :background "grey")) | |
2567 | "Basic tool-bar face." | |
2568 | :version "21.1" | |
5f5c8ee5 | 2569 | :group 'basic-faces) |
bdda3754 | 2570 | |
51d44a36 JL |
2571 | (defface menu |
2572 | '((((type tty)) | |
2573 | :inverse-video t) | |
2574 | (((type x-toolkit)) | |
2575 | ) | |
16320ac7 | 2576 | (t |
51d44a36 JL |
2577 | :inverse-video t)) |
2578 | "Basic face for the font and colors of the menu bar and popup menus." | |
a4391cf1 | 2579 | :version "21.1" |
51d44a36 | 2580 | :group 'menu |
a4391cf1 | 2581 | :group 'basic-faces) |
465fceed | 2582 | |
4c47bd1e | 2583 | (defface help-argument-name '((t :inherit italic)) |
6c58c39c CY |
2584 | "Face to highlight argument names in *Help* buffers." |
2585 | :group 'help) | |
b2cca856 | 2586 | |
b18fad6d KH |
2587 | (defface glyphless-char |
2588 | '((((type tty)) :inherit underline) | |
1cd64aae | 2589 | (((type pc)) :inherit escape-glyph) |
b18fad6d | 2590 | (t :height 0.6)) |
b2cca856 KH |
2591 | "Face for displaying non-graphic characters (e.g. U+202A (LRE)). |
2592 | It is used for characters of no fonts too." | |
2593 | :version "24.1" | |
2594 | :group 'basic-faces) | |
bc987f8b JL |
2595 | |
2596 | (defface error | |
4b56d0fe CY |
2597 | '((default :weight bold) |
2598 | (((class color) (min-colors 88) (background light)) :foreground "Red1") | |
2599 | (((class color) (min-colors 88) (background dark)) :foreground "Pink") | |
2600 | (((class color) (min-colors 16) (background light)) :foreground "Red1") | |
2601 | (((class color) (min-colors 16) (background dark)) :foreground "Pink") | |
2602 | (((class color) (min-colors 8)) :foreground "red") | |
2603 | (t :inverse-video t)) | |
bc987f8b JL |
2604 | "Basic face used to highlight errors and to denote failure." |
2605 | :version "24.1" | |
2606 | :group 'basic-faces) | |
2607 | ||
2608 | (defface warning | |
4b56d0fe CY |
2609 | '((default :weight bold) |
2610 | (((class color) (min-colors 16)) :foreground "DarkOrange") | |
2611 | (((class color)) :foreground "yellow")) | |
bc987f8b JL |
2612 | "Basic face used to highlight warnings." |
2613 | :version "24.1" | |
2614 | :group 'basic-faces) | |
2615 | ||
2616 | (defface success | |
4b56d0fe CY |
2617 | '((default :weight bold) |
2618 | (((class color) (min-colors 16) (background light)) :foreground "ForestGreen") | |
2619 | (((class color) (min-colors 88) (background dark)) :foreground "Green1") | |
2620 | (((class color) (min-colors 16) (background dark)) :foreground "Green") | |
2621 | (((class color)) :foreground "green")) | |
bc987f8b JL |
2622 | "Basic face used to indicate successful operation." |
2623 | :version "24.1" | |
2624 | :group 'basic-faces) | |
2625 | ||
0fe3602a EZ |
2626 | ;; Faces for TTY menus. |
2627 | (defface tty-menu-enabled-face | |
2628 | '((t | |
2629 | :foreground "yellow" :background "blue" :weight bold)) | |
2630 | "Face for displaying enabled items in TTY menus." | |
2631 | :group 'basic-faces) | |
2632 | ||
2633 | (defface tty-menu-disabled-face | |
2634 | '((((class color) (min-colors 16)) | |
2635 | :foreground "lightgray" :background "blue") | |
2636 | (t | |
2637 | :foreground "white" :background "blue")) | |
2638 | "Face for displaying disabled items in TTY menus." | |
2639 | :group 'basic-faces) | |
2640 | ||
2641 | (defface tty-menu-selected-face | |
2642 | '((t :background "red")) | |
2643 | "Face for displaying the currently selected item in TTY menus." | |
2644 | :group 'basic-faces) | |
2645 | ||
84c73ba0 DG |
2646 | (defgroup paren-showing-faces nil |
2647 | "Faces used to highlight paren matches." | |
2648 | :group 'paren-showing | |
2649 | :group 'faces | |
2650 | :version "22.1") | |
2651 | ||
2652 | (defface show-paren-match | |
2653 | '((((class color) (background light)) | |
2654 | :background "turquoise") ; looks OK on tty (becomes cyan) | |
2655 | (((class color) (background dark)) | |
2656 | :background "steelblue3") ; looks OK on tty (becomes blue) | |
2657 | (((background dark)) | |
2658 | :background "grey50") | |
2659 | (t | |
2660 | :background "gray")) | |
2661 | "Face used for a matching paren." | |
2662 | :group 'paren-showing-faces) | |
2663 | ||
2664 | (defface show-paren-mismatch | |
2665 | '((((class color)) (:foreground "white" :background "purple")) | |
2666 | (t (:inverse-video t))) | |
2667 | "Face used for a mismatching paren." | |
2668 | :group 'paren-showing-faces) | |
2669 | ||
465fceed | 2670 | \f |
5f5c8ee5 GM |
2671 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2672 | ;;; Manipulating font names. | |
2673 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
2674 | ||
da6062e6 | 2675 | ;; This is here for compatibility with Emacs 20.2. For example, |
07f27947 DL |
2676 | ;; international/fontset.el uses x-resolve-font-name. The following |
2677 | ;; functions are not used in the face implementation itself. | |
465fceed | 2678 | |
d7fa5aa2 RS |
2679 | (defvar x-font-regexp nil) |
2680 | (defvar x-font-regexp-head nil) | |
2681 | (defvar x-font-regexp-weight nil) | |
2682 | (defvar x-font-regexp-slant nil) | |
465fceed | 2683 | |
021ca129 KH |
2684 | (defconst x-font-regexp-weight-subnum 1) |
2685 | (defconst x-font-regexp-slant-subnum 2) | |
2686 | (defconst x-font-regexp-swidth-subnum 3) | |
2687 | (defconst x-font-regexp-adstyle-subnum 4) | |
2688 | ||
465fceed ER |
2689 | ;;; Regexps matching font names in "Host Portable Character Representation." |
2690 | ;;; | |
2691 | (let ((- "[-?]") | |
2692 | (foundry "[^-]+") | |
2693 | (family "[^-]+") | |
2694 | (weight "\\(bold\\|demibold\\|medium\\)") ; 1 | |
2695 | ; (weight\? "\\(\\*\\|bold\\|demibold\\|medium\\|\\)") ; 1 | |
2696 | (weight\? "\\([^-]*\\)") ; 1 | |
2697 | (slant "\\([ior]\\)") ; 2 | |
2698 | ; (slant\? "\\([ior?*]?\\)") ; 2 | |
2699 | (slant\? "\\([^-]?\\)") ; 2 | |
2700 | ; (swidth "\\(\\*\\|normal\\|semicondensed\\|\\)") ; 3 | |
2701 | (swidth "\\([^-]*\\)") ; 3 | |
2702 | ; (adstyle "\\(\\*\\|sans\\|\\)") ; 4 | |
c8787b81 | 2703 | (adstyle "\\([^-]*\\)") ; 4 |
465fceed ER |
2704 | (pixelsize "[0-9]+") |
2705 | (pointsize "[0-9][0-9]+") | |
2706 | (resx "[0-9][0-9]+") | |
2707 | (resy "[0-9][0-9]+") | |
2708 | (spacing "[cmp?*]") | |
2709 | (avgwidth "[0-9]+") | |
2710 | (registry "[^-]+") | |
2711 | (encoding "[^-]+") | |
2712 | ) | |
2713 | (setq x-font-regexp | |
1e8780b1 | 2714 | (purecopy (concat "\\`\\*?[-?*]" |
465fceed | 2715 | foundry - family - weight\? - slant\? - swidth - adstyle - |
e20d641f RS |
2716 | pixelsize - pointsize - resx - resy - spacing - avgwidth - |
2717 | registry - encoding "\\*?\\'" | |
1e8780b1 | 2718 | ))) |
465fceed | 2719 | (setq x-font-regexp-head |
1e8780b1 DN |
2720 | (purecopy (concat "\\`[-?*]" foundry - family - weight\? - slant\? |
2721 | "\\([-*?]\\|\\'\\)"))) | |
2722 | (setq x-font-regexp-slant (purecopy (concat - slant -))) | |
2723 | (setq x-font-regexp-weight (purecopy (concat - weight -))) | |
70d0c3b0 | 2724 | nil) |
465fceed | 2725 | |
5f5c8ee5 | 2726 | |
281dc1c2 JB |
2727 | (defun x-resolve-font-name (pattern &optional face frame) |
2728 | "Return a font name matching PATTERN. | |
ac4c2e6b | 2729 | All wildcards in PATTERN are instantiated. |
10d89673 JB |
2730 | If PATTERN is nil, return the name of the frame's base font, which never |
2731 | contains wildcards. | |
e17dbede RS |
2732 | Given optional arguments FACE and FRAME, return a font which is |
2733 | also the same size as FACE on FRAME, or fail." | |
14e6867c RS |
2734 | (or (symbolp face) |
2735 | (setq face (face-name face))) | |
2736 | (and (eq frame t) | |
2737 | (setq frame nil)) | |
10d89673 | 2738 | (if pattern |
8db93e45 | 2739 | ;; Note that x-list-fonts has code to handle a face with nil as its font. |
abd89b80 | 2740 | (let ((fonts (x-list-fonts pattern face frame 1))) |
10d89673 JB |
2741 | (or fonts |
2742 | (if face | |
5e400cb3 | 2743 | (if (string-match-p "\\*" pattern) |
962a60aa RS |
2744 | (if (null (face-font face)) |
2745 | (error "No matching fonts are the same height as the frame default font") | |
2746 | (error "No matching fonts are the same height as face `%s'" face)) | |
2747 | (if (null (face-font face)) | |
2748 | (error "Height of font `%s' doesn't match the frame default font" | |
2749 | pattern) | |
2750 | (error "Height of font `%s' doesn't match face `%s'" | |
2751 | pattern face))) | |
7cf6fac1 | 2752 | (error "No fonts match `%s'" pattern))) |
10d89673 JB |
2753 | (car fonts)) |
2754 | (cdr (assq 'font (frame-parameters (selected-frame)))))) | |
281dc1c2 | 2755 | |
49238e7f CY |
2756 | (defcustom font-list-limit 100 |
2757 | "This variable is obsolete and has no effect." | |
2758 | :type 'integer | |
2759 | :group 'display) | |
2760 | (make-obsolete-variable 'font-list-limit nil "24.3") | |
2761 | ||
f0138172 JB |
2762 | (provide 'faces) |
2763 | ||
70d0c3b0 | 2764 | ;;; faces.el ends here |