From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.help Subject: RE: defcustom: changing from defvar - order of execution Date: Tue, 3 May 2005 09:13:19 -0700 Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1115238172 15891 80.91.229.2 (4 May 2005 20:22:52 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 4 May 2005 20:22:52 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed May 04 22:22:50 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DTQNb-00077V-HI for geh-help-gnu-emacs@m.gmane.org; Wed, 04 May 2005 22:21:59 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DTQUy-0007LD-R2 for geh-help-gnu-emacs@m.gmane.org; Wed, 04 May 2005 16:29:36 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DT9v3-0004C4-V0 for help-gnu-emacs@gnu.org; Tue, 03 May 2005 22:47:26 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DT9uI-0003pL-67 for help-gnu-emacs@gnu.org; Tue, 03 May 2005 22:46:38 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DT9rF-0001Tj-Qv for help-gnu-emacs@gnu.org; Tue, 03 May 2005 22:43:29 -0400 Original-Received: from [199.232.41.67] (helo=mx20.gnu.org) by monty-python.gnu.org with esmtp (TLS-1.0:RSA_ARCFOUR_SHA:16) (Exim 4.34) id 1DT9hj-00010U-Lh for help-gnu-emacs@gnu.org; Tue, 03 May 2005 22:33:40 -0400 Original-Received: from [141.146.126.231] (helo=agminet04.oracle.com) by mx20.gnu.org with esmtp (Exim 4.34) id 1DT028-0004Ax-0q for help-gnu-emacs@gnu.org; Tue, 03 May 2005 12:14:04 -0400 Original-Received: from agminet04.oracle.com (localhost [127.0.0.1]) by agminet04.oracle.com (Switch-3.1.7/Switch-3.1.7) with ESMTP id j43GDNuZ024878 for ; Tue, 3 May 2005 11:13:23 -0500 Original-Received: from rgmsgw301.us.oracle.com (rgmsgw301.us.oracle.com [138.1.186.50]) by agminet04.oracle.com (Switch-3.1.7/Switch-3.1.7) with ESMTP id j43GDMGC024873 for ; Tue, 3 May 2005 11:13:23 -0500 Original-Received: from rgmsgw301.us.oracle.com (localhost [127.0.0.1]) by rgmsgw301.us.oracle.com (Switch-3.1.4/Switch-3.1.0) with ESMTP id j43GDMU2016074 for ; Tue, 3 May 2005 10:13:22 -0600 Original-Received: from dradamslap (dhcp-amer-csvpn-gw1-141-144-69-28.vpn.oracle.com [141.144.69.28]) by rgmsgw301.us.oracle.com (Switch-3.1.4/Switch-3.1.0) with SMTP id j43GDLO8016061 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Tue, 3 May 2005 10:13:21 -0600 Original-To: "Help-Gnu-Emacs" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 In-Reply-To: X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:26292 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:26292 Oops - before someone gripes about users using defvar for variables that are defined in libraries, let me change the initial user setup from this: (defvar foovar t) (load-library "foo") (foo-fn) to this: (setq foovar t) (load-library "foo") (foo-fn) I don't think it changes my overall question, in any case. Thanks. - Drew -----Original Message----- 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.