From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joseph Turner 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: Wed, 11 Oct 2023 21:53:31 -0700 Message-ID: <87v8bcqvr0.fsf@breatheoutbreathe.in> 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: Joseph Turner Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26518"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Dmitry Gutov , Philip Kaludercic , Eli Zaretskii , Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= , 65797@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 12 07:03:04 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 1qqnqg-0006cL-Js for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 12 Oct 2023 07:03:03 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqnqO-0007Ie-UY; Thu, 12 Oct 2023 01:02:44 -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 1qqnqK-0007IB-KK for bug-gnu-emacs@gnu.org; Thu, 12 Oct 2023 01:02: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 1qqnqK-0005M7-CU for bug-gnu-emacs@gnu.org; Thu, 12 Oct 2023 01:02:40 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qqnqg-00006z-GY for bug-gnu-emacs@gnu.org; Thu, 12 Oct 2023 01:03:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Joseph Turner Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 12 Oct 2023 05:03:02 +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.1697086949373 (code B ref 65797); Thu, 12 Oct 2023 05:03:02 +0000 Original-Received: (at 65797) by debbugs.gnu.org; 12 Oct 2023 05:02:29 +0000 Original-Received: from localhost ([127.0.0.1]:40389 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qqnq8-00005w-UA for submit@debbugs.gnu.org; Thu, 12 Oct 2023 01:02:29 -0400 Original-Received: from out-201.mta1.migadu.com ([2001:41d0:203:375::c9]:65215) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qqnq6-00005Z-EU for 65797@debbugs.gnu.org; Thu, 12 Oct 2023 01:02:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=breatheoutbreathe.in; s=key1; t=1697086920; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=QTxNUUpeGwK4VQGPhwQj79CQLt2st/lw/vbYX6y1ax0=; b=Zt2LYv2y40FoR1CibRy0Drh7BZ9mWj7fjpslxqWHK07p9/yB8y3xrwrucRHSB5Iq2ElvZL BjHdnEhrboN9oMqsuaxtYDvrsCcyg7yK4V5prncCyo/W4W2dJa4/NaNp4In9pzFRo84rbA BH1FSUpESDr+KZwF8tAFajBhobNhpBM= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-reply-to: X-Migadu-Flow: FLOW_OUT 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:272275 Archived-At: Stefan Monnier writes: >> 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)))) At first, I was concerned that the condition-case would mess up error handling in user code, but all 9 permutations give the expected results: (let ((condition (lambda (buf) t) ;; (lambda (buf arg1) t) ;; (lambda (buf arg1 arg2) t) )) (condition-case err (buffer-match-p condition (current-buffer) ;; 'arg1 ;; 'arg2 ) (wrong-number-of-arguments "Caught"))) > -(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)) >