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#65797: `buffer-match-p` should not use `func-arity` Date: Fri, 13 Oct 2023 11:57:59 -0400 Message-ID: References: <87v8cmct9b.fsf@breatheoutbreathe.in> <87sf7o38g1.fsf_-_@posteo.net> <871qf1rbdo.fsf@posteo.net> <87o7hz4zg2.fsf@posteo.net> <87sf7b8ker.fsf@posteo.net> <87y1h2blxq.fsf@posteo.net> <874jjqb715.fsf@posteo.net> <0371b6ff-58e4-961e-29c9-4efb65b82185@gutov.dev> <87v8bhtr3k.fsf@breatheoutbreathe.in> <3a282a0b-3efa-ec12-2143-0496ebf6c828@gutov.dev> 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="3448"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 65797@debbugs.gnu.org, Philip Kaludercic , Eli Zaretskii , Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= , Joseph Turner To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Oct 13 17:59:09 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 1qrKZA-0000ft-CW for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 13 Oct 2023 17:59:08 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qrKYj-0003jc-UR; Fri, 13 Oct 2023 11:58:41 -0400 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 1qrKYi-0003jD-OX for bug-gnu-emacs@gnu.org; Fri, 13 Oct 2023 11:58:40 -0400 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 1qrKYi-0007ic-Gd for bug-gnu-emacs@gnu.org; Fri, 13 Oct 2023 11:58:40 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qrKZ5-0007u1-IS for bug-gnu-emacs@gnu.org; Fri, 13 Oct 2023 11:59:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 13 Oct 2023 15:59:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65797 X-GNU-PR-Package: emacs Original-Received: via spool by 65797-submit@debbugs.gnu.org id=B65797.169721271230259 (code B ref 65797); Fri, 13 Oct 2023 15:59:03 +0000 Original-Received: (at 65797) by debbugs.gnu.org; 13 Oct 2023 15:58:32 +0000 Original-Received: from localhost ([127.0.0.1]:47244 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qrKYa-0007ry-C1 for submit@debbugs.gnu.org; Fri, 13 Oct 2023 11:58:32 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:23406) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qrKYY-0007rd-2x for 65797@debbugs.gnu.org; Fri, 13 Oct 2023 11:58:30 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 597C6100143; Fri, 13 Oct 2023 11:58:01 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1697212680; bh=9kVOmfW9GpGe+AcBrbCcBtl5mDqkYA65CUEb/3w8bkk=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=KZ0Nsuy+ozy3GZxxYJYGmI88yI0l7Gd/d8GyfAUJSV3mmVA0uKHB/f0zpwZ7cIyB4 +3TYgT3hztN4bZHMQz90Wmwc3WDpr6SU609C/Bti4RxZa+d4b0yChbXtH35uRTGEfN R+BdRZOsCcUZAu49mTAp6tDPoLuPyTeIaV2RsN/I1Y2VcBgkIZ92Dm+Tk7o22pxZj7 Y/yrZHXI6qEPLiH9oJ/javYq22FuQC3U2dDK6kAGOIFlQ7CAne1dCzgyYrBtzHI1n5 v0Kdm7xQEC/FFgyJIn2voqtP59FZu28gCj3kkN9108wVgjsI69Pa4lu1q39R2ApC/c 4MxK3V6RBbovw== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 07B7E100068; Fri, 13 Oct 2023 11:58:00 -0400 (EDT) Original-Received: from alfajor (unknown [23.233.149.155]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id C96E91200A1; Fri, 13 Oct 2023 11:57:59 -0400 (EDT) In-Reply-To: <3a282a0b-3efa-ec12-2143-0496ebf6c828@gutov.dev> (Dmitry Gutov's message of "Thu, 12 Oct 2023 14:34:13 +0300") 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:272356 Archived-At: >> Then how 'bout something like the patch below which changes the >> `&optional` into an `&rest` but tries to preserve compatibility with the >> old calling convention. > Personally, I figured that using &rest would already help with backward > compatibility to an extent. I don't have a good intuition for how important backward compatibility is here, so I went for the "safe" choice. But maybe we don't need to go that far. The patch below keeps the same compatibility hack as we currently have but doesn't add any new compatibility, so it will break those uses where `buffer-match-p` is called without additional args but the predicate function still expects 2 args (where the second is always nil). Indeed, that case seemes extremely unlikely. Eli, Stefan, WDYT? Stefan diff --git a/lisp/subr.el b/lisp/subr.el index e88815fa58c..b38a29058a4 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -7295,13 +7295,13 @@ string-lines (setq start (length string))))) (nreverse lines)))) -(defun buffer-match-p (condition buffer-or-name &optional arg) +(defun buffer-match-p (condition buffer-or-name &rest args) "Return non-nil if BUFFER-OR-NAME matches CONDITION. CONDITION is either: - the symbol t, to always match, - the symbol nil, which never matches, - a regular expression, to match a buffer name, -- a predicate function that takes BUFFER-OR-NAME and ARG as +- a predicate function that takes BUFFER-OR-NAME plus ARGS as arguments, and returns non-nil if the buffer matches, - a cons-cell, where the car describes how to interpret the cdr. The car can be one of the following: @@ -7326,9 +7326,14 @@ buffer-match-p ((pred stringp) (string-match-p condition (buffer-name buffer))) ((pred functionp) - (if (eq 1 (cdr (func-arity condition))) - (funcall condition buffer-or-name) - (funcall condition buffer-or-name arg))) + (apply condition buffer-or-name + (cond + ;; Backward compatibility with + ;; Emacs-29 semantics. + ((and args (null (cdr args)) + (eq 1 (cdr (func-arity condition)))) + nil) + (t args)))) (`(major-mode . ,mode) (eq (buffer-local-value 'major-mode buffer) @@ -7350,17 +7355,17 @@ buffer-match-p (throw 'match t))))))) (funcall match (list condition)))) -(defun match-buffers (condition &optional buffers arg) +(defun match-buffers (condition &optional buffers &rest args) "Return a list of buffers that match CONDITION, or nil if none match. See `buffer-match-p' for various supported CONDITIONs. By default all buffers are checked, but the optional argument BUFFERS can restrict that: its value should be an explicit list of buffers to check. -Optional argument ARG is passed to `buffer-match-p', for +Optional arguments ARGS are passed to `buffer-match-p', for predicate conditions in CONDITION." (let (bufs) (dolist (buf (or buffers (buffer-list))) - (when (buffer-match-p condition (get-buffer buf) arg) + (when (apply #'buffer-match-p condition (get-buffer buf) args) (push buf bufs))) bufs))