unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Enabling a globalized-minor-mode by default
@ 2020-09-10 19:09 Kévin Le Gouguec
  2020-09-10 21:14 ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Kévin Le Gouguec @ 2020-09-10 19:09 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 386 bytes --]

Hello Emacs,

I'm trying to understand how to define a globalized minor mode that is
enabled by default.  My goal is to make this mode's keymap available
with no configuration on the user's part, unless the user explicitly
disables the minor mode.

I've attached a toy example which defines the testautoload-mode minor
mode, as well as its globalized variant global-testautoload-mode:


[-- Attachment #2: testautoload.el --]
[-- Type: application/emacs-lisp, Size: 747 bytes --]

[-- Attachment #3: Type: text/plain, Size: 616 bytes --]


Now, if I:

- byte-compile this file,
- M-: (package-generate-autoloads "testautoload" default-directory)
- emacs -Q -L .
- M-: (load-file "testautoload-autoloads.el")

then:

- global-testautoload-mode is t,
- the testautoload-mode variable is undefined,
- the testautoload-mode-map keymap is undefined.

From there, (customize-set-variable 'global-testautoload-mode t) enables
the mode in all buffers and the keymap works.  Is there a way to do away
with this extra step?  I've messed with :require and :initialize, but
they don't help AFAICT.

What does help is adding this snippet at the bottom of my library:


[-- Attachment #4: addendum.el --]
[-- Type: application/emacs-lisp, Size: 150 bytes --]

[-- Attachment #5: Type: text/plain, Size: 949 bytes --]


Is that bad form somehow, or is that the way to go?


Admittedly, maybe forcing a globalized minor mode on users by default is
bad form.  For context, I am trying to make magit-file-mode work
out-of-the-box, i.e. without users having to (1) (require 'anything) in
their config or (2) customize global-magit-file-mode to t explicitly,
which should be redundant because this is the default value.

I made a naive attempt to fix this[1] with more or less the same
autoload form I showed above, but that seemed to have unfortunate
side-effects[2].  Jonas suggests moving magit-file-mode and its keymap
to a new library that does not (require 'magit); IIUC the autoload form
would then work with no further complication?


I hope I'm making sense; if not, I hope somebody will tell me where I
got off the rails.

Thank you for your time!


[1] https://github.com/magit/magit/pull/4207
[2] https://github.com/magit/magit/pull/4207#issuecomment-688320025

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-09-12 10:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-10 19:09 Enabling a globalized-minor-mode by default Kévin Le Gouguec
2020-09-10 21:14 ` Stefan Monnier
2020-09-11  9:03   ` Kévin Le Gouguec
2020-09-11 15:03     ` Stefan Monnier
2020-09-12 10:01       ` Kévin Le Gouguec

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).