diff options
| author | Richard M. Stallman | 1997-08-03 04:10:36 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1997-08-03 04:10:36 +0000 |
| commit | 95c7d3d3176d599faae3d6210de187d89e6e3e09 (patch) | |
| tree | 4fdaec8dab878e59e21984b7105fa89dc35413d5 | |
| parent | fa0b3d466d268cf4775377d4a537143ea70a6117 (diff) | |
| download | emacs-95c7d3d3176d599faae3d6210de187d89e6e3e09.tar.gz emacs-95c7d3d3176d599faae3d6210de187d89e6e3e09.zip | |
(face-attr-match-p): New function.
(face-attr-match-1, face-spec-match-p, face-attr-construct): Likewise.
(face-spec-choose): New function.
(face-spec-set): Use face-spec-choose.
| -rw-r--r-- | lisp/faces.el | 131 |
1 files changed, 107 insertions, 24 deletions
diff --git a/lisp/faces.el b/lisp/faces.el index f925daa6e70..0ff08e2efe7 100644 --- a/lisp/faces.el +++ b/lisp/faces.el | |||
| @@ -1147,23 +1147,108 @@ selected frame." | |||
| 1147 | 1147 | ||
| 1148 | ;;; Setting a face based on a SPEC. | 1148 | ;;; Setting a face based on a SPEC. |
| 1149 | 1149 | ||
| 1150 | (defun face-spec-set (face spec &optional frame) | 1150 | (defun face-attr-match-p (face attrs &optional frame) |
| 1151 | "Set FACE's face attributes according to the first matching entry in SPEC. | 1151 | (or frame (setq frame (selected-frame))) |
| 1152 | If optional FRAME is non-nil, set it for that frame only. | 1152 | (and (face-attr-match-1 face frame attrs ':inverse-video |
| 1153 | If it is nil, then apply SPEC to each frame individually. | 1153 | 'face-inverse-video-p) |
| 1154 | See `defface' for information about SPEC." | 1154 | (if (face-inverse-video-p face frame) |
| 1155 | (let ((tail spec)) | 1155 | (and |
| 1156 | (while tail | 1156 | (face-attr-match-1 face frame attrs |
| 1157 | ':foreground 'face-background | ||
| 1158 | (cdr (assq 'foreground-color | ||
| 1159 | (frame-parameters frame)))) | ||
| 1160 | (face-attr-match-1 face frame attrs | ||
| 1161 | ':background 'face-foreground | ||
| 1162 | (cdr (assq 'background-color | ||
| 1163 | (frame-parameters frame))))) | ||
| 1164 | (and | ||
| 1165 | (face-attr-match-1 face frame attrs ':foreground 'face-foreground) | ||
| 1166 | (face-attr-match-1 face frame attrs ':background 'face-background))) | ||
| 1167 | (face-attr-match-1 face frame attrs ':stipple 'face-stipple) | ||
| 1168 | (face-attr-match-1 face frame attrs ':bold 'face-bold-p) | ||
| 1169 | (face-attr-match-1 face frame attrs ':italic 'face-italic-p) | ||
| 1170 | (face-attr-match-1 face frame attrs ':underline 'face-underline-p) | ||
| 1171 | )) | ||
| 1172 | |||
| 1173 | (defun face-attr-match-1 (face frame plist property function | ||
| 1174 | &optional defaultval) | ||
| 1175 | (while (and plist (not (eq (car plist) property))) | ||
| 1176 | (setq plist (cdr (cdr plist)))) | ||
| 1177 | (eq (funcall function face frame) | ||
| 1178 | (if plist | ||
| 1179 | (nth 1 plist) | ||
| 1180 | (or defaultval | ||
| 1181 | (funcall function 'default frame))))) | ||
| 1182 | |||
| 1183 | (defun face-spec-match-p (face spec &optional frame) | ||
| 1184 | "Return t if FACE, on FRAME, matches what SPEC says it should look like." | ||
| 1185 | (face-attr-match-p face (face-spec-choose spec frame) frame)) | ||
| 1186 | |||
| 1187 | (defun face-attr-construct (face &optional frame) | ||
| 1188 | "Return a defface-style attribute list for FACE, as it exists on FRAME." | ||
| 1189 | (let (result) | ||
| 1190 | (if (face-inverse-video-p face frame) | ||
| 1191 | (progn | ||
| 1192 | (setq result (cons ':inverse-video (cons t result))) | ||
| 1193 | (or (face-attr-match-1 face frame nil | ||
| 1194 | ':foreground 'face-background | ||
| 1195 | (cdr (assq 'foreground-color | ||
| 1196 | (frame-parameters frame)))) | ||
| 1197 | (setq result (cons ':foreground | ||
| 1198 | (cons (face-foreground face frame) result)))) | ||
| 1199 | (or (face-attr-match-1 face frame nil | ||
| 1200 | ':background 'face-foreground | ||
| 1201 | (cdr (assq 'background-color | ||
| 1202 | (frame-parameters frame)))) | ||
| 1203 | (setq result (cons ':background | ||
| 1204 | (cons (face-background face frame) result))))) | ||
| 1205 | (if (face-foreground face frame) | ||
| 1206 | (setq result (cons ':foreground | ||
| 1207 | (cons (face-foreground face frame) result)))) | ||
| 1208 | (if (face-background face frame) | ||
| 1209 | (setq result (cons ':background | ||
| 1210 | (cons (face-background face frame) result))))) | ||
| 1211 | (if (face-stipple face frame) | ||
| 1212 | (setq result (cons ':stipple | ||
| 1213 | (cons (face-stipple face frame) result)))) | ||
| 1214 | (if (face-bold-p face frame) | ||
| 1215 | (setq result (cons ':bold | ||
| 1216 | (cons (face-bold-p face frame) result)))) | ||
| 1217 | (if (face-italic-p face frame) | ||
| 1218 | (setq result (cons ':italic | ||
| 1219 | (cons (face-italic-p face frame) result)))) | ||
| 1220 | (if (face-underline-p face frame) | ||
| 1221 | (setq result (cons ':underline | ||
| 1222 | (cons (face-underline-p face frame) result)))) | ||
| 1223 | result)) | ||
| 1224 | |||
| 1225 | ;; Choose the proper attributes for FRAME, out of SPEC. | ||
| 1226 | (defun face-spec-choose (spec &optional frame) | ||
| 1227 | (or frame (setq frame (selected-frame))) | ||
| 1228 | (let ((tail spec) | ||
| 1229 | result) | ||
| 1230 | (while tail | ||
| 1157 | (let* ((entry (car tail)) | 1231 | (let* ((entry (car tail)) |
| 1158 | (display (nth 0 entry)) | 1232 | (display (nth 0 entry)) |
| 1159 | (attrs (nth 1 entry))) | 1233 | (attrs (nth 1 entry))) |
| 1160 | (setq tail (cdr tail)) | 1234 | (setq tail (cdr tail)) |
| 1161 | ;; If the font was set automatically, clear it out | ||
| 1162 | ;; to allow it to be set it again. | ||
| 1163 | (unless (face-font-explicit face frame) | ||
| 1164 | (set-face-font face nil frame)) | ||
| 1165 | (modify-face face nil nil nil nil nil nil frame) | ||
| 1166 | (when (face-spec-set-match-display display frame) | 1235 | (when (face-spec-set-match-display display frame) |
| 1236 | (setq result attrs tail nil)))) | ||
| 1237 | result)) | ||
| 1238 | |||
| 1239 | (defun face-spec-set (face spec &optional frame) | ||
| 1240 | "Set FACE's face attributes according to the first matching entry in SPEC. | ||
| 1241 | If optional FRAME is non-nil, set it for that frame only. | ||
| 1242 | If it is nil, then apply SPEC to each frame individually. | ||
| 1243 | See `defface' for information about SPEC." | ||
| 1244 | (if frame | ||
| 1245 | (let ((attrs (face-spec-choose spec frame))) | ||
| 1246 | (when attrs | ||
| 1247 | ;; If the font was set automatically, clear it out | ||
| 1248 | ;; to allow it to be set it again. | ||
| 1249 | (unless (face-font-explicit face frame) | ||
| 1250 | (set-face-font face nil frame)) | ||
| 1251 | (modify-face face nil nil nil nil nil nil frame) | ||
| 1167 | (face-spec-set-1 face frame attrs ':foreground 'set-face-foreground) | 1252 | (face-spec-set-1 face frame attrs ':foreground 'set-face-foreground) |
| 1168 | (face-spec-set-1 face frame attrs ':background 'set-face-background) | 1253 | (face-spec-set-1 face frame attrs ':background 'set-face-background) |
| 1169 | (face-spec-set-1 face frame attrs ':stipple 'set-face-stipple) | 1254 | (face-spec-set-1 face frame attrs ':stipple 'set-face-stipple) |
| @@ -1171,18 +1256,16 @@ See `defface' for information about SPEC." | |||
| 1171 | (face-spec-set-1 face frame attrs ':italic 'set-face-italic-p) | 1256 | (face-spec-set-1 face frame attrs ':italic 'set-face-italic-p) |
| 1172 | (face-spec-set-1 face frame attrs ':underline 'set-face-underline-p) | 1257 | (face-spec-set-1 face frame attrs ':underline 'set-face-underline-p) |
| 1173 | (face-spec-set-1 face frame attrs ':inverse-video | 1258 | (face-spec-set-1 face frame attrs ':inverse-video |
| 1174 | 'set-face-inverse-video-p) | 1259 | 'set-face-inverse-video-p))) |
| 1175 | (setq tail nil))))) | 1260 | (let ((frames (frame-list)) |
| 1176 | (if (null frame) | 1261 | frame) |
| 1177 | (let ((frames (frame-list)) | 1262 | (while frames |
| 1178 | frame) | 1263 | (setq frame (car frames) |
| 1179 | (while frames | 1264 | frames (cdr frames)) |
| 1180 | (setq frame (car frames) | 1265 | (face-spec-set face (or (get face 'saved-face) |
| 1181 | frames (cdr frames)) | 1266 | (get face 'face-defface-spec)) |
| 1182 | (face-spec-set face (or (get face 'saved-face) | 1267 | frame) |
| 1183 | (get face 'face-defface-spec)) | 1268 | (face-spec-set face spec frame))))) |
| 1184 | frame) | ||
| 1185 | (face-spec-set face spec frame))))) | ||
| 1186 | 1269 | ||
| 1187 | (defun face-spec-set-1 (face frame plist property function) | 1270 | (defun face-spec-set-1 (face frame plist property function) |
| 1188 | (while (and plist (not (eq (car plist) property))) | 1271 | (while (and plist (not (eq (car plist) property))) |