help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

defcustom: changing from defvar - order of execution


From: Drew Adams
Subject: defcustom: changing from defvar - order of execution
Date: Tue, 3 May 2005 08:50:57 -0700

I'm unclear on the recommended way to change Lisp code from using defvar for
user options to using defcustom. I guess I'm also unclear on just how
defcustom and Customize work. I couldn't find an explanation of this in Info
for Emacs or Emacs Lisp.

Initial setup - library foo.el has this:

 (defvar foovar nil)
 (defun foo-fn () foovar)

Initial setup - user has this in .emacs:

 (defvar foovar t)
 (load-library "foo")
 (foo-fn)

When .emacs is loaded, (foo-fn) is executed, foovar is `t', so (foo-fn)
returns `t'.


Second setup - library foo.el has this:

 (defcustom foovar nil)
 (defun foo-fn () foovar)

Second setup - user has this in .emacs, after customizing foovar to `t' with
Customize:

 (load-library "foo")
 (foo-fn)
 ...
 (custom-set-variables '(foovar t)...)

When .emacs is loaded, (foo-fn) is executed, foovar is (has default value)
`nil', so (foo-fn) returns `nil'.

That is, because (custom-set-variables...) is executed after (foo-fn), it
has no effect during foo-fn's execution.

What am I missing/confusing here? What is the proper way for library foo.el
to move from using defvar to using defcustom? Also, what difference does it
make, if any, whether a defcustom is executed at the top level or a lower
level of a file.

Thanks. - Drew





reply via email to

[Prev in Thread] Current Thread [Next in Thread]