From: Philip Kaludercic <philipk@posteo.net>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 65797@debbugs.gnu.org, Joseph Turner <joseph@breatheoutbreathe.in>
Subject: bug#65797: `buffer-match-p` should not use `func-arity`
Date: Fri, 08 Sep 2023 17:01:50 +0000 [thread overview]
Message-ID: <87sf7o38g1.fsf_-_@posteo.net> (raw)
In-Reply-To: <jwvv8cmdmzz.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Thu, 07 Sep 2023 11:50:16 -0400")
Stefan Monnier <monnier@iro.umontreal.ca> 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
next prev parent reply other threads:[~2023-09-08 17:01 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-07 7:53 bug#65797: 29.0.92; func-arity should not return (0 . many) with apply-partially Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-07 12:35 ` Mattias Engdegård
2023-09-07 15:11 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-07 15:17 ` Mattias Engdegård
2023-09-07 13:43 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-07 15:50 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-08 4:40 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-08 6:46 ` Eli Zaretskii
2023-09-08 15:52 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-08 16:37 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-08 17:18 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-08 18:16 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-08 18:20 ` Eli Zaretskii
2023-09-11 16:57 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-11 18:58 ` Eli Zaretskii
2023-09-12 18:30 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-08 17:01 ` Philip Kaludercic [this message]
2023-09-12 18:28 ` bug#65797: `buffer-match-p` should not use `func-arity` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-13 21:50 ` Philip Kaludercic
2023-09-14 13:47 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-18 9:12 ` Philip Kaludercic
2023-09-18 11:55 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-18 17:23 ` Philip Kaludercic
2023-09-18 18:05 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-19 8:34 ` Philip Kaludercic
2023-09-19 10:06 ` Dmitry Gutov
2023-09-19 13:56 ` Philip Kaludercic
2023-09-19 16:13 ` Dmitry Gutov
2023-10-08 9:10 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-08 10:25 ` Dmitry Gutov
2023-10-09 21:40 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-12 4:53 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-12 11:34 ` Dmitry Gutov
2023-10-13 15:57 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-14 6:13 ` Eli Zaretskii
2023-10-14 14:31 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-15 6:13 ` Eli Zaretskii
2023-10-16 16:33 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-16 20:16 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-19 12:18 ` Eli Zaretskii
2023-10-21 2:52 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-15 0:45 ` Dmitry Gutov
2023-09-15 1:38 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-15 16:38 ` Dmitry Gutov
2023-09-15 17:54 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-15 18:00 ` Dmitry Gutov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sf7o38g1.fsf_-_@posteo.net \
--to=philipk@posteo.net \
--cc=65797@debbugs.gnu.org \
--cc=joseph@breatheoutbreathe.in \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).