feat(mu4e): improve part selection experience

It's not nice having to think of the index of the MIME part you want to
look at, it's much nicer to get a completing read with information about
those parts.
This commit is contained in:
TEC 2021-09-11 22:07:39 +08:00
parent 251705149b
commit c4aba242a3
No known key found for this signature in database
GPG key ID: 779591AFDB81F06C

View file

@ -202,8 +202,25 @@ Acts like a singular `mu4e-view-save-attachments', without the saving."
(mu4e~view-open-file
(mu4e~view-mime-part-to-temp-file (cdr (+mu4e-select-attachment)))))
(defun +mu4e-select-part ()
(let ((parts (mu4e~view-gather-mime-parts)) labeledparts)
(dolist (part parts)
(push (cons (concat (propertize (format "%-2s " (car part)) 'face '(bold font-lock-type-face))
(or (cdr (assoc 'filename (assoc "attachment" (cdr part))))
(propertize "unnamed" 'face '(italic font-lock-doc-face)))
(propertize (format " [%s]" (caaddr part)) 'face 'font-lock-constant-face))
part)
labeledparts))
(cdr (assoc (completing-read "Select part: " (mapcar #'car labeledparts))
labeledparts))))
(defun +mu4e-view-select-mime-part-action ()
"Select a MIME part, and perform an action on it."
(interactive)
(mu4e-view-mime-part-action (car (+mu4e-select-part))))
(map! :map mu4e-view-mode-map
:ne "A" #'mu4e-view-mime-part-action
:ne "A" #'+mu4e-view-select-mime-part-action
:ne "p" #'mu4e-view-save-attachments
:ne "o" #'+mu4e-open-attachment))