From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?K=C3=A9vin_Le_Gouguec?= Newsgroups: gmane.emacs.help Subject: Enabling a globalized-minor-mode by default Date: Thu, 10 Sep 2020 21:09:13 +0200 Message-ID: <87pn6tmoti.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40180"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 10 21:09:48 2020 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kGRx6-000AKC-4B for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 10 Sep 2020 21:09:48 +0200 Original-Received: from localhost ([::1]:38562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kGRx5-0006i3-5k for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 10 Sep 2020 15:09:47 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43344) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kGRwd-0006gQ-SE for help-gnu-emacs@gnu.org; Thu, 10 Sep 2020 15:09:19 -0400 Original-Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]:34515) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kGRwb-0002f8-VG for help-gnu-emacs@gnu.org; Thu, 10 Sep 2020 15:09:19 -0400 Original-Received: by mail-ej1-x62c.google.com with SMTP id gr14so10380079ejb.1 for ; Thu, 10 Sep 2020 12:09:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:user-agent:mime-version; bh=cD0d1PQBHyHqyBLXCmvWjw3FaYCifNWKknN5pT8c1j4=; b=Xu1QF+xg6nK6ZFHAnGUQOgyJdIiRTo7NMcx92hsotipXVc5VgGvaQb6k+JK80ovugJ 7QRZiI1o7u/87+FlN0RmhwTRkTx3cC2J7E1PHI5SkIWPE5bCY2wgKCHwV5rtS6u1333L kYIGr0PG3Ywj7DjCv8+IvtvDz0orJnapttrXy3dDBhmV9nhCoYGBoplK0G10euU1JPFn l6wxRdwdy9fmchPTvOCEV9mAczCCNwSz3Cd6zy4MhLalR8Xs6//9QaPoYzCJYjwEzV+B jNt+0m/Fa/rNBgay5KM0qsvxlHRy0uz5eY8SPDVOi0w5AIquxzzLHgyYoaV+FIFi+EyG bAvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:user-agent :mime-version; bh=cD0d1PQBHyHqyBLXCmvWjw3FaYCifNWKknN5pT8c1j4=; b=ARS6FJcV3JXcbayEEEsJOIPqsLzbo/5pYNStdM64MNcnxIwp2tlUfE074iJttYj1z5 zu38tLVsvx/9NygMws6K7PeJXJPgXGiq5nR0av25c+yjPHF+7FP+x/wvanAWiEQDyhv+ E8jA8rr7c5NujTFnd8x8OEe3iL2iYJG30wR1MiD7CwPnphMpV9LQvdEqvOE4yqbMzX0g oFhZw0SS1cnhoiMs5c6DCV4gOvVA1IBqcMOL/ONiBB6OGov7z6vEtdjCQMGkkTkDscAe KAW5aMNragVGe9mdH/k/y8omLNwgNFQRs+r2vvX4uJvn81uCku03wtSq/Mv6/CH8xs0j VGtw== X-Gm-Message-State: AOAM530aGVqdpssQ/8uOIf+Cdreaz/B/AIF7sZ2un9tk/bcUcO+XSkGK 88bfpJxil3a9+D+DEGZAmYnV5BSN83M= X-Google-Smtp-Source: ABdhPJyDH4K6H6GYgpEPsVWKByIMwWc51ZF1j4PSuu0gOsvKBXuzpzq7svb/Q/GjcbHcbjcYdRCUjQ== X-Received: by 2002:a17:907:37b:: with SMTP id rs27mr11100883ejb.0.1599764956270; Thu, 10 Sep 2020 12:09:16 -0700 (PDT) Original-Received: from hirondell ([109.190.253.16]) by smtp.gmail.com with ESMTPSA id k1sm7954726eji.20.2020.09.10.12.09.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 12:09:15 -0700 (PDT) Received-SPF: pass client-ip=2a00:1450:4864:20::62c; envelope-from=kevin.legouguec@gmail.com; helo=mail-ej1-x62c.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:124012 Archived-At: --=-=-= Content-Type: text/plain 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: --=-=-= Content-Type: application/emacs-lisp Content-Disposition: inline; filename=testautoload.el Content-Transfer-Encoding: quoted-printable ;;; testautoload.el --- what it says on the tin -*- lexical-binding: t -*- (defun testautoload-hello () (interactive) (message "Hello world!")) (defvar testautoload-mode-map (let ((map (make-sparse-keymap))) (define-key map "\C-c\M-h" 'testautoload-hello) map) "Keymap for `testautoload-mode'") ;;;###autoload (define-minor-mode testautoload-mode "Doc" :lighter "=F0=9F=91=8B" :keymap testautoload-mode-map) ;;;###autoload (defun turn-on-testautoload-mode () (testautoload-mode 1)) ;;;###autoload (define-globalized-minor-mode global-testautoload-mode testautoload-mode turn-on-testautoload-mode :group 'testautoload :init-value t) (provide 'testautoload) ;;; testautoload.el ends here --=-=-= Content-Type: text/plain 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: --=-=-= Content-Type: application/emacs-lisp Content-Disposition: inline; filename=addendum.el Content-Transfer-Encoding: quoted-printable ;;;###autoload (progn (require 'cl-macs) (cl-eval-when (load eval) (when global-testautoload-mode (global-testautoload-mode 1)))) --=-=-= Content-Type: text/plain 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 --=-=-=--