From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#65797: `buffer-match-p` should not use `func-arity` Date: Fri, 08 Sep 2023 17:01:50 +0000 Message-ID: <87sf7o38g1.fsf_-_@posteo.net> References: <87v8cmct9b.fsf@breatheoutbreathe.in> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24111"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 65797@debbugs.gnu.org, Joseph Turner To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 08 19:03:47 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 1qeetV-00061I-VM for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 08 Sep 2023 19:03:46 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeeso-0003zt-9e; Fri, 08 Sep 2023 13:03:02 -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 1qeesm-0003yt-BC for bug-gnu-emacs@gnu.org; Fri, 08 Sep 2023 13:03: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 1qeesm-0000Vq-3A for bug-gnu-emacs@gnu.org; Fri, 08 Sep 2023 13:03:00 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qeeso-000554-Ct for bug-gnu-emacs@gnu.org; Fri, 08 Sep 2023 13:03:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 08 Sep 2023 17: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.169419252319453 (code B ref 65797); Fri, 08 Sep 2023 17:03:02 +0000 Original-Received: (at 65797) by debbugs.gnu.org; 8 Sep 2023 17:02:03 +0000 Original-Received: from localhost ([127.0.0.1]:45439 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qeerr-00053g-Ep for submit@debbugs.gnu.org; Fri, 08 Sep 2023 13:02:03 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:44023) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qeero-000537-NF for 65797@debbugs.gnu.org; Fri, 08 Sep 2023 13:02:01 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 2CC41240028 for <65797@debbugs.gnu.org>; Fri, 8 Sep 2023 19:01:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1694192512; bh=2dcTZOZ1om9QM26C9pw+U1Lh6k99ntqKCgcreLjMh3w=; h=From:To:Cc:Subject:Autocrypt:Date:Message-ID:MIME-Version:From; b=jvHd7rfC7bbCVmk9roNnxEDW5A1Z474nSZjzBMn+I0Gjhppd6ioOqvileGRZjCsQm 6aikKRqhik1mkTp9ucu2UolFUNODMLJLVMhSiaHRbdeFYTar2N4+wlBelfmbeZqNPM ejdpgG4SIx40COMBFzlq8c+qhYwbqwRGcVTZhdP+Y/5W68hSfnCDIFMcQsqhw9GMoU o2MlAemElVbJspPrx5xUstweHELkwaKX7Cto0CWESDWbx+AXRiJbXQvoUwZBUrz5D/ regmxneo/jz3t1WzsnSSqzzr0D9gO7kRSkJVDzb2nQ0ySSRSc58OeDQfCwnZtzeKu7 KV6R5hizAZOlg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Rj2TC16MXz9rxT; Fri, 8 Sep 2023 19:01:51 +0200 (CEST) In-Reply-To: (Stefan Monnier's message of "Thu, 07 Sep 2023 11:50:16 -0400") Autocrypt: addr=philipk@posteo.net; keydata= mDMEZBBQQhYJKwYBBAHaRw8BAQdAHJuofBrfqFh12uQu0Yi7mrl525F28eTmwUDflFNmdui0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiWBBMWCAA+FiEEDg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwMFCQHhM4AFCwkI BwIGFQoJCAsCBBYCAwECHgECF4AACgkQ8xYDWXahwulikAEA77hloUiSrXgFkUVJhlKBpLCHUjA0 mWZ9j9w5d08+jVwBAK6c4iGP7j+/PhbkxaEKa4V3MzIl7zJkcNNjHCXmvFcEuDgEZBBQQhIKKwYB BAGXVQEFAQEHQI5NLiLRjZy3OfSt1dhCmFyn+fN/QKELUYQetiaoe+MMAwEIB4h+BBgWCAAmFiEE Dg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwwFCQHhM4AACgkQ8xYDWXahwukm+wEA8cml4JpK NeAu65rg+auKrPOP6TP/4YWRCTIvuYDm0joBALw98AMz7/qMHvSCeU/hw9PL6u6R2EScxtpKnWof z4oM 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:269799 Archived-At: Stefan Monnier writes: > 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 :-( FWIW The intention here was to be able and specify simpler conditions that don't have to handle the alist. > - 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