Subject: bug#55310: 27.2; vc-revert: unhelpful error message when modified buffers exist

From: Sean Whitton <[email-masked]>
Date: Sat, 15 Mar 2025 16:04:53 +0800

tag 55310 + patch
thanks

Hello again Dmitry,

Okay, how do these look?

-- 
Sean Whitton
>From e1359bd44de4b139f4cd971c07d356ebea754ee0 Mon Sep 17 00:00:00 2001
From: Sean Whitton <[email-masked]>
Date: Sat, 15 Mar 2025 16:02:56 +0800
Subject: [PATCH 1/2] vc-revert: Offer to save modified buffers (bug#55310)

* lisp/vc/vc.el (vc-revert): Offer to save modified buffers that
otherwise prevent proceeding with the revert (bug#55310).
---
 lisp/vc/vc.el | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index bc96173d198..5c2f848b891 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -3243,14 +3243,21 @@ vc-revert
     ;; show the changes and ask for confirmation to discard them.
     (when (or (not files) (memq (buffer-file-name) files))
       (vc-buffer-sync nil))
-    (dolist (file files)
-      (let ((buf (get-file-buffer file)))
-	(when (and buf (buffer-modified-p buf))
-	  (error "Please kill or save all modified buffers before reverting")))
-      (when (vc-up-to-date-p file)
-	(if (yes-or-no-p (format "%s seems up-to-date.  Revert anyway? " file))
-	    (setq queried t)
-	  (error "Revert canceled"))))
+    (save-some-buffers nil (lambda ()
+                             (member (buffer-file-name) files)))
+    (let (needs-save)
+      (dolist (file files)
+        (let ((buf (get-file-buffer file)))
+	  (when (and buf (buffer-modified-p buf))
+            (push buf needs-save)))
+        (when (vc-up-to-date-p file)
+	  (if (yes-or-no-p (format "%s seems up-to-date.  Revert anyway? "
+                                   file))
+	      (setq queried t)
+	    (error "Revert canceled"))))
+      (when needs-save
+        (error "Cannot revert with these buffers unsaved: %s"
+               (string-join (mapcar #'buffer-name needs-save) ", "))))
     (unwind-protect
 	(when (if vc-revert-show-diff
 		  (progn
-- 
2.45.2

>From 39d812ce59362b6da359a6f338730735b29b7f0d Mon Sep 17 00:00:00 2001
From: Sean Whitton <[email-masked]>
Date: Sat, 15 Mar 2025 16:03:38 +0800
Subject: [PATCH 2/2] New project-save-some-buffers command

* lisp/progmodes/project.el (project-save-some-buffers): New command.
(project-prefix-map): Bind it to C-x p C-x s.
---
 lisp/progmodes/project.el | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index d954b78a745..e2cd5bfa231 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -903,6 +903,7 @@ project-prefix-map
     (define-key map "x" 'project-execute-extended-command)
     (define-key map "o" 'project-any-command)
     (define-key map "\C-b" 'project-list-buffers)
+    (define-key map "\C-xs" 'project-save-some-buffers)
     map)
   "Keymap for project commands.")
 
@@ -1828,6 +1829,12 @@ project-kill-buffers
           ((funcall query-user)
            (mapc #'kill-buffer bufs)))))
 
+;;;###autoload
+(defun project-save-some-buffers (arg)
+  "Like `save-some-buffers', but only for this project's buffers."
+  (interactive "P")
+  (save-some-buffers arg (save-some-buffers-root)))
+
 
 ;;; Project list
 
-- 
2.45.2