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: 29.0.92; func-arity should not return (0 . many) with apply-partially Date: Thu, 07 Sep 2023 11:50:16 -0400 Message-ID: References: <87v8cmct9b.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="16868"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 65797@debbugs.gnu.org To: Joseph Turner Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 07 17:51:23 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 1qeHHu-000457-6d for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 07 Sep 2023 17:51:22 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeHHa-0000gz-Gs; Thu, 07 Sep 2023 11:51:03 -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 1qeHHY-0000en-QX for bug-gnu-emacs@gnu.org; Thu, 07 Sep 2023 11:51: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 1qeHHY-00058m-Ik for bug-gnu-emacs@gnu.org; Thu, 07 Sep 2023 11:51:00 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qeHHa-0005pf-8y for bug-gnu-emacs@gnu.org; Thu, 07 Sep 2023 11:51:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 07 Sep 2023 15:51: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.169410182922370 (code B ref 65797); Thu, 07 Sep 2023 15:51:02 +0000 Original-Received: (at 65797) by debbugs.gnu.org; 7 Sep 2023 15:50:29 +0000 Original-Received: from localhost ([127.0.0.1]:41136 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qeHH3-0005oj-95 for submit@debbugs.gnu.org; Thu, 07 Sep 2023 11:50:29 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:25681) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qeHH0-0005oG-JB; Thu, 07 Sep 2023 11:50:27 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id EA449807A7; Thu, 7 Sep 2023 11:50:18 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1694101817; bh=IvQPlC+7GJ888GMegvfMX2k4Df8roKipxYVrNYqVWyg=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=GB1ortxW0yfXuWZK2IkGyjK17CY9oc5Xdb8Bom0moIoz63asBGHqyirUTTkox7/SP vgpsutv+lz3/gzsT/B3ukG3okpjeuYSPrcrMJaYK1DuwjcwpfajJBxvE9/0nMIUGOq QtVKiz3gCHdm9fmBfkvfhfekzzRDH47yQkvu2wxp5MlChd57EC/rsJZO0y8vqqFrsd aOKUACY4g1PjSXvzBYGNXJbftKCckkaTYAfSThlzGDi3jB2FnlNb4SyjvMvb3X6DrJ zKcBkSxDjZOFP21I+shTSI9RBFqcWBbdYxiQaEFCj8ec4DB/o1MvD+sOUpcE7/4BQC t4s0+OvGsxX4A== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 921CF8044C; Thu, 7 Sep 2023 11:50:17 -0400 (EDT) Original-Received: from pastel (69-165-136-223.dsl.teksavvy.com [69.165.136.223]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 6BE15120270; Thu, 7 Sep 2023 11:50:17 -0400 (EDT) In-Reply-To: <87v8cmct9b.fsf@breatheoutbreathe.in> (Joseph Turner's message of "Thu, 07 Sep 2023 00:53:07 -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:269680 Archived-At: retitle 65797 `buffer-match-p` should not use `func-arity` thanks > (match-buffers (apply-partially #'local-variable-p 'foo)) Note that this call is incorrect according to the docstring of `buffer-match-p`, which says: CONDITION is either: [...] - a predicate function that takes BUFFER-OR-NAME and ARG as arguments, and returns non-nil if the buffer matches, IOW, you have to pass a function that accepts 2 arguments, whereas your (apply-partially #'local-variable-p 'foo) only accepts one. The Texinfo docs instead say: @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). but in general we can't reliably decide whether "the function expects one argument", so we can't implement the above promise in a reliable way. `apply-partially` is just one case where this shows up, but the problem is much more general. `buffer-match-p` uses the `func-arity` hack to try to make it work with some functions of 1 argument, but it's just a hack. We should get rid of this hack. Here are some possible replacements (by order of my preference): - 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. - Always pass both args to the function (i.e. as documented in the docstring). - Get rid of `&optional arg` altogether. AFAICT, most callers don't use it, but it's used for `display-buffer-alist`, so it would have further consequences there :-( - Use a hack like (condition-case nil (funcall condition buffer-or-name arg) (wrong-number-of-arguments (funcall condition buffer-or-name))) which handles the arity mismatch a bit more reliably, but at the cost of occasionally running the function twice. Stefan