GNU bug report logs - #46374
28.0.50; Ask me to save buffers only if they are under callers dir

Previous Next

Package: emacs;

Reported by: Tino Calancha <tino.calancha <at> gmail.com>

Date: Sun, 7 Feb 2021 22:33:01 UTC

Severity: wishlist

Tags: fixed

Merged with 50380

Fixed in version 28.0.60

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Hauke Rehfeld <hauke <at> haukerehfeld.de>
To: Juri Linkov <juri <at> linkov.net>
Cc: 46374 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>, Tino Calancha <tino.calancha <at> gmail.com>
Subject: bug#46374: Regression: erronous calls to PRED switch major-mode of unrelated modified buffers
Date: Mon, 30 Aug 2021 18:04:31 +0200
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 <hauke <at> haukerehfeld.de> 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 <juri <at> linkov.net> 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))




This bug report was last modified 3 years and 191 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.