From baa257a9c60cb629b1ff60a5965530863e9c11e3 Mon Sep 17 00:00:00 2001 From: Ellis Kenyo 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. + * 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))))) + ;;; Project list -- 2.41.0