GNU bug report logs - #67034
30.0.50; Make `derived-mode-p` take a single arg

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Stefan Monnier <monnier@HIDDEN>; dated Fri, 10 Nov 2023 04:00:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 67034 <at> debbugs.gnu.org:


Received: (at 67034) by debbugs.gnu.org; 16 Nov 2023 22:28:39 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Nov 16 17:28:39 2023
Received: from localhost ([127.0.0.1]:44787 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1r3kqk-0000Wc-3z
	for submit <at> debbugs.gnu.org; Thu, 16 Nov 2023 17:28:39 -0500
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:25799)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <monnier@HIDDEN>) id 1r3kqh-0000WI-PW
 for 67034 <at> debbugs.gnu.org; Thu, 16 Nov 2023 17:28:37 -0500
Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 6E452442792;
 Thu, 16 Nov 2023 17:28:29 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1700173705;
 bh=hU8OJCK80VcSOawpPpQjTvl40gMsTJ4HTqshTuhpgYg=;
 h=From:To:Subject:In-Reply-To:References:Date:From;
 b=gKUzlUidc0FCMm7yIYC4qddXaicpmtNMT2JRVUm+nECN85dnyik3XfXMWK+7Dzgre
 Eh0KX24v5tW0o90ux45QTCao8DG4GAonhxeVJFCYj+FWTec9uIaOpwX1WIZlsE+ZwX
 YMLcx5k8phxtXJBGKmw1nVEwfxCOAgAx+FNWaC6Hq2GzzxDjIlFO7aGR/i7Uogl3/B
 iKRroVCHjNvN45oekV62wqHfbndnmwpXJ9tbxwJi+/wuJruXZx8NO/JbN7kqsdv0CU
 pnMYBMW0zhWaUetHQHev8lr1U3AfAXjj714SSN3WZWiEMGHhtxFo8QV46otnXwfk8l
 iTTcV7UgqJT9A==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id A33A244278B;
 Thu, 16 Nov 2023 17:28:25 -0500 (EST)
Received: from pastel (unknown [45.72.227.120])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 80C051201B4;
 Thu, 16 Nov 2023 17:28:25 -0500 (EST)
From: Stefan Monnier <monnier@HIDDEN>
To: 67034 <at> debbugs.gnu.org
Subject: Re: bug#67034: 30.0.50; Make `derived-mode-p` take a single arg
In-Reply-To: <jwv8r76mf8d.fsf@HIDDEN> (Stefan Monnier's message of
 "Thu, 09 Nov 2023 22:58:26 -0500")
Message-ID: <jwv34x5jpul.fsf-monnier+emacs@HIDDEN>
References: <jwv8r76mf8d.fsf@HIDDEN>
Date: Thu, 16 Nov 2023 17:28:24 -0500
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL 0.027 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain T_SCC_BODY_TEXT_LINE    -0.01 -
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 67034
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

--=-=-=
Content-Type: text/plain

> Draft patch below.

More realistic patches below.


        Stefan

--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline;
 filename=0001-derived-mode-p-Take-MODES-as-a-single-argument.patch

From 6ccf21f1e3137012d0335fac05dfc476cc9ebec2 Mon Sep 17 00:00:00 2001
From: Stefan Monnier <monnier@HIDDEN>
Date: Thu, 16 Nov 2023 17:21:18 -0500
Subject: [PATCH 1/2] (derived-mode-p): Take MODES as a single argument

Looking at uses of `derived-mode-p` and `provide-mode-derived-p`,
I can't find a single use case where it wouldn't be preferable for
it to take a single argument instead of `&rest`: all the calls are
either passing a single argument anyway, or passing a fixed list of modes.
The use of `&rest` just makes the code less efficient and sometimes
more clunky (because of the need for `apply`).
So let's change that (while preserving backward compatibility, of course).

* doc/lispref/modes.texi (Derived Modes): Adjust accordingly.

* lisp/subr.el (provided-mode-derived-p, derived-mode-p): Take the
`modes` as a single argument.
---
 doc/lispref/modes.texi |  6 +++++-
 lisp/subr.el           | 26 +++++++++++++++++++-------
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index 130bc10cd59..1d60c3a01e0 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -932,9 +932,13 @@ Derived Modes
 @code{define-derived-mode} does that automatically.
 @end defmac
 
-@defun derived-mode-p &rest modes
+@defun derived-mode-p modes
 This function returns non-@code{nil} if the current major mode is
 derived from any of the major modes given by the symbols @var{modes}.
+Instead of a list, @var{modes} can also be a single symbol.
+
+Furthermore, we still support a deprecated calling convention where the
+@var{modes} were passed as separate arguments.
 @end defun
 
 The graph of major modes is accessed with the following lower-level
