all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Lennart Borgman (gmail)" <lennart.borgman@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: cyd@stupidchicken.com, rms@gnu.org, emacs-devel@gnu.org
Subject: Re: How global is a define-global-minor-mode mode?
Date: Wed, 24 Jan 2007 20:29:50 +0100	[thread overview]
Message-ID: <45B7B3AE.9020000@gmail.com> (raw)
In-Reply-To: <jwv1wllb4zw.fsf-monnier+emacs@gnu.org>

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.

  reply	other threads:[~2007-01-24 19:29 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-14 18:35 How global is a define-global-minor-mode mode? Lennart Borgman
2006-12-25  0:43 ` Richard Stallman
2006-12-29 15:44 ` Richard Stallman
2006-12-29 17:21   ` Lennart Borgman (gmail)
2006-12-30  6:23     ` Richard Stallman
2006-12-30 10:57       ` Lennart Borgman (gmail)
2006-12-31  1:46         ` Richard Stallman
2006-12-31  2:27           ` Lennart Borgman (gmail)
2006-12-31 22:13             ` Richard Stallman
2007-01-03  0:18   ` Johan Bockgård
2007-01-03 21:11     ` Richard Stallman
2007-01-20 19:34 ` Chong Yidong
2007-01-21 22:27   ` Richard Stallman
2007-01-21 23:11   ` Stefan Monnier
2007-01-22  9:04     ` Richard Stallman
2007-01-22 14:55       ` Stefan Monnier
2007-01-23 20:55         ` Richard Stallman
2007-01-23 23:00           ` Stefan Monnier
2007-01-23 23:59             ` Lennart Borgman (gmail)
2007-01-24  1:15               ` Stefan Monnier
2007-01-24 19:29                 ` Lennart Borgman (gmail) [this message]
2007-01-25  4:57                   ` Stefan Monnier
2007-01-25  8:56                     ` Lennart Borgman (gmail)
2007-01-25 19:27                       ` Stefan Monnier
2007-01-25 21:47                     ` Lennart Borgman (gmail)
2007-01-25 23:56                       ` Lennart Borgman (gmail)
2007-01-26  4:34                         ` Stefan Monnier
2007-01-27 19:43                           ` Chong Yidong
2007-01-26  4:35                       ` Stefan Monnier
2007-01-28  7:42                       ` Richard Stallman
2007-01-28  7:42             ` Richard Stallman
2007-01-28 15:47               ` Chong Yidong
2007-01-28 16:37                 ` David Kastrup
2007-01-28 19:53                   ` Chong Yidong
2007-01-29  4:32               ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45B7B3AE.9020000@gmail.com \
    --to=lennart.borgman@gmail.com \
    --cc=cyd@stupidchicken.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=rms@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.