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: Wed, 24 Jan 2007 20:29:50 +0100 Message-ID: <45B7B3AE.9020000@gmail.com> References: <4581996F.3050700@student.lu.se> <87y7nxmqzh.fsf@stupidchicken.com> <45B6A179.9020604@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 1169667106 28461 80.91.229.12 (24 Jan 2007 19:31:46 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 24 Jan 2007 19:31:46 +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 Wed Jan 24 20:31:35 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 1H9nqH-0003u7-Ag for ged-emacs-devel@m.gmane.org; Wed, 24 Jan 2007 20:31:33 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1H9nqG-000856-SJ for ged-emacs-devel@m.gmane.org; Wed, 24 Jan 2007 14:31:32 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1H9npX-00077r-Kn for emacs-devel@gnu.org; Wed, 24 Jan 2007 14:30:47 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1H9npV-00074J-Lh for emacs-devel@gnu.org; Wed, 24 Jan 2007 14:30:47 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1H9npV-000744-G0 for emacs-devel@gnu.org; Wed, 24 Jan 2007 14:30:45 -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 1H9npQ-0001qm-MU; Wed, 24 Jan 2007 14:30:41 -0500 Original-Received: from c83-254-145-24.bredband.comhem.se ([83.254.145.24]:60917 helo=[127.0.0.1]) by ch-smtp02.sth.basefarm.net with esmtp (Exim 4.63) (envelope-from ) id 1H9npO-0008Be-87; Wed, 24 Jan 2007 20:30:39 +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-1, 2007-01-24), Outbound message X-Antivirus-Status: Clean X-Scan-Result: No virus found in message 1H9npO-0008Be-87. X-Scan-Signature: ch-smtp02.sth.basefarm.net 1H9npO-0008Be-87 0c104d24c9cd081f17ce78706912016d 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:65450 Archived-At: Stefan Monnier wrote: >>>>> Isn't it the case that it works if the minor mode function >>>>> corresponding to the variable is autoloaded? Otherwise, IIRC you need >>>>> to add a :require to the definition of the minor mode. >>>> Not really: if the global minor mode is autoloaded, then :require is >>>> a nuisance, >>>> I don't follow. Could you explain why it is a nuisance? >>> The :require thingy is a risk: if you move the definition of the mode to >>> another file, then the user's customizations will be broken (it happened >>> with global-font-lock-mode). > >> I have lost my way here, but I did some tests to try to understand. If I use >> defcustom with a :set function this will be called when the elisp file is >> loaded. Why can't something similar be done for define-global-minor-mode >> also? It is a global mode and then :set is passed to defcustom, or? > > I don't understand your question. What do you suggest exactly and for > what purpose? 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). Actually define-minor-mode says that "other keywords will be passed to defcustom if the minor mode is global". Should not this mean that :set should be passed to defcustom and therefore be run when loading the library file if the minor mode as been customized to be on? I can not see that :set is run however. On the other hand one may wonder why not the body or the hook of the minor mode is run when loading the library. I can see the purpose of this (that you should be able to load a library without running any code), but there are a few inconsistenceis here (compared with defcustom). I think this inconsistencies should be addressed before trying to fix define-globalized-minor-mode. But I am quite a bit unsure about how to handle the problem with body/hook/:set for a define-minor-mode. Below are some test code I have used in my own library. This code should give some messages when loading the library they are put in. Please test it with the defcustom and define-minor-mode set. (defvar html-site-temp-mode-hook nil) (add-hook 'html-site-temp-mode-hook (lambda() (message "html-site-temp-mode-hook, html-site-temp-mode=%s" html-site-temp-mode))) (define-minor-mode html-site-temp-mode "dummy" :init-value nil :lighter nil :global t :keymap (let ((m (make-sparse-keymap))) (define-key m [f11] (lambda() (interactive) (message "html-site-mode-temp f11 here"))) m) :set (lambda(sym val) (message ":set html-site-temp-mode: sym=%s, val=%s" sym val) (set-default sym val)) (message "body html-site-temp-mode=%s, current-buffer=%s" html-site-mode (current-buffer))) (defcustom html-site-temp nil "doc" :type 'boolean :set (lambda(sym val) (message ":set html-site-temp: sym=%s, val=%s" sym val) (set-default sym val))) (message "html-site.el loaded, html-site-global-mode=%s, html-site-temp=%s, html-site-temp-mode=%s" html-site-global-mode html-site-temp html-site-temp-mode ) >> BTW should not the name be define-globalized-minor-mode as was >> suggested before? > > I believe so, yes. Feel free to implement this change, > > > Stefan As I use to say: I do not want to touch the CVS this close to the release since I am unfamiliar with cvs. I would be glad if you changed the name.