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

From: Juri Linkov <[email-masked]>
Date: Wed, 28 Apr 2021 22:51:51 +0300

> I have found a way to merge the two approaches.  Not sure if
> idiomatic, but it works.
>
> [The patch omits NEWS entry and documentation; I will add those once we
> found the implementation]

Thanks, now your patch is taking a good shape.  I'm testing it now.
Here is a condensed version of your patch to think about it.

#+begin_src emacs-lisp
(defvar save-some-buffers-default-fun (lambda () nil))

(defvar save-some-buffers-in-current-project-fun
  (lambda ()
    (let ((project-dir (or (and (project-current) (project-root (project-current)))
                           default-directory)))
      (lambda () (file-in-directory-p default-directory project-dir)))))

(defcustom save-some-buffers-default-predicate save-some-buffers-default-fun
  :type `(choice
          (function :tag "All buffers" :value ,save-some-buffers-default-fun)
          (function :tag "Buffers inside current project"
                    :value ,save-some-buffers-in-current-project-fun)))

(defun save-some-buffers-fun ()
  (funcall save-some-buffers-default-predicate))

(defun save-some-buffers (&optional arg pred)
  (unless pred
    (setq pred (save-some-buffers-fun)))
#+end_src

I see a problem in save-some-buffers-fun: what if
save-some-buffers-default-predicate is still customized to nil?
This value is currently allowed.  It seems it should check
if it's a function, then call it.  Also needs to check if the function
doesn't return another lambda, then return its original value.