Mercurial > emacs
comparison lisp/faces.el @ 55899:4592654cd2e9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-369
Rewrite face-differs-from-default-p
author | Miles Bader <miles@gnu.org> |
---|---|
date | Fri, 04 Jun 2004 02:50:50 +0000 |
parents | 7f92c3f5d841 |
children | 7814348a02ec |
comparison
equal
deleted
inserted
replaced
55898:7f92c3f5d841 | 55899:4592654cd2e9 |
---|---|
238 If FRAME is omitted or nil, use the selected frame." | 238 If FRAME is omitted or nil, use the selected frame." |
239 (internal-lisp-face-equal-p face1 face2 frame)) | 239 (internal-lisp-face-equal-p face1 face2 frame)) |
240 | 240 |
241 | 241 |
242 (defun face-differs-from-default-p (face &optional frame) | 242 (defun face-differs-from-default-p (face &optional frame) |
243 "Non-nil if FACE displays differently from the default face. | 243 "Return non-nil if FACE displays differently from the default face. |
244 If the optional argument FRAME is given, report on face FACE in that frame. | 244 If the optional argument FRAME is given, report on face FACE in that frame. |
245 If FRAME is t, report on the defaults for face FACE (for new frames). | 245 If FRAME is t, report on the defaults for face FACE (for new frames). |
246 If FRAME is omitted or nil, use the selected frame. | 246 If FRAME is omitted or nil, use the selected frame." |
247 A face is considered to be ``the same'' as the default face if it is | 247 (if (not (equal (face-font face frame) (face-font 'default frame))) |
248 actually specified in the same way (equal attributes) or if it is | 248 ;; The font is different from the default face's font, so clearly it |
249 fully-unspecified, and thus inherits the attributes of any face it | 249 ;; differs. This only really works on window-systems; on ttys, the |
250 is displayed on top of." | 250 ;; "font" is a constant, with attributes layered on top of it. |
251 (cond ((eq frame t) (setq frame nil)) | 251 :font |
252 ((null frame) (setq frame (selected-frame)))) | 252 ;; General face attribute check. On graphical displays |
253 (let* ((v1 (internal-lisp-face-p face frame)) | 253 ;; `display-supports-face-attributes-p' just checks whether each |
254 (n (if v1 (length v1) 0)) | 254 ;; attribute is different that the default face, so we just check to |
255 (v2 (internal-lisp-face-p 'default frame)) | 255 ;; make sure each attribute of the merged face is not `unspecified'; |
256 (i 1)) | 256 ;; we already checked the font above, so font-related attributes are |
257 (unless v1 | 257 ;; omitted for that reason. On a tty, |
258 (error "Not a face: %S" face)) | 258 ;; display-supports-face-attributes-p actually does do further |
259 (while (and (< i n) | 259 ;; checks, and correctly deals with the display's capabilities, so |
260 (or (eq 'unspecified (aref v1 i)) | 260 ;; we use it to check all attributes. |
261 (equal (aref v1 i) (aref v2 i)))) | 261 (let ((attrs |
262 (setq i (1+ i))) | 262 (if (memq (framep (or frame (selected-frame))) '(x w32 mac)) |
263 (< i n))) | 263 ;; Omit font-related attributes on a window-system |
264 '(:foreground :foreground :background :underline :overline | |
265 :strike-through :box :inverse-video :stipple) | |
266 ;; On a tty, check all attributes | |
267 '(:family :width :height :weight :slant :foreground | |
268 :foreground :background :underline :overline | |
269 :strike-through :box :inverse-video :stipple))) | |
270 (differs nil)) | |
271 (while (and attrs (not differs)) | |
272 (let* ((attr (pop attrs)) | |
273 (attr-val (face-attribute face attr frame t))) | |
274 (when (and | |
275 (not (eq attr-val 'unspecified)) | |
276 (display-supports-face-attributes-p (list attr attr-val) | |
277 frame)) | |
278 (setq differs attr)))) | |
279 differs))) | |
264 | 280 |
265 | 281 |
266 (defun face-nontrivial-p (face &optional frame) | 282 (defun face-nontrivial-p (face &optional frame) |
267 "True if face FACE has some non-nil attribute. | 283 "True if face FACE has some non-nil attribute. |
268 If the optional argument FRAME is given, report on face FACE in that frame. | 284 If the optional argument FRAME is given, report on face FACE in that frame. |