[Top][All Lists]

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

Re: How global is a define-global-minor-mode mode?

From: Lennart Borgman (gmail)
Subject: Re: How global is a define-global-minor-mode mode?
Date: Thu, 25 Jan 2007 22:47:07 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20061207 Thunderbird/ Mnenhy/

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

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.

reply via email to

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