"Shuguang Sun" <shuguang79@qq.com> writes:

> Hi,
>
> How to repeat it:
> 1. I have org-capture-templates with 2 commands in the custom-set-variables of my dot
> emacs file
> 2. I use add-to-list adding another 4 commands to org-capture-templates in other file, so
> that finally I have 6 commands in org-capture-templates for org-capture
> 3. I customized a theme which involves custom-theme-set-variables, but it doesn't inlcude
> org-capture-templates, and org-capture-templates is not in the theme any where
> 4. After I load the theme, it leave only the 2 commands for org-capture with in the
> custom-set-variables of my dot emacs file
>
> It looks like the load-theme with custom-theme-set-variables will eval
> custom-theme-set-variables? Is it a bug of feature? Is there an option to disable it and only
> eval custimize the variables in custom-theme-set-variables?
>

What happens is that when custom sets the variable with
custom-set-variables, it stores the value in the custom-set-variables
form in a theme called user, which takes precedence over any other theme
you have active.

When later you add to the list new values, custom doesn't get notified
about that, so the value stored in the user theme is the same as before,
the one from the custom-set-variables form.

When you enable a theme, custom will "re-enable" the user theme, so the
settings in the user theme take precedence over the other theme.  While
doing that, it will set the list to the value stored in the user theme,
and that's how it is overwriting your settings.

I would recommend against setting org-capture-templates both in
custom-set-variables and after with add-to-list.  Is there any reason
why you do that? In any case, if you want to keep the configuration
as it is, you can add
(customize-mark-as-set 'org-capture-templates)
*after* adding to the list, and that way you effectively notify custom
of the new value, and it won't override your settings when loading other
theme.