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: 29.0.92; func-arity should not return (0 . many) with apply-partially Date: Thu, 07 Sep 2023 21:40:28 -0700 Message-ID: <87cyytwa14.fsf@breatheoutbreathe.in> References: <87v8cmct9b.fsf@breatheoutbreathe.in> Reply-To: Joseph Turner Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21695"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 65797@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 08 06:43:22 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 1qeTKz-0005UC-2h for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 08 Sep 2023 06:43:22 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeTKl-00062h-1X; Fri, 08 Sep 2023 00:43:07 -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 1qeTKe-00062S-If for bug-gnu-emacs@gnu.org; Fri, 08 Sep 2023 00:43:00 -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 1qeTKe-00049j-B6 for bug-gnu-emacs@gnu.org; Fri, 08 Sep 2023 00:43:00 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qeTKg-0008CJ-5r for bug-gnu-emacs@gnu.org; Fri, 08 Sep 2023 00:43: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: Fri, 08 Sep 2023 04:43: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.169414816231485 (code B ref 65797); Fri, 08 Sep 2023 04:43:02 +0000 Original-Received: (at 65797) by debbugs.gnu.org; 8 Sep 2023 04:42:42 +0000 Original-Received: from localhost ([127.0.0.1]:41899 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qeTKL-0008Bl-Tm for submit@debbugs.gnu.org; Fri, 08 Sep 2023 00:42:42 -0400 Original-Received: from out-212.mta1.migadu.com ([95.215.58.212]:33200) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qeTKJ-0008Bb-D0 for 65797@debbugs.gnu.org; Fri, 08 Sep 2023 00:42:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=breatheoutbreathe.in; s=key1; t=1694148156; 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=mGavx0I9/tlZ0m1RUdfHstotg/Q0DB1d+XDxNHchy7g=; b=jYAHmaULVIh17HDIq/wn+xHcDyHdjNNhMsIKRbwKiL2av9ffJjoVYQz7MpqEKtUs+mYlMO RG+Fq/5mq3dF2WPlLeonIZlaDQd5NVQmTCu3ay8q+YvHxQvDfQ5MDvhj/vDerrrqOJOF9j v4EmDfg8oaRiUYadLEMRAcAO4h3N53c= 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:269718 Archived-At: --=-=-= Content-Type: text/plain Stefan Monnier writes: > - Replace `&optional arg` with `&rest args` and pass those args via > `apply`, so the number of args passed doesn't depend on the function > but on the caller. I like this idea. See patch. > - Always pass both args to the function (i.e. as documented in the > docstring). This isn't backwards compatible, is it? Joseph --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Don-t-use-func-arity-in-buffer-match-p.patch >From 5abc2ff47b0c61baecaddd615d7f2783fe8f9c0e Mon Sep 17 00:00:00 2001 From: Joseph Turner Date: Thu, 7 Sep 2023 21:27:01 -0700 Subject: [PATCH] Don't use func-arity in buffer-match-p * lisp/subr.el (buffer-match-p): Use &rest args instead of &optional arg so that the number of args passed doesn't depend on the function but on the caller. (Bug#65797) (match-buffers): Use &rest args instead of &optional arg to match function signature of buffer-match-p. * doc/lispref/buffers.texi (Buffer List): Update documentation to say ARGS instead of ARG. --- doc/lispref/buffers.texi | 23 ++++++++++------------- lisp/subr.el | 17 ++++++++--------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/doc/lispref/buffers.texi b/doc/lispref/buffers.texi index 86c47ae7310..fa29afd2697 100644 --- a/doc/lispref/buffers.texi +++ b/doc/lispref/buffers.texi @@ -957,11 +957,11 @@ with a @code{nil} @var{norecord} argument since this may lead to infinite recursion. @end defvar -@defun buffer-match-p condition buffer-or-name &optional arg +@defun buffer-match-p condition buffer-or-name &rest args This function checks if a buffer designated by @code{buffer-or-name} -satisfies the specified @code{condition}. Optional third argument -@var{arg} is passed to the predicate function in @var{condition}. A -valid @var{condition} can be one of the following: +satisfies the specified @code{condition}. Remaining arguments +@var{args} are passed using @code{apply} to the predicate function in +@var{condition}. A valid @var{condition} can be one of the following: @itemize @bullet{} @item A string, interpreted as a regular expression. The buffer @@ -969,23 +969,20 @@ satisfies the condition if the regular expression matches the buffer name. @item A predicate function, which should return non-@code{nil} if the buffer -matches. If the function expects one argument, it is called with -@var{buffer-or-name} as the argument; if it expects 2 arguments, the -first argument is @var{buffer-or-name} and the second is @var{arg} -(or @code{nil} if @var{arg} is omitted). +matches. @item A cons-cell @code{(@var{oper} . @var{expr})} where @var{oper} is one of @table @code @item (not @var{cond}) Satisfied if @var{cond} doesn't satisfy @code{buffer-match-p} with -the same buffer and @code{arg}. +the same buffer and @code{args}. @item (or @var{conds}@dots{}) Satisfied if @emph{any} condition in @var{conds} satisfies -@code{buffer-match-p}, with the same buffer and @code{arg}. +@code{buffer-match-p}, with the same buffer and @code{args}. @item (and @var{conds}@dots{}) Satisfied if @emph{all} the conditions in @var{conds} satisfy -@code{buffer-match-p}, with the same buffer and @code{arg}. +@code{buffer-match-p}, with the same buffer and @code{args}. @item derived-mode Satisfied if the buffer's major mode derives from @var{expr}. @item major-mode @@ -998,14 +995,14 @@ string) or @code{(and)} (empty conjunction). @end itemize @end defun -@defun match-buffers condition &optional buffer-list arg +@defun match-buffers condition &optional buffer-list &rest args This function returns a list of all buffers that satisfy the @code{condition}. If no buffers match, the function returns @code{nil}. The argument @var{condition} is as defined in @code{buffer-match-p} above. By default, all the buffers are considered, but this can be restricted via the optional argument @code{buffer-list}, which should be a list of buffers to consider. -Optional third argument @var{arg} will be passed to @var{condition} in +Remaining arguments @var{args} will be passed to @var{condition} in the same way as @code{buffer-match-p} does. @end defun diff --git a/lisp/subr.el b/lisp/subr.el index ce23a699624..87f08c669d4 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -7079,14 +7079,15 @@ 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 - arguments, and returns non-nil if the buffer matches, +- a predicate function that takes BUFFER-OR-NAME as its first + argument and remaining arguments ARGS, 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: * `derived-mode': the buffer matches if the buffer's major mode @@ -7110,9 +7111,7 @@ CONDITION is either: ((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 args)) (`(major-mode . ,mode) (eq (buffer-local-value 'major-mode buffer) @@ -7134,17 +7133,17 @@ CONDITION is either: (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 +Remaining 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 (buffer-match-p condition (get-buffer buf) args) (push buf bufs))) bufs)) -- 2.41.0 --=-=-=--