diff options
| author | Craig Jennings <c@cjennings.net> | 2026-07-02 01:39:58 -0400 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-07-02 01:39:58 -0400 |
| commit | 6f659aa3b424c513979ba83ea4f15856f9491c01 (patch) | |
| tree | 474828fbfd2617cbf6abe03055b881697d7bd8f5 /modules/mu4e-attachments.el | |
| parent | 67e767466ba63e6e673e4157b68d58948a493462 (diff) | |
| download | dotemacs-6f659aa3b424c513979ba83ea4f15856f9491c01.tar.gz dotemacs-6f659aa3b424c513979ba83ea4f15856f9491c01.zip | |
feat(mail): annotate the attachment picker with MIME type and size
cj/mu4e-save-attachment-here now completes through an annotated table (category mu4e-attachment), so marginalia shows each attachment's MIME type and decoded size beside the filename. Unknown candidates annotate as nil. The existing picker test queries the function table via all-completions instead of car-mapping the old alist.
Diffstat (limited to 'modules/mu4e-attachments.el')
| -rw-r--r-- | modules/mu4e-attachments.el | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/modules/mu4e-attachments.el b/modules/mu4e-attachments.el index 4acdfd6a..6c2be6fb 100644 --- a/modules/mu4e-attachments.el +++ b/modules/mu4e-attachments.el @@ -15,6 +15,7 @@ ;;; Code: (require 'seq) +(require 'system-lib) ;; cj/completion-table-annotated (defvar mu4e-uniquify-save-file-name-function) (defvar-local cj/mu4e-attachment-selection-directory nil @@ -67,6 +68,19 @@ The result is an alist of display labels to MIME part plists." (cons (cj/mu4e--attachment-label part duplicates) part)) parts))) +(defun cj/mu4e--attachment-annotator (candidates) + "Return an annotation function over attachment CANDIDATES. +CANDIDATES is the label->part alist from `cj/mu4e--attachment-candidates'. +The annotation shows the part's MIME type and human-readable decoded +size; an unknown candidate annotates as nil so marginalia shows nothing." + (lambda (cand) + (when-let* ((part (cdr (assoc cand candidates)))) + (let ((mime (or (plist-get part :mime-type) "")) + (size (if-let* ((bytes (plist-get part :decoded-size-approx))) + (file-size-human-readable bytes) + ""))) + (format " %-24s %s" mime size))))) + (defun cj/mu4e--attachment-default-directory (parts) "Return a sensible default save directory for attachment PARTS." (file-name-as-directory @@ -126,7 +140,13 @@ The result is an alist of display labels to MIME part plists." (user-error "No attachments for this message")) (let* ((directory (cj/mu4e--read-attachment-directory parts)) (candidates (cj/mu4e--attachment-candidates parts)) - (choice (completing-read "Save attachment: " candidates nil t)) + (choice (completing-read + "Save attachment: " + (cj/completion-table-annotated + 'mu4e-attachment + (cj/mu4e--attachment-annotator candidates) + candidates) + nil t)) (part (cdr (assoc choice candidates))) (path (cj/mu4e--save-attachment-part part directory))) (message "Saved attachment to %s" path) |
