From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Hauke Rehfeld Newsgroups: gmane.emacs.bugs Subject: bug#46374: Regression: erronous calls to PRED switch major-mode of unrelated modified buffers Date: Mon, 30 Aug 2021 18:04:31 +0200 Message-ID: <87sfyqdijl.fsf@haukerehfeld.de> References: <878s7z4ihk.fsf@gmail.com> <87r1ecilqn.fsf@haukerehfeld.de> <87a6l0cjyj.fsf@mail.linkov.net> <87bl5f1lbn.fsf@mail.linkov.net> <87v93ncg0n.fsf@haukerehfeld.de> Mime-Version: 1.0 Content-Type: text/plain; format=flowed Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2939"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.6.3; emacs 28.0.50 Cc: 46374@debbugs.gnu.org, Stefan Monnier , Tino Calancha To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Aug 30 18:09:16 2021 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 1mKjqV-0000aL-8Y for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 30 Aug 2021 18:09:15 +0200 Original-Received: from localhost ([::1]:36038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mKjqT-0007tC-Rj for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 30 Aug 2021 12:09:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42976) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKjoM-00058h-41 for bug-gnu-emacs@gnu.org; Mon, 30 Aug 2021 12:07:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48486) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mKjoL-0006jE-S0 for bug-gnu-emacs@gnu.org; Mon, 30 Aug 2021 12:07:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mKjoL-0000or-KZ for bug-gnu-emacs@gnu.org; Mon, 30 Aug 2021 12:07:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Hauke Rehfeld Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 30 Aug 2021 16:07:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46374 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: fixed Original-Received: via spool by 46374-submit@debbugs.gnu.org id=B46374.16303395683044 (code B ref 46374); Mon, 30 Aug 2021 16:07:01 +0000 Original-Received: (at 46374) by debbugs.gnu.org; 30 Aug 2021 16:06:08 +0000 Original-Received: from localhost ([127.0.0.1]:60029 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mKjnP-0000mv-OQ for submit@debbugs.gnu.org; Mon, 30 Aug 2021 12:06:07 -0400 Original-Received: from helin.uberspace.de ([185.26.156.195]:45596) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mKjnK-0000mJ-4T for 46374@debbugs.gnu.org; Mon, 30 Aug 2021 12:06:02 -0400 Original-Received: (qmail 1959 invoked from network); 30 Aug 2021 16:05:55 -0000 Original-Received: from localhost (HELO localhost) (127.0.0.1) by helin.uberspace.de with SMTP; 30 Aug 2021 16:05:55 -0000 In-reply-to: <87v93ncg0n.fsf@haukerehfeld.de> 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:213034 Archived-At: Sorry, that was broken when called with an empty `pred' argument. This should work (but testing all code paths is indeed not a simple task): ;; Allow `pred' to be a function that returns a predicate ;; with lexical bindings in its original environment (bug#46374). (when (functionp pred) ;; don't use the result of `pred' if it returns the current buffer major-mode (with-temp-buffer (let ((pred-fun (funcall pred))) (when (and (functionp pred-fun) (not (eq major-mode pred-fun))) (setq pred pred-fun))))) Hauke Rehfeld writes: > I'm way not deep enough into this issue, but how about using a > temp buffer and checking for major mode equivalent (can pred > ever > reasonably be fundamental-mode?): > > ;; Allow `pred' to be a function that returns a predicate > ;; with lexical bindings in its original environment > (bug#46374). > (let ((pred-fun (and (functionp pred)))) > ;; don't use the result of `pred' if it returns the current > buffer major-mode > (with-temp-buffer > (let ((pred-fun (funcall pred))) > (when (and (functionp pred-fun) (not (eq major-mode > pred-fun))) > (setq pred pred-fun))))) > > > Juri Linkov writes: > >>> This means we need to invent some ad-hoc format to distinguish >>> between >>> these cases. For example, to create a lexically-bound >>> predicate >>> at the beginning, it could be called with e.g. >>> >>> (save-some-buffers t '(eval . save-some-buffers-root)) >>> >>> and defcustom will look like: >>> >>> (defcustom save-some-buffers-default-predicate nil >>> :type '(choice (const :tag "Default" nil) >>> (function :tag "Only in subdirs of root" >>> (eval . save-some-buffers-root)) >>> (function :tag "Custom function")) >> >> Or maybe simply '(save-some-buffers-root): >> >> (defcustom save-some-buffers-default-predicate nil >> :type '(choice (const :tag "Default" nil) >> (function :tag "Only in subdirs of root" >> (save-some-buffers-root)) >> >> Then the following two calls both will have exactly the same >> effect: >> >> (save-some-buffers t '(save-some-buffers-root)) >> (save-some-buffers t (save-some-buffers-root))