discussion and development of piem
 help / color / mirror / code / Atom feed
* [RFC PATCH] gnus: Add piem-gnus-mid-to-thread
@ 2021-01-18 10:34 Xinglu Chen
  2021-01-19  4:17 ` Kyle Meyer
  2021-01-20  8:56 ` [RFC PATCH v2] " Xinglu Chen
  0 siblings, 2 replies; 8+ messages in thread
From: Xinglu Chen @ 2021-01-18 10:34 UTC (permalink / raw)
  To: piem


Inserts a string of the whole thread in mbox format.

---
The function works as expected when running
'M-: (funcall (piem-gnus-mid-thread t))', but when running
piem-b4-am-from-mid interactively, it just inserts an empty string.

Any ideas of why this happens?  Sorry, my elisp skills are not that great.

 piem-gnus.el | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/piem-gnus.el b/piem-gnus.el
index 5f10be8..f91f91c 100644
--- a/piem-gnus.el
+++ b/piem-gnus.el
@@ -58,6 +58,30 @@
 ;; If there is an easy way to generate an mbox for a thread in Gnus, a
 ;; function for `piem-mid-to-thread-functions' should be defined.
 
+(defun piem-gnus-mid-to-thread (_mid)
+  (lambda ()
+    (save-excursion
+      ;; Cursor has to be at the root of the thread
+      (gnus-summary-refer-parent-article most-positive-fixnum)
+      (let ((articles (gnus-summary-articles-in-thread))
+	    message
+	    ;; Just show raw message
+	    (gnus-have-all-headers t)
+	    gnus-article-prepare-hook
+	    gnus-article-decode-hook
+	    gnus-display-mime-function
+	    gnus-break-pages)
+	(mapc (lambda (article)
+		(gnus-summary-display-article article)
+		(push (format "From mboxrd@z Thu Jan  1 00:00:00 1970\n%s\n"
+			      (with-current-buffer gnus-article-buffer
+				(buffer-substring-no-properties
+				 (point-min)
+				 (point-max))))
+			      message))
+		articles)
+	      (insert (apply #'concat (nreverse message)))))))
+
 (defun piem-gnus-am-ready-mbox ()
   "Return a function that inserts an am-ready mbox.
 If the buffer has any MIME parts that look like a patch, use
@@ -97,10 +121,12 @@ the mode if ARG is omitted or nil."
       (progn
         (add-hook 'piem-am-ready-mbox-functions #'piem-gnus-am-ready-mbox)
         (add-hook 'piem-get-inbox-functions #'piem-gnus-get-inbox)
-        (add-hook 'piem-get-mid-functions #'piem-gnus-get-mid))
+        (add-hook 'piem-get-mid-functions #'piem-gnus-get-mid)
+	(add-hook 'piem-mid-to-thread-functions #'piem-gnus-mid-to-thread))
     (remove-hook 'piem-am-ready-mbox-functions #'piem-gnus-am-ready-mbox)
     (remove-hook 'piem-get-inbox-functions #'piem-gnus-get-inbox)
-    (remove-hook 'piem-get-mid-functions #'piem-gnus-get-mid)))
+    (remove-hook 'piem-get-mid-functions #'piem-gnus-get-mid)
+    (remove-hook 'piem-mid-to-thread-functions #'piem-gnus-mid-to-thread)))
 
 ;;; piem-gnus.el ends here
 (provide 'piem-gnus)

base-commit: 57f802b2a43ac64c28a5a9ddb9da0afaf910975e
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-01-21  8:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-18 10:34 [RFC PATCH] gnus: Add piem-gnus-mid-to-thread Xinglu Chen
2021-01-19  4:17 ` Kyle Meyer
2021-01-19  8:32   ` yoctocell
2021-01-19 23:41     ` Kyle Meyer
2021-01-20  7:27       ` Xinglu Chen
2021-01-20  8:56 ` [RFC PATCH v2] " Xinglu Chen
2021-01-21  2:45   ` Kyle Meyer
2021-01-21  8:36     ` Xinglu Chen

Code repositories for project(s) associated with this public inbox

	https://git.kyleam.com/piem/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).