Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Correct way of overriding custom-set-faces after the color-theme is loaded

635 views
Skip to first unread message

Vineet Naik

unread,
Feb 3, 2012, 2:48:31 AM2/3/12
to help-gn...@gnu.org
Hello,

I use the Solarized Dark theme on emacs 23. This theme defines
background color as orange for flymake error line. I wanted to change
this to DarkRed. So in my .emacs file, I added the following lines
after requiring the color theme

;; flymake error and warning faces
(custom-set-faces
 '(flymake-errline ((t (:background "DarkRed"))))
 '(flymake-warnline ((((class color)) (:background "DarkBlue")))))

This was working as expected. Today I set some customization options
using M-x customize-group and saved them due to which, emacs moved the
above lines to the top of the .emacs file resulting in the default
solalized faces to be applied to flymake error.

It also added the following comment under custom-set-faces which is
self explanatory

;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.

I need to know what would be the correct way to manage my
customizations for the solarized theme without editing the definitions
in the theme itself and make sure they are not overwritten by
customize-*

Thanks
--
Vineet Naik

Philipp Haselwarter

unread,
Feb 3, 2012, 3:58:29 AM2/3/12
to help-gn...@gnu.org
two solutions come to my mind:

1) set the face attributes outside of customize, that way they won't be
affected by customize.
#+begin_src elisp
(set-face-background 'flymake-errline "DarkRed")
#+end_src

2) put custom stuff into a separate file and load that at some point of
your .emacs
#+begin_src elisp
(load
(setq custom-file
(expand-file-name "custom.el" user-emacs-directory))
'noerror)
#+end_src

--
Philipp Haselwarter


Vineet Naik

unread,
Feb 3, 2012, 5:11:17 AM2/3/12
to help-gn...@gnu.org
@Philipp - Oops, I replied back to you directly instead of the list.
Sorry for that.

I couldn't find your reply on the list besides the first one. I
checked here - http://lists.gnu.org/archive/html/help-gnu-emacs/2012-02/threads.html

is there a different emacs.help list ?

Thanks
--
Vineet Naik

Vineet Naik

unread,
Feb 3, 2012, 6:04:33 AM2/3/12
to help-gn...@gnu.org
How do I get my changes to take effect right at the time emacs loads ?

Here is the reply I had sent to Philipp by mistake instead of replying
to the mailing list.

I tried to use the second method, but the overriden changes don't take
effect automatically on starting emacs.
But if I open .emacs file and evaluate the expression, then the
changes are seen.

Here is the code I added

#+begin_src elisp
;; in .emacs file
(setq user-emacs-dir (expand-file-name "emacs/site/common"))
(load
(setq custom-file
(expand-file-name "theme-custom.el" user-emacs-dir))
'noerror)
#+end_src

#+begin_src elisp
;; in theme-custom.el
(set-face-background 'flymake-errline "DarkRed")
(set-face-background 'flymake-warnline "DarkBlue")
#+end_src

Am I missing anything ?
Sorry if this is a dumb question to ask but my I emacs lisp knowledge
is very little.

Thanks for helping out.
--
Vineet Naik

Philipp Haselwarter

unread,
Feb 3, 2012, 6:13:37 AM2/3/12
to help-gn...@gnu.org
my bad, got confused with my mail accounts.


On Fri, Feb 03 2012 09:58 (@1328259509), Philipp Haselwarter wrote:

> two solutions come to my mind:
>
> 1) set the face attributes outside of customize, that way they won't be
> affected by customize.
> #+begin_src elisp
> (set-face-background 'flymake-errline "DarkRed")
> #+end_src
>
> 2) put custom stuff into a separate file and load that at some point of
> your .emacs
> #+begin_src elisp
> (load
> (setq custom-file
> (expand-file-name "custom.el" user-emacs-directory))
> 'noerror)
> #+end_src

Clarification: Do one /or/ the other :) If you choose option two, make
sure to create the file you set as `custom-file' (C-h v custom-file RET)
and move all the custom-* stuff from your .emacs into that file. Also,
use an absolute path-name. If things don't work as expected, remove the
'noerror and start emacs as "emacs --debug-init".

--
Philipp Haselwarter


Vineet Naik

unread,
Feb 3, 2012, 10:36:24 AM2/3/12
to help-gn...@gnu.org
Oh! got it now. Your explanantion also helped me refactor my .emacs file :)

Thank you for all the help.

--
Vineet Naik

Raffaele Ricciardi

unread,
Feb 5, 2012, 9:14:22 AM2/5/12
to
On 02/03/2012 07:48 AM, Vineet Naik wrote:
> I need to know what would be the correct way to manage my
> customizations for the solarized theme without editing the definitions
> in the theme itself and make sure they are not overwritten by
> customize-*

Color-theme does not provide hooks for customization. Luckily we have
advices:

(defadvice color-theme-solarized-dark (after rr-fix-faces activate)
;; Code here gets executed after the theme has been applied.
;; Customize your faces here.
)

(defadvice color-theme-solarized-light (after rr-fix-faces activate)
;; Code here gets executed after the theme has been applied.
;; Customize your faces here.
)
0 new messages