aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorMiles Bader2008-06-17 11:27:36 +0000
committerMiles Bader2008-06-17 11:27:36 +0000
commitd03d411d4a487dd690831a6d36be662f2f896989 (patch)
tree4c961a9d96d7ccc96e7050cb1ad269e578b854e0 /lisp
parentb597d348c47edcdc66edeb4e33e4e2150d712941 (diff)
downloademacs-d03d411d4a487dd690831a6d36be662f2f896989.tar.gz
emacs-d03d411d4a487dd690831a6d36be662f2f896989.zip
Order multiple entries more cleverly in face-remap-add-relative
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-1250
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/face-remap.el49
2 files changed, 52 insertions, 3 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2cb7249d985..e638c2630c2 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12008-06-17 Miles Bader <miles@gnu.org>
2
3 * face-remap.el (internal-lisp-face-attributes): New variable.
4 (face-attrs-more-relative-p, face-remap-order): New functions.
5 (face-remap-add-relative): Use `face-remap-order'.
6
12008-06-17 Glenn Morris <rgm@gnu.org> 72008-06-17 Glenn Morris <rgm@gnu.org>
2 8
3 * mouse.el (x-select-font): Declare. 9 * mouse.el (x-select-font): Declare.
diff --git a/lisp/face-remap.el b/lisp/face-remap.el
index 956c215afdd..fce25af834b 100644
--- a/lisp/face-remap.el
+++ b/lisp/face-remap.el
@@ -61,6 +61,48 @@
61;; ---------------------------------------------------------------- 61;; ----------------------------------------------------------------
62;; Utility functions 62;; Utility functions
63 63
64;; Names of face attributes corresponding to lisp face-vector positions.
65;; This variable should probably be defined in C code where the actual
66;; definitions are available.
67;;
68(defvar internal-lisp-face-attributes
69 [nil
70 :family :foundry :swidth :height :weight :slant :underline :inverse
71 :foreground :background :stipple :overline :strike :box
72 :font :inherit :fontset :vector])
73
74(defun face-attrs-more-relative-p (attrs1 attrs2)
75"Return true if ATTRS1 contains a greater number of relative
76face-attributes than ATTRS2. A face attribute is considered
77relative if `face-attribute-relative-p' returns non-nil.
78
79ATTRS1 and ATTRS2 may be any value suitable for a `face' text
80property, including face names, lists of face names,
81face-attribute plists, etc.
82
83This function can be used as a predicate with `sort', to sort
84face lists so that more specific faces are located near the end."
85 (unless (vectorp attrs1)
86 (setq attrs1 (face-attributes-as-vector attrs1)))
87 (unless (vectorp attrs2)
88 (setq attrs2 (face-attributes-as-vector attrs2)))
89 (let ((rel1-count 0) (rel2-count 0))
90 (dotimes (i (length attrs1))
91 (let ((attr (aref internal-lisp-face-attributes i)))
92 (when attr
93 (when (face-attribute-relative-p attr (aref attrs1 i))
94 (setq rel1-count (+ rel1-count 1)))
95 (when (face-attribute-relative-p attr (aref attrs2 i))
96 (setq rel2-count (+ rel2-count 1))))))
97 (< rel1-count rel2-count)))
98
99(defun face-remap-order (entry)
100 "Order ENTRY so that more relative face specs are near the beginning.
101The list structure of ENTRY may be destructively modified."
102 (setq entry (nreverse entry))
103 (setcdr entry (sort (cdr entry) 'face-attrs-more-relative-p))
104 (nreverse entry))
105
64;;;### autoload 106;;;### autoload
65(defun face-remap-add-relative (face &rest specs) 107(defun face-remap-add-relative (face &rest specs)
66 "Add a face remapping entry of FACE to SPECS in the current buffer. 108 "Add a face remapping entry of FACE to SPECS in the current buffer.
@@ -72,8 +114,9 @@ SPECS can be any value suitable for the `face' text property,
72including a face name, a list of face names, or a face-attribute 114including a face name, a list of face names, or a face-attribute
73property list. The attributes given by SPECS will be merged with 115property list. The attributes given by SPECS will be merged with
74any other currently active face remappings of FACE, and with the 116any other currently active face remappings of FACE, and with the
75global definition of FACE, with the most recently added relative 117global definition of FACE. An attempt is made to sort multiple
76remapping taking precedence. 118entries so that entries with relative face-attributes are applied
119after entries with absolute face-attributes.
77 120
78The base (lowest priority) remapping may be set to a specific 121The base (lowest priority) remapping may be set to a specific
79value, instead of the default of the global face definition, 122value, instead of the default of the global face definition,
@@ -83,7 +126,7 @@ using `face-remap-set-base'."
83 (when (null entry) 126 (when (null entry)
84 (setq entry (list face face)) ; explicitly merge with global def 127 (setq entry (list face face)) ; explicitly merge with global def
85 (push entry face-remapping-alist)) 128 (push entry face-remapping-alist))
86 (setcdr entry (cons specs (cdr entry))) 129 (setcdr entry (face-remap-order (cons specs (cdr entry))))
87 (cons face specs))) 130 (cons face specs)))
88 131
89(defun face-remap-remove-relative (cookie) 132(defun face-remap-remove-relative (cookie)