discussion and development of piem
 help / color / mirror / code / Atom feed
From: Kyle Meyer <kyle@kyleam.com>
To: piem@inbox.kyleam.com
Subject: [PATCH 11/18] piem-lei-query-thread: Omit main part of subject if shared
Date: Sat,  5 Jun 2021 17:13:55 -0400	[thread overview]
Message-ID: <20210605211402.20304-12-kyle@kyleam.com> (raw)
In-Reply-To: <20210605211402.20304-1-kyle@kyleam.com>

In addition to suppressing identical subjects (after stripping "re:"),
public-inbox's web interface will compare the current line's subject
with the previous line's, and cut off the shared tail:

  [PATCH] Add basic integration for Rmail
  ` <suppressed completely>
    ` [PATCH v2] "                                    <-- here
      ` <suppressed completely>

I think the above is helpful.  However, in some cases, I find the
presentation more confusing than helpful:

  [PATCH 0/3] notmuch: Improve handling of attached patches
  ` [PATCH 1/3] piem-notmuch--with-current-message: Declare debug and indent specs
  ` [PATCH 2/3] piem-notmuch-am-ready-mbox: Improve handling of attachments
    ` <suppressed completely>
      ` [PATCH v2 0/3] notmuch: Improve handling of attached patches
        ` [PATCH v2 1/3] piem-notmuch--with-current-message: Declare debug and indent specs
        ` [PATCH v2 2/3] piem-notmuch-am-ready-mbox: Improve handling of attachments
        ` [PATCH v2 3/3] gnus, notmuch: Absorb now-shared bits into patch attachment helper
  ` [PATCH "

It takes me a second to figure out what the omitted bits in the last
line's subject are.  I'm not sure, but I think the subject truncation
that I find clear is where the omitted text is the main subject after
a bracketed tag (i.e. "[tag] main"), not more or less.

Teach piem-lei-query-thread to split the subject into a "prefix" (some
number of "[tag]" items) and a "main" part (everything else), and
elide a line's main part if it matches the previous line's.  In the
above example, the last line would be

  ` [PATCH 3/3] …
---
 piem-lei.el             | 30 ++++++++++++++++++++++++++++-
 tests/piem-lei-tests.el | 42 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/piem-lei.el b/piem-lei.el
index cf19195b..f7ccc6e4 100644
--- a/piem-lei.el
+++ b/piem-lei.el
@@ -341,6 +341,33 @@ (defun piem-lei-query--thread (records)
        thread)
       (nreverse roots))))
 
