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

From: Stefan Monnier <[email-masked]>
Date: Tue, 16 Mar 2021 18:54:12 -0400

>   (let ((one-arg (equal (func-arity pred) '(1 . 1))))

Please don't.  This will break down as soon as you set the function
with `add-function`.
[ I wish people could forget that `func-arity` exists.  Its use is
  a bug-in-the-waiting in most cases.  ]

>     (dolist (buffer (buffer-list))
>       (if one-arg
>           (funcall pred buffer)
>         (with-current-buffer buffer (funcall pred))))
>
> Then 'default-directory' of the original buffer will be preserved
> inside the pred function, so it will be possible to call the pred function
> with one arg 'buffer' and check whether the buffer is under the original
> 'default-directory' with
>
>   (file-in-directory-p (buffer-local-value 'default-directory buffer)
>                        default-directory)

How 'bout using something like `isearch-search-fun-function`:
i.e. *compute* the predicate by calling
save-some-buffers-predicate-function, so this function can return
a predicate that remembers the default-dir of the original buffer (or
any other aspect relevant to the state from which we started the
save-some-buffers).

        Stefan