unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#65928: [PATCH] Introduce 'project-save-buffers'
@ 2023-09-13 21:26 me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-09-14  6:51 ` Juri Linkov
  0 siblings, 1 reply; 13+ messages in thread
From: me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-09-13 21:26 UTC (permalink / raw)
  To: 65928

[-- Attachment #1: Type: text/plain, Size: 183 bytes --]

Hi all,

A small patch to introduce a function from projectile that I feel is 
missing, please feel free to yell at me if this has already been 
rejected :)

Thanks all,

Ellis (@lkn)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Introduce-project-save-buffers.patch --]
[-- Type: text/x-diff; name=0001-Introduce-project-save-buffers.patch, Size: 2103 bytes --]

From baa257a9c60cb629b1ff60a5965530863e9c11e3 Mon Sep 17 00:00:00 2001
From: Ellis Kenyo <me@elken.dev>
Date: Wed, 13 Sep 2023 22:19:54 +0100
Subject: [PATCH] Introduce 'project-save-buffers'

* etc/NEWS: Update NEWS file.

* lisp/progmodes/project.el (project-save-buffers): Add new function to
save all modified buffers in current project.
---
 etc/NEWS                  |  4 ++++
 lisp/progmodes/project.el | 19 +++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index c146f464585..d9d5f7ffd94 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -828,6 +828,10 @@ additionally traverse the parent directories until a VCS root is found
 (if any), so that the ignore rules for that repository are used, and
 the file listing's performance is still optimized.
 
+*** New command 'project-save-buffers'.
+Save all the modified buffers in the current project. If no relevant
+buffers are found, print a message instead.
+
 \f
 * Incompatible Lisp Changes in Emacs 30.1
 
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 2e6ae89a443..45fb33dc77d 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -1646,6 +1646,25 @@ defun project-kill-buffers
           ((funcall query-user)
            (mapc #'kill-buffer bufs)))))
 
+;;;###autoload
+(defun project-save-buffers ()
+  "Save the modified buffers in the current project.
+Two buffers belong to the same project if their
+project instances, as reported by `project-current' in each
+buffer, are identical. "
+  (interactive)
+  (let* ((pr (project-current t))
+         (bufs (cl-remove-if-not (lambda (buf)
+                                   (and (buffer-file-name buf)
+                                        (buffer-modified-p buf)))
+                                 (project-buffers pr))))
+    (if (null bufs)
+        (message "No buffers to save in %s" (project-name pr))
+      (dolist (buf bufs)
+        (with-current-buffer buf
+          (save-buffer)))
+      (message "Saved %d buffers in %s" (length bufs) (project-name pr)))))
+
 \f
 ;;; Project list
 
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-09-18  6:56 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-13 21:26 bug#65928: [PATCH] Introduce 'project-save-buffers' me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-14  6:51 ` Juri Linkov
2023-09-14 13:45   ` Elken via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-14 14:09     ` Stefan Kangas
2023-09-14 14:12       ` Dmitry Gutov
2023-09-14 14:18       ` me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-14 14:30     ` Dmitry Gutov
2023-09-14 14:07   ` Stefan Kangas
2023-09-14 14:13     ` Dmitry Gutov
2023-09-14 14:16     ` me--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-15  6:32     ` Juri Linkov
2023-09-15 16:39       ` Dmitry Gutov
2023-09-18  6:56         ` Juri Linkov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).