GNU bug report logs - #46374
28.0.50; Ask me to save buffers only if they are under callers dir

Previous Next

Package: emacs;

Reported by: Tino Calancha <tino.calancha <at> gmail.com>

Date: Sun, 7 Feb 2021 22:33:01 UTC

Severity: wishlist

Tags: fixed

Merged with 50380

Fixed in version 28.0.60

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Tino Calancha <tino.calancha <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: 46374 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>, Quách Mỹ Uyên Nhi <uyennhi.qm <at> gmail.com>
Subject: bug#46374: 28.0.50; Ask me to save buffers only if they are under callers dir
Date: Sun, 18 Apr 2021 16:27:33 +0200
Juri Linkov <juri <at> linkov.net> writes:

>> I have noticed that I haven't enabled lexical-binding in my .emacs file,
>> which it is crucial for my use case.
>> To avoid surprises, I have mentioned this issue in the docstring.
>
> Unfortunately, your patch is truncated.  Could you send a complete patch?

Here is:

--8<-----------------------------cut here---------------start------------->8---
commit 73b2ff479ab1f9af399e6d09ceff85bb8eaa66b0
Author: Tino Calancha <ccalancha <at> suse.com>
Date:   Sun Apr 18 16:14:13 2021 +0200

    patch for Bug#46374
    
    On top of commit 2822246b5d8154d0166e17ffd28a1d85b57d68aa

diff --git a/lisp/files.el b/lisp/files.el
index 7440c11a21..56ef949eeb 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -5520,6 +5520,28 @@ save-some-buffers-default-predicate
   :type '(choice (const :tag "Default" nil) function)
   :version "26.1")
 
+(defvar save-some-buffers-fun-function (lambda () save-some-buffers-default-predicate)
+  "Overrides the behavior of `save-some-buffers-default-predicate'.
+This variable's value should be a function, which will be called
+by `save-some-buffers' with no arguments to override the default predicate.
+This allow you to capture variables in the environment of `save-some-buffers',
+and use them to decide which buffers must be saved.
+For instance, the following expression restricts to save only buffers inside
+the project from where `save-some-buffers' is invoked, or under the
+caller's `default-directory' if no project is found:
+
+\(lambda ()
+  (let ((project-dir
+         (or (and (project-current) (project-root (project-current)))
+             default-directory)))
+    (lambda () (file-in-directory-p default-directory project-dir))))
+
+Note that, the example above requires that you evaluate this expression
+in a file or buffer with lexical binding enabled.")
+
+(defun save-some-buffers-fun ()
+  (funcall save-some-buffers-fun-function))
+
 (defun save-some-buffers (&optional arg pred)
   "Save some modified file-visiting buffers.  Asks user about each one.
 You can answer `y' or SPC to save, `n' or DEL not to save, `C-r'
@@ -5547,7 +5569,7 @@ save-some-buffers
 change the additional actions you can take on files."
   (interactive "P")
   (unless pred
-    (setq pred save-some-buffers-default-predicate))
+    (setq pred (save-some-buffers-fun)))
   (let* ((switched-buffer nil)
          (save-some-buffers--switch-window-callback
           (lambda (buffer)

--8<-----------------------------cut here---------------end--------------->8---




This bug report was last modified 3 years and 192 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.