From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 67034@debbugs.gnu.org
Subject: bug#67034: 30.0.50; Make `derived-mode-p` take a single arg
Date: Thu, 09 Nov 2023 22:58:26 -0500 [thread overview]
Message-ID: <jwv8r76mf8d.fsf@iro.umontreal.ca> (raw)
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)
next reply other threads:[~2023-11-10 3:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-10 3:58 Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-11-10 12:18 ` bug#67034: 30.0.50; Make `derived-mode-p` take a single arg Daniel Mendler
2023-11-11 0:04 ` Dmitry Gutov
2023-11-11 9:08 ` Daniel Mendler
2023-11-16 22:38 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-16 22:28 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-17 8:24 ` Eli Zaretskii
2023-11-17 21:18 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-23 17:00 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwv8r76mf8d.fsf@iro.umontreal.ca \
--to=bug-gnu-emacs@gnu.org \
--cc=67034@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).