Subject: Re: bug#11213: 24.0.95; (Maybe/Wish): Should color-themes be buffer local?

From: Jambunathan K <[email-masked]>
Date: Thu, 26 Apr 2012 00:37:24 +0530

Chong Yidong <[email-masked]> writes:

> Jambunathan K <[email-masked]> writes:
>
>>> Probably the best way to do that is to set up face remappings in the
>>> to-be-exported buffer.  See the Face Remapping node in the Lisp manual
>>> for details.
>>
>> Given a(ny) theme, let's say "adwaita-theme.el", can someone give me a
>> recipe which runs through all the face definitions defined in that theme
>> file and hand it off to `face-remapping-alist'.
>
> Do
>
>    (get 'adwaita 'theme-settings)
>
> and collect all the face settings in the resulting list.  Each list
> element should have the form
>
>    (theme-face FACE adwaita SPEC)
>
> where FACE is a face which is customized by the theme, and SPEC is the
> face spec specified.  Once you know FACE, you probably want to
>
>   (face-spec-choose (face-default-spec FACE)
>
> to get the face attributes for the face's default (uncustomized,
> unthemed) face spec, on the selected frame.  Then you can put that
> attribute in face-remapping-alist.

Based on your suggestion this is what I have cooked up.  I am recording
what I see as problems and invite your comments.

1. Copy the attached form to color-theme.el
2. emacs -q, C-x C-f color-theme.el
3. M-x load-theme-buffer-local RET tango-dark RET
4. Look at the attached png image for a screenshot of the image.
5. Place your cursor on `load-theme-buffer-local' and C-u C-x =.  Follow
   the link to `font-lock-function-name-face'.
6. You will see that foreground color is reported as "Blue1" while /in
   fact/ the face is yellowish.
7. Now M-x htmlfontify-buffer.  I am attaching the .html file created
   by this command.  You will see that the buffer is colorized based on
   uncustomized face settings.

I believe the problems in 5-7 are related.  

I think C-u C-x = and whatever the underlying APIs that htmlfontify uses
for retrieving face properties should act on effective value and not
global values.

(defun load-theme-buffer-local (theme)
(interactive
(list
(intern (completing-read "Load custom theme: "
(mapcar 'symbol-name
(custom-available-themes))))))
(require 'cl)
;; load the theme; but don't enable it
(load-theme theme t t)
(loop for (theme-face face-name theme spec) in (get theme 'theme-settings)
;; ,----
;; | (custom-theme-set-variables
;; | 'tango
;; | `(ansi-color-names-vector [,alum-6 ,red-3 ,cham-3 ,butter-3
;; | ,blue-3 ,plum-3 ,blue-1 ,alum-1]))
;; `----
when (listp spec) ; FIXME: tango-theme.el has
; the above form which is not
; a face spec. Use this test
; as to guard against an error
; when tango-theme is loaded.
collecting (cons face-name (face-spec-choose spec)) into remapping-alist
finally (set (make-local-variable 'face-remapping-alist)
remapping-alist)))