From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:863f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id +BumBP0qdmHWPgAAsNZ9tg (envelope-from ); Mon, 25 Oct 2021 03:56:45 +0000 Received: from out1.migadu.com ([2001:41d0:2:863f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id 6HmTAP0qdmEhOgAA1q6Kng (envelope-from ); Mon, 25 Oct 2021 03:56:45 +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=1635134203; 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=PWfUcF6DXhMhdFuCog2q2yBELZ+9BAy9o/7NaFPur+8=; b=und3Cf+xfx5yeCrmu9pJKjZ9gRjB7lasyGZOu34A7K4J/2DEUMTbA1LHOV7bN51RkY5crh JSq2KPLCfXuxjHnGiE+pWdgHudPwm8XuGBYnGbLUx5FM0D9JDhSIL4DSWkoo9oqy8mSYNj zwu/n2CkCRc5fjH/7JuVXEtwrQ5SW5bssEO8ltg8VM49geINa53Etu/Hwn1Epj5HLaTijV 4CIZj+BACn2RMbImZFBjILkoxZ3amEOU4FpGUIvF+W0RksrLh2HAqRtLer6s6nkVT3wztg 3HuxWzm1ALFlcpZvBMRHSxn9RY7yEb5ITenqHLOqJIm5UetITrWyG0YgiZOLWQ== From: Kyle Meyer To: piem@inbox.kyleam.com Subject: [PATCH 04/10] lei: Add call-process wrapper for inserting lei output Date: Sun, 24 Oct 2021 23:56:24 -0400 Message-Id: <20211025035630.297598-5-kyle@kyleam.com> In-Reply-To: <20211025035630.297598-1-kyle@kyleam.com> References: <20211025035630.297598-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: PS9cIaNPkzPV This is a bit more readable, and it introduces a single spot where error handling can be added. --- piem-lei.el | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/piem-lei.el b/piem-lei.el index 904bf972..5f381173 100644 --- a/piem-lei.el +++ b/piem-lei.el @@ -37,6 +37,15 @@ (defcustom piem-lei-lei-executable "lei" "Which lei executable to use." :type 'string) + +;;;; Helpers + +(defun piem-lei-insert-output (args &optional buffer) + "Call lei with ARGS and insert standard output in BUFFER. +If BUFFER is nil, the current buffer is used." + (apply #'call-process piem-lei-lei-executable nil + (list (or buffer t) nil) nil args)) + ;;;; Message display @@ -124,8 +133,8 @@ (defun piem-lei-show (mid &optional display) (with-current-buffer (get-buffer-create "*lei-show*") (let ((inhibit-read-only t)) (erase-buffer) - (call-process piem-lei-lei-executable nil '(t nil) nil - "q" "--format=text" (concat "mid:" mid)) + (piem-lei-insert-output + (list "q" "--format=text" (concat "mid:" mid))) (goto-char (point-min)) (when (looking-at-p "# blob:") (delete-region (line-beginning-position) @@ -214,8 +223,8 @@ (defun piem-lei-query (query) (with-current-buffer (get-buffer-create "*lei-query*") (let ((inhibit-read-only t)) (erase-buffer) - (apply #'call-process piem-lei-lei-executable nil '(t nil) nil - "q" "--format=ldjson" query) + (piem-lei-insert-output + (list "q" "--format=ldjson" query)) (goto-char (point-min)) (while (not (eobp)) (let ((data (piem-lei-query--read-json-item))) @@ -487,8 +496,8 @@ (defun piem-lei-query--format-thread-marker (level) (defun piem-lei-query--slurp (args) (with-temp-buffer - (apply #'call-process piem-lei-lei-executable nil '(t nil) nil - "q" "--format=ldjson" args) + (piem-lei-insert-output + (append (list "q" "--format=ldjson") args)) (goto-char (point-min)) (let (items) (while (not (eobp)) @@ -574,8 +583,8 @@ (defun piem-lei-get-inbox () "Return inbox name from a lei buffer." (when-let ((mid (piem-lei-get-mid))) (with-temp-buffer - (call-process piem-lei-lei-executable nil '(t nil) nil - "q" "--format=mboxrd" (concat "mid:" mid)) + (piem-lei-insert-output + (list "q" "--format=mboxrd" (concat "mid:" mid))) (goto-char (point-min)) (piem-inbox-by-header-match)))) @@ -584,17 +593,16 @@ (defun piem-lei-known-mid-p (mid) The message ID should not include have surrounding brackets." (not (string-empty-p (with-output-to-string - (call-process piem-lei-lei-executable - nil (list standard-output nil) nil - "q" "--format=ldjson" (concat "mid:" mid)))))) + (piem-lei-insert-output + (list "q" "--format=ldjson" (concat "mid:" mid)) + standard-output))))) (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 piem-lei-lei-executable nil '(t nil) nil - "q" "--format=mboxrd" "--threads" - (concat "mid:" mid))))) + (piem-lei-insert-output + (list "q" "--format=mboxrd" "--threads" (concat "mid:" mid)))))) ;;;###autoload (define-minor-mode piem-lei-mode -- 2.33.1