]> git.eshelyaron.com Git - emacs.git/commitdiff
Update gnus-draft-check-draft-articles to use find-buffer-visiting
authorEric Abrahamsen <eric@ericabrahamsen.net>
Fri, 10 May 2024 19:38:57 +0000 (12:38 -0700)
committerEshel Yaron <me@eshelyaron.com>
Sun, 12 May 2024 15:48:47 +0000 (17:48 +0200)
* lisp/gnus/gnus-draft.el (gnus-draft-check-draft-articles): Don't loop
through all the buffers; this removes the need for the `file-remote-p'
check. Also give the user some nicer feedback about what's going on.

(cherry picked from commit 41bfca00051b590c24fca9e8614b67724fab272d)

lisp/gnus/gnus-draft.el

index 7c52e8750e4bb3b3dd63f7b9c1badd151db91713..c4266a7060ecd8d694489e829d8bfc03937b5f13 100644 (file)
@@ -289,30 +289,25 @@ If DONT-POP is nil, display the buffer after setting it up."
 (defun gnus-draft-check-draft-articles (articles)
   "Check whether the draft articles ARTICLES are under edit."
   (when (equal gnus-newsgroup-name "nndraft:drafts")
-    (let ((buffers (buffer-list))
-         file buffs buff)
-      (save-current-buffer
-       (while (and articles
-                   (not buff))
-         (setq file (nndraft-article-filename (pop articles))
-               buffs buffers)
-         (while buffs
-           (set-buffer (setq buff (pop buffs)))
-           (if (and buffer-file-name
-                    (equal (file-remote-p file)
-                           (file-remote-p buffer-file-name))
-                    (string-equal (file-truename buffer-file-name)
-                                  (file-truename file))
-                    (buffer-modified-p))
-               (setq buffs nil)
-             (setq buff nil)))))
-      (when buff
-       (let* ((window (get-buffer-window buff t))
-              (frame (and window (window-frame window))))
-         (if frame
-             (select-frame-set-input-focus frame)
-           (pop-to-buffer buff t)))
-       (error "The draft %s is under edit" file)))))
+    (let* ((files (mapcar #'nndraft-article-filename articles))
+           (buffs (delq nil (mapcar (lambda (f)
+                                      (find-buffer-visiting
+                                       f (lambda (b) (buffer-modified-p b))))
+                                    files))))
+      (when buffs
+        (if (= 1 (length buffs))
+            ;; We might have arrived here via `gnus-draft-edit-message';
+            ;; either way show the user the draft with unsaved changes.
+            (let* ((window (get-buffer-window (car buffs) t))
+                  (frame (and window (window-frame window))))
+             (if frame
+                 (select-frame-set-input-focus frame)
+               (pop-to-buffer (car buffs) t))
+              (error "Draft is already under edit"))
+          ;; Otherwise we got here from `gnus-draft-send-message', and
+          ;; the main thing is to interrupt the sending.
+          (display-buffer (list-buffers-noselect t buffs))
+          (error "Some drafts have unsaved changes: %S" buffs))))))
 
 (defun gnus-draft-clear-marks ()
   (setq gnus-newsgroup-reads nil