From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Elijah G." Newsgroups: gmane.emacs.bugs Subject: bug#71814: define-globalized-minor-mode Should predicate variable be defined before? Date: Thu, 27 Jun 2024 19:20:53 -0600 Message-ID: <864j9d7thm.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14093"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (windows-nt) To: 71814@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jun 28 08:06:37 2024 Return-path: Envelope-to: geb-bug-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 1sN4kn-0003Sa-8I for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 28 Jun 2024 08:06:37 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sN4kR-0003I0-MB; Fri, 28 Jun 2024 02:06:15 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sN4kG-0003Gv-Dp for bug-gnu-emacs@gnu.org; Fri, 28 Jun 2024 02:06:06 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sN4kF-0006P0-AR for bug-gnu-emacs@gnu.org; Fri, 28 Jun 2024 02:06:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sN4kD-0000vp-R6 for bug-gnu-emacs@gnu.org; Fri, 28 Jun 2024 02:06:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Elijah G." Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 28 Jun 2024 06:06:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 71814 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.17195547063288 (code B ref -1); Fri, 28 Jun 2024 06:06:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 28 Jun 2024 06:05:06 +0000 Original-Received: from localhost ([127.0.0.1]:51479 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sN4jJ-0000qx-Mf for submit@debbugs.gnu.org; Fri, 28 Jun 2024 02:05:06 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:57570) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sN4jI-0000q1-Oa for submit@debbugs.gnu.org; Fri, 28 Jun 2024 02:05:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sN0IQ-0000Xr-2R for bug-gnu-emacs@gnu.org; Thu, 27 Jun 2024 21:21:02 -0400 Original-Received: from mail-oo1-xc42.google.com ([2607:f8b0:4864:20::c42]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sN0IO-0003P4-Ah for bug-gnu-emacs@gnu.org; Thu, 27 Jun 2024 21:21:01 -0400 Original-Received: by mail-oo1-xc42.google.com with SMTP id 006d021491bc7-5c21f1bb810so35594eaf.3 for ; Thu, 27 Jun 2024 18:20:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719537658; x=1720142458; darn=gnu.org; h=mime-version:user-agent:message-id:date:subject:to:from:from:to:cc :subject:date:message-id:reply-to; bh=FPbjUL+o1dafXQeWMjjqEV4UfP3aszNbVqM//DVCkm4=; b=Nos0sndAHbEv+zRTqHaaMLp/Ze4fh5eQiFJFCqbEfGd18YiWLDcnO0Q4aWh2Ulyg6E 36dSNDTAjccsitgs5/LWPMpfvK3GgqgUl3Uwz/DTDYZO7Hx0+CF9b46/P7CCwt2gRcVb 4h+Djax30Sd4zVKVyHuS+ALVfalWrQLfHIBEG7Rv8XT2KpfDTuIbD+ANSwGAA+YML86Z WbT6nhB+r9RBABZ6WUp2lHzQLz0SfFoXiMfik785D+qo+0ISKWgDV9bHDdrqrtv42N1O ytEWRevC+IR3yjoEyJCI1yRy/En1nYjNwsCIlvnLjwQGvpbCSALPpmSIYsfSVjWfR8In iwyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719537658; x=1720142458; h=mime-version:user-agent:message-id:date:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FPbjUL+o1dafXQeWMjjqEV4UfP3aszNbVqM//DVCkm4=; b=AjQyWLN7iw0agzM5PuIAV/EE/3cXGQb3YhuWbkKZSzUAldnlPIWgICYhC5NM20PIsh SCqNbukUQTyY5ESnXzW8ZSuGn3NZzT1K90CU3jlq3lE0swLrKrFU7sM9zxdFGC5JWRIL oVyPqEwRsWE52jRjMavsqgxCLKEOwT7uGdVjHTHyxH3CYDcKFHMJjGhuah8fst3gR9GT knicXT3d15i4cDUfX/fbAe5Rv3R93Edm+Sdx2RnlY6QmBNqwsefCidnLPnNbBAkJz6U9 a13nz3gfOAbvik2GFWvRA+HHovfeFobimDOtHtGlfJSOmdM3l8zqYo7GzQdRch+/LIMX Rqig== X-Gm-Message-State: AOJu0YxfmdFAo/8aWzdivE6y11crG6a7BFHnvFLa7rqyDZLwsf7U5I0t XHZjNIRSMwoDrok2PVjqNaDQX7YibVEXW1jXEzKLjuDEgIJPLs5Tg+PtbNsM X-Google-Smtp-Source: AGHT+IHr8OSdXXs+HYVjPEfVKeaLYcrseQe5TluYlgCCIKojYF2EP+d7/vCAC7HXhlESaPkxh6cqfQ== X-Received: by 2002:a4a:ea36:0:b0:5c2:268c:278 with SMTP id 006d021491bc7-5c229e1a3b9mr6338646eaf.0.1719537657911; Thu, 27 Jun 2024 18:20:57 -0700 (PDT) Original-Received: from LIBERO ([187.184.26.123]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5c41480bf48sm109737eaf.2.2024.06.27.18.20.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 18:20:57 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::c42; envelope-from=eg642616@gmail.com; helo=mail-oo1-xc42.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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_ENVFROM_END_DIGIT=0.25, 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: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:288050 Archived-At: Hello, i've noticed when defining a globalized minor mode using the define-globalized-minor-mode macro, gives a byte-compile warning about the auto-generated :predicate variable not being defined. I found that it's because the macro defines the predicate user option after defining the minor mode: (put ',global-mode 'globalized-minor-mode t) :autoload-end (defvar-local ,MODE-major-mode nil)) ;; The actual global minor-mode (define-minor-mode ,global-mode ,(concat (format "Toggle %s in all buffers.\n" pretty-name) (internal--format-docstring-line ...) ;; Setup hook to handle future mode changes and new buffers. (if ,global-mode (add-hook 'after-change-major-mode-hook #',MODE-enable-in-buffer) (remove-hook 'after-change-major-mode-hook #',MODE-enable-in-buffer)) ;; Go through existing buffers. (dolist (buf (buffer-list)) (with-current-buffer buf (if ,global-mode (funcall ,turn-on-function) (when ,mode (,mode -1))))) ,@body) ,(when predicate `(defcustom ,MODE-predicate ,(car predicate) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ My question is, should it be defined before defining the minor mode? if not, then why it's defined like that? I made a little patch for solve this, since i think it would be it would be beneficial for packages that use that macro (also i barely remember that there are some built-in packages that defines the user-option before using the macro for solve this issue). Thanks. --8<---------------cut here---------------start------------->8--- diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el index ba0f8bad393..69cc1332282 100644 --- a/lisp/emacs-lisp/easy-mmode.el +++ b/lisp/emacs-lisp/easy-mmode.el @@ -525,6 +525,36 @@ define-globalized-minor-mode (put ',global-mode 'globalized-minor-mode t) :autoload-end (defvar-local ,MODE-major-mode nil)) + ,(when predicate + `(defcustom ,MODE-predicate ,(car predicate) + ,(format "Which major modes `%s' is switched on in. +This variable can be either t (all major modes), nil (no major modes), +or a list of modes and (not modes) to switch use this minor mode or +not. For instance + + (c-mode (not message-mode mail-mode) text-mode) + +means \"use this mode in all modes derived from `c-mode', don't use in +modes derived from `message-mode' or `mail-mode', but do use in other +modes derived from `text-mode'\". An element with value t means \"use\" +and nil means \"don't use\". There's an implicit nil at the end of the +list." + mode) + :type '(choice + (const :tag "Enable in all major modes" t) + (const :tag "Don't enable in any major mode" nil) + (repeat + :tag "Rules (earlier takes precedence)..." + (choice + (const :tag "Enable in all (other) modes" t) + (const :tag "Don't enable in any (other) mode" nil) + (symbol :value fundamental-mode + :tag "Enable in major mode") + (cons :tag "Don't enable in major modes" + (const :tag "Don't enable in..." not) + (repeat (symbol :value fundamental-mode + :tag "Major mode")))))) + ,@group)) ;; The actual global minor-mode (define-minor-mode ,global-mode ,(concat (format "Toggle %s in all buffers.\n" pretty-name) @@ -565,37 +595,6 @@ define-globalized-minor-mode (when ,mode (,mode -1))))) ,@body) - ,(when predicate - `(defcustom ,MODE-predicate ,(car predicate) - ,(format "Which major modes `%s' is switched on in. -This variable can be either t (all major modes), nil (no major modes), -or a list of modes and (not modes) to switch use this minor mode or -not. For instance - - (c-mode (not message-mode mail-mode) text-mode) - -means \"use this mode in all modes derived from `c-mode', don't use in -modes derived from `message-mode' or `mail-mode', but do use in other -modes derived from `text-mode'\". An element with value t means \"use\" -and nil means \"don't use\". There's an implicit nil at the end of the -list." - mode) - :type '(choice - (const :tag "Enable in all major modes" t) - (const :tag "Don't enable in any major mode" nil) - (repeat - :tag "Rules (earlier takes precedence)..." - (choice - (const :tag "Enable in all (other) modes" t) - (const :tag "Don't enable in any (other) mode" nil) - (symbol :value fundamental-mode - :tag "Enable in major mode") - (cons :tag "Don't enable in major modes" - (const :tag "Don't enable in..." not) - (repeat (symbol :value fundamental-mode - :tag "Major mode")))))) - ,@group)) - ;; Autoloading define-globalized-minor-mode autoloads everything ;; up-to-here. :autoload-end --8<---------------cut here---------------end--------------->8--- -- E.G. from Gnus The Emacs Newsreader and E-mail client