Subject: bug#39543: 28.0.50; Add completion to gnus-summary-save-parts from mime parts in the message

From: Eric Abrahamsen <[email-masked]>
Date: Mon, 10 Feb 2020 11:29:23 -0800

Filipp Gunbin <[email-masked]> writes:

> As gnus-summary-save-parts (X m) is invoked on the article, it could
> offer completion based on what mime parts are present in the article.

I've attached a "dumb" version of what that could look like.

Two notes:

1. This would obsolete `gnus-summary-save-parts-default-mime'.
   Personally I think that's totally fine: between completion and
   a history variable, I don't see any use for a default
   value.
2. If we go this route, it would be nice to extend it so that, for
   instance, if _any_ image/ media types are present, we also manually
   add a "image/*" entry to the completion collection. Or for maximum
   OCD, only add that "image/*" entry if there are more than one image/
   type handles present. Matches are not required, so you could always
   just type in your own regexp, anyway.

Let's see if anyone has any comments.

diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index a47e657623..39d9ad5057 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -12508,10 +12508,12 @@ gnus-summary-save-parts
   "Save parts matching TYPE to DIR.
 If REVERSE, save parts that do not match TYPE."
   (interactive
-   (list (read-string "Save parts of type: "
-		      (or (car gnus-summary-save-parts-type-history)
-			  gnus-summary-save-parts-default-mime)
-		      'gnus-summary-save-parts-type-history)
+   (list (completing-read "Save parts of type: "
+			  (gnus-eval-in-buffer-window gnus-article-buffer
+			    (delete-dups
+			     (mapcar (lambda (h) (mm-handle-media-type (cdr h)))
+				     gnus-article-mime-handle-alist)))
+			  nil nil nil 'gnus-summary-save-parts-type-history)
 	 (setq gnus-summary-save-parts-last-directory
 	       (read-directory-name "Save to directory: "
                                     gnus-summary-save-parts-last-directory