diff --git a/lisp/subr.el b/lisp/subr.el
index dcf49509177..dd01d79b1d0 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2782,19 +2782,31 @@ derived-mode-all-parents
             (cons mode (remq mode all-parents))
           (put mode 'derived-mode--all-parents (cons mode all-parents))))))))
 
-(defun provided-mode-derived-p (mode &rest modes)
+(defun provided-mode-derived-p (mode &optional modes &rest old-modes)
   "Non-nil if MODE is derived from one of MODES.
-If you just want to check `major-mode', use `derived-mode-p'."
-  (declare (side-effect-free t))
+MODES can also be a single mode instead of a list.
+If you just want to check `major-mode', use `derived-mode-p'.
+We also still support the deprecated calling convention:
+\(provided-mode-derived-p MODE &rest MODES)."
+  (declare (side-effect-free t)
+           (advertised-calling-convention (mode modes) "30.1"))
+  (cond
+   (old-modes (setq modes (cons modes old-modes)))
+   ((not (listp modes)) (setq modes (list modes))))
   (let ((ps (derived-mode-all-parents mode)))
     (while (and modes (not (memq (car modes) ps)))
       (setq modes (cdr modes)))
     (car modes)))
 
-(defun derived-mode-p (&rest modes)
-  "Non-nil if the current major mode is derived from one of MODES."
-  (declare (side-effect-free t))
-  (apply #'provided-mode-derived-p major-mode modes))
+(defun derived-mode-p (&optional modes &rest old-modes)
+ "Non-nil if the current major mode is derived from one of MODES.
+MODES can also be a single mode instead of a list.
+We also still support the deprecated calling convention:
+\(derived-mode-p &rest MODES)."
+ (declare (side-effect-free t)
+          (advertised-calling-convention (modes) "30.1"))
+ (provided-mode-derived-p major-mode (if old-modes (cons modes old-modes)
+                                       modes)))
 
 (defun derived-mode-set-parent (mode parent)
   "Declare PARENT to be the parent of MODE."
-- 
2.42.0


--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline;
 filename=0002-Adjust-affected-callers-of-derived-mode-p-to-use-the.patch

From 705f1c15469985cb6387663c85c4d29fc66729b9 Mon Sep 17 00:00:00 2001
From: Stefan Monnier <monnier@HIDDEN>
Date: Mon, 13 Nov 2023 19:09:17 -0500
Subject: [PATCH 2/2] Adjust affected callers of derived-mode-p` to use the new
 convention

* lisp/align.el (align-rules-list): Prefer `derived-mode-p` over
`provided-mode-derived-p`.
(align--rule-should-run):
* lisp/window.el (display-buffer-reuse-mode-window):
* lisp/whitespace.el (whitespace-enable-predicate):
* lisp/transient.el (transient--do-suffix-p):
* lisp/so-long.el (so-long--set-auto-mode):
* lisp/simple.el (command-completion-with-modes-p):
* lisp/progmodes/tcl.el (tcl-current-word):
* lisp/progmodes/idlwave.el (idlwave-fix-keywords):
* lisp/progmodes/gdb-mi.el (gdb, gdb-locals-mode-map)
(gdb-registers-mode-map, gdb-function-buffer-p):
* lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-style-setter)
(c-ts-mode-set-style):
* lisp/progmodes/bug-reference.el (bug-reference--try-setup-gnus-article):
* lisp/help-fns.el (help-fns--list-local-commands):
* lisp/emulation/viper.el (viper-mode)
(viper-this-major-mode-requires-vi-state):
* lisp/emacs-lisp/easy-mmode.el (easy-mmode--globalized-predicate-p):
* lisp/dired.el (dired-hide-details-mode, dired-click-to-select-mode):
* lisp/calendar/todo-mode.el (todo-reset-nondiary-marker)
(todo-reset-done-string, todo-reset-comment-string):
* lisp/vc/vc.el (vc-deduce-backend): Use new calling convention for
`derived-mode-p` and `provided-mode-derived-p`.
---
 lisp/align.el                   |  5 ++---
 lisp/calendar/todo-mode.el      |  6 +++---
 lisp/dired.el                   |  4 ++--
 lisp/emacs-lisp/easy-mmode.el   |  2 +-
 lisp/emulation/viper.el         | 10 +++++-----
 lisp/help-fns.el                |  2 +-
 lisp/progmodes/bug-reference.el |  8 ++++----
 lisp/progmodes/c-ts-mode.el     |  4 ++--
 lisp/progmodes/gdb-mi.el        | 15 +++++++++------
 lisp/progmodes/idlwave.el       |  4 ++--
 lisp/progmodes/tcl.el           |  4 ++--
 lisp/simple.el                  |  4 +---
 lisp/so-long.el                 |  2 +-
 lisp/transient.el               |  5 +++--
 lisp/vc/vc.el                   |  2 +-
 lisp/whitespace.el              |  4 ++--
 lisp/window.el                  |  6 ++----
 17 files changed, 43 insertions(+), 44 deletions(-)

diff --git a/lisp/align.el b/lisp/align.el
index 9fa78525ecb..4daa20ddd2a 100644
--- a/lisp/align.el
+++ b/lisp/align.el
@@ -555,8 +555,7 @@ align-rules-list
      (repeat   . t)
      (run-if   . ,(lambda ()
                     (and (not (eq '- current-prefix-arg))
-                         (not (apply #'provided-mode-derived-p
-                                     major-mode align-tex-modes))))))
+                         (not (derived-mode-p align-tex-modes))))))
 
     ;; With a negative prefix argument, lists of dollar figures will
     ;; be aligned.
@@ -1286,7 +1285,7 @@ align--rule-should-run
 This is decided by the `modes' and `run-if' keys in the alist
 RULE.  Their meaning is documented in `align-rules-list' (which see)."
   (let-alist rule
-    (not (or (and .modes (not (apply #'derived-mode-p (eval .modes))))
+    (not (or (and .modes (not (derived-mode-p (eval .modes))))
              (and .run-if (not (funcall .run-if)))))))
 
 (defun align-region (beg end separate rules exclude-rules
diff --git a/lisp/calendar/todo-mode.el b/lisp/calendar/todo-mode.el
index 4f6a964eb4d..ab9d629d9fc 100644
--- a/lisp/calendar/todo-mode.el
+++ b/lisp/calendar/todo-mode.el
@@ -6350,7 +6350,7 @@ todo-reset-nondiary-marker
 		      (replace-match (nth 1 value) t t nil 2))
 		  (forward-line)))
 	      (if buf
-		  (when (derived-mode-p 'todo-mode 'todo-archive-mode)
+		  (when (derived-mode-p '(todo-mode todo-archive-mode))
 		    (todo-category-select))
 		(save-buffer)
 		(kill-buffer)))))))))
@@ -6394,7 +6394,7 @@ todo-reset-done-string
 		    (replace-match value t t nil 1)
 		  (forward-line)))
 	      (if buf
-		  (when (derived-mode-p 'todo-mode 'todo-archive-mode)
+		  (when (derived-mode-p '(todo-mode todo-archive-mode))
 		    (todo-category-select))
 		(save-buffer)
 		(kill-buffer)))))))))
@@ -6420,7 +6420,7 @@ todo-reset-comment-string
 		    (replace-match value t t nil 1)
 		  (forward-line)))
 	      (if buf
-		  (when (derived-mode-p 'todo-mode 'todo-archive-mode)
+		  (when (derived-mode-p '(todo-mode todo-archive-mode))
 		    (todo-category-select))
 		(save-buffer)
 		(kill-buffer)))))))))
diff --git a/lisp/dired.el b/lisp/dired.el
index 8919d2c223f..3f488afaa3c 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -3074,7 +3074,7 @@ dired-hide-details-mode
 See options: `dired-hide-details-hide-symlink-targets' and
 `dired-hide-details-hide-information-lines'."
   :group 'dired
-  (unless (derived-mode-p 'dired-mode 'wdired-mode)
+  (unless (derived-mode-p '(dired-mode wdired-mode))
     (error "Not a Dired buffer"))
   (dired-hide-details-update-invisibility-spec)
   (if dired-hide-details-mode
@@ -5096,7 +5096,7 @@ dired-click-to-select-mode
 completes."
   :group 'dired
   :lighter " Click-To-Select"
-  (unless (derived-mode-p 'dired-mode 'wdired-mode)
+  (unless (derived-mode-p '(dired-mode wdired-mode))
     (error "Not a Dired buffer"))
   (if dired-click-to-select-mode
       (setq-local tool-bar-map
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el
index 529f6e90e88..c9e7b3a4dfe 100644
--- a/lisp/emacs-lisp/easy-mmode.el
+++ b/lisp/emacs-lisp/easy-mmode.el
@@ -661,7 +661,7 @@ easy-mmode--globalized-predicate-p
           (throw 'found nil))
          ((and (consp elem)
                (eq (car elem) 'not))
-          (when (apply #'derived-mode-p (cdr elem))
+          (when (derived-mode-p (cdr elem))
             (throw 'found nil)))
          ((symbolp elem)
           (when (derived-mode-p elem)
diff --git a/lisp/emulation/viper.el b/lisp/emulation/viper.el
index 96da914275b..767ad57c471 100644
--- a/lisp/emulation/viper.el
+++ b/lisp/emulation/viper.el
@@ -593,8 +593,8 @@ viper-mode
 		    ))
 	      (viper-set-expert-level 'dont-change-unless)))
 
-	(or (apply #'derived-mode-p viper-emacs-state-mode-list) ; don't switch to Vi
-	    (apply #'derived-mode-p viper-insert-state-mode-list) ; don't switch
+	(or (derived-mode-p viper-emacs-state-mode-list) ; don't switch to Vi
+	    (derived-mode-p viper-insert-state-mode-list) ; don't switch
 	    (viper-change-state-to-vi))
 	))
 
@@ -607,9 +607,9 @@ viper-mode
 ;; that are not listed in viper-vi-state-mode-list
 (defun viper-this-major-mode-requires-vi-state (mode)
   (let ((major-mode mode))
-    (cond ((apply #'derived-mode-p viper-vi-state-mode-list) t)
-          ((apply #'derived-mode-p viper-emacs-state-mode-list) nil)
-          ((apply #'derived-mode-p viper-insert-state-mode-list) nil)
+    (cond ((derived-mode-p viper-vi-state-mode-list) t)
+          ((derived-mode-p viper-emacs-state-mode-list) nil)
+          ((derived-mode-p viper-insert-state-mode-list) nil)
           (t (and (eq (key-binding "a") 'self-insert-command)
                   (eq (key-binding " ") 'self-insert-command))))))
 
diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index e723d97cfc2..a8c60946121 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -2240,7 +2240,7 @@ help-fns--list-local-commands
                   (not (get sym 'byte-obsolete-info))
                   ;; Ignore everything bound.
                   (not (where-is-internal sym nil t))
-                  (apply #'derived-mode-p (command-modes sym)))
+                  (derived-mode-p (command-modes sym)))
          (push sym functions))))
     (with-temp-buffer
       (when functions
diff --git a/lisp/progmodes/bug-reference.el b/lisp/progmodes/bug-reference.el
index 3f6e1e68e5b..0afed5276f5 100644
--- a/lisp/progmodes/bug-reference.el
+++ b/lisp/progmodes/bug-reference.el
@@ -467,10 +467,10 @@ bug-reference-mode
 (defun bug-reference--try-setup-gnus-article ()
   (when (and bug-reference-mode ;; Only if enabled in article buffers.
              (derived-mode-p
-              'gnus-article-mode
-              ;; Apparently, gnus-article-prepare-hook is run in the
-              ;; summary buffer...
-              'gnus-summary-mode)
+              '(gnus-article-mode
+                ;; Apparently, `gnus-article-prepare-hook' is run in the
+                ;; summary buffer...
+                gnus-summary-mode))
              gnus-article-buffer
              gnus-original-article-buffer
              (buffer-live-p (get-buffer gnus-article-buffer))
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 70717a90caa..a56ce26fc79 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -135,7 +135,7 @@ c-ts-mode--indent-style-setter
               res)
       (let ((buffer (car buffers)))
         (with-current-buffer buffer
-          (if (derived-mode-p 'c-ts-mode 'c++-ts-mode)
+          (if (derived-mode-p '(c-ts-mode c++-ts-mode))
               (loop (append res (list buffer)) (cdr buffers))
             (loop res (cdr buffers))))))))
 
@@ -193,7 +193,7 @@ c-ts-mode-set-style
 To set the default indent style globally, use
 `c-ts-mode-set-global-style'."
   (interactive (list (c-ts-mode--prompt-for-style)))
-  (if (not (derived-mode-p 'c-ts-mode 'c++-ts-mode))
+  (if (not (derived-mode-p '(c-ts-mode c++-ts-mode)))
       (user-error "The current buffer is not in `c-ts-mode' nor `c++-ts-mode'")
     (setq-local c-ts-mode-indent-style style)
     (setq treesit-simple-indent-rules
diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index 3afdc59a67e..7ae4bcea1e1 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -1006,9 +1006,10 @@ gdb
   (gud-def gud-pp
 	   (gud-call
 	    (concat
-	     "pp " (if (eq (buffer-local-value
-			    'major-mode (window-buffer)) 'speedbar-mode)
-		       (gdb-find-watch-expression) "%e")) arg)
+	     "pp " (if (eq (buffer-local-value 'major-mode (window-buffer))
+			   'speedbar-mode)
+		       (gdb-find-watch-expression) "%e"))
+	    arg)
 	   nil   "Print the Emacs s-expression.")
 
   (define-key gud-minor-mode-map [left-margin mouse-1]
@@ -4586,7 +4587,8 @@ gdb-locals-mode-map
                            (gdb-set-window-buffer
                             (gdb-get-buffer-create
                              'gdb-registers-buffer
-                             gdb-thread-number) t)))
+                             gdb-thread-number)
+                            t)))
     map))
 
 (define-derived-mode gdb-locals-mode gdb-parent-mode "Locals"
@@ -4706,7 +4708,8 @@ gdb-registers-mode-map
                            (gdb-set-window-buffer
                             (gdb-get-buffer-create
                              'gdb-locals-buffer
-                             gdb-thread-number) t)))
+                             gdb-thread-number)
+                            t)))
     (define-key map "f" #'gdb-registers-toggle-filter)
     map))
 
