From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Lennart Borgman (gmail)" Newsgroups: gmane.emacs.devel Subject: Re: How global is a define-global-minor-mode mode? Date: Thu, 25 Jan 2007 22:47:07 +0100 Message-ID: <45B9255B.6030002@gmail.com> References: <4581996F.3050700@student.lu.se> <87y7nxmqzh.fsf@stupidchicken.com> <45B6A179.9020604@gmail.com> <45B7B3AE.9020000@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1169761699 11514 80.91.229.12 (25 Jan 2007 21:48:19 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 25 Jan 2007 21:48:19 +0000 (UTC) Cc: cyd@stupidchicken.com, rms@gnu.org, emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jan 25 22:48:12 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HACS3-00020f-R1 for ged-emacs-devel@m.gmane.org; Thu, 25 Jan 2007 22:48:12 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HACS3-0007HS-Dm for ged-emacs-devel@m.gmane.org; Thu, 25 Jan 2007 16:48:11 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HACRl-0007ET-6D for emacs-devel@gnu.org; Thu, 25 Jan 2007 16:47:53 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HACRk-0007E5-LY for emacs-devel@gnu.org; Thu, 25 Jan 2007 16:47:52 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HACRk-0007Dz-An for emacs-devel@gnu.org; Thu, 25 Jan 2007 16:47:52 -0500 Original-Received: from ch-smtp02.sth.basefarm.net ([80.76.149.213]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1HACRi-0005Y7-IL; Thu, 25 Jan 2007 16:47:51 -0500 Original-Received: from c83-254-145-24.bredband.comhem.se ([83.254.145.24]:64825 helo=[127.0.0.1]) by ch-smtp02.sth.basefarm.net with esmtp (Exim 4.63) (envelope-from ) id 1HACRe-0004Sd-9d; Thu, 25 Jan 2007 22:47:48 +0100 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.9) Gecko/20061207 Thunderbird/1.5.0.9 Mnenhy/0.7.4.666 In-Reply-To: X-Antivirus: avast! (VPS 000706-2, 2007-01-25), Outbound message X-Antivirus-Status: Clean X-Scan-Result: No virus found in message 1HACRe-0004Sd-9d. X-Scan-Signature: ch-smtp02.sth.basefarm.net 1HACRe-0004Sd-9d f6bb18bc55bbf347c8f4394f6a2fb4c2 X-detected-kernel: Linux 2.6? (barebone, rare!) 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:65465 Archived-At: Stefan Monnier wrote: >> I previously used defcustom variables to manage something similar to >> define-globalized-mode MY-GLOBAL-MODE MY-MODE. This worked ok. I then used >> the :set function to turn on the minor mode MY-MODE. > >> Using define-minor-mode there is no way to do something similar. There is no >> code that is run when the library file is loaded, even if the minor mode is >> global and that is in my opinion a bug (or at least a very inconvenient >> inconsistency). > > Yes, there is code that runs the minor-mode function if it is global and has > been set. This *should* work. So please tell us what you tried that failed > to work. I think I am beginning to understand what is happening now because of the trick with macroexpand you mentioned. I felt rather confused, but I beleive that to a not too small extent depends on my inability to see a clear thought behind what should actually be run when for defcustom and define-minor-mode. My initial problem was that a define-global-minor-mode did not work as I wanted it too. The define-minor-mode were not turned on at startup of Emacs even though I had customized the define-global-minor-mode to true. However it worked if I turned off and on the define-global-minor-mode again. And it had worked before with my a little bit more low tech solution where I used a defcustom and the :set function instead. I thought that the problem was more of the type a typo in define-global-minor-mode, but I did not look very much at it. Now since the problem remains I took a closer look at it and did some tests. I was surprised about the incongruencies I found. I have attached a test file that can show them. More about that later. Now a bit about the incongruencies (a little bit simplified picture to make it more clear): - When a defcustom is set through custom (the GUI interface or customize-set-variable) the :set function is run. - That is true also for the implicit defcustom created by a define-minor-mode. - However for define-minor-mode you can also change the value of the implicit defcustom by using the mode function instead. In this case the :set function is not run. - On the other hand when you use the mode function the body of the define-minor-mode is run. - And then this body is in turned not run when you use set the implicit defcustom through customize. I think this has led to the trouble we have seen with define-global-minor-mode. *** My suggestion is this: Let the :set function and the body of a define-minor-mode be the same thing. I believe this will make it much easier for users and programmers. Now back to the tests. If the above was a bit hard to grasp then maybe the test will help. To run the tests first load this file and customize the defcustom, define-minor-mode and define-global-minor-mode, all to t. Then restart Emacs and load the file again and now look in the *Message* buffer for the result.