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