[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#67034: 30.0.50; Make `derived-mode-p` take a single arg
From: |
Stefan Monnier |
Subject: |
bug#67034: 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)
- bug#67034: 30.0.50; Make `derived-mode-p` take a single arg,
Stefan Monnier <=