+(defvar piem-lei-query--subject-split-re
+  (rx string-start
+      ;; Prefix.
+      (group (zero-or-more space)
+             (one-or-more "[" (one-or-more (not (any "]" "\n"))) "]"
+                          (one-or-more space)))
+      ;; Main subject.  A match consists of at least two islands of
+      ;; non-space characters because there's not much point in
+      ;; eliding one word.
+      (group (one-or-more (not space))
+             (one-or-more space)
+             (not space)
+             (one-or-more anychar))))
+
+(defun piem-lei-query--split-subject (s)
+  (if (string-match piem-lei-query--subject-split-re s)
+      (cons (match-string 1 s) (match-string 2 s))
+    (cons nil s)))
+
+(defun piem-lei-query--elide-subject (s1 s2)
+  (pcase-let ((`(,head2 . ,tail2) (piem-lei-query--split-subject s2)))
+    (if (and s1 head2
+             (let ((tail1 (cdr (piem-lei-query--split-subject s1))))
+               (equal tail1 tail2)))
+        (concat head2 (if (char-displayable-p ?…) "…" "..."))
+      s2)))
+
 (defun piem-lei-query--format-thread-marker (level)
   (if (= level 0)
       ""
@@ -400,7 +427,8 @@ (defun piem-lei-query-thread (mid)
                    (if (equal subject subject-prev)
                        ""
                      (concat "  "
-                             (propertize subject
+                             (propertize (piem-lei-query--elide-subject
+                                          subject-prev subject)
                                          'font-lock-face
                                          'piem-lei-query-subject))))
                   (add-text-properties (line-beginning-position)
diff --git a/tests/piem-lei-tests.el b/tests/piem-lei-tests.el
index e20c62fa..71dc1099 100644
--- a/tests/piem-lei-tests.el
+++ b/tests/piem-lei-tests.el
@@ -70,5 +70,47 @@ (ert-deftest piem-lei-query--has-descendant ()
     (should-not (piem-lei-query--has-descendant m3 m2))
     (should-not (piem-lei-query--has-descendant m3 m1))))
 
+(ert-deftest piem-lei-query--elide-subject:keep-original ()
+  (should (equal "ghi jlk"
+                 (piem-lei-query--elide-subject
+                  nil
+                  "ghi jlk")))
+  (should (equal "ghi jlk"
+                 (piem-lei-query--elide-subject
+                  "abc def"
+                  "ghi jlk")))
+  (should (equal "abc def"
+                 (piem-lei-query--elide-subject
+                  "[PATCH] abc def"
+                  "abc def")))
+  (should (equal "abc def"
+                 (piem-lei-query--elide-subject
+                  "[bug#00000] [PATCH] abc def"
+                  "abc def")))
+  (should (equal "abc def"
+                 (piem-lei-query--elide-subject
+                  "[PATCH] abc def"
+                  "abc def")))
+  (should (equal "[bug#00000] [PATCH v2] abc"
+                 (piem-lei-query--elide-subject
+                  "[bug#00000] [PATCH] abc"
+                  "[bug#00000] [PATCH v2] abc")))
+  (should (equal "[bug#00000] [PATCH v2] ghi jlk mno"
+                 (piem-lei-query--elide-subject
+                  "[bug#00000] [PATCH] abc def"
+                  "[bug#00000] [PATCH v2] ghi jlk mno"))))
+
+(defvar piem-lei-tests-elide-string (if (char-displayable-p ?…) "…" "..."))
+
+(ert-deftest piem-lei-query--elide-subject:elide ()
+  (should (equal (concat "[PATCH v2] " piem-lei-tests-elide-string)
+                 (piem-lei-query--elide-subject
+                  "[PATCH] abc def"
+                  "[PATCH v2] abc def")))
+  (should (equal (concat "[bug#00000] [PATCH v2] " piem-lei-tests-elide-string)
+                 (piem-lei-query--elide-subject
+                  "[bug#00000] [PATCH] abc def"
+                  "[bug#00000] [PATCH v2] abc def"))))
+
 (provide 'piem-lei-tests)
 ;;; piem-lei-tests.el ends here
-- 
2.31.1


  parent reply	other threads:[~2021-06-05 21:14 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-05 21:13 [PATCH 00/18] Initial lei support Kyle Meyer
2021-06-05 21:13 ` [PATCH 01/18] lei: Add command and mode for displaying a message Kyle Meyer
2021-06-05 21:13 ` [PATCH 02/18] piem-lei-show: Let caller suppress displaying buffer Kyle Meyer
2021-06-05 21:13 ` [PATCH 03/18] piem-lei-show: Highlight headers and quoted text Kyle Meyer
2021-06-05 21:13 ` [PATCH 04/18] lei: Add command and mode for displaying overview of search results Kyle Meyer
2021-06-05 21:13 ` [PATCH 05/18] lei query: Add piem-lei-show wrapper for displaying line's message Kyle Meyer
2021-06-05 21:13 ` [PATCH 06/18] lei: Add command for viewing a thread Kyle Meyer
2021-06-05 21:13 ` [PATCH 07/18] lei query: Fontify results Kyle Meyer
2021-06-05 21:13 ` [PATCH 08/18] piem-lei-query-thread: Position point on seed message Kyle Meyer
2021-06-05 21:13 ` [PATCH 09/18] piem-lei-query-thread: Drop repeated subjects Kyle Meyer
2021-06-05 21:13 ` [PATCH 10/18] piem-lei-query-thread: Deal with multiple "re:"s Kyle Meyer
2021-06-05 21:13 ` Kyle Meyer [this message]
2021-06-05 21:13 ` [PATCH 12/18] piem-lei-query-thread: Add bug#NNN special case when eliding subject Kyle Meyer
2021-06-05 21:13 ` [PATCH 13/18] lei query: Add next/previous line variants that update message buffer Kyle Meyer
2021-06-05 21:13 ` [PATCH 14/18] piem-lei-show: Record message ID Kyle Meyer
2021-06-05 21:13 ` [PATCH 15/18] lei query: Add commands for showing or scrolling message buffer Kyle Meyer
2021-06-05 21:14 ` [PATCH 16/18] lei: Configure bindings for query and show modes Kyle Meyer
2021-06-05 21:14 ` [PATCH 17/18] lei: Wire up piem.el hooks Kyle Meyer
2021-06-05 21:14 ` [PATCH 18/18] piem-lei-query-thread: Use piem-lei-get-mid to get message ID Kyle Meyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://git.kyleam.com/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210605211402.20304-12-kyle@kyleam.com \
    --to=kyle@kyleam.com \
    --cc=piem@inbox.kyleam.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).