Subject: bug#49980: 28.0.50; [PATCH] Should we have project-save-buffers?

From: Giap Tran <[email-masked]>
Date: Tue, 10 Aug 2021 16:23:34 +0700

Hello,

After using `project-query-replace-regexp to query and replace. I see we don't have the function to save all buffers in project.
So after learning from projectile package. I have this patch, hope it is
useful. Thanks

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 4620ea8f47..b257222e21 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -1395,5 +1395,22 @@ to directory DIR."
           (project-current-inhibit-prompt t))
       (call-interactively command))))
 
+(defun project-save-buffers ()
+  "Save all project buffers."
+  (interactive)
+  (let* ((project (project-current t))
+         (buffers (project--buffer-list project))
+         (modified-buffers (cl-remove-if-not (lambda (buf)
+                                               (and (buffer-file-name buf)
+                                                    (buffer-modified-p buf)))
+                                             buffers)))
+    (if (null modified-buffers)
+        (message "No buffers need saving")
+      (dolist (buf modified-buffers)
+        (with-current-buffer buf
+          (save-buffer)))
+      (message "Saved %d buffers" (length modified-buffers)))))
+
+
 (provide 'project)
 ;;; project.el ends here