From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Richard M. Stallman" Newsgroups: gmane.emacs.devel Subject: Re: [drew.adams@oracle.com: Info on define-minor-mode - :init-valueor :initial-value?] Date: Sat, 30 Jul 2005 19:44:39 -0400 Message-ID: References: <200507290256.j6T2uPh18315@raven.dms.auburn.edu> Reply-To: rms@gnu.org NNTP-Posting-Host: main.gmane.org X-Trace: sea.gmane.org 1122768183 2238 80.91.229.2 (31 Jul 2005 00:03:03 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 31 Jul 2005 00:03:03 +0000 (UTC) Cc: drew.adams@oracle.com, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jul 31 02:03:03 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Dz1HY-0006cM-6I for ged-emacs-devel@m.gmane.org; Sun, 31 Jul 2005 02:02:20 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Dz1K7-0005Vl-LN for ged-emacs-devel@m.gmane.org; Sat, 30 Jul 2005 20:04:59 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Dz1H2-00047c-IL for emacs-devel@gnu.org; Sat, 30 Jul 2005 20:01:48 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Dz1Gw-00043x-NV for emacs-devel@gnu.org; Sat, 30 Jul 2005 20:01:44 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Dz1Gv-00040r-4H for emacs-devel@gnu.org; Sat, 30 Jul 2005 20:01:41 -0400 Original-Received: from [199.232.76.164] (helo=fencepost.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Dz1DB-0005yh-KE for emacs-devel@gnu.org; Sat, 30 Jul 2005 19:57:49 -0400 Original-Received: from rms by fencepost.gnu.org with local (Exim 4.34) id 1Dz10R-0002a4-7L; Sat, 30 Jul 2005 19:44:39 -0400 Original-To: Luc Teirlinck In-reply-to: <200507290256.j6T2uPh18315@raven.dms.auburn.edu> (message from Luc Teirlinck on Thu, 28 Jul 2005 21:56:25 -0500 (CDT)) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:41361 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:41361 The _default_ :initialize function is custom-initialize-reset. That means that whenever a file containing a defcustom with a :set function is loaded, that :set function is called That seems like the right thing to me. If the user set the variable, he probably wanted to control the mode. _even_ if the user customized the variable outside Custom, possibly in an attempt to avoid the :set function. So what? One can't please everybody. This has repeatedly caused me (and other people) problems in practice. If you describe these problems, we could think about whether they are worth solving by changing this mechanism. However, if the problems only occur with a few particularly troublesome variables, it would be easier to deal with them one by one. hand, I have trouble convincing Stefan that the _much_ more benign custom-initialize-set can be safe for minor modes that are natural to enable by default. It seems plausible to me. don't know how you'll decide to handle this, but I agree with Luc that it is confusing to set the :init-value to, say, `t' and then not see that initial value be effective. I agree completely. Stefan wrote: > (if foo-mode (foo-mode 1)) This will turn on the minor mode if you happen to browse the corresponding customize group (because Custom will then load the file). I.e. it'd be a bug. Consider minor modes that work in the classical way: just setting the variable enables the mode, and no :set-function is needed. If the default value is t, just loading the file will enable the mode. What this means is that a minor mode's default value should never be t unless t is a harmless value for it. Once we decide that, there's no particular problem about :set functions. Regardless of whether the minor mode takes effect through a :set function or just by setting the variable, either way, the default value should be nil, unless for specific reasons t is harmless. Therefore, it is ok to run the :set function when the minor mode code is loaded. It is ok to use custom-initialize-reset for them. FWIW, that's OK by me. In the user doc (Elisp), we should say "this is how you create a minor mode..." and include the bit about (if foo-mode (foo-mode 1)) for non-nil init value. That is apparently an integral part of coding a minor mode with a non-nil init value. If so, this should not be mentioned only as an afterthought in an explanation of one of the examples. If we can't arrange to make just the defcustom do the job, documenting this method is ok with me. Perhaps we should document a simple way and a complex way. The simple way is that it all gets done by the :set function when the defcustom's expansion is executed. That requires putting the defcustom after the minor mode function and generating a defvar before the function. You'd use custom-initialize-reset. For cases which are more complex, you'd use custom-initialize-default and then write (if foo-mode (foo-mode 1)) at the end of the file.