mu4e: mu4e-mime-parts: small cleanups

Small refactorings in mu4e--part-affixation, factoring out some shared
code.
This commit is contained in:
Dirk-Jan C. Binnema
2026-04-13 22:18:16 +03:00
committed by Seth Ladygo
parent 2a3f9a1399
commit e6e463fc95

View File

@ -229,39 +229,30 @@ COMPLETIONS is the list of completion strings to affixate."
'face 'mu4e-system-face)) 'face 'mu4e-system-face))
(target (propertize (or (plist-get part :target-dir) "") (target (propertize (or (plist-get part :target-dir) "")
'face 'mu4e-system-face)) 'face 'mu4e-system-face))
;; Prefer the real filename: `nerd-icons' matches filenames
;; against regexes, so a specific name like `foo.patch' picks
;; a better icon than the dummy `file.patch' derived from the
;; MIME type. Only fall back to the MIME type when there's
;; no filename.
(icon (or (and (> (length raw-filename) 0) (icon (or (and (> (length raw-filename) 0)
(mu4e-file-name-to-icon raw-filename)) (mu4e-file-name-to-icon raw-filename))
(mu4e-mime-type-to-icon (mu4e-mime-type-to-icon
(plist-get part :mime-type)))) (plist-get part :mime-type))))
(prefix (if icon (concat icon " ") "")) (prefix (if icon (concat icon " ") ""))
(suffix ;; For 'attachment the candidate itself is the filename; for
;; 'mime-part the candidate is a numeric part-id, so prepend
;; the filename here. Either way, pad to align the columns
;; that follow.
(filename-col
(pcase type (pcase type
('attachment ('attachment
(concat (make-string (- (+ longest-filename 2)
(make-string (- (+ longest-filename 2) (length (format "%s" candidate))) ?\s))
(length (format "%s" candidate))) ?\s)
(format "%20s" mimetype)
" "
(format "%8s" size)
" "
(format "%s" (concat "-> " target))))
('mime-part ('mime-part
(concat (concat " " filename
" " (make-string (- (+ longest-filename 2)
filename (length filename)) ?\s)))
(make-string (- (+ longest-filename 2) (_ (mu4e-error "Unsupported annotation type %s" type))))
(length filename)) ?\s) (suffix
(format "%20s" mimetype) (concat filename-col
" " (format "%20s" mimetype) " "
(format "%8s" size) (format "%8s" size) " "
" " "-> " target)))
(format "%s" (concat "-> " target))))
(_ (mu4e-error "Unsupported annotation type %s" type)))))
(list candidate prefix suffix))) (list candidate prefix suffix)))
completions)) completions))