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: Mon, 09 Oct 2023 17:40:57 -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> 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="36284"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Dmitry Gutov , Philip Kaludercic , Eli Zaretskii , Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= , 65797@debbugs.gnu.org To: Joseph Turner Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Oct 09 23:41:55 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 1qpy0g-0009DT-Bg for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 09 Oct 2023 23:41:54 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qpy0V-0006sl-U3; Mon, 09 Oct 2023 17:41:43 -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 1qpy0T-0006sR-AI for bug-gnu-emacs@gnu.org; Mon, 09 Oct 2023 17:41:41 -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 1qpy0T-0003mc-2F for bug-gnu-emacs@gnu.org; Mon, 09 Oct 2023 17:41:41 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qpy0n-0008Td-RN for bug-gnu-emacs@gnu.org; Mon, 09 Oct 2023 17:42:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 09 Oct 2023 21:42:01 +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.169688769332543 (code B ref 65797); Mon, 09 Oct 2023 21:42:01 +0000 Original-Received: (at 65797) by debbugs.gnu.org; 9 Oct 2023 21:41:33 +0000 Original-Received: from localhost ([127.0.0.1]:33620 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qpy0L-0008So-3W for submit@debbugs.gnu.org; Mon, 09 Oct 2023 17:41:33 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:3965) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qpy0J-0008SW-MC for 65797@debbugs.gnu.org; Mon, 09 Oct 2023 17:41:32 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 7CB2D1000A3; Mon, 9 Oct 2023 17:41:05 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1696887660; bh=xqxEJwsqnB8J7GmDDtjKwCPBmxaVsKQ2j+/lOTs0dp8=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=fI7uDPGAhNsChv3v3moDEVo9MMKqe6CJgEVMyV0huvBsS+odYMXSIv8mWLfRHwOch nj57dhwv/fKf/T1/obaQaoOzi2gGshNZoe3eptffvbbL4oQ1RvYUk6VaCKhbNqKdIx D+Jwqxw3iFKQON8ldTpG+6S/nlWyhNSI/l/em5puXOpuLTBLUBD9DaH8oGjHp2Drpu nfhhQNVAlVIRtO1PJ8Z4naFCgnjSzLk8YpEogzrqGZSlDO6+8iF4akmc/TheFpXKhm 8poADFZoM+JA8UeiKk6IlF74aPCCpL65syzN9IDQ8GGRqFMG9h72T/ps9uJvHoTj2R xhz7zAylU+4HQ== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id EF8AF100061; Mon, 9 Oct 2023 17:40:59 -0400 (EDT) Original-Received: from pastel (unknown [216.154.28.175]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id BA7641202FA; Mon, 9 Oct 2023 17:40:59 -0400 (EDT) In-Reply-To: <87v8bhtr3k.fsf@breatheoutbreathe.in> (Joseph Turner's message of "Sun, 08 Oct 2023 02:10:33 -0700") 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:272174 Archived-At: > I am in favor of this solution as well. 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. Stefan diff --git a/lisp/subr.el b/lisp/subr.el index e88815fa58c..06c9923b525 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -7295,13 +7292,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 +7323,18 @@ 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))) + (if (cdr args) + ;; More than 1 argument: no need for + ;; Emacs-29 backward compatibility! + (apply condition buffer-or-name args) + (condition-case err + (apply condition buffer-or-name args) + (wrong-number-of-arguments + ;; Backward compatibility with Emacs-29 semantics. + (message "Trying obsolete calling convention for: %S" + condition) + (apply condition buffer-or-name + (if args '(nil) nil)))))) (`(major-mode . ,mode) (eq (buffer-local-value 'major-mode buffer) @@ -7350,17 +7356,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))