From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id cHVNNjfjnGLe3AAAbAwnHQ (envelope-from ) for ; Sun, 05 Jun 2022 19:09:11 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id KF8pNjfjnGIBRAEAauVa8A (envelope-from ) for ; Sun, 05 Jun 2022 19:09:11 +0200 Received: from mail.notmuchmail.org (yantan.tethera.net [135.181.149.255]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 6E2D52E0EA for ; Sun, 5 Jun 2022 19:09:11 +0200 (CEST) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 614455F478; Sun, 5 Jun 2022 17:09:04 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 4468D5E025 for ; Sun, 5 Jun 2022 17:09:01 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id 895F25FC01; Sun, 5 Jun 2022 13:09:00 -0400 (EDT) Received: (nullmailer pid 1595565 invoked by uid 1000); Sun, 05 Jun 2022 17:08:57 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 2/3] emacs/show: optionally insert bodies lazily Date: Sun, 5 Jun 2022 14:08:50 -0300 Message-Id: <20220605170851.1595387-3-david@tethera.net> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220605170851.1595387-1-david@tethera.net> References: <20220605170851.1595387-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: CTDUWTQQRCDX4CXDRCUGIPUSTVO7S2VV X-Message-ID-Hash: CTDUWTQQRCDX4CXDRCUGIPUSTVO7S2VV X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1654448951; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=CF9APLqKFxd+fe7ONA89F4k49FXCEPr5kQqTriSqHEE=; b=JjfB2iujAidXQ5Spp7lnu2YFrAQMWaYhzMsCEbXwXM0sKCD7NfaCECTnsPqfkglGt8SzLA 8Z1xPo14saXMJsieQ4PoJk9i/X2xEOFAtvuW4m7qbKhXXPWNlnBjf08JD4xU8PDsFZeuv/ KR8kMS2ayFlRlUGuG1OPMZRn+sBmAbSDNZECKg9+65IvYj7jBh6Wfoeh9vloSP1AqEFxyF PqIb+Wfm2oN3B4a5tswH410VLzKsIF6tSS7McwzgqH9riCWmrcMLRwhGjyt01RXYuSNaox zHoeZbNayz/Q/C+gBk9h5bZvdf+ksuuuM/Fqa+7ZSAa3wEU3/uYAT9lrgdQrWQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1654448951; a=rsa-sha256; cv=none; b=HqQimpbSI3i1yT9pM33TMNJM3SwQrlzBKUN5u1GEA8ORzWyXlL6bNK25NuOIreTyrLdvX4 BUNDpi/dsFvSuOFa29EOi8mrnf3rYIgJdX5lATS2mZTCIjQrgdpefjYE+gWjAK6pXiCScG 0IOnB5bv2Ma0mCJqxl9GIsHNJWonZZbEM7ZQ5BtFkVZKajbuY/bZP4MUg5Y+5cCpEn/74n rI2LJJ3tGSsTRzodM0nkvbhTGWcpUc3JStZctx60WOgqyvj5cYeLASzihwxzihFirxLmfn 0JvjBciZ+8Qvmf83QLJa98Uc7Tu0oaPLPB6gOw1rZKTMFhWtyopBr5LSfJ4MMg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.06 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 6E2D52E0EA X-Spam-Score: -1.06 X-Migadu-Scanner: scn1.migadu.com X-TUID: nSUkaJAKuZme Intially control lazy insertion by a depth limit. --- emacs/notmuch-show.el | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 203ca7f0..55c4e274 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -111,6 +111,12 @@ displayed." (function :tag "Function")) :group 'notmuch-show) +(defcustom notmuch-show-depth-limit nil + "Depth beyond which message bodies are inserted lazily" + :type '(choice (const :tag "No limit" nil) + (number :tag "Limit" 10)) + :group 'notmuch-show) + (defcustom notmuch-show-relative-dates t "Display relative dates in the message summary line." :type 'boolean @@ -1065,13 +1071,35 @@ is t, hide the part initially and show the button." (notmuch-show-toggle-part-invisibility button))) (notmuch-show-record-part-information part beg (point)))) +(defun notmuch-show--insert-body-internal (msg body depth) + (mapc (lambda (part) (notmuch-show-insert-bodypart msg part depth)) body)) + +(defun notmuch-show--insert-body-button (msg body depth) + (insert-button + "[body]" + :type 'notmuch-button-type + 'action (lambda (button) + (save-excursion + (let* ((inhibit-read-only t) + (start (button-start button)) + (end (button-end button)) + (marker (copy-marker (1+ end)))) + (delete-region start end) + (notmuch-show--insert-body-internal msg body depth) + (when notmuch-show-indent-content + (indent-rigidly start marker + (* notmuch-show-indent-messages-width depth)))))))) + (defun notmuch-show-insert-body (msg body depth) "Insert the body BODY at depth DEPTH in the current thread." ;; Register all content IDs for this message. According to RFC ;; 2392, content IDs are *global*, but it's okay if an MUA treats ;; them as only global within a message. (notmuch-show--register-cids msg (car body)) - (mapc (lambda (part) (notmuch-show-insert-bodypart msg part depth)) body)) + (if (and notmuch-show-depth-limit + (> depth notmuch-show-depth-limit)) + (notmuch-show--insert-body-button msg body depth) + (notmuch-show--insert-body-internal msg body depth))) (defun notmuch-show-make-symbol (type) (make-symbol (concat "notmuch-show-" type))) -- 2.35.2