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#57502: 29.0.50; Issue with `or' clause of buffer-match-p Date: Wed, 31 Aug 2022 12:50:14 +0000 Message-ID: <878rn47f21.fsf@posteo.net> References: <87o7w0fwnt.fsf@gmail.com> <87ilm87f78.fsf@posteo.net> 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="2720"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 57502@debbugs.gnu.org To: Augusto Stoffel Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Aug 31 14:51:22 2022 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 1oTNBh-0000Qt-4s for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 31 Aug 2022 14:51:21 +0200 Original-Received: from localhost ([::1]:38664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oTNBg-00033F-7z for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 31 Aug 2022 08:51:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46052) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oTNBP-000337-EU for bug-gnu-emacs@gnu.org; Wed, 31 Aug 2022 08:51:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48747) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oTNBN-0000km-TD for bug-gnu-emacs@gnu.org; Wed, 31 Aug 2022 08:51:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oTNBN-0001gW-K1 for bug-gnu-emacs@gnu.org; Wed, 31 Aug 2022 08:51:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 31 Aug 2022 12:51:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57502 X-GNU-PR-Package: emacs Original-Received: via spool by 57502-submit@debbugs.gnu.org id=B57502.16619502256414 (code B ref 57502); Wed, 31 Aug 2022 12:51:01 +0000 Original-Received: (at 57502) by debbugs.gnu.org; 31 Aug 2022 12:50:25 +0000 Original-Received: from localhost ([127.0.0.1]:38496 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oTNAm-0001fO-V1 for submit@debbugs.gnu.org; Wed, 31 Aug 2022 08:50:25 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:54557) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oTNAk-0001f6-1O for 57502@debbugs.gnu.org; Wed, 31 Aug 2022 08:50:23 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 12D6C240101 for <57502@debbugs.gnu.org>; Wed, 31 Aug 2022 14:50:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1661950216; bh=qpfizfo5xpvPsn20O7SWZGO1LYK24uyLA5RsF6b15g8=; h=From:To:Cc:Subject:Autocrypt:Date:From; b=glDZvfZa9vXDz5FnSFU0/EOE+nwazgYOJcM0BWh3B/sgQ6dDr3mTKYkfv5Fxig6VH VFYADOEHmI2rTta91Bkps9YQ+WIlQ85tD5jubTHUC4HZ3wtwD2rMEOz09aqCAZ49zE hCWZnBBn2y2AjbRMyXzlpgzsMLDiFgnz0xFLnyBOZqFjyi+XEGAHw5Q2ozOqpnI56Z LjbsQ0+Nndio5J5mI/9WbQliK/hU8cPvJ324cIoaNn88ETHfZ6fHnShw9PivtHnYqt Ylk0S/a4BhoPUOBzw/EfXjFI+qzQ7uRFhv6tW6GmU6ZYgSpBuGLbAsZgXCPOGfnpVt +NAEUVcasbbvw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4MHkY24fpYz9rxb; Wed, 31 Aug 2022 14:50:14 +0200 (CEST) In-Reply-To: <87ilm87f78.fsf@posteo.net> (Philip Kaludercic's message of "Wed, 31 Aug 2022 12:47:07 +0000") Autocrypt: addr=philipk@posteo.net; prefer-encrypt=nopreference; keydata= mDMEYHHqUhYJKwYBBAHaRw8BAQdAp3GdmYJ6tm5McweY6dEvIYIiry+Oz9rU4MH6NHWK0Ee0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiQBBMWCAA4FiEEDM2H44ZoPt9Ms0eHtVrAHPRh1FwFAmBx6lICGwMFCwkIBwIGFQoJ CAsCBBYCAwECHgECF4AACgkQtVrAHPRh1FyTkgEAjlbGPxFchvMbxzAES3r8QLuZgCxeAXunM9gh io0ePtUBALVhh9G6wIoZhl0gUCbQpoN/UJHI08Gm1qDob5zDxnIHuDgEYHHqUhIKKwYBBAGXVQEF AQEHQNcRB+MUimTMqoxxMMUERpOR+Q4b1KgncDZkhrO2ql1tAwEIB4h4BBgWCAAgFiEEDM2H44Zo Pt9Ms0eHtVrAHPRh1FwFAmBx6lICGwwACgkQtVrAHPRh1Fw1JwD/Qo7kvtib8jy7puyWrSv0MeTS g8qIxgoRWJE/KKdkCLEA/jb9b9/g8nnX+UcwHf/4VfKsjExlnND3FrBviXUW6NcB 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" Xref: news.gmane.io gmane.emacs.bugs:241193 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Philip Kaludercic writes: > Augusto Stoffel 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 =E2=80=9C(wrong-type-argument= listp >> special-mode)=E2=80=9D 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: --=-=-= Content-Type: text/plain Content-Disposition: inline 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)))) --=-=-=--