Setting Background Face Per Buffer

Setting Background Face Per Buffer

Post by Chri » Thu, 04 Aug 2005 02:07:04


Howdy.

I've thoroughly confused myself in trying to chase down how to set
background colors per buffer. I use an 'after-advice' to do the work
of determining the color[1] (and eventually setting the face).

Enter the confusion of faces and themes. Do themes apply in this
context? (If so, I'm at a loss on how to use them.) If I solely used
faces, I think I would: a) define a new face copied from my default
face; b) modify the new face's background color; and then c) set it for
the local buffer (how?).

What is the suggested way to go about this? Thanks.

- Chris

[1] Although I do have one problem with the 'defadvice'. The 'if'
works if I evaluate it within buffers directly, but I get an error if I
switch to a buffer without a filename in the advice context.

(defadvice switch-to-buffer (after bg-buffer-face (arg))
"..."
(if (buffer-file-name) ; evals non-nil
(cond
((string-match ".*frogger.*" buffer-file-name) ; stringp, nil
error
(some-stuff))
(t (default-stuff)))))
 
 
 

Setting Background Face Per Buffer

Post by Nigel Warn » Fri, 05 Aug 2005 21:41:29


Chris,

I too would like to do this if only as a nice to have. However there
seems to be some complicating factors involved. If you place the
function under into the scratch buffer, evaluate it and execute it,
nothing appears to happen. If however you change the colour to "green"
evaluate and execute then the function works. Doing this multiple
times leads me to the conclusion that the background pixmap will only
be changed if Emacs thinks it should. Why this should be so I have no
idea.

(defun python-decor ()
(interactive)
(set-face-background 'default "black"
(current-buffer) nil 'prepend)
(set-face-background-pixmap 'default
[jpeg :file ~/.xemacs/testBack.jpg"]
(current-buffer) nil 'prepend)
)

If you ever figure this out I would like to know ;-)

Regards,
Nigel.

 
 
 

Setting Background Face Per Buffer

Post by Nigel Warn » Fri, 05 Aug 2005 21:41:58


Chris,

I too would like to do this if only as a nice to have. However there
seems to be some complicating factors involved. If you place the
function under into the scratch buffer, evaluate it and execute it,
nothing appears to happen. If however you change the colour to "green"
evaluate and execute then the function works. Doing this multiple
times leads me to the conclusion that the background pixmap will only
be changed if Emacs thinks it should. Why this should be so I have no
idea.

(defun python-decor ()
(interactive)
(set-face-background 'default "black"
(current-buffer) nil 'prepend)
(set-face-background-pixmap 'default
[jpeg :file ~/.xemacs/testBack.jpg"]
(current-buffer) nil 'prepend)
)

If you ever figure this out I would like to know ;-)

Regards,
Nigel.