From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#67034: 30.0.50; Make `derived-mode-p` take a single arg Date: Thu, 09 Nov 2023 22:58:26 -0500 Message-ID: Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17075"; mail-complaints-to="usenet@ciao.gmane.io" To: 67034@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Nov 10 04:59:49 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r1IgO-0004EY-Fu for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 10 Nov 2023 04:59:48 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r1Ig0-0001UP-05; Thu, 09 Nov 2023 22:59:24 -0500 Original-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 ) id 1r1Ifz-0001UG-AD for bug-gnu-emacs@gnu.org; Thu, 09 Nov 2023 22:59:23 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r1Ifz-0000HQ-2A for bug-gnu-emacs@gnu.org; Thu, 09 Nov 2023 22:59:23 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r1Igc-0008K2-HQ for bug-gnu-emacs@gnu.org; Thu, 09 Nov 2023 23:00:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 10 Nov 2023 04:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 67034 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.169958876031902 (code B ref -1); Fri, 10 Nov 2023 04:00:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 10 Nov 2023 03:59:20 +0000 Original-Received: from localhost ([127.0.0.1]:49278 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r1Ifv-0008IT-Ps for submit@debbugs.gnu.org; Thu, 09 Nov 2023 22:59:20 -0500 Original-Received: from lists.gnu.org ([2001:470:142::17]:40034) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r1Ifs-0008ID-Ra for submit@debbugs.gnu.org; Thu, 09 Nov 2023 22:59:19 -0500 Original-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 ) id 1r1IfA-0001La-1l for bug-gnu-emacs@gnu.org; Thu, 09 Nov 2023 22:58:32 -0500 Original-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 ) id 1r1If8-0000BY-87 for bug-gnu-emacs@gnu.org; Thu, 09 Nov 2023 22:58:31 -0500 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id CCD711000AD for ; 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== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 14579100061 for ; Thu, 9 Nov 2023 22:58:27 -0500 (EST) Original-Received: from pastel (unknown [45.72.227.120]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id ED7D91203DD for ; Thu, 9 Nov 2023 22:58:26 -0500 (EST) Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; 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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:274083 Archived-At: 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)