From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id OC/cJTRTumKGJgAAbAwnHQ (envelope-from ) for ; Tue, 28 Jun 2022 03:02:44 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id yE3TJTRTumKtUwEAauVa8A (envelope-from ) for ; Tue, 28 Jun 2022 03:02:44 +0200 Received: from mail.notmuchmail.org (yantan.tethera.net [IPv6:2a01:4f9:c011:7a79::1]) (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 39CE612D0A for ; Tue, 28 Jun 2022 03:02:44 +0200 (CEST) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 4A3695F727; Tue, 28 Jun 2022 01:02:23 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 3C44D5E553 for ; Tue, 28 Jun 2022 01:02:20 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id 895425FBD0; Mon, 27 Jun 2022 21:02:19 -0400 (EDT) Received: (nullmailer pid 1569350 invoked by uid 1000); Tue, 28 Jun 2022 01:02:13 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 4/5] emacs/show: introduce notmuch-show-height-limit Date: Mon, 27 Jun 2022 22:02:04 -0300 Message-Id: <20220628010205.1567784-5-david@tethera.net> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220628010205.1567784-1-david@tethera.net> References: <20220628010205.1567784-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: WHTPXCTAO5IS2F6JNIFOTGJHYZCFZEWF X-Message-ID-Hash: WHTPXCTAO5IS2F6JNIFOTGJHYZCFZEWF 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=1656378164; 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=+xCGwbwj+mDRHS9jqVuvB5Fwm6NvM3Eyw2qYpTdOYRE=; b=qXSiKCUv7rIIoWgNpBdEXdu3rp6o32g5N3WH8jhG4gzVVbCCuLUF3BBlRP7uhFuJvuPFhK ptKQNZgGlr7p5cHmiTeO/zeKtI2U0pyeIss0ChKkyBck9l6XtUrNJ7zmPAo7ED8O8ba6eY tP7Pq4IDYA3DCH0loKbI2ogeWq8D1EUr/IJ3GSwiwBFMjcC7EImFqjHACDvg4V+9i+vUvw MeqBZ9OtknPmcypL/b9Q5NoVc40RXiDLLUs4KM+zbjiPvQLmmLZ0udOnnKivH9wv4VtWeS aeChTTHwNOCQffLUE2eub2whB7GM9hJepfnUTsIvUShQt/2/M4OYhIhqgi5w7Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1656378164; a=rsa-sha256; cv=none; b=qBWx/rhCa9+gj5NWLPlJvBNHO8pFKu5GvybE4tniJljqu8SGELQgtM0/dAUeQQUOo9cSOq WLQjP+/bXypBOTG/8zNOwWQ9veMt3uuijCXRHRu9wRIMIupagNn0U/fFn45+l3+a2RTiNx bFhd9MgzqhafWs3lElNu7QkvdmPtk28kevOCAGYJsgSoCSaWFOZR2Bqj5T+fRqFoz7sovk CwgUib52pTmk89nU7SYq+a3AkX+8vPKj58oVqJaRM/nVEYIXxCLa2uOaOIi1xdK7jdkrCU TcwD9G6yr1pSWwn7e2k1vU2Qtz2PwlIsNnAoHgotEGFAwJKI0sOpOFWjf4a7eA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -2.24 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 39CE612D0A X-Spam-Score: -2.24 X-Migadu-Scanner: scn0.migadu.com X-TUID: kCu4vYLgkKr4 Analogous to notmuch-show-depth-limit, it requires a bit more calculation, but that cost seems dominated by the rendering cost. --- doc/notmuch-emacs.rst | 3 + emacs/notmuch-show.el | 32 +++++- test/T450-emacs-show.sh | 20 ++++ .../notmuch-show-height-0 | 97 +++++++++++++++++++ 4 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 test/emacs-show.expected-output/notmuch-show-height-0 diff --git a/doc/notmuch-emacs.rst b/doc/notmuch-emacs.rst index d6fa37e0..be7e324d 100644 --- a/doc/notmuch-emacs.rst +++ b/doc/notmuch-emacs.rst @@ -280,6 +280,9 @@ Display of messages can be controlled by the following variables :index:`notmuch-show-depth-limit` |docstring::notmuch-show-depth-limit| +:index:`notmuch-show-height-limit` + |docstring::notmuch-show-height-limit| + :index:`notmuch-show-max-text-part-size` |docstring::notmuch-show-max-text-part-size| diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index a25ea061..7d6c9c1f 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -124,6 +124,19 @@ insertion is done." (number :tag "Limit" 10)) :group 'notmuch-show) +(defcustom notmuch-show-height-limit nil + "Height (from leaves) beyond which message bodies are displayed lazily. + +If bound to an integer, any message with height in the message +tree greater than this will have its body displayed lazily, +initially only a button. + +If this variable is set to nil (the default) no such lazy +display is done." + :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 @@ -506,6 +519,18 @@ Return unchanged ADDRESS if parsing fails." ;; Otherwise format the name and address together. (concat p-name " <" p-address ">")))) +(defun notmuch-show--mark-height (tree) + "Calculate and cache height (distance from deepest descendent)" + (let* ((msg (car tree)) + (children (cadr tree)) + (cached-height (plist-get msg :height))) + (or cached-height + (let ((height + (if (null children) 0 + (1+ (apply #'max (mapcar #'notmuch-show--mark-height children)))))) + (plist-put msg :height height) + height)))) + (defun notmuch-show-insert-headerline (headers date tags depth) "Insert a notmuch style headerline based on HEADERS for a message at DEPTH in the current thread." @@ -1040,16 +1065,19 @@ is t, hide the part initially and show the button." (let* ((content-type (plist-get part :content-type)) (mime-type (notmuch-show-mime-type part)) (nth (plist-get part :id)) + (height (plist-get msg :height)) (long (and (notmuch-match-content-type mime-type "text/*") (> notmuch-show-max-text-part-size 0) (> (length (plist-get part :content)) notmuch-show-max-text-part-size))) (deep (and notmuch-show-depth-limit (> depth notmuch-show-depth-limit))) + (high (and notmuch-show-height-limit + (> height notmuch-show-height-limit))) (beg (point)) ;; This default header-p function omits the part button for ;; the first (or only) part if this is text/plain. - (button (and (or deep long + (button (and (or deep long high (funcall notmuch-show-insert-header-p-function part hide)) (notmuch-show-insert-part-header nth mime-type @@ -1059,6 +1087,7 @@ is t, hide the part initially and show the button." ;; and we have a button to allow toggling. (show-part (not (or (equal hide t) (and deep button) + (and high button) (and long button)))) (content-beg (point))) ;; Store the computed mime-type for later use (e.g. by attachment handlers). @@ -1202,6 +1231,7 @@ is t, hide the part initially and show the button." (replies (cadr tree))) ;; We test whether there is a message or just some replies. (when msg + (notmuch-show--mark-height tree) (notmuch-show-insert-msg msg depth)) (notmuch-show-insert-thread replies (1+ depth)))) diff --git a/test/T450-emacs-show.sh b/test/T450-emacs-show.sh index e9c59cd3..64f174cf 100755 --- a/test/T450-emacs-show.sh +++ b/test/T450-emacs-show.sh @@ -100,6 +100,26 @@ test_emacs '(let ((notmuch-show-depth-limit -1)) (test-visible-output))' test_expect_equal_file $EXPECTED/notmuch-show-depth OUTPUT + +test_begin_subtest "Hide bodies of messages by height" +test_emacs '(let ((notmuch-show-height-limit -1)) + (notmuch-search "thread:{id:87ocn0qh6d.fsf@yoom.home.cworth.org}") + (notmuch-test-wait) + (notmuch-search-show-thread) + (notmuch-test-wait) + (test-visible-output))' +# folding all messages by height or depth should look the same +test_expect_equal_file $EXPECTED/notmuch-show-depth OUTPUT + +test_begin_subtest "Hide bodies of messages; show only leaves." +test_emacs '(let ((notmuch-show-height-limit 0)) + (notmuch-search "thread:{id:87ocn0qh6d.fsf@yoom.home.cworth.org}") + (notmuch-test-wait) + (notmuch-search-show-thread) + (notmuch-test-wait) + (test-visible-output))' +test_expect_equal_file $EXPECTED/notmuch-show-height-0 OUTPUT + test_begin_subtest "Hide bodies of messages (depth > 1)" test_emacs '(let ((notmuch-show-depth-limit 1)) (notmuch-search "thread:{id:87ocn0qh6d.fsf@yoom.home.cworth.org}") diff --git a/test/emacs-show.expected-output/notmuch-show-height-0 b/test/emacs-show.expected-output/notmuch-show-height-0 new file mode 100644 index 00000000..d646353e --- /dev/null +++ b/test/emacs-show.expected-output/notmuch-show-height-0 @@ -0,0 +1,97 @@ +Lars Kellogg-Stedman (2009-11-17) (inbox signed) +Subject: [notmuch] Working with Maildir storage? +To: notmuch@notmuchmail.org +Date: Tue, 17 Nov 2009 14:00:54 -0500 + +[ multipart/mixed (hidden) ] + Mikhail Gusarov (2009-11-17) (inbox signed unread) + Subject: Re: [notmuch] Working with Maildir storage? + To: notmuch@notmuchmail.org + Date: Wed, 18 Nov 2009 01:02:38 +0600 + + [ multipart/mixed (hidden) ] + Lars Kellogg-Stedman (2009-11-17) (inbox signed) + Subject: Re: [notmuch] Working with Maildir storage? + To: Mikhail Gusarov + Cc: notmuch@notmuchmail.org + Date: Tue, 17 Nov 2009 15:33:01 -0500 + + [ multipart/mixed (hidden) ] + Mikhail Gusarov (2009-11-17) (inbox unread) + Subject: [notmuch] Working with Maildir storage? + To: notmuch@notmuchmail.org + Date: Wed, 18 Nov 2009 02:50:48 +0600 + + Twas brillig at 15:33:01 17.11.2009 UTC-05 when lars at seas.harvard.edu + did gyre and gimble: + + LK> Is the list archived anywhere? The obvious archives + LK> (http://notmuchmail.org/pipermail/notmuch/) aren't available, and I + LK> think I subscribed too late to get the patch (I only just saw the + LK> discussion about it). + + LK> It doesn't look like the patch is in git yet. + + Just has been pushed + + [ 10-line signature. Click/Enter to show. ] + Keith Packard (2009-11-17) (inbox unread) + Subject: [notmuch] Working with Maildir storage? + To: notmuch@notmuchmail.org + Date: Tue, 17 Nov 2009 13:24:13 -0800 + + [ text/plain (hidden) ] + Lars Kellogg-Stedman (2009-11-18) (inbox signed unread) + Subject: Re: [notmuch] Working with Maildir storage? + To: Keith Packard + Cc: notmuch@notmuchmail.org + Date: Tue, 17 Nov 2009 19:50:40 -0500 + + [ multipart/mixed ] + [ multipart/signed ] + [ Unknown key ID 0xD74695063141ACD8 or unsupported algorithm ] + [ text/plain ] + > I've also pushed a slightly more complicated (and complete) fix to my + > private notmuch repository + + The version of lib/messages.cc in your repo doesn't build because it's + missing "#include " (for the uint32_t on line 466). + + [ 4-line signature. Click/Enter to show. ] + [ application/pgp-signature ] + [ text/plain ] + [ 4-line signature. Click/Enter to show. ] + Carl Worth (2009-11-18) (inbox unread) + Subject: [notmuch] Working with Maildir storage? + To: notmuch@notmuchmail.org + Date: Wed, 18 Nov 2009 02:08:10 -0800 + + On Tue, 17 Nov 2009 14:00:54 -0500, Lars Kellogg-Stedman wrote: + > I saw the LWN article and decided to take a look at notmuch. I'm + > currently using mutt and mairix to index and read a collection of + > Maildir mail folders (around 40,000 messages total). + + Welcome, Lars! + + I hadn't even seen that Keith's blog post had been picked up by lwn.net. + That's very interesting. So, thanks for coming and trying out notmuch. + + > Error opening + > /home/lars/Mail/read-messages.2008/cur/1246413773.24928_27334.hostname,U=3026:2,S: + > Too many open files + + Sadly, the lwn article coincided with me having just introduced this + bug, and then getting on a Trans-Atlantic flight. So I fixed the bug + fairly quickly, but there was quite a bit of latency before I could push + the fix out. It should be fixed now. + + > I'm curious if this is expected behavior (i.e., notmuch does not work + > with Maildir) or if something else is going on. + + Notmuch works just fine with maildir---it's one of the things that it + likes the best. + + Happy hacking, + + -Carl -- 2.35.2