@@ -5106,7 +5109,7 @@ gdb-function-buffer-p
 not including main command buffer (the one where you type GDB
 commands) or source buffers (that display program source code)."
   (with-current-buffer buffer
-    (derived-mode-p 'gdb-parent-mode 'gdb-inferior-io-mode)))
+    (derived-mode-p '(gdb-parent-mode gdb-inferior-io-mode))))
 
 (defun gdb--buffer-type (buffer)
   "Return the type of BUFFER if it is a function buffer.
diff --git a/lisp/progmodes/idlwave.el b/lisp/progmodes/idlwave.el
index d9eccacc48b..f60cc9372eb 100644
--- a/lisp/progmodes/idlwave.el
+++ b/lisp/progmodes/idlwave.el
@@ -6892,7 +6892,7 @@ idlwave-one-key-select
     ;; Display prompt and wait for quick reply
     (message "%s[%s]" prompt
              (mapconcat (lambda(x) (char-to-string (car x)))
-                        keys-alist ""))
+                        keys-alist))
     (if (sit-for delay)
         ;; No quick reply: Show help
         (save-window-excursion
@@ -7958,7 +7958,7 @@ idlwave-fix-keywords
     ;; If this is the OBJ_NEW function, try to figure out the class and use
     ;; the keywords from the corresponding INIT method.
     (if (and (equal (upcase name) "OBJ_NEW")
-	     (derived-mode-p 'idlwave-mode 'idlwave-shell-mode))
+	     (derived-mode-p '(idlwave-mode idlwave-shell-mode)))
 	(let* ((bos (save-excursion (idlwave-beginning-of-statement) (point)))
 	       (string (buffer-substring bos (point)))
 	       (case-fold-search t)
diff --git a/lisp/progmodes/tcl.el b/lisp/progmodes/tcl.el
index ba0cbc8b066..b983c671cd9 100644
--- a/lisp/progmodes/tcl.el
+++ b/lisp/progmodes/tcl.el
@@ -1340,7 +1340,7 @@ tcl-current-word
 If FLAG is nil, just uses `current-word'.
 Otherwise scans backward for most likely Tcl command word."
   (if (and flag
-	   (derived-mode-p 'tcl-mode 'inferior-tcl-mode))
+	   (derived-mode-p '(tcl-mode inferior-tcl-mode)))
       (condition-case nil
 	  (save-excursion
 	    ;; Look backward for first word actually in alist.
@@ -1575,7 +1575,7 @@ tcl-quote
 	       (if (memq char '(?\[ ?\] ?{ ?} ?\\ ?\" ?$ ?\s ?\;))
 		   (concat "\\" (char-to-string char))
 		 (char-to-string char)))
-	     string ""))
+	     string))
 
 
 
diff --git a/lisp/simple.el b/lisp/simple.el
index de6eed3fe8f..2e2d73e9bf4 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2427,9 +2427,7 @@ command-completion-with-modes-p
   "Say whether MODES are in action in BUFFER.
 This is the case if either the major mode is derived from one of MODES,
 or (if one of MODES is a minor mode), if it is switched on in BUFFER."
-  (or (apply #'provided-mode-derived-p
-             (buffer-local-value 'major-mode buffer)
-             modes)
+  (or (provided-mode-derived-p (buffer-local-value 'major-mode buffer) modes)
       ;; It's a minor mode.
       (seq-intersection modes
                         (buffer-local-value 'local-minor-modes buffer)
diff --git a/lisp/so-long.el b/lisp/so-long.el
index e5f7b81e717..d91002e873a 100644
--- a/lisp/so-long.el
+++ b/lisp/so-long.el
@@ -1716,7 +1716,7 @@ so-long--set-auto-mode
        (not so-long--inhibited)
        (not so-long--calling)
        (or (eq so-long-target-modes t)
-           (apply #'derived-mode-p so-long-target-modes))
+           (derived-mode-p so-long-target-modes))
        (setq so-long-detected-p (funcall so-long-predicate))
        ;; `so-long' should be called; but only if and when the buffer is
        ;; displayed in a window.  Long lines in invisible buffers are generally
diff --git a/lisp/transient.el b/lisp/transient.el
index 52c21871548..dd2b4e0db0b 100644
--- a/lisp/transient.el
+++ b/lisp/transient.el
@@ -1959,10 +1959,11 @@ transient--do-suffix-p
    (if-not-mode    (not (if (atom if-not-mode)
                             (eq major-mode if-not-mode)
                           (memq major-mode if-not-mode))))
-   (if-derived          (if (atom if-derived)
+   (if-derived          (if (or (atom if-derived) (>= emacs-major-version 30))
                             (derived-mode-p if-derived)
                           (apply #'derived-mode-p if-derived)))
-   (if-not-derived (not (if (atom if-not-derived)
+   (if-not-derived (not (if (or (atom if-not-derived)
+                                (>= emacs-major-version 30))
                             (derived-mode-p if-not-derived)
                           (apply #'derived-mode-p if-not-derived))))
    (t default)))
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index d768af678c3..1bd9ecb2193 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -1084,7 +1084,7 @@ vc-deduce-backend
 	((derived-mode-p 'log-edit-mode) log-edit-vc-backend)
 	((derived-mode-p 'diff-mode)     diff-vc-backend)
 	((or (null vc-deduce-backend-nonvc-modes)
-	     (apply #'derived-mode-p vc-deduce-backend-nonvc-modes))
+	     (derived-mode-p vc-deduce-backend-nonvc-modes))
 	 (ignore-errors (vc-responsible-backend default-directory)))
 	(vc-mode (vc-backend buffer-file-name))))
 
diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index 86fc179396e..f4095c99089 100644
--- a/lisp/whitespace.el
+++ b/lisp/whitespace.el
@@ -1026,8 +1026,8 @@ whitespace-enable-predicate
           ((eq whitespace-global-modes t))
           ((listp whitespace-global-modes)
            (if (eq (car-safe whitespace-global-modes) 'not)
-               (not (apply #'derived-mode-p (cdr whitespace-global-modes)))
-             (apply #'derived-mode-p whitespace-global-modes)))
+               (not (derived-mode-p (cdr whitespace-global-modes)))
+             (derived-mode-p whitespace-global-modes)))
           (t nil))
          ;; ...we have a display (not running a batch job)
          (not noninteractive)
diff --git a/lisp/window.el b/lisp/window.el
index 06d5cfc0077..0c5ccf167dc 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -8054,10 +8054,8 @@ display-buffer-reuse-mode-window
       (dolist (window windows)
         (let ((mode?
                (with-current-buffer (window-buffer window)
-                 (cond ((memq major-mode allowed-modes)
-                        'same)
-                       ((apply #'derived-mode-p allowed-modes)
-                        'derived)))))
+                 (cond ((memq major-mode allowed-modes) 'same)
+                       ((derived-mode-p allowed-modes)  'derived)))))
           (when (and mode?
                      (not (and inhibit-same-window-p
                                (eq window curwin))))
-- 
2.42.0


--=-=-=--





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#67034; Package emacs. Full text available.

Message received at 67034 <at> debbugs.gnu.org:


Received: (at 67034) by debbugs.gnu.org; 11 Nov 2023 09:09:31 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Nov 11 04:09:31 2023
Received: from localhost ([127.0.0.1]:51849 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1r1jzf-00029z-1F
	for submit <at> debbugs.gnu.org; Sat, 11 Nov 2023 04:09:31 -0500
Received: from server.qxqx.de ([2a01:4f8:121:346::180]:48761 helo=mail.qxqx.de)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <mail@HIDDEN>) id 1r1jzc-00029X-Fr
 for 67034 <at> debbugs.gnu.org; Sat, 11 Nov 2023 04:09:29 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=qxqx.de;
 s=mail1392553390; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From:
 References:To:Subject:MIME-Version:Date:Message-ID:Sender:Reply-To:Cc:
 Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender:
 Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:
 List-Subscribe:List-Post:List-Owner:List-Archive;
 bh=R6xDRYW3OCjwepFFm8XEqNjCcjRN9wD0p/SbfYQe5RY=; b=Q6Bdg35b6fjGLcVKD/9zNumtF+
 18Ct3Lg447Z49iBKbg5C4HA+a4iljDrpNSuXprbkKnzXYCpOCL19pawjy9aaMt1EL08xh5aCsQocA
 Rwp3/yadZlNCaA1J5mlmhfonVJTaD+5y2THdKi0ztYn329HnhQOALx7xMIRdRXICw4ng=;
Message-ID: <f7265153-4d14-4863-bf9a-b1d43ed46b19@HIDDEN>
Date: Sat, 11 Nov 2023 10:08:40 +0100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: bug#67034: 30.0.50; Make `derived-mode-p` take a single arg
To: Dmitry Gutov <dmitry@HIDDEN>, 67034 <at> debbugs.gnu.org
References: <jwv8r76mf8d.fsf@HIDDEN>
 <96367d39-4861-41e6-9383-a9a18efa0678@HIDDEN>
 <6ded2256-4537-3a51-8ecd-ab3bd5a862d1@HIDDEN>
Content-Language: en-US
From: Daniel Mendler <mail@HIDDEN>
In-Reply-To: <6ded2256-4537-3a51-8ecd-ab3bd5a862d1@HIDDEN>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 67034
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

On 11/11/23 01:04, Dmitry Gutov wrote:
> I wonder if this extra allocation of &rest makes any difference in any 
> benchmark, though.

derived-mode-p is usually not called in some kind of hot loop, but
rather during initialization/setup. So it shouldn't matter? I am
generally a bit wary of backward incompatible calling convention changes.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#67034; Package emacs. Full text available.

Message received at 67034 <at> debbugs.gnu.org:


Received: (at 67034) by debbugs.gnu.org; 11 Nov 2023 00:05:18 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Nov 10 19:05:18 2023
Received: from localhost ([127.0.0.1]:51053 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1r1bV0-0004Fo-9c
	for submit <at> debbugs.gnu.org; Fri, 10 Nov 2023 19:05:18 -0500
Received: from out2-smtp.messagingengine.com ([66.111.4.26]:36881)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <dmitry@HIDDEN>) id 1r1bUy-0004Fa-PH
 for 67034 <at> debbugs.gnu.org; Fri, 10 Nov 2023 19:05:17 -0500
Received: from compute3.internal (compute3.nyi.internal [10.202.2.43])
 by mailout.nyi.internal (Postfix) with ESMTP id 99B825C0218;
 Fri, 10 Nov 2023 19:04:31 -0500 (EST)
Received: from mailfrontend2 ([10.202.2.163])
 by compute3.internal (MEProxy); Fri, 10 Nov 2023 19:04:31 -0500
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc
 :content-transfer-encoding:content-type:content-type:date:date
 :from:from:in-reply-to:in-reply-to:message-id:mime-version
 :references:reply-to:sender:subject:subject:to:to; s=fm2; t=
 1699661071; x=1699747471; bh=YQ1oKE6xVLJ3SZiua+KSMvjqEcBYK/Mvoe3
 aj5mXTv8=; b=H7YqLWiSaOIHSY8q5VTfJDdRGxZI2wvcIvknjy+olgqMV3nlABi
 xfn/VfpzcbXxMMS4Hrs+XLtoVkhjgGDdVuQr2oHdp7AHV1CmNJCDYCQsUwU0qlui
 bdYAPkQ6HWEX6ttXAeAz8ROTX3D0Nq+J6qs8Yuh4fGdGu6DnliCZsVNx9C6IgsAw
 chvAK27u6bAJTgD4KTT+4KmiLdAlkDpXD8Eez96Zkq/4IJPIaeLQ/9yXGhTxhFya
 kI0UCVMB6vqypdT5bP14N1lVcHF/CwZ51+Gj8DAAk+XMH+5zh2acc6ahObpgpbsq
 sVLXj9nAr2FHDNomrHDjhwJL3PVR0doyVdA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
 messagingengine.com; h=cc:content-transfer-encoding:content-type
 :content-type:date:date:feedback-id:feedback-id:from:from
 :in-reply-to:in-reply-to:message-id:mime-version:references
 :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy
 :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1699661071; x=
 1699747471; bh=YQ1oKE6xVLJ3SZiua+KSMvjqEcBYK/Mvoe3aj5mXTv8=; b=H
 ufGdRniQrmhK5ukZCrIJw1McZFAiAHOg5VvDJ9WaF4NLpk6DFJd+Olr1kTgeMm4l
 DgSXvQBmvIWZ1i+h3n46Gl3P8LQzdxRUGf7zidhijhm0ar0L7KQjp3Tqevkjab1l
 6C9sBtTn4s6rHXMTq2ileW9XLRL3YSMpiIEP1dR7u8w4lTP1AliIrKO5xHg/Duva
 MTY6RuemQVFAdGP3dw6IrWuPWaW+Guj4dVBId9LOXo4lf4ebhnh5NzNXNDwSbYVU
 +2PvjP6LF/F3hOx9tSCduEVbJp2JdnIIFWYjOdbuUaI8oJbQ4CkKCQEZzMh1Bj91
 DbdsJaFcl9zsamvXJNeAg==
X-ME-Sender: <xms:D8VOZZrTaKI_dX_iuZ3kueRf6Ez4-Hi2X9rbK4SSOmcchIUJdXy4cQ>
 <xme:D8VOZbqQrDqjnzN9BYXevF4tBnV5JWa_UQJ01Vvl8jpmhl0Jv7J0rjUI9YdClIV0_
 HqK3lX8QRMWDCzcGBs>
X-ME-Received: <xmr:D8VOZWMTWbShoPFrC0IJLu_4MqYu97wZS4a7mIxIq9k13Q2Jb-JFVdj-8SYMYzY>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedruddvgedgudeiucetufdoteggodetrfdotf
 fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen
 uceurghilhhouhhtmecufedttdenucenucfjughrpefkffggfgfuvfhfhfgjtgfgsehtje
 ertddtfeejnecuhfhrohhmpeffmhhithhrhicuifhuthhovhcuoegumhhithhrhiesghhu
 thhovhdruggvvheqnecuggftrfgrthhtvghrnhepgeehtdehudejieetuedttdejkeehje
 etueekheffuddtjeeuvdefveeuveeiuddunecuvehluhhsthgvrhfuihiivgeptdenucfr
 rghrrghmpehmrghilhhfrhhomhepughmihhtrhihsehguhhtohhvrdguvghv
X-ME-Proxy: <xmx:D8VOZU6ff8-P2pAtFD6o5gyeA1c1k8zpY-6v1pCipEJXd7s2B3BBMw>
 <xmx:D8VOZY6sor6bY8NVqeDnGe8V0iywsDmOr3wv6ZCnI5jn5scGZqChrg>
 <xmx:D8VOZcioGQo84PW7-0bHOAMOJdxoOT7c5EuXu-XcjuU_BtOCMv4zwg>
 <xmx:D8VOZdgZIgWXtrFRiXK1Rrkeogc-li-eiP20oDjxEj55De6PosTupw>
Feedback-ID: i0e71465a:Fastmail
Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri,
 10 Nov 2023 19:04:30 -0500 (EST)
Message-ID: <6ded2256-4537-3a51-8ecd-ab3bd5a862d1@HIDDEN>
Date: Sat, 11 Nov 2023 02:04:29 +0200
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
 Thunderbird/102.13.0
Subject: Re: bug#67034: 30.0.50; Make `derived-mode-p` take a single arg
Content-Language: en-US
To: Daniel Mendler <mail@HIDDEN>, 67034 <at> debbugs.gnu.org
References: <jwv8r76mf8d.fsf@HIDDEN>
 <96367d39-4861-41e6-9383-a9a18efa0678@HIDDEN>
From: Dmitry Gutov <dmitry@HIDDEN>
In-Reply-To: <96367d39-4861-41e6-9383-a9a18efa0678@HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Spam-Score: -2.2 (--)
X-Debbugs-Envelope-To: 67034
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.2 (---)

On 10/11/2023 14:18, Daniel Mendler wrote:
> There are also multiple call sites with apply, but these would be
> arguably nicer if derived-mode-p takes a list argument as proposed.
> Still, do the benefits of this change outweigh the required changes?

I've also found some call sites with multiple arguments (one of them 
being sml-mode 6.12) and also uses with (apply #'derived-mode-p 
some-user-option-list-of-modes). But those are indeed in the minority.

I wonder if this extra allocation of &rest makes any difference in any 
benchmark, though.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#67034; Package emacs. Full text available.

Message received at 67034 <at> debbugs.gnu.org:


Received: (at 67034) by debbugs.gnu.org; 10 Nov 2023 12:19:25 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Nov 10 07:19:25 2023
Received: from localhost ([127.0.0.1]:49660 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1r1QTs-0007pK-OC
	for submit <at> debbugs.gnu.org; Fri, 10 Nov 2023 07:19:25 -0500
Received: from server.qxqx.de ([2a01:4f8:121:346::180]:44033 helo=mail.qxqx.de)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <mail@HIDDEN>) id 1r1QTn-0007p1-E0
 for 67034 <at> debbugs.gnu.org; Fri, 10 Nov 2023 07:19:23 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=qxqx.de;
 s=mail1392553390; h=Content-Transfer-Encoding:Content-Type:Subject:From:To:
 MIME-Version:Date:Message-ID:Sender:Reply-To:Cc:Content-ID:
 Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc
 :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:
 List-Subscribe:List-Post:List-Owner:List-Archive;
 bh=ZUWJxixitztV1J6XYMZopn8mGrcGrggOvBnuuWHeikY=; b=Tv5lQg5FojG3KPqCfQnJkHGTjB
 RH9iCbeJrpPnZLHvEJe7+AgYPrZSpPpjxCKbIuwtJU8GUweE+Unt43+cz6Hs/vpOYZ7gpJymJbs2B
 e+TsmJmiwGOeE/QhvGVq1P7KP5q1F+W4D0UpX5eCXPvbGsKGfuY0sAmYVIQR1rjFRW5s=;
Message-ID: <96367d39-4861-41e6-9383-a9a18efa0678@HIDDEN>
Date: Fri, 10 Nov 2023 13:18:32 +0100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Content-Language: en-US
To: 67034 <at> debbugs.gnu.org
From: Daniel Mendler <mail@HIDDEN>
Subject: Re: 30.0.50; Make `derived-mode-p` take a single arg
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 67034
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

This change would affect many packages. I grepped through my elpa
directory and found multiple uses of derived-mode-p and
provided-mode-derived-p with multiple arguments as shortcuts:

(derived-mode-p 'mode1 'mode2) instead of (or (derived-mode-p 'mode1)
(derived-mode-p 'mode2)

There are also multiple call sites with apply, but these would be
arguably nicer if derived-mode-p takes a list argument as proposed.
Still, do the benefits of this change outweigh the required changes?




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#67034; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 10 Nov 2023 03:59:20 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Nov 09 22:59:20 2023
Received: from localhost ([127.0.0.1]:49278 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1r1Ifv-0008IT-Ps
	for submit <at> debbugs.gnu.org; Thu, 09 Nov 2023 22:59:20 -0500
Received: from lists.gnu.org ([2001:470:142::17]:40034)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <monnier@HIDDEN>) id 1r1Ifs-0008ID-Ra
 for submit <at> debbugs.gnu.org; Thu, 09 Nov 2023 22:59:19 -0500
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 <monnier@HIDDEN>)
 id 1r1IfA-0001La-1l
 for bug-gnu-emacs@HIDDEN; Thu, 09 Nov 2023 22:58:32 -0500
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <monnier@HIDDEN>)
 id 1r1If8-0000BY-87
 for bug-gnu-emacs@HIDDEN; Thu, 09 Nov 2023 22:58:31 -0500
Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id CCD711000AD
 for <bug-gnu-emacs@HIDDEN>; Thu,  9 Nov 2023 22:58:27 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1699588707;
 bh=sHckZheSuMiGB0ASZmYzivqvRZaTaDs2IEku+qrSigs=;
 h=From:To:Subject:Date:From;
 b=mJm0y2mMGMp66w1Ov/iWpMfIx1dN5Hcd6fQ+oT7QYohnbNNA2YZk5pWb5BNXU20qt
 TzA1YTqKQOcZAonhCBZ6uCoY9ThnVBpqgWdZhuR6qVVpi7aIHDcsb8Z3B1kU7tDtqi
 ODjKQliCxsrnyYE+hCHRzYoCAQEsA2+q4WKgKPuBxOXOFzhndmQy9tMv5B4iqXUb8U
 8LMuQgXKvYzv7M8C78GxWFlk/6jCnpjzIjp7EJDyXgvRaRNH6rBwQLW2WV3dbk7Ok1
 oNZ8lZY5ECxtNUCy8hQKvNOxmEIhYyuZAVxppcGtTB5HA+iGa2S7uENVRX3S6xT2ZA
 vipNYb/P5uKLw==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 14579100061
 for <bug-gnu-emacs@HIDDEN>; Thu,  9 Nov 2023 22:58:27 -0500 (EST)
Received: from pastel (unknown [45.72.227.120])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id ED7D91203DD
 for <bug-gnu-emacs@HIDDEN>; Thu,  9 Nov 2023 22:58:26 -0500 (EST)
From: Stefan Monnier <monnier@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 30.0.50; Make `derived-mode-p` take a single arg
Date: Thu, 09 Nov 2023 22:58:26 -0500
Message-ID: <jwv8r76mf8d.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.135 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain T_SCC_BODY_TEXT_LINE    -0.01 -
X-SPAM-LEVEL: 
Received-SPF: pass client-ip=132.204.25.50;
 envelope-from=monnier@HIDDEN; helo=mailscanner.iro.umontreal.ca
X-Spam_score_int: -42
X-Spam_score: -4.3
X-Spam_bar: ----
X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3,
 SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
 T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Package: Emacs
Version: 30.0.50


Looking at uses of `derived-mode-p`, I can't find a single use case
where it wouldn't be preferable for it to take a single argument
instead of `&rest`: all the calls are either passing a single
argument anyway, or passing a fixed list of modes.

So making `derived-mode-p` take a single arg (which we'd allow to be
either a mode or a list of modes) would not make any real difference to
the callers (it would even be more convenient since it could often avoid
the use of `apply`), and in return we'd save allocating the
`&rest` list.

Same for `provided-mode-derived-p`.

And yes, I plead guilty for the `&rest` of `derived-mode-p`.
Seemed like a good idea at the time :-(

Draft patch below.


        Stefan


diff --git a/lisp/subr.el b/lisp/subr.el
index d4173b4daba..cd6407ef4b2 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2678,11 +2678,17 @@ while-let
 
 ;; PUBLIC: find if the current mode derives from another.
 
-(defun provided-mode-derived-p (mode &rest modes)
+(defun provided-mode-derived-p (mode &optional parent &rest modes)
   "Non-nil if MODE is derived from one of MODES.
 Uses the `derived-mode-parent' property of the symbol to trace backwards.
 If you just want to check `major-mode', use `derived-mode-p'."
-  (declare (side-effect-free t))
+  (declare (side-effect-free t)
+           (advertised-calling-convention (mode parent) "30.1"))
+  (setq modes (if (not (listp parent))
+                  (cons parent modes)
+                ;; New calling convention can't use MODES at the same time.
+                (cl-assert (null modes))
+                parent))
   (while
       (and
        (not (memq mode modes))
@@ -2693,11 +2699,19 @@ provided-mode-derived-p
                          (and (symbolp alias) alias)))))))
   mode)
 
-(defun derived-mode-p (&rest modes)
-  "Non-nil if the current major mode is derived from one of MODES.
-Uses the `derived-mode-parent' property of the symbol to trace backwards."
-  (declare (side-effect-free t))
-  (apply #'provided-mode-derived-p major-mode modes))
+(defun derived-mode-p (&optional mode &rest modes)
+  "Non-nil if the current major mode is derived from MODE.
+MODE can also be a list of modes, in which case we check if major mode
+is derived from one of them.
+It also supports an obsolete `&rest MODES' calling convention."
+  (declare (side-effect-free t)
+           (advertised-calling-convention (mode) "30.1"))
+  (provided-mode-derived-p major-mode
+                           (if (not (listp mode)) (cons mode modes)
+                             ;; New calling convention can't use MODES
+                             ;; at the same time.
+                             (cl-assert (null modes))
+                             mode)))
 
 (defvar-local major-mode--suspended nil)
 (put 'major-mode--suspended 'permanent-local t)





Acknowledgement sent to Stefan Monnier <monnier@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#67034; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Thu, 16 Nov 2023 22:30:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.