Mercurial > emacs
comparison lisp/faces.el @ 91304:c938ab6810a4
Merge from emacs--devo--0
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-308
author | Miles Bader <miles@gnu.org> |
---|---|
date | Wed, 02 Jan 2008 04:13:39 +0000 |
parents | 56a72e2bd635 6a0c500ca3a9 |
children | 606f2d163a64 |
comparison
equal
deleted
inserted
replaced
91303:1ae1f4066439 | 91304:c938ab6810a4 |
---|---|
274 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 274 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
275 ;;; Predicates, type checks. | 275 ;;; Predicates, type checks. |
276 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 276 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
277 | 277 |
278 (defun facep (face) | 278 (defun facep (face) |
279 "Return non-nil if FACE is a face name or internal face object. | 279 "Return non-nil if FACE is a face name; nil otherwise. |
280 Return nil otherwise. A face name can be a string or a symbol. | 280 A face name can be a string or a symbol." |
281 An internal face object is a vector of the kind used internally | |
282 to record face data." | |
283 (internal-lisp-face-p face)) | 281 (internal-lisp-face-p face)) |
284 | 282 |
285 | 283 |
286 (defun check-face (face) | 284 (defun check-face (face) |
287 "Signal an error if FACE doesn't name a face. | 285 "Signal an error if FACE doesn't name a face. |
317 "Return non-nil if FACE displays differently from the default face. | 315 "Return non-nil if FACE displays differently from the default face. |
318 If the optional argument FRAME is given, report on face FACE in that frame. | 316 If the optional argument FRAME is given, report on face FACE in that frame. |
319 If FRAME is t, report on the defaults for face FACE (for new frames). | 317 If FRAME is t, report on the defaults for face FACE (for new frames). |
320 If FRAME is omitted or nil, use the selected frame." | 318 If FRAME is omitted or nil, use the selected frame." |
321 (let ((attrs | 319 (let ((attrs |
322 '(:family :width :height :weight :slant :foreground | 320 (delq :inherit (mapcar 'car face-attribute-name-alist))) |
323 :background :underline :overline :strike-through | |
324 :box :inverse-video)) | |
325 (differs nil)) | 321 (differs nil)) |
326 (while (and attrs (not differs)) | 322 (while (and attrs (not differs)) |
327 (let* ((attr (pop attrs)) | 323 (let* ((attr (pop attrs)) |
328 (attr-val (face-attribute face attr frame t))) | 324 (attr-val (face-attribute face attr frame t))) |
329 (when (and | 325 (when (and |
420 | 416 |
421 (defun face-name (face) | 417 (defun face-name (face) |
422 "Return the name of face FACE." | 418 "Return the name of face FACE." |
423 (symbol-name (check-face face))) | 419 (symbol-name (check-face face))) |
424 | 420 |
421 | |
422 (defun face-all-attributes (face &optional frame) | |
423 "Return an alist stating the attributes of FACE. | |
424 Each element of the result has the form (ATTR-NAME . ATTR-VALUE). | |
425 Normally the value describes the default attributes, | |
426 but if you specify FRAME, the value describes the attributes | |
427 of FACE on FRAME." | |
428 (mapcar (lambda (pair) | |
429 (let ((attr (car pair))) | |
430 (cons attr (face-attribute face attr (or frame t))))) | |
431 face-attribute-name-alist)) | |
425 | 432 |
426 (defun face-attribute (face attribute &optional frame inherit) | 433 (defun face-attribute (face attribute &optional frame inherit) |
427 "Return the value of FACE's ATTRIBUTE on FRAME. | 434 "Return the value of FACE's ATTRIBUTE on FRAME. |
428 If the optional argument FRAME is given, report on face FACE in that frame. | 435 If the optional argument FRAME is given, report on face FACE in that frame. |
429 If FRAME is t, report on the defaults for face FACE (for new frames). | 436 If FRAME is t, report on the defaults for face FACE (for new frames). |
1514 (let ((attr-and-name (car attrs))) | 1521 (let ((attr-and-name (car attrs))) |
1515 (set-face-attribute face frame (car attr-and-name) 'unspecified)) | 1522 (set-face-attribute face frame (car attr-and-name) 'unspecified)) |
1516 (setq attrs (cdr attrs))))) | 1523 (setq attrs (cdr attrs))))) |
1517 | 1524 |
1518 | 1525 |
1519 (defun face-spec-set (face spec &optional frame) | 1526 (defun face-spec-set (face spec &optional for-defface) |
1520 "Set FACE's attributes according to the first matching entry in SPEC. | 1527 "Set FACE's face spec, which controls its appearance, to SPEC> |
1521 FRAME is the frame whose frame-local face is set. FRAME nil means | 1528 If FOR-DEFFACE is t, set the base spec, the one that `defface' |
1522 do it on all frames (and change the default for new frames). | 1529 and Custom set. (In that case, the caller must put it in the |
1523 See `defface' for information about SPEC. If SPEC is nil, do nothing." | 1530 appropriate property, because that depends on the caller.) |
1524 (let ((attrs (face-spec-choose spec frame))) | 1531 If FOR-DEFFACE is nil, set the overriding spec (and store it |
1525 (when spec | 1532 in the `face-override-spec' property of FACE). |
1526 (face-spec-reset-face face (or frame t))) | 1533 |
1534 The appearance of FACE is controlled by the base spec, | |
1535 by any custom theme specs on top of that, and by the | |
1536 the overriding spec on top of all the rest. | |
1537 | |
1538 FOR-DEFFACE can also be a frame, in which case we set the | |
1539 frame-specific attributes of FACE for that frame based on SPEC. | |
1540 That usage is deprecated. | |
1541 | |
1542 See `defface' for information about the format and meaning of SPEC." | |
1543 (if (framep for-defface) | |
1544 ;; Handle the deprecated case where third arg is a frame. | |
1545 (face-spec-set-2 face for-defface spec) | |
1546 (if for-defface | |
1547 ;; When we reset the face based on its custom spec, then it is | |
1548 ;; unmodified as far as Custom is concerned. | |
1549 (put (or (get face 'face-alias) face) 'face-modified nil) | |
1550 ;; When we change a face based on a spec from outside custom, | |
1551 ;; record it for future frames. | |
1552 (put (or (get face 'face-alias) face) 'face-override-spec spec)) | |
1553 ;;; RMS 29 dec 2007: Perhaps this code should be reinstated. | |
1554 ;;; That depends on whether the overriding spec | |
1555 ;;; or the default face attributes | |
1556 ;;; should take priority. | |
1557 ;;; ;; Clear all the new-frame default attributes for this face. | |
1558 ;;; ;; face-spec-reset-face won't do it right. | |
1559 ;;; (let ((facevec (cdr (assq face face-new-frame-defaults)))) | |
1560 ;;; (dotimes (i (length facevec)) | |
1561 ;;; (unless (= i 0) | |
1562 ;;; (aset facevec i 'unspecified)))) | |
1563 ;; Reset each frame according to the rules implied by all its specs. | |
1564 (dolist (frame (frame-list)) | |
1565 (face-spec-recalc face frame)))) | |
1566 | |
1567 (defun face-spec-recalc (face frame) | |
1568 "Reset the face attributes of FACE on FRAME according to its specs. | |
1569 This applies the defface/custom spec first, then the custom theme specs, | |
1570 then the override spec." | |
1571 (face-spec-reset-face face frame) | |
1572 (let ((face-sym (or (get face 'face-alias) face))) | |
1573 (face-spec-set-2 face frame | |
1574 (face-user-default-spec face)) | |
1575 (let ((theme-faces (reverse (get face-sym 'theme-face)))) | |
1576 (dolist (spec theme-faces) | |
1577 (face-spec-set-2 face frame (cadr spec)))) | |
1578 (face-spec-set-2 face frame (get face-sym 'face-override-spec)))) | |
1579 | |
1580 (defun face-spec-set-2 (face frame spec) | |
1581 "Set the face attributes of FACE on FRAME according to SPEC." | |
1582 (let* ((attrs (face-spec-choose spec frame))) | |
1527 (while attrs | 1583 (while attrs |
1528 (let ((attribute (car attrs)) | 1584 (let ((attribute (car attrs)) |
1529 (value (car (cdr attrs)))) | 1585 (value (car (cdr attrs)))) |
1530 ;; Support some old-style attribute names and values. | 1586 ;; Support some old-style attribute names and values. |
1531 (case attribute | 1587 (case attribute |
1532 (:bold (setq attribute :weight value (if value 'bold 'normal))) | 1588 (:bold (setq attribute :weight value (if value 'bold 'normal))) |
1533 (:italic (setq attribute :slant value (if value 'italic 'normal))) | 1589 (:italic (setq attribute :slant value (if value 'italic 'normal))) |
1534 ((:foreground :background) | 1590 ((:foreground :background) |
1535 ;; Compatibility with 20.x. Some bogus face specs seem to | 1591 ;; Compatibility with 20.x. Some bogus face specs seem to |
1536 ;; exist containing things like `:foreground nil'. | 1592 ;; exist containing things like `:foreground nil'. |
1537 (if (null value) (setq value 'unspecified))) | 1593 (if (null value) (setq value 'unspecified))) |
1538 (t (unless (assq attribute face-x-resources) | 1594 (t (unless (assq attribute face-x-resources) |
1539 (setq attribute nil)))) | 1595 (setq attribute nil)))) |
1540 (when attribute | 1596 (when attribute |
1541 ;; If frame is nil, set the default for new frames. | 1597 (set-face-attribute face frame attribute value))) |
1542 ;; Existing frames are handled below. | 1598 (setq attrs (cdr (cdr attrs)))))) |
1543 (set-face-attribute face (or frame t) attribute value))) | |
1544 (setq attrs (cdr (cdr attrs))))) | |
1545 (unless frame | |
1546 ;; When we reset the face based on its spec, then it is unmodified | |
1547 ;; as far as Custom is concerned. | |
1548 (put (or (get face 'face-alias) face) 'face-modified nil) | |
1549 ;;; ;; Clear all the new-frame defaults for this face. | |
1550 ;;; ;; face-spec-reset-face won't do it right. | |
1551 ;;; (let ((facevec (cdr (assq face face-new-frame-defaults)))) | |
1552 ;;; (dotimes (i (length facevec)) | |
1553 ;;; (unless (= i 0) | |
1554 ;;; (aset facevec i 'unspecified)))) | |
1555 ;; Set each frame according to the rules implied by SPEC. | |
1556 (dolist (frame (frame-list)) | |
1557 (face-spec-set face spec frame)))) | |
1558 | |
1559 | 1599 |
1560 (defun face-attr-match-p (face attrs &optional frame) | 1600 (defun face-attr-match-p (face attrs &optional frame) |
1561 "Return t if attributes of FACE match values in plist ATTRS. | 1601 "Return t if attributes of FACE match values in plist ATTRS. |
1562 Optional parameter FRAME is the frame whose definition of FACE | 1602 Optional parameter FRAME is the frame whose definition of FACE |
1563 is used. If nil or omitted, use the selected frame." | 1603 is used. If nil or omitted, use the selected frame." |
1866 | 1906 |
1867 (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type)) | 1907 (unless (and (eq bg-mode old-bg-mode) (eq display-type old-display-type)) |
1868 (let ((locally-modified-faces nil)) | 1908 (let ((locally-modified-faces nil)) |
1869 ;; Before modifying the frame parameters, we collect a list of | 1909 ;; Before modifying the frame parameters, we collect a list of |
1870 ;; faces that don't match what their face-spec says they should | 1910 ;; faces that don't match what their face-spec says they should |
1871 ;; look like; we then avoid changing these faces below. A | 1911 ;; look like; we then avoid changing these faces below. |
1872 ;; negative list is used on the assumption that most faces will | 1912 ;; These are the faces whose attributes were modified on FRAME. |
1913 ;; We use a negative list on the assumption that most faces will | |
1873 ;; be unmodified, so we can avoid consing in the common case. | 1914 ;; be unmodified, so we can avoid consing in the common case. |
1874 (dolist (face (face-list)) | 1915 (dolist (face (face-list)) |
1875 (when (not (face-spec-match-p face | 1916 (and (not (get face 'face-override-spec)) |
1876 (face-user-default-spec face) | 1917 (not (face-spec-match-p face |
1877 (selected-frame))) | 1918 (face-user-default-spec face) |
1878 (push face locally-modified-faces))) | 1919 (selected-frame))) |
1920 (push face locally-modified-faces))) | |
1879 ;; Now change to the new frame parameters | 1921 ;; Now change to the new frame parameters |
1880 (modify-frame-parameters frame | 1922 (modify-frame-parameters frame |
1881 (list (cons 'background-mode bg-mode) | 1923 (list (cons 'background-mode bg-mode) |
1882 (cons 'display-type display-type))) | 1924 (cons 'display-type display-type))) |
1883 ;; For all named faces, choose face specs matching the new frame | 1925 ;; For all named faces, choose face specs matching the new frame |
1884 ;; parameters, unless they have been locally modified. | 1926 ;; parameters, unless they have been locally modified. |
1885 (dolist (face (face-list)) | 1927 (dolist (face (face-list)) |
1886 (unless (memq face locally-modified-faces) | 1928 (unless (memq face locally-modified-faces) |
1887 (face-spec-set face (face-user-default-spec face) frame))))))) | 1929 (face-spec-recalc face frame))))))) |
1888 | 1930 |
1889 | 1931 |
1890 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 1932 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1891 ;;; Frame creation. | 1933 ;;; Frame creation. |
1892 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 1934 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2016 ;; condition-case prevents invalid specs from causing frame | 2058 ;; condition-case prevents invalid specs from causing frame |
2017 ;; creation to fail. | 2059 ;; creation to fail. |
2018 (dolist (face (delq 'default (face-list))) | 2060 (dolist (face (delq 'default (face-list))) |
2019 (condition-case () | 2061 (condition-case () |
2020 (progn | 2062 (progn |
2021 (face-spec-set face (face-user-default-spec face) frame) | 2063 (face-spec-recalc face frame) |
2022 (if (memq (window-system frame) '(x w32 mac)) | 2064 (if (memq (window-system frame) '(x w32 mac)) |
2023 (make-face-x-resource-internal face frame)) | 2065 (make-face-x-resource-internal face frame)) |
2024 (internal-merge-in-global-face face frame)) | 2066 (internal-merge-in-global-face face frame)) |
2025 (error nil))) | 2067 (error nil))) |
2026 ;; Apply the attributes specified by frame parameters. This | 2068 ;; Apply the attributes specified by frame parameters. This |