Subject: Re: bug#65414: save-some-buffers-functions are unexpectedly called when save-some-buffers pred is non-nil

From: Joseph Turner <[email-masked]>
Date: Sat, 26 Aug 2023 00:32:23 -0700

Eli Zaretskii <[email-masked]> writes:
> So your problem is with Lisp programs that add functions to
> save-some-buffers-functions, but don't expect or don't want those
> functions to be called each time save-some-buffers is invoked?

Yes.

> I'm not sure how did those Lisp programs get the idea that
> save-some-buffers-functions will not be called always -- is it hinted
> by some documentation somewhere?  If not, I'd say that those Lisp
> programs have a bug that needs to be fixed in those programs.  Right?

I agree.

> In any case, not calling save-some-buffers-functions when PRED is
> non-nil is not something we can do, as that would be an incompatible
> behavior change.  We could perhaps add PRED to the arguments with
> which save-some-buffers-functions are called, as an optional argument.
> Would that be satisfactory?

Yes, that would solve the interference between Magit and hyperdrive.el.

See patch.

Thank you!

Joseph

>From 28e8745b579da5f83afc7f9eb5b5ed2df2f3204e Mon Sep 17 00:00:00 2001
From: Joseph Turner <[email-masked]>
Date: Sat, 26 Aug 2023 00:50:28 -0700
Subject: [PATCH] Pass PRED to each of save-some-buffers-functions

* lisp/abbrev.el (abbrev--possibly-save): Ignore PRED
* lisp/files.el (save-some-buffers-functions): Fix documentation
(save-some-buffers): Pass PRED to each of save-some-buffers-functions
---
 lisp/abbrev.el | 2 +-
 lisp/files.el  | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lisp/abbrev.el b/lisp/abbrev.el
index e1311dbc83b..43e7c7e5e5d 100644
--- a/lisp/abbrev.el
+++ b/lisp/abbrev.el
@@ -1242,7 +1242,7 @@ which see."
               '(edit-abbrevs-mode-font-lock-keywords nil nil ((?_ . "w"))))
   (setq font-lock-multiline nil))
 
-(defun abbrev--possibly-save (query &optional arg)
+(defun abbrev--possibly-save (query &optional arg _pred)
   ;; Query mode.
   (if (eq query 'query)
       (and save-abbrevs abbrevs-changed)
diff --git a/lisp/files.el b/lisp/files.el
index 29d109ab385..6ab10cc3310 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -6003,8 +6003,8 @@ function should return non-nil if there is something to be
 saved (but it should not actually save anything).
 
 If the first argument is something else, then the function should
-save according to the value of the second argument, which is the
-ARG argument from `save-some-buffers'.")
+save according to the values of the second and third arguments,
+which are the ARG and PRED arguments from `save-some-buffers'.")
 
 (defun save-some-buffers (&optional arg pred)
   "Save some modified file-visiting buffers.  Asks user about each one.
@@ -6099,7 +6099,7 @@ after saving the buffers."
 	         save-some-buffers-action-alist))
           ;; Allow other things to be saved at this time, like abbrevs.
           (dolist (func save-some-buffers-functions)
-            (setq inhibit-message (or (funcall func nil arg) inhibit-message)))
+            (setq inhibit-message (or (funcall func nil arg pred) inhibit-message)))
           (or queried (> files-done 0) inhibit-message
 	      (cond
 	       ((null autosaved-buffers)
-- 
2.41.0