diff options
| author | Richard M. Stallman | 2007-12-30 03:32:34 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2007-12-30 03:32:34 +0000 |
| commit | 24837f13fcb75ee1eb1a91dc09a539b15c0e86c7 (patch) | |
| tree | c8c794c63e70d38343ec9a66914a72407407898f /lisp | |
| parent | babfb70b906961213428539387b82e0553062623 (diff) | |
| download | emacs-24837f13fcb75ee1eb1a91dc09a539b15c0e86c7.tar.gz emacs-24837f13fcb75ee1eb1a91dc09a539b15c0e86c7.zip | |
(face-spec-set): Third arg is now FOR-DEFFACE.
Use of frame as third arg is deprecated.
Handle `face-override-spec' property.
(face-spec-recalc): New function.
(face-spec-set-2): New function.
(frame-set-background-mode): Handle `face-override-spec' property.
Use `face-spec-recalc'.
(face-set-after-frame-default): Use `face-spec-recalc'.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/faces.el | 119 |
1 files changed, 77 insertions, 42 deletions
diff --git a/lisp/faces.el b/lisp/faces.el index 925b76844e9..74d1a4e4f25 100644 --- a/lisp/faces.el +++ b/lisp/faces.el | |||
| @@ -1445,46 +1445,79 @@ If SPEC is nil, return nil." | |||
| 1445 | (setq attrs (cdr attrs))))) | 1445 | (setq attrs (cdr attrs))))) |
| 1446 | 1446 | ||
| 1447 | 1447 | ||
| 1448 | (defun face-spec-set (face spec &optional frame) | 1448 | (defun face-spec-set (face spec &optional for-defface) |
| 1449 | "Set FACE's attributes according to the first matching entry in SPEC. | 1449 | "Set FACE's face spec, which controls its appearance, to SPEC> |
| 1450 | FRAME is the frame whose frame-local face is set. FRAME nil means | 1450 | If FOR-DEFFACE is t, set the base spec, the one that `defface' |
| 1451 | do it on all frames (and change the default for new frames). | 1451 | and Custom set. (In that case, the caller must put it in the |
| 1452 | See `defface' for information about SPEC. If SPEC is nil, do nothing." | 1452 | appropriate property, because that depends on the caller.) |
| 1453 | (let ((attrs (face-spec-choose spec frame))) | 1453 | If FOR-DEFFACE is nil, set the overriding spec (and store it |
| 1454 | (when spec | 1454 | in the `face-override-spec' property of FACE). |
| 1455 | (face-spec-reset-face face (or frame t))) | 1455 | |
| 1456 | (while attrs | 1456 | The appearance of FACE is controlled by the base spec, |
| 1457 | (let ((attribute (car attrs)) | 1457 | by any custom theme specs on top of that, and by the |
| 1458 | (value (car (cdr attrs)))) | 1458 | the overriding spec on top of all the rest. |
| 1459 | ;; Support some old-style attribute names and values. | 1459 | |
| 1460 | (case attribute | 1460 | FOR-DEFFACE can also be a frame, in which case we set the |
| 1461 | (:bold (setq attribute :weight value (if value 'bold 'normal))) | 1461 | frame-specific attributes of FACE for that frame based on SPEC. |
| 1462 | (:italic (setq attribute :slant value (if value 'italic 'normal))) | 1462 | That usage is deprecated. |
| 1463 | ((:foreground :background) | 1463 | |
| 1464 | ;; Compatibility with 20.x. Some bogus face specs seem to | 1464 | See `defface' for information about the format and meaning of SPEC." |
| 1465 | ;; exist containing things like `:foreground nil'. | 1465 | (if (framep for-defface) |
| 1466 | (if (null value) (setq value 'unspecified))) | 1466 | ;; Handle the deprecated case where third arg is a frame. |
| 1467 | (t (unless (assq attribute face-x-resources) | 1467 | (face-spec-set-2 face for-defface spec) |
| 1468 | (setq attribute nil)))) | 1468 | (if for-defface |
| 1469 | (when attribute | 1469 | ;; When we reset the face based on its custom spec, then it is |
| 1470 | ;; If frame is nil, set the default for new frames. | 1470 | ;; unmodified as far as Custom is concerned. |
| 1471 | ;; Existing frames are handled below. | 1471 | (put (or (get face 'face-alias) face) 'face-modified nil) |
| 1472 | (set-face-attribute face (or frame t) attribute value))) | 1472 | ;; When we change a face based on a spec from outside custom, |
| 1473 | (setq attrs (cdr (cdr attrs))))) | 1473 | ;; record it for future frames. |
| 1474 | (unless frame | 1474 | (put (or (get face 'face-alias) face) 'face-override-spec spec)) |
| 1475 | ;; When we reset the face based on its spec, then it is unmodified | 1475 | ;;; RMS 29 dec 2007: Perhaps this code should be reinstated. |
| 1476 | ;; as far as Custom is concerned. | 1476 | ;;; That depends on whether the overriding spec |
| 1477 | (put (or (get face 'face-alias) face) 'face-modified nil) | 1477 | ;;; or the default face attributes |
| 1478 | ;;; ;; Clear all the new-frame defaults for this face. | 1478 | ;;; should take priority. |
| 1479 | ;;; ;; Clear all the new-frame default attributes for this face. | ||
| 1479 | ;;; ;; face-spec-reset-face won't do it right. | 1480 | ;;; ;; face-spec-reset-face won't do it right. |
| 1480 | ;;; (let ((facevec (cdr (assq face face-new-frame-defaults)))) | 1481 | ;;; (let ((facevec (cdr (assq face face-new-frame-defaults)))) |
| 1481 | ;;; (dotimes (i (length facevec)) | 1482 | ;;; (dotimes (i (length facevec)) |
| 1482 | ;;; (unless (= i 0) | 1483 | ;;; (unless (= i 0) |
| 1483 | ;;; (aset facevec i 'unspecified)))) | 1484 | ;;; (aset facevec i 'unspecified)))) |
| 1484 | ;; Set each frame according to the rules implied by SPEC. | 1485 | ;; Reset each frame according to the rules implied by all its specs. |
| 1485 | (dolist (frame (frame-list)) | 1486 | (dolist (frame (frame-list)) |
| 1486 | (face-spec-set face spec frame)))) | 1487 | (face-spec-recalc face frame)))) |
| 1487 | 1488 | ||
| 1489 | (defun face-spec-recalc (face frame) | ||
| 1490 | "Reset the face attributes of FACE on FRAME according to its specs. | ||
| 1491 | This applies the defface/custom spec first, then the custom theme specs, | ||
| 1492 | then the override spec." | ||
| 1493 | (face-spec-reset-face face frame) | ||
| 1494 | (let ((face-sym (or (get face 'face-alias) face))) | ||
| 1495 | (face-spec-set-2 face frame | ||
| 1496 | (face-user-default-spec face)) | ||
| 1497 | (let ((theme-faces (reverse (get face-sym 'theme-face)))) | ||
| 1498 | (dolist (spec theme-faces) | ||
| 1499 | (face-spec-set-2 face frame (cadr spec)))) | ||
| 1500 | (face-spec-set-2 face frame (get face-sym 'face-override-spec)))) | ||
| 1501 | |||
| 1502 | (defun face-spec-set-2 (face frame spec) | ||
| 1503 | "Set the face attributes of FACE on FRAME according to SPEC." | ||
| 1504 | (let* ((attrs (face-spec-choose spec frame))) | ||
| 1505 | (while attrs | ||
| 1506 | (let ((attribute (car attrs)) | ||
| 1507 | (value (car (cdr attrs)))) | ||
| 1508 | ;; Support some old-style attribute names and values. | ||
| 1509 | (case attribute | ||
| 1510 | (:bold (setq attribute :weight value (if value 'bold 'normal))) | ||
| 1511 | (:italic (setq attribute :slant value (if value 'italic 'normal))) | ||
| 1512 | ((:foreground :background) | ||
| 1513 | ;; Compatibility with 20.x. Some bogus face specs seem to | ||
| 1514 | ;; exist containing things like `:foreground nil'. | ||
| 1515 | (if (null value) (setq value 'unspecified))) | ||
| 1516 | (t (unless (assq attribute face-x-resources) | ||
| 1517 | (setq attribute nil)))) | ||
| 1518 | (when attribute | ||
| 1519 | (set-face-attribute face frame attribute value))) | ||
| 1520 | (setq attrs (cdr (cdr attrs)))))) | ||
| 1488 | 1521 | ||
| 1489 | (defun face-attr-match-p (face attrs &optional frame) | 1522 | (defun face-attr-match-p (face attrs &optional frame) |
| 1490 | "Return t if attributes of FACE match values in plist ATTRS. | 1523 | "Return t if attributes of FACE match values in plist ATTRS. |
| @@ -1797,14 +1830,16 @@ according to the `background-mode' and `display-type' frame parameters." | |||
| 1797 | (let ((locally-modified-faces nil)) | 1830 | (let ((locally-modified-faces nil)) |
| 1798 | ;; Before modifying the frame parameters, we collect a list of | 1831 | ;; Before modifying the frame parameters, we collect a list of |
| 1799 | ;; faces that don't match what their face-spec says they should | 1832 | ;; faces that don't match what their face-spec says they should |
| 1800 | ;; look like; we then avoid changing these faces below. A | 1833 | ;; look like; we then avoid changing these faces below. |
| 1801 | ;; negative list is used on the assumption that most faces will | 1834 | ;; These are the faces whose attributes were modified on FRAME. |
| 1835 | ;; We use a negative list on the assumption that most faces will | ||
| 1802 | ;; be unmodified, so we can avoid consing in the common case. | 1836 | ;; be unmodified, so we can avoid consing in the common case. |
| 1803 | (dolist (face (face-list)) | 1837 | (dolist (face (face-list)) |
| 1804 | (when (not (face-spec-match-p face | 1838 | (and (not (get face 'face-override-spec)) |
| 1805 | (face-user-default-spec face) | 1839 | (not (face-spec-match-p face |
| 1806 | (selected-frame))) | 1840 | (face-user-default-spec face) |
| 1807 | (push face locally-modified-faces))) | 1841 | (selected-frame))) |
| 1842 | (push face locally-modified-faces))) | ||
| 1808 | ;; Now change to the new frame parameters | 1843 | ;; Now change to the new frame parameters |
| 1809 | (modify-frame-parameters frame | 1844 | (modify-frame-parameters frame |
| 1810 | (list (cons 'background-mode bg-mode) | 1845 | (list (cons 'background-mode bg-mode) |
| @@ -1813,7 +1848,7 @@ according to the `background-mode' and `display-type' frame parameters." | |||
| 1813 | ;; parameters, unless they have been locally modified. | 1848 | ;; parameters, unless they have been locally modified. |
| 1814 | (dolist (face (face-list)) | 1849 | (dolist (face (face-list)) |
| 1815 | (unless (memq face locally-modified-faces) | 1850 | (unless (memq face locally-modified-faces) |
| 1816 | (face-spec-set face (face-user-default-spec face) frame))))))) | 1851 | (face-spec-recalc face frame))))))) |
| 1817 | 1852 | ||
| 1818 | 1853 | ||
| 1819 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 1854 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| @@ -1947,7 +1982,7 @@ Initialize colors of certain faces from frame parameters." | |||
| 1947 | (dolist (face (delq 'default (face-list))) | 1982 | (dolist (face (delq 'default (face-list))) |
| 1948 | (condition-case () | 1983 | (condition-case () |
| 1949 | (progn | 1984 | (progn |
| 1950 | (face-spec-set face (face-user-default-spec face) frame) | 1985 | (face-spec-recalc face frame) |
| 1951 | (if (memq (window-system frame) '(x w32 mac)) | 1986 | (if (memq (window-system frame) '(x w32 mac)) |
| 1952 | (make-face-x-resource-internal face frame)) | 1987 | (make-face-x-resource-internal face frame)) |
| 1953 | (internal-merge-in-global-face face frame)) | 1988 | (internal-merge-in-global-face face frame)) |