unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* custom + theme recursion
@ 2011-11-04 11:24 joakim
  2011-11-22  5:59 ` Chong Yidong
  0 siblings, 1 reply; 2+ messages in thread
From: joakim @ 2011-11-04 11:24 UTC (permalink / raw)
  To: emacs-devel

So, lets say I have a variable zen-state. when zen-state is set, I want
to change custom-enabled-themes. I also want zen-state to be a
customizable variable.

For some reason this causes recursion. I don't think that is intuitive,
because zen-state is supposed to be in the user-theme, which has the
highest precedence of the themes, and the other themes should have no
opinion of the value of zen-state.

Anyway, how should I reason about themes and custom?

Here is the relevant snippets from zen-mode.el

(defcustom zen-state 0
  "Current zen state.  0 means no zen.  other states correspond to a theme."
  :group 'zen-mode
  :set 'zen-set-state)

(defun zen-set-state (name new-state)
  "Which zen NEW-STATE to enter."
  (interactive (list "zen-state" (read-number "zen:")))
  (if (> 0 new-state) (setq new-state 0))
  (if (>= new-state 3)  (setq new-state 3));;TODO
  ;; 0 means a wordly state.
  ;;other states are themes
  (if zen-state (disable-theme (zen-state-theme zen-state)))
  ;;  (if new-state (enable-theme (zen-state-theme new-state)))
  ;;enable-theme doesnt work in the way I expected

  ;; this works. somewhat.
  (if (>  new-state 0)
      (custom-set-variables (list 'custom-enabled-themes
                                  (list 'quote (append (list (zen-state-theme new-state)) custom-enabled-themes )) nil)
                            ))

  (setq zen-state new-state)
  (message "Now entering Zen %d" zen-state)
  )

  
-- 
Joakim Verona



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: custom + theme recursion
  2011-11-04 11:24 custom + theme recursion joakim
@ 2011-11-22  5:59 ` Chong Yidong
  0 siblings, 0 replies; 2+ messages in thread
From: Chong Yidong @ 2011-11-22  5:59 UTC (permalink / raw)
  To: joakim; +Cc: emacs-devel

joakim@verona.se writes:

> So, lets say I have a variable zen-state. when zen-state is set, I
> want to change custom-enabled-themes. I also want zen-state to be a
> customizable variable.
>
> For some reason this causes recursion. I don't think that is intuitive,
> because zen-state is supposed to be in the user-theme, which has the
> highest precedence of the themes, and the other themes should have no
> opinion of the value of zen-state.
>
> Anyway, how should I reason about themes and custom?

Sorry for the delay.  Here, I think, is the problem: you have a custom
:set function that calls `enable-theme', and the code in `enable-theme'
calls `custom-theme-recalc-variable' to apply all variables in every
theme (to ensure that theme values are applied in the correct order).
Obviously, `custom-theme-recalc-variable' ends up calling the :set
function again, etc.

I'm not sure what's a good way to address this within Emacs itself, but
you can get around it in your own code by doing

	(unless (custom-theme-enabled-p 'zen)
	  (enable-theme 'zen))



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-11-22  5:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-04 11:24 custom + theme recursion joakim
2011-11-22  5:59 ` Chong Yidong

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).