From 6776cacf0e524389d8177df7e295ea38e7116a73 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sat, 9 Jul 2022 02:45:14 -0400 Subject: piem-am: Order attached patches by file name prefix When extracting patches from attachments, piem-gnus-am-ready-mbox and piem-notmuch-am-ready-mbox construct the mbox messages in the same order as the attachments. This depends on the sender attaching the patches in ascending order. Be a bit more helpful in situations where the sender attaches the patches out of order by reordering patches according to the NNNN- prefix that git-format-patch adds to the start of the patch file name. This approach won't be able to reliably sort patches that aren't generated by git-format-patch, but that's outside of any use case that piem is intended to support. Suggested-by: Ihor Radchenko Link: https://inbox.kyleam.com/piem/87mtdj9dzt.fsf@localhost Message-Id: <878rp2pyx1.fsf@kyleam.com> --- piem.el | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'piem.el') diff --git a/piem.el b/piem.el index 47944e4..63c358a 100644 --- a/piem.el +++ b/piem.el @@ -817,17 +817,21 @@ message for MID, not the entire thread." ;;;; Patch handling (defun piem-am-extract-attached-patch (handle) - "Return content for HANDLE if it looks like a patch." - (and (listp handle) - (let ((type (mm-handle-media-type handle)) - (filename (mm-handle-filename handle))) - (or (member type '("text/x-diff" "text/x-patch")) - (and filename - (equal type "text/plain") - (string-suffix-p ".patch" filename t)))) - (with-temp-buffer - (mm-display-inline handle) - (buffer-substring-no-properties (point-min) (point-max))))) + "Get the content for HANDLE if it looks like a patch. +The return value is of the form (N . CONTENT), where N is the +number at the start of the file name." + (when (listp handle) + (let ((type (mm-handle-media-type handle)) + (filename (mm-handle-filename handle))) + (and (or (member type '("text/x-diff" "text/x-patch")) + (and filename + (equal type "text/plain") + (string-suffix-p ".patch" filename t))) + (with-temp-buffer + (mm-display-inline handle) + (cons + (string-to-number filename) + (buffer-substring-no-properties (point-min) (point-max)))))))) (defun piem-extract-mbox-info (&optional buffer) "Collect information from message in BUFFER. -- cgit v1.2.3