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: Tino Calancha <tino.calancha <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: 46374 <at> debbugs.gnu.org, Hauke Rehfeld <hauke <at> haukerehfeld.de>, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: bug#46374: 28.0.50; Ask me to save buffers only if they are under callers dir
Date: Sun, 05 Sep 2021 12:09:26 +0200
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):

Hi Juri!

Being able to set `save-some-buffers-root' as the value of
`save-some-buffers-default-predicate' is easy for users.

The problem I see is that it hides the real nature of `save-some-buffers-root':
- it's not a predicate (as the docstring of `save-some-buffers-default-predicate' suggests).
- it's a function generating the default predicate.

We can make the distinction (default predicate <-> func generating a default predicate)
more clear if we put the generating functions in a list.

Then, we can restrict the allowed pred-fun to the elements inside such a list.

I have played today with this quick-and-dirty patch:
How do you think?

--8<-----------------------------cut here---------------start------------->8---
diff --git a/lisp/files.el b/lisp/files.el
index 7e4bdab507..91582ec9b0 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -5731,6 +5731,13 @@ save-some-buffers-action-alist
 (defvar-local buffer-save-without-query nil
   "Non-nil means `save-some-buffers' should save this buffer without asking.")
 
+(defvar save-some-buffers-fn-generating-pred '(save-some-buffers-root)
+  "List of supported functions to generate a default predicate for `save-some-buffers'.
+Each element is a function with no arguments that returns a predicate
+suitable for `save-some-buffers'.
+You can use any of these functions as the value of
+`save-some-buffers-default-predicate'.")
+
 (defcustom save-some-buffers-default-predicate nil
   "Default predicate for `save-some-buffers'.
 
@@ -5789,7 +5796,8 @@ save-some-buffers
     (setq pred save-some-buffers-default-predicate))
   ;; 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) (funcall pred))))
+  (let ((pred-fun (and (memq pred save-some-buffers-fn-generating-pred)
+                       (funcall pred))))
     (when (functionp pred-fun)
       (setq pred pred-fun)))
   (let* ((switched-buffer nil)



--8<-----------------------------cut here---------------end--------------->8---




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

Previous Next


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