From: Philip Kaludercic <philipk@posteo.net>
To: Augusto Stoffel <arstoffel@gmail.com>
Cc: 57502@debbugs.gnu.org
Subject: bug#57502: 29.0.50; Issue with `or' clause of buffer-match-p
Date: Sat, 03 Sep 2022 11:04:20 +0000 [thread overview]
Message-ID: <87edwsk9cb.fsf@posteo.net> (raw)
In-Reply-To: <878rn47f21.fsf@posteo.net> (Philip Kaludercic's message of "Wed, 31 Aug 2022 12:50:14 +0000")
Philip Kaludercic <philipk@posteo.net> writes:
> Philip Kaludercic <philipk@posteo.net> writes:
>
>> Augusto Stoffel <arstoffel@gmail.com> writes:
>>
>>> This buffer-match-p condition does the expected job:
>>>
>>> (buffer-match-p '(or "\\*" (derived-mode . special-mode))
>>> (current-buffer))
>>>
>>> But this presumably equivalent one gives a “(wrong-type-argument listp
>>> special-mode)” error:
>>>
>>> (buffer-match-p '(or (and "\\*")
>>> (derived-mode . special-mode))
>>> (current-buffer))
>>
>> It seems to me that the issue is related to the `and' being wrapped by
>> an `or', specifically because of a typo in the handling of `and':
>>
>> diff --git a/lisp/subr.el b/lisp/subr.el
>> index 2ffc594997..0350c16ccf 100644
>> --- a/lisp/subr.el
>> +++ b/lisp/subr.el
>> @@ -7014,8 +7014,8 @@ buffer-match-p
>> (funcall match (cdr condition)))
>> ((eq (car-safe condition) 'and)
>> (catch 'fail
>> - (dolist (c (cdr conditions))
>> - (unless (funcall match c)
>> + (dolist (c (cdr condition))
>> + (unless (funcall match (list c))
>> (throw 'fail nil)))
>> t)))
>> (throw 'match t)))))))
>>
>>
>> As you have pointed out to me privately, it might make sense to rewrite
>> the case distinction using pcase, to avoid simple mistakes like these.
>
> That might look something like this:
>
> diff --git a/lisp/subr.el b/lisp/subr.el
> index 2ffc594997..db1dc25044 100644
> --- a/lisp/subr.el
> +++ b/lisp/subr.el
> @@ -6992,32 +6992,32 @@ buffer-match-p
> (lambda (conditions)
> (catch 'match
> (dolist (condition conditions)
> - (when (cond
> - ((eq condition t))
> - ((stringp condition)
> - (string-match-p condition (buffer-name buffer)))
> - ((functionp condition)
> - (if (eq 1 (cdr (func-arity condition)))
> - (funcall condition buffer)
> - (funcall condition buffer arg)))
> - ((eq (car-safe condition) 'major-mode)
> - (eq
> - (buffer-local-value 'major-mode buffer)
> - (cdr condition)))
> - ((eq (car-safe condition) 'derived-mode)
> - (provided-mode-derived-p
> - (buffer-local-value 'major-mode buffer)
> - (cdr condition)))
> - ((eq (car-safe condition) 'not)
> - (not (funcall match (cdr condition))))
> - ((eq (car-safe condition) 'or)
> - (funcall match (cdr condition)))
> - ((eq (car-safe condition) 'and)
> - (catch 'fail
> - (dolist (c (cdr conditions))
> - (unless (funcall match c)
> - (throw 'fail nil)))
> - t)))
> + (when (pcase condition
> + ('t t)
> + ((pred stringp)
> + (string-match-p condition (buffer-name buffer)))
> + ((pred functionp)
> + (if (eq 1 (cdr (func-arity condition)))
> + (funcall condition buffer)
> + (funcall condition buffer arg)))
> + (`(major-mode . ,mode)
> + (eq
> + (buffer-local-value 'major-mode buffer)
> + mode))
> + (`(derived-mode . ,mode)
> + (provided-mode-derived-p
> + (buffer-local-value 'major-mode buffer)
> + mode))
> + (`(not . cond)
> + (not (funcall match cond)))
> + (`(or . ,args)
> + (funcall match args))
> + (`(and . ,args)
> + (catch 'fail
> + (dolist (c args)
> + (unless (funcall match (list c))
> + (throw 'fail nil)))
> + t)))
> (throw 'match t)))))))
> (funcall match (list condition))))
Are there any objections against applying this change? From what I see
pcase is used elsewhere in seq, so it should be possible to recognise
and expand the macro, right?
next prev parent reply other threads:[~2022-09-03 11:04 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-31 12:02 bug#57502: 29.0.50; Issue with `or' clause of buffer-match-p Augusto Stoffel
2022-08-31 12:47 ` Philip Kaludercic
2022-08-31 12:50 ` Philip Kaludercic
2022-08-31 16:22 ` Augusto Stoffel
2022-08-31 16:30 ` Philip Kaludercic
2022-09-03 11:04 ` Philip Kaludercic [this message]
2022-09-03 11:10 ` Eli Zaretskii
2022-09-03 11:19 ` Philip Kaludercic
2022-09-03 11:54 ` Lars Ingebrigtsen
2022-09-03 12:56 ` Philip Kaludercic
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=87edwsk9cb.fsf@posteo.net \
--to=philipk@posteo.net \
--cc=57502@debbugs.gnu.org \
--cc=arstoffel@gmail.com \
/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).