GNU bug report logs -
#67034
30.0.50; Make `derived-mode-p` take a single arg
Previous Next
Reported by: Stefan Monnier <monnier <at> iro.umontreal.ca>
Date: Fri, 10 Nov 2023 04:00:02 UTC
Severity: normal
Found in version 30.0.50
Done: Stefan Monnier <monnier <at> iro.umontreal.ca>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your bug report
#67034: 30.0.50; Make `derived-mode-p` take a single arg
which was filed against the emacs package, has been closed.
The explanation is attached below, along with your original report.
If you require more details, please reply to 67034 <at> debbugs.gnu.org.
--
67034: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=67034
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
Pushed, thanks,
Stefan
[Message part 3 (message/rfc822, inline)]
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)
This bug report was last modified 1 year and 182 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.