emacs-bug-tracker
[Top][All Lists]
Advanced

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

bug#67034: closed (30.0.50; Make `derived-mode-p` take a single arg)


From: GNU bug Tracking System
Subject: bug#67034: closed (30.0.50; Make `derived-mode-p` take a single arg)
Date: Thu, 23 Nov 2023 17:01:02 +0000

Your message dated Thu, 23 Nov 2023 12:00:33 -0500
with message-id <jwvr0kgl80x.fsf-monnier+emacs@gnu.org>
and subject line Re: bug#67034: 30.0.50; Make `derived-mode-p` take a single arg
has caused the debbugs.gnu.org bug report #67034,
regarding 30.0.50; Make `derived-mode-p` take a single arg
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs@gnu.org.)


-- 
67034: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=67034
GNU Bug Tracking System
Contact help-debbugs@gnu.org with problems
--- Begin Message --- Subject: 30.0.50; Make `derived-mode-p` take a single arg Date: Thu, 09 Nov 2023 22:58:26 -0500
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)




--- End Message ---
--- Begin Message --- Subject: Re: bug#67034: 30.0.50; Make `derived-mode-p` take a single arg Date: Thu, 23 Nov 2023 12:00:33 -0500 User-agent: Gnus/5.13 (Gnus v5.13)
Pushed, thanks,


        Stefan



--- End Message ---

reply via email to

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