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

From: Tino Calancha <[email-masked]>
Date: Sun, 07 Mar 2021 21:34:13 +0100

Sorry for the late response: many meetings with investors.
Then I went on a vacation to my castle in Seychelles.

Eli Zaretskii <[email-masked]> writes:
>> You are assuming that when save-some-buffers runs, the default
>> directory is the same as when you issued whatever command triggered
>> the call to save-some-buffers?  Is that assumption really accurate?
I don't know if there are some corner cases.
In my experience, I am hit by this (very often) when using packages
that call `compilation-start`.  Prominent examples are `rgrep` or
when downloading ELPA updates (they will trigger a compilation as well).
The patch is serving me very well so far.

Juri Linkov <[email-masked]> writes:
>>  @vindex save-some-buffers-default-predicategn
>> +@vindex save-some-buffers-restrict-to-caller-subdirs
>>  You can customize the value of
>> -@code{save-some-buffers-default-predicate} to control which buffers
>> -Emacs will ask about.
>> +@code{save-some-buffers-default-predicate} and
>> +@code{save-some-buffers-restrict-to-caller-subdirs} to control which
>> +buffers Emacs will ask about.
>
> Why not simply add a new option to the existing variable
> save-some-buffers-default-predicate?  For example:
>
> (defcustom save-some-buffers-default-predicate nil
>   "Default predicate for `save-some-buffers'."
>   :group 'auto-save
>   ;; FIXME nil should not be a valid option, let alone the default,
>   ;; eg so that add-function can be used.
>   :type '(choice (const :tag "Default" nil)
>                  (const :tag "Subdirs of default directory" default-directory)
>                  (const :tag "Project root" project-root)
>                  function)

Indeed, this was my initial implemention.
Then I moved to the one I shared here; I found my second version
superior for the following reason:

1. Users can restrict the buffer default directory AND still pass a
   predicate to filter by any other thing they wish;
   i.e. you don't need to chose either one of the other.

2. I find it cleaner having it in a separated option.

Stefan Monnier <[email-masked]>
>> If we want to have such a behavior and make it optional, it's fine by me.
It's optional in my patch; some people might like the current situation:
been prompted about any modified buffer.

>> But if we want to make it a default behavior, then I think
>> `project-root` would be much a much better choice (when available) than
>> `default-directory`.

Would this `project-root` feature work for `rgrep`?
I mean, I can call `rgrep` in my local computer, out of any project, for
instance to search for information in some plain text notes.  In this
case, `default-directory` works quite well.