all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Kévin Le Gouguec" <kevin.legouguec@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Enabling a globalized-minor-mode by default
Date: Thu, 10 Sep 2020 21:09:13 +0200	[thread overview]
Message-ID: <87pn6tmoti.fsf@gmail.com> (raw)

[-- 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

             reply	other threads:[~2020-09-10 19:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-10 19:09 Kévin Le Gouguec [this message]
2020-09-10 21:14 ` Enabling a globalized-minor-mode by default 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

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=87pn6tmoti.fsf@gmail.com \
    --to=kevin.legouguec@gmail.com \
    --cc=help-gnu-emacs@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.