[Top][All Lists]

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

Enabling a globalized-minor-mode by default

From: Kévin Le Gouguec
Subject: Enabling a globalized-minor-mode by default
Date: Thu, 10 Sep 2020 21:09:13 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

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: testautoload.el
Description: application/emacs-lisp

Now, if I:

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


- 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: addendum.el
Description: application/emacs-lisp

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!


reply via email to

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