* How global is a define-global-minor-mode mode? @ 2006-12-14 18:35 Lennart Borgman 2006-12-25 0:43 ` Richard Stallman ` (2 more replies) 0 siblings, 3 replies; 35+ messages in thread From: Lennart Borgman @ 2006-12-14 18:35 UTC (permalink / raw) I am trying to use define-global-minor-mode, see below. I have customized the global mode to be t, but when I open new buffers the minor mode is not set in them. Is this a bug in define-global-minor-mode? (define-minor-mode html-site-mode "Adds a menu for easy access of setting site, uploading etc." :init-value nil :lighter nil :keymap html-site-mode-map :group 'html-site) (defvar html-site-mode-off-list '(nxhtml-mode)) (define-global-minor-mode html-site-global-mode html-site-mode (lambda() (html-site-mode 1) (when t ;buffer-file-name (unless (memq major-mode html-site-mode-off-list) (html-site-mode 1)))) :group 'html-site) ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 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 2007-01-20 19:34 ` Chong Yidong 2 siblings, 0 replies; 35+ messages in thread From: Richard Stallman @ 2006-12-25 0:43 UTC (permalink / raw) Cc: emacs-devel I am trying to use define-global-minor-mode, see below. I have customized the global mode to be t, but when I open new buffers the minor mode is not set in them. Is this a bug in define-global-minor-mode? My impression is that the global mode defined with define-global-minor-mode does not affect all buffers to be created in the future. It only catches buffers created by visiting files. If so, I think what is needed is to add this to the documentation of define-global-minor-mode. Globally enabling the mode also affects buffers subsequently created by visiting files, but not buffers subsequently created in other ways. Can anyone confirm that this is right? ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 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) 2007-01-03 0:18 ` Johan Bockgård 2007-01-20 19:34 ` Chong Yidong 2 siblings, 2 replies; 35+ messages in thread From: Richard Stallman @ 2006-12-29 15:44 UTC (permalink / raw) Cc: emacs-devel [I sent this message a few days ago but did not get a response. Could we get the discussion moving again?] I am trying to use define-global-minor-mode, see below. I have customized the global mode to be t, but when I open new buffers the minor mode is not set in them. Is this a bug in define-global-minor-mode? My impression is that the global mode defined with define-global-minor-mode does not affect all buffers to be created in the future. It only catches buffers created by visiting files. If so, I think what is needed is to add this to the documentation of define-global-minor-mode. Globally enabling the mode also affects buffers subsequently created by visiting files, but not buffers subsequently created in other ways. Can anyone confirm that this is right? ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2006-12-29 15:44 ` Richard Stallman @ 2006-12-29 17:21 ` Lennart Borgman (gmail) 2006-12-30 6:23 ` Richard Stallman 2007-01-03 0:18 ` Johan Bockgård 1 sibling, 1 reply; 35+ messages in thread From: Lennart Borgman (gmail) @ 2006-12-29 17:21 UTC (permalink / raw) Cc: Lennart Borgman, Drew Adams, emacs-devel Richard Stallman wrote: > [I sent this message a few days ago but did not get a response. > Could we get the discussion moving again?] > > I am trying to use define-global-minor-mode, see below. I have > customized the global mode to be t, but when I open new buffers the > minor mode is not set in them. Is this a bug in define-global-minor-mode? > > My impression is that the global mode defined with > define-global-minor-mode does not affect all buffers to be created in > the future. It only catches buffers created by visiting files. > > If so, I think what is needed is to add this to the documentation of > define-global-minor-mode. > > Globally enabling the mode also affects buffers subsequently created > by visiting files, but not buffers subsequently created in other ways. > > Can anyone confirm that this is right? > I believe the problem is that the setup of the hook functions is not done as expected. I have my global minor mode set to t in customize, but I do not found the global mode hook functions in the hook after startup. (The global minor mode is t.) I think Drew said that the documentation for define-global-minor-mode needs some enhancement. I think that too, especially something could be mentioned about the difference using :global t with define-minor-mode. BTW, it looks to me that there is no way to catch creation of new buffers. ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2006-12-29 17:21 ` Lennart Borgman (gmail) @ 2006-12-30 6:23 ` Richard Stallman 2006-12-30 10:57 ` Lennart Borgman (gmail) 0 siblings, 1 reply; 35+ messages in thread From: Richard Stallman @ 2006-12-30 6:23 UTC (permalink / raw) Cc: lennart.borgman.073, drew.adams, emacs-devel I believe the problem is that the setup of the hook functions is not done as expected. I have my global minor mode set to t in customize, but I do not found the global mode hook functions in the hook after startup. (The global minor mode is t.) That sounds like a bug. Can you debug it? Can you provide a _precise_ self-contained test case so someone else can debug it? I think Drew said that the documentation for define-global-minor-mode needs some enhancement. I think that too, especially something could be mentioned about the difference using :global t with define-minor-mode. Maybe it does, but not based on a bug. We should fix the bug, and document the correct behavior. ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2006-12-30 6:23 ` Richard Stallman @ 2006-12-30 10:57 ` Lennart Borgman (gmail) 2006-12-31 1:46 ` Richard Stallman 0 siblings, 1 reply; 35+ messages in thread From: Lennart Borgman (gmail) @ 2006-12-30 10:57 UTC (permalink / raw) Cc: lennart.borgman.073, drew.adams, emacs-devel Richard Stallman wrote: > I believe the problem is that the setup of the hook functions is not > done as expected. I have my global minor mode set to t in customize, but > I do not found the global mode hook functions in the hook after startup. > (The global minor mode is t.) > > That sounds like a bug. Can you debug it? Can you provide a > _precise_ self-contained test case so someone else can debug it? > Create a file tg.el in your emacs load-path: (define-minor-mode tg-mode "" :lighter " **TG** ") (define-global-minor-mode tg-globalized-mode tg-mode (lambda() (tg-mode 1))) Eval it and customize tg-globalized-mode permanently to t. Start Emacs again: emacs M-x load-library tg C-h v tg-globalized-mode => Its value is t C-h v tg-mode => Its value is nil Then try Mx tg-globalized-mode => Tg-Globalized mode disabled M-x tg-globalized-mode => Tg-Globalized mode enabled C-h v tg-mode => Its value is t ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2006-12-30 10:57 ` Lennart Borgman (gmail) @ 2006-12-31 1:46 ` Richard Stallman 2006-12-31 2:27 ` Lennart Borgman (gmail) 0 siblings, 1 reply; 35+ messages in thread From: Richard Stallman @ 2006-12-31 1:46 UTC (permalink / raw) Cc: lennart.borgman.073, drew.adams, emacs-devel It looks like define-global-minor-mode simply fails to do anything to arrange to handle customization of the globalized mode's variable. Would someone please work on this? ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2006-12-31 1:46 ` Richard Stallman @ 2006-12-31 2:27 ` Lennart Borgman (gmail) 2006-12-31 22:13 ` Richard Stallman 0 siblings, 1 reply; 35+ messages in thread From: Lennart Borgman (gmail) @ 2006-12-31 2:27 UTC (permalink / raw) Cc: lennart.borgman.073, drew.adams, emacs-devel Richard Stallman wrote: > It looks like define-global-minor-mode simply fails to do anything > to arrange to handle customization of the globalized mode's variable. > > Would someone please work on this? > I can't do that now, however I have a suggestion. define-globalized-minor-mode takes care of the nasty technical details, but maybe it could still be easier to use. If we assume that the minor mode to globalize is defined with define-minor-mode we know how to turn it on and off. How about something like this? : :turn-on-if (lambda() ....) :turn-off-if (lambda() ...) where the two functions should used for turning on/off the minor mode in each buffer when the globalized mode is turned on/off. ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2006-12-31 2:27 ` Lennart Borgman (gmail) @ 2006-12-31 22:13 ` Richard Stallman 0 siblings, 0 replies; 35+ messages in thread From: Richard Stallman @ 2006-12-31 22:13 UTC (permalink / raw) Cc: lennart.borgman.073, drew.adams, emacs-devel I'd rather not think about changes in this now, other than what is necessary to get it working correctly with the custom mechanism. ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2006-12-29 15:44 ` Richard Stallman 2006-12-29 17:21 ` Lennart Borgman (gmail) @ 2007-01-03 0:18 ` Johan Bockgård 2007-01-03 21:11 ` Richard Stallman 1 sibling, 1 reply; 35+ messages in thread From: Johan Bockgård @ 2007-01-03 0:18 UTC (permalink / raw) Richard Stallman <rms@gnu.org> writes: > My impression is that the global mode defined with > define-global-minor-mode does not affect all buffers to be created > in the future. It only catches buffers created by visiting files. It also affects buffers that use a non-fundamental mode. It does this: ;; Setup hook to handle future mode changes and new buffers. (if ,global-mode (progn (add-hook 'after-change-major-mode-hook ',MODE-enable-in-buffers) (add-hook 'find-file-hook ',MODE-check-buffers) (add-hook 'change-major-mode-hook ',MODE-cmhh)) -- Johan Bockgård ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2007-01-03 0:18 ` Johan Bockgård @ 2007-01-03 21:11 ` Richard Stallman 0 siblings, 0 replies; 35+ messages in thread From: Richard Stallman @ 2007-01-03 21:11 UTC (permalink / raw) Cc: emacs-devel It also affects buffers that use a non-fundamental mode. It does this: Thanks. I will update that point in the Lisp manual. ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 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 @ 2007-01-20 19:34 ` Chong Yidong 2007-01-21 22:27 ` Richard Stallman 2007-01-21 23:11 ` Stefan Monnier 2 siblings, 2 replies; 35+ messages in thread From: Chong Yidong @ 2007-01-20 19:34 UTC (permalink / raw) Lennart Borgman <lennart.borgman.073@student.lu.se> writes: > I am trying to use define-global-minor-mode, see below. I have > customized the global mode to be t, but when I open new buffers the > minor mode is not set in them. Is this a bug in > define-global-minor-mode? Seems to be working fine. Your recipe is a little vague, but here is a simple example: 1. Evaluate the following in *scratch* buffer: (define-minor-mode foo-mode "Foo." nil " foo" :group 'foo) (define-global-minor-mode html-site-global-mode foo-mode (lambda () (foo-mode 1)) :group 'foo) 2. M-x customize-option RET foo RET 3. Click on "Toggle" (global-foo-mode is turned on) 4. Click on "Set for Current Session" 5. C-x C-f asdf RET (open a new file) 6. Observe the presence of the " foo" lighter in the modeline. There is one subtlety, which is that if you save the custom option for future sessions, it won't activate foo-mode in future sessions unless the above code defining foo-mode and global-foo-mode is already loaded. But I don't think that's necessary a bug; it's a flaw but not one that's easily avoidable. In short, I don't think there's anything that needs to be done here. ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2007-01-20 19:34 ` Chong Yidong @ 2007-01-21 22:27 ` Richard Stallman 2007-01-21 23:11 ` Stefan Monnier 1 sibling, 0 replies; 35+ messages in thread From: Richard Stallman @ 2007-01-21 22:27 UTC (permalink / raw) Cc: emacs-devel There is one subtlety, which is that if you save the custom option for future sessions, it won't activate foo-mode in future sessions unless the above code defining foo-mode and global-foo-mode is already loaded. But I don't think that's necessary a bug; it's a flaw but not one that's easily avoidable. That is the bug. It can be fixed somehow, I'm sure. ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 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 1 sibling, 1 reply; 35+ messages in thread From: Stefan Monnier @ 2007-01-21 23:11 UTC (permalink / raw) Cc: emacs-devel >> I am trying to use define-global-minor-mode, see below. I have >> customized the global mode to be t, but when I open new buffers the >> minor mode is not set in them. Is this a bug in >> define-global-minor-mode? > Seems to be working fine. Your recipe is a little vague, but here is > a simple example: > 1. Evaluate the following in *scratch* buffer: > (define-minor-mode foo-mode > "Foo." > nil > " foo" > :group 'foo) > (define-global-minor-mode html-site-global-mode foo-mode > (lambda () (foo-mode 1)) > :group 'foo) > 2. M-x customize-option RET foo RET > 3. Click on "Toggle" (global-foo-mode is turned on) > 4. Click on "Set for Current Session" > 5. C-x C-f asdf RET (open a new file) > 6. Observe the presence of the " foo" lighter in the modeline. > There is one subtlety, which is that if you save the custom option for > future sessions, it won't activate foo-mode in future sessions unless > the above code defining foo-mode and global-foo-mode is already > loaded. But I don't think that's necessary a bug; it's a flaw but not > one that's easily avoidable. 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. Stefan ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2007-01-21 23:11 ` Stefan Monnier @ 2007-01-22 9:04 ` Richard Stallman 2007-01-22 14:55 ` Stefan Monnier 0 siblings, 1 reply; 35+ messages in thread From: Richard Stallman @ 2007-01-22 9:04 UTC (permalink / raw) Cc: cyd, emacs-devel 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. Could define-global-minor-mode do that automatically? ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2007-01-22 9:04 ` Richard Stallman @ 2007-01-22 14:55 ` Stefan Monnier 2007-01-23 20:55 ` Richard Stallman 0 siblings, 1 reply; 35+ messages in thread From: Stefan Monnier @ 2007-01-22 14:55 UTC (permalink / raw) Cc: cyd, emacs-devel > 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. > Could define-global-minor-mode do that automatically? Not really: if the global minor mode is autoloaded, then :require is a nuisance, so to do it automatically, define-global-minor-mode would have to know whether it's autoloaded or not. And in most/all cases it's autoloaded anyway and if not, it should. Stefan ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2007-01-22 14:55 ` Stefan Monnier @ 2007-01-23 20:55 ` Richard Stallman 2007-01-23 23:00 ` Stefan Monnier 0 siblings, 1 reply; 35+ messages in thread From: Richard Stallman @ 2007-01-23 20:55 UTC (permalink / raw) Cc: cyd, emacs-devel > 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? And how does this relate to the question of whether the globalized mode is autoloaded? so to do it automatically, define-global-minor-mode would have to know whether it's autoloaded or not. And in most/all cases it's autoloaded anyway and if not, it should. Are you proposing that every use of define-global-minor-mode should have an autoload cookie? ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2007-01-23 20:55 ` Richard Stallman @ 2007-01-23 23:00 ` Stefan Monnier 2007-01-23 23:59 ` Lennart Borgman (gmail) 2007-01-28 7:42 ` Richard Stallman 0 siblings, 2 replies; 35+ messages in thread From: Stefan Monnier @ 2007-01-23 23:00 UTC (permalink / raw) Cc: cyd, emacs-devel >> 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). > And how does this relate to the question of whether the globalized > mode is autoloaded? If it's autoloaded, then the :require is not necessary because the handling of the autoload cookie will make sure that the minor mode function will be called when the user has customized the mode (and will thus trigger loading the relevant file). > so to do it automatically, define-global-minor-mode would have > to know whether it's autoloaded or not. And in most/all cases it's > autoloaded anyway and if not, it should. > Are you proposing that every use of define-global-minor-mode should > have an autoload cookie? As a general rule, yes. I'm sure we can come up with counter examples, tho, so there's no point trying to enforce it. Stefan ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2007-01-23 23:00 ` Stefan Monnier @ 2007-01-23 23:59 ` Lennart Borgman (gmail) 2007-01-24 1:15 ` Stefan Monnier 2007-01-28 7:42 ` Richard Stallman 1 sibling, 1 reply; 35+ messages in thread From: Lennart Borgman (gmail) @ 2007-01-23 23:59 UTC (permalink / raw) Cc: cyd, rms, emacs-devel 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? BTW should not the name be define-globalized-minor-mode as was suggested before? ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2007-01-23 23:59 ` Lennart Borgman (gmail) @ 2007-01-24 1:15 ` Stefan Monnier 2007-01-24 19:29 ` Lennart Borgman (gmail) 0 siblings, 1 reply; 35+ messages in thread From: Stefan Monnier @ 2007-01-24 1:15 UTC (permalink / raw) Cc: cyd, rms, emacs-devel >>>> 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? > 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 ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2007-01-24 1:15 ` Stefan Monnier @ 2007-01-24 19:29 ` Lennart Borgman (gmail) 2007-01-25 4:57 ` Stefan Monnier 0 siblings, 1 reply; 35+ messages in thread From: Lennart Borgman (gmail) @ 2007-01-24 19:29 UTC (permalink / raw) To: Stefan Monnier; +Cc: cyd, rms, emacs-devel 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. ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2007-01-24 19:29 ` Lennart Borgman (gmail) @ 2007-01-25 4:57 ` Stefan Monnier 2007-01-25 8:56 ` Lennart Borgman (gmail) 2007-01-25 21:47 ` Lennart Borgman (gmail) 0 siblings, 2 replies; 35+ messages in thread From: Stefan Monnier @ 2007-01-25 4:57 UTC (permalink / raw) To: Lennart Borgman (gmail); +Cc: cyd, rms, emacs-devel > 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. > 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. Try to look at the macro expansion of (define-minor-mode foo-mode "Foo" :global t) and you'll see it's got a :set. > Please test it with the defcustom and define-minor-mode set. I don't know what the above sentence means. > (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))) Passing a :set here is likely to lead to surprises. > As I use to say: I do not want to touch the CVS this close to the release > since I am unfamiliar with cvs. It's never too late to learn. You can start by posting a patch generated from "cvs diff", at which point "cvs commit -m <message>" should be all that's needed. > I would be glad if you changed the name. So would I, but I don't have much time, Stefan ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 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) 1 sibling, 1 reply; 35+ messages in thread From: Lennart Borgman (gmail) @ 2007-01-25 8:56 UTC (permalink / raw) To: Stefan Monnier; +Cc: cyd, rms, emacs-devel Stefan Monnier wrote: > 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. Just put the code I sent in a previous message in a file, set customize the defcustom and the define-minor-mode variables to t. Save this customization and make sure the file is loaded when you restart Emacs. Read the messages in the *Message* buffer to see what code from those two variables were run. ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2007-01-25 8:56 ` Lennart Borgman (gmail) @ 2007-01-25 19:27 ` Stefan Monnier 0 siblings, 0 replies; 35+ messages in thread From: Stefan Monnier @ 2007-01-25 19:27 UTC (permalink / raw) To: Lennart Borgman (gmail); +Cc: cyd, rms, emacs-devel >> 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. > Just put the code I sent in a previous message in a file, As mentioned, this code uses a :set which is a bad idea. So I see no point in trying that out before you try out a simpler code. When simple code doesn't do what one wants, it's clearly a bug. When convoluted code behaves strange, it's never really clear whether it's a bug in Emacs or in the convoluted code. > set customize the defcustom and the define-minor-mode variables to t. How? Where? Those details are very important. > Save this customization and make sure the file is loaded when you restart > Emacs. Which file? How do you ensure it's loaded? Again, those details are very important. Stefan ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2007-01-25 4:57 ` Stefan Monnier 2007-01-25 8:56 ` Lennart Borgman (gmail) @ 2007-01-25 21:47 ` Lennart Borgman (gmail) 2007-01-25 23:56 ` Lennart Borgman (gmail) ` (2 more replies) 1 sibling, 3 replies; 35+ messages in thread From: Lennart Borgman (gmail) @ 2007-01-25 21:47 UTC (permalink / raw) To: Stefan Monnier; +Cc: cyd, rms, emacs-devel 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. ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 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-26 4:35 ` Stefan Monnier 2007-01-28 7:42 ` Richard Stallman 2 siblings, 1 reply; 35+ messages in thread From: Lennart Borgman (gmail) @ 2007-01-25 23:56 UTC (permalink / raw) To: Lennart Borgman (gmail); +Cc: cyd, emacs-devel, Stefan Monnier, rms [-- Attachment #1: Type: text/plain, Size: 399 bytes --] Lennart Borgman (gmail) wrote: > 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. And here are the tests, sorry ... ;-) [-- Attachment #2: defcustom-or-minor.el --] [-- Type: text/plain, Size: 1935 bytes --] (message "\n\n>>>>>>> defcustom-or-minor.el starting loading, temp-global-mode=%s" (if (boundp 'temp-global-mode) temp-global-mode "not boundp")) (message "\n****** Declarations: *********") (define-minor-mode temp-mode "dummy" :init-value nil :lighter nil :global t :group 'temp-test :initialize 'custom-initialize-set :set (lambda(sym val) (message " temp-mode :set => sym=%s, val=%s" sym val) (set-default sym val)) (message " temp-mode body => temp-mode=%s, current-buffer=%s" temp-mode (current-buffer))) (define-global-minor-mode temp-global-mode temp-mode (lambda() ;;(message "here %s" (substring (buffer-name) 0 1)) (when (cond ((member (substring (buffer-name) 0 1) '(" " "*" ".")) nil) (t t)) (message " temp-global-mode turn on called") (temp-mode 1))) :group 'temp-test :initialize 'custom-initialize-set :set (lambda(sym val) (message " temp-global-mode :set => sym=%s, val=%s" sym val) (set-default sym val))) (defcustom temp-defcustom nil "doc" :type 'boolean :group 'temp-test :set (lambda(sym val) (message " temp-defcustom :set => sym=%s, val=%s" sym val) (set-default sym val))) (message "\n****** Running tests: *********") (message "*** (customize-set-variable 'temp-defcustom t) =>") (customize-set-variable 'temp-defcustom t) (message "\n*** (customize-set-variable 'temp-mode t) =>") (customize-set-variable 'temp-mode t) (message "*** (temp-mode 1) =>") (temp-mode 1) (message "\n*** (customize-set-variable 'temp-global-mode t) =>") (temp-global-mode 1) (message "*** (temp-global-mode 1) =>") (customize-set-variable 'temp-global-mode t) (message "\n<<<<<<<<< defcustom-or-minor.el loaded: temp-global-mode=%s, temp-mode=%s, temp-defcustom=%s\n\n" temp-global-mode temp-mode temp-defcustom) [-- Attachment #3: Type: text/plain, Size: 142 bytes --] _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2007-01-25 23:56 ` Lennart Borgman (gmail) @ 2007-01-26 4:34 ` Stefan Monnier 2007-01-27 19:43 ` Chong Yidong 0 siblings, 1 reply; 35+ messages in thread From: Stefan Monnier @ 2007-01-26 4:34 UTC (permalink / raw) To: Lennart Borgman (gmail); +Cc: cyd, rms, emacs-devel > (define-minor-mode temp-mode > "dummy" > :init-value nil > :lighter nil > :global t > :group 'temp-test > :initialize 'custom-initialize-set > :set (lambda(sym val) > (message " temp-mode :set => sym=%s, val=%s" sym val) > (set-default sym val)) > (message " temp-mode body => temp-mode=%s, current-buffer=%s" temp-mode (current-buffer))) I do not care to support a define-minor-mode with a :set. And same thing about a :initialize. The same holds for define-global-minor-mode of course. Please take a big step back and tell me what you want to do, rather than try to ask how to get your ugly-hack to work. Stefan ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2007-01-26 4:34 ` Stefan Monnier @ 2007-01-27 19:43 ` Chong Yidong 0 siblings, 0 replies; 35+ messages in thread From: Chong Yidong @ 2007-01-27 19:43 UTC (permalink / raw) To: emacs-devel Stefan Monnier <monnier@iro.umontreal.ca> writes: >> (define-minor-mode temp-mode >> "dummy" >> :init-value nil >> :lighter nil >> :global t >> :group 'temp-test >> :initialize 'custom-initialize-set >> :set (lambda(sym val) >> (message " temp-mode :set => sym=%s, val=%s" sym val) >> (set-default sym val)) >> (message " temp-mode body => temp-mode=%s, current-buffer=%s" temp-mode (current-buffer))) > > I do not care to support a define-minor-mode with a :set. And same thing > about a :initialize. The same holds for define-global-minor-mode of course. > > Please take a big step back and tell me what you want to do, rather than > try to ask how to get your ugly-hack to work. I concur. This should not be a FOR-RELEASE bug. ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2007-01-25 21:47 ` Lennart Borgman (gmail) 2007-01-25 23:56 ` Lennart Borgman (gmail) @ 2007-01-26 4:35 ` Stefan Monnier 2007-01-28 7:42 ` Richard Stallman 2 siblings, 0 replies; 35+ messages in thread From: Stefan Monnier @ 2007-01-26 4:35 UTC (permalink / raw) To: Lennart Borgman (gmail); +Cc: cyd, rms, emacs-devel > *** 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. Huh, check the code: the :set does nothing more than run the body of the define-minor-mode. Stefan ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2007-01-25 21:47 ` Lennart Borgman (gmail) 2007-01-25 23:56 ` Lennart Borgman (gmail) 2007-01-26 4:35 ` Stefan Monnier @ 2007-01-28 7:42 ` Richard Stallman 2 siblings, 0 replies; 35+ messages in thread From: Richard Stallman @ 2007-01-28 7:42 UTC (permalink / raw) To: Lennart Borgman (gmail); +Cc: cyd, monnier, emacs-devel 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. That seems to be what define-minor-mode produces now, when the minor mode is global. This cannot be done for a minor mode that is normally local because customizing a variable is always global. ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2007-01-23 23:00 ` Stefan Monnier 2007-01-23 23:59 ` Lennart Borgman (gmail) @ 2007-01-28 7:42 ` Richard Stallman 2007-01-28 15:47 ` Chong Yidong 2007-01-29 4:32 ` Stefan Monnier 1 sibling, 2 replies; 35+ messages in thread From: Richard Stallman @ 2007-01-28 7:42 UTC (permalink / raw) To: Stefan Monnier; +Cc: cyd, emacs-devel > 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). It seems that you are saying the risk is that the :require has to specify the file name, so if you move the definition to another file, the :require argument will be wrong. If the :require is generated automatically, perhaps it would never be wrong. > And how does this relate to the question of whether the globalized > mode is autoloaded? If it's autoloaded, then the :require is not necessary because the handling of the autoload cookie will make sure that the minor mode function will be called when the user has customized the mode (and will thus trigger loading the relevant file). I don't see how that is the case. If the minor mode is autoloaded then calling the minor mode function will load the file. But how would this autoload cause the function to be called in the first place? > Are you proposing that every use of define-global-minor-mode should > have an autoload cookie? As a general rule, yes. I'm sure we can come up with counter examples, tho, so there's no point trying to enforce it. It might be an ok solution. But do you have any objection to using :require if we make sure it never gets the wrong file? ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2007-01-28 7:42 ` Richard Stallman @ 2007-01-28 15:47 ` Chong Yidong 2007-01-28 16:37 ` David Kastrup 2007-01-29 4:32 ` Stefan Monnier 1 sibling, 1 reply; 35+ messages in thread From: Chong Yidong @ 2007-01-28 15:47 UTC (permalink / raw) To: rms; +Cc: Stefan Monnier, emacs-devel Richard Stallman <rms@gnu.org> writes: > > 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). > > It seems that you are saying the risk is that the :require has to > specify the file name, so if you move the definition to another file, > the :require argument will be wrong. > > If the :require is generated automatically, perhaps it would never be > wrong. The only way for Emacs to know which source file to :require, for a third-party package, is to look at the custom-set-variables declaration in .emacs. Therefore, the only way your suggestion can work is for define-global-minor-mode to somehow put this information in .emacs. If you move the source file to a different location there is no way for .emacs to be automatically updated. So there's no sane way to handle this automagically. ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2007-01-28 15:47 ` Chong Yidong @ 2007-01-28 16:37 ` David Kastrup 2007-01-28 19:53 ` Chong Yidong 0 siblings, 1 reply; 35+ messages in thread From: David Kastrup @ 2007-01-28 16:37 UTC (permalink / raw) To: Chong Yidong; +Cc: emacs-devel, rms, Stefan Monnier Chong Yidong <cyd@stupidchicken.com> writes: > Richard Stallman <rms@gnu.org> writes: > >> > 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). >> >> It seems that you are saying the risk is that the :require has to >> specify the file name, so if you move the definition to another >> file, the :require argument will be wrong. >> >> If the :require is generated automatically, perhaps it would never be >> wrong. > > The only way for Emacs to know which source file to :require, for a > third-party package, is to look at the custom-set-variables > declaration in .emacs. Uh, wouldn't the file to require be load-file-name at the time define-global-minor-mode is loaded or executed via autoload? -- David Kastrup ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2007-01-28 16:37 ` David Kastrup @ 2007-01-28 19:53 ` Chong Yidong 0 siblings, 0 replies; 35+ messages in thread From: Chong Yidong @ 2007-01-28 19:53 UTC (permalink / raw) To: David Kastrup; +Cc: emacs-devel, rms, Stefan Monnier David Kastrup <dak@gnu.org> writes: >> The only way for Emacs to know which source file to :require, for a >> third-party package, is to look at the custom-set-variables >> declaration in .emacs. > > Uh, wouldn't the file to require be load-file-name at the time > define-global-minor-mode is loaded or executed via autoload? That breaks if you move a third-party package to another directory or another file name. More importantly, this kind of behavior is different from similar existing Emacs mechanisms. For instance, when you write define-minor-mode and defcustom statements, it does not automagically :require the current load-file. I really don't see why it's a problem having to separately specify the requisite load-file. ^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: How global is a define-global-minor-mode mode? 2007-01-28 7:42 ` Richard Stallman 2007-01-28 15:47 ` Chong Yidong @ 2007-01-29 4:32 ` Stefan Monnier 1 sibling, 0 replies; 35+ messages in thread From: Stefan Monnier @ 2007-01-29 4:32 UTC (permalink / raw) To: rms; +Cc: cyd, emacs-devel > 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). > It seems that you are saying the risk is that the :require has to > specify the file name, so if you move the definition to another file, > the :require argument will be wrong. > If the :require is generated automatically, perhaps it would never be > wrong. No, the :require is of course correct. The problem is that when you set the variable, the current :require gets copied into your .emacs file, and when you later run an Emacs where that minor mode was moved to another file, your .emacs still points to the old location and the startup fails to set the var (and complains that the file doesn't define function bar-mode). Stefan ^ permalink raw reply [flat|nested] 35+ messages in thread
end of thread, other threads:[~2007-01-29 4:32 UTC | newest] Thread overview: 35+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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) 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
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).