Subject: Re: bug#46374: 28.0.50; Ask me to save buffers only if they are under callers dir

From: Juri Linkov <[email-masked]>
Date: Mon, 15 Mar 2021 19:10:02 +0200

>> This means reusing the existing save-some-buffers-default-predicate
>> would be still preferable that guarantees backward-compatibility.
>> When it's customized to a predicate to filter out non-current subdirs,
>> then such call '(save-some-buffers t (lambda () (derived-mode-p 'org-mode)))'
>> still overrides the customized value.  This is the right thing to do.
>
> OK, back to my original implementation (i.e., adding a new option
> to `save-some-buffers-default-predicate`).
>
> I have been playing with the followig patch this morning.
> - it only adds a new option 'project-root
> - in case there is not a root there, then `default-directory` is taken
>   (this is a requirement from the OP, that ie me :-)
> - this patch doesn't interfere with the 2nd argument of `save-some-buffers'.
>
> Please, try it:

Thanks, I tried it.  The only problem is that the value 'project-root'
is hard-coded.  Would it be possible to create a real function from it?
This will require giving a proper prefix to it, indeed, such as e.g.
'save-some-buffers-project-root'.  But this will allow greater customization.
For example, everyone could copy its default implementation to the init file
and modify its logic to check separately project-root from subdirs, etc.
Also it will remove unnecessary details of getting the project root
from the implementation of 'save-some-buffers', and to avoid the need
to preload project.el.

Is it a problem that such separate function can't get
information about the original default-directory when
called as: (with-current-buffer buffer (funcall pred))?

Actually, this is the shortcoming of the old design of
save-some-buffers-default-predicate.  Is it possible to add
a new arg (with an original dir) to the predicate function?
Then for backward-compatibility before calling it, the function arity
could be checked, then called with one arg when it's accepted
by the function, otherwise call without args.