[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: C-M-x on defface doesn't always work
From: |
Juri Linkov |
Subject: |
Re: C-M-x on defface doesn't always work |
Date: |
Sun, 19 Jun 2005 16:07:29 +0300 |
User-agent: |
Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux) |
> C-M-x on a `defface' form doesn't work for resetting a face if the
> user has set the face through custom. The face spec is not used; in
> custom-declare-face:
>
> ;; If the user has already created the face, respect that.
> (let ((value (or (get face 'saved-face) spec)))
I think a good solution here is to reset `saved-face' property to nil
before evaluating the defface form, and to restore its original value
afterwards. And also to set `customized-face' to the new specification.
This requires modification of the function `face-user-default-spec' to
try getting `customized-face' prior to trying `saved-face'. This change
in `face-user-default-spec' also fixes one bug where the saved face was
merged with customized non-saved attributes of the same face.
The workflow for reproducing the bug is the following:
1. Customize the foreground color of some face and save it
([Save for Future Sessions]).
2. Reset (uncheck) the foreground attribute, set some background color,
and set the face without saving it ([Set for Current Session]).
3. Create new frame.
Now in a new frame this face appears as merged with customized non-saved
background and saved foreground. The patch makes such face having
only customized non-saved background.
Index: lisp/emacs-lisp/lisp-mode.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/emacs-lisp/lisp-mode.el,v
retrieving revision 1.176
diff -u -r1.176 lisp-mode.el
--- lisp/emacs-lisp/lisp-mode.el 7 Jun 2005 10:51:36 -0000 1.176
+++ lisp/emacs-lisp/lisp-mode.el 19 Jun 2005 11:19:33 -0000
@@ -617,10 +617,15 @@
;; `defface' is macroexpanded to `custom-declare-face'.
((eq (car form) 'custom-declare-face)
;; Reset the face.
- (put (eval (nth 1 form)) 'face-defface-spec nil)
(setq face-new-frame-defaults
(assq-delete-all (eval (nth 1 form)) face-new-frame-defaults))
- form)
+ (put (eval (nth 1 form)) 'face-defface-spec nil)
+ (prog1 `(prog1 ,form
+ (put ',(eval (nth 1 form)) 'saved-face
+ ',(get (eval (nth 1 form)) 'saved-face))
+ (put ',(eval (nth 1 form)) 'customized-face
+ ',(eval (nth 2 form))))
+ (put (eval (nth 1 form)) 'saved-face nil)))
((eq (car form) 'progn)
(cons 'progn (mapcar 'eval-defun-1 (cdr form))))
(t form)))
Index: lisp/emacs-lisp/edebug.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/emacs-lisp/edebug.el,v
retrieving revision 3.75
diff -u -r3.75 edebug.el
--- lisp/emacs-lisp/edebug.el 17 Jun 2005 14:32:46 -0000 3.75
+++ lisp/emacs-lisp/edebug.el 19 Jun 2005 11:21:18 -0000
@@ -511,9 +511,15 @@
(set-default (nth 1 form) (eval (nth 2 form))))
((eq (car form) 'defface)
;; Reset the face.
- (put (nth 1 form) 'face-defface-spec nil)
(setq face-new-frame-defaults
- (assq-delete-all (nth 1 form) face-new-frame-defaults))))
+ (assq-delete-all (nth 1 form) face-new-frame-defaults))
+ (put (nth 1 form) 'face-defface-spec nil)
+ (setq form (prog1 `(prog1 ,form
+ (put ',(nth 1 form) 'saved-face
+ ',(get (nth 1 form) 'saved-face))
+ (put ',(nth 1 form) 'customized-face
+ ',(nth 2 form)))
+ (put (nth 1 form) 'saved-face nil)))))
(setq edebug-result (eval form))
(if (not edebugging)
(princ edebug-result)
Index: lisp/faces.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/faces.el,v
retrieving revision 1.318
diff -u -r1.318 faces.el
--- lisp/faces.el 17 Jun 2005 14:30:55 -0000 1.318
+++ lisp/faces.el 19 Jun 2005 11:19:15 -0000
@@ -1477,7 +1477,8 @@
(defsubst face-user-default-spec (face)
"Return the user's customized face-spec for FACE, or the default if none.
If there is neither a user setting nor a default for FACE, return nil."
- (or (get face 'saved-face)
+ (or (get face 'customized-face)
+ (get face 'saved-face)
(face-default-spec face)))
--
Juri Linkov
http://www.jurta.org/emacs/