From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:267::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id ELidCE7pu2CBcAAAsNZ9tg (envelope-from ); Sat, 05 Jun 2021 21:14:54 +0000 Received: from out0.migadu.com ([2001:41d0:2:267::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id YHnICErpu2CoXwAAB5/wlQ (envelope-from ); Sat, 05 Jun 2021 21:14:50 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kyleam.com; s=key1; t=1622927690; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R9sebbzWh0OUKGO4MidDwlCUcfqXDrzXig7CKJXhg5c=; b=nLATa9+AaJUqWG1eLYvqKJ32rNPFlLOCU4gZ/SXEGTwocVnH3p6khuWG3IR45edu0SVIDJ ed2IMbd9veb7PqWAiHvZUJLjt4Nuq9S8L/TvOEMmu8VR7TA9uc8H9cjZlkJAM5C7Gtxnzs 57JlTDRauCVQEu0opmpNTvlfu+XYjcoXqFMaN1hXOEoDLu7dKEO+uhpTNPYbvZeoPLU3rt v2kXb55i3DlYAIMJMtB4YNZa23I6I1bAahNEmIH2oUGWEn94tcMD0t1XasX15Butuye6AH dG74tH7U2iFzESJQV1LnAX4DId3YpWheUVZ9Y6wbsvHnwInPC0S8AWGnUlaNgA== From: Kyle Meyer To: piem@inbox.kyleam.com Subject: [PATCH 17/18] lei: Wire up piem.el hooks Date: Sat, 5 Jun 2021 17:14:01 -0400 Message-Id: <20210605211402.20304-18-kyle@kyleam.com> In-Reply-To: <20210605211402.20304-1-kyle@kyleam.com> References: <20210605211402.20304-1-kyle@kyleam.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: kyle@kyleam.com X-TUID: v4qkofSU/X+N piem-lei-show-mode and piem-lei-query-mode now have enough functionality to implement all piem.el hooks except for piem-am-ready-mbox-functions. --- piem-lei.el | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/piem-lei.el b/piem-lei.el index 71f548c9..bcc25896 100644 --- a/piem-lei.el +++ b/piem-lei.el @@ -27,6 +27,7 @@ (require 'json) (require 'message) (require 'piem) (require 'seq) +(require 'subr-x) (defgroup piem-lei nil "lei integration for piem." @@ -554,5 +555,58 @@ (defun piem-lei-query-thread (mid) (piem-lei-query-mode) (pop-to-buffer-same-window (current-buffer))))) + +;;;; piem integration + +(defun piem-lei-get-mid () + "Return the message ID of a lei buffer." + (cond ((derived-mode-p 'piem-lei-show-mode) + piem-lei-show-mid) + ((derived-mode-p 'piem-lei-query-mode) + (piem-lei-query-get-mid)))) + +(defun piem-lei-get-inbox () + "Return inbox name from a lei buffer." + (when-let ((mid (piem-lei-get-mid))) + (with-temp-buffer + (call-process "lei" nil '(t nil) nil + "q" "--format=mboxrd" (concat "m:" mid)) + (goto-char (point-min)) + (piem-inbox-by-header-match)))) + +(defun piem-lei-known-mid-p (mid) + "Return non-nil if MID is known to lei. +The message ID should not include have surrounding brackets." + (not (string-empty-p + (with-temp-buffer + (call-process "lei" nil '(t nil) nil + "q" "--format=ldjson" (concat "m:" mid)) + (buffer-string))))) + +(defun piem-lei-mid-to-thread (mid) + "Return a function that inserts an mbox for MID's thread." + (when (piem-lei-known-mid-p mid) + (lambda () + (call-process "lei" nil '(t nil) nil + "q" "--format=mboxrd" "--threads" + (concat "m:" mid))))) + +;;;###autoload +(define-minor-mode piem-lei-mode + "Toggle lei support for piem. +With a prefix argument ARG, enable piem-lei mode if ARG is +positive, and disable it otherwise. If called from Lisp, enable +the mode if ARG is omitted or nil." + :global t + :init-value nil + (if piem-lei-mode + (progn + (add-hook 'piem-get-inbox-functions #'piem-lei-get-inbox) + (add-hook 'piem-get-mid-functions #'piem-lei-get-mid) + (add-hook 'piem-mid-to-thread-functions #'piem-lei-mid-to-thread)) + (remove-hook 'piem-get-inbox-functions #'piem-lei-get-inbox) + (remove-hook 'piem-get-mid-functions #'piem-lei-get-mid) + (remove-hook 'piem-mid-to-thread-functions #'piem-lei-mid-to-thread))) + ;;; piem-lei.el ends here (provide 'piem-lei) -- 2.31.1