discussion and development of piem
 help / color / mirror / code / Atom feed
From: Kyle Meyer <kyle@kyleam.com>
To: piem@inbox.kyleam.com
Cc: Xinglu Chen <public@yoctocell.xyz>
Subject: [PATCH 3/6] lei q: Support displaying multiple threads
Date: Mon, 27 Dec 2021 21:20:34 -0500	[thread overview]
Message-ID: <20211228022037.206597-4-kyle@kyleam.com> (raw)
In-Reply-To: <20211228022037.206597-1-kyle@kyleam.com>

piem-lei-query shows unthreaded results.  From there,
piem-lei-query-thread can be used to show the entire thread for that
result.  This design is driven largely by my use of Notmuch, where I
call notmuch-search and then follow up with a custom variant of
notmuch-tree to show _one_ thread.

However, users familiar with notmuch-tree probably expect to be able
to display _multiple_ threads.  piem-lei-query--thread already returns
a list of threads, so it really just needs to be exposed at the
command level.

Update piem-lei-query-thread to make it handle a general query,
renaming it slightly to make it clearer that the command now supports
displaying multiple threads.  Then, add a wrapper piem-lei-mid-thread
that handles the old "single thread for a given MID" behavior.

Rather than adding another suffix command to the lei-q transient
(piem-lei-query-threads in addition to the existing piem-lei-query), I
considered adding --threads to the transient and then having
piem-lei-query check whether it's in the arguments.  Conceptually, I
dislike that because it conflates threaded _display_ with lei's
--threads behavior that's instead about whether to include other
messages from a match's thread in the results.  Also, it'd mean some
downstream handling of piem-lei-buffer-args (e.g., by
piem-lei-query-show) would be complicated by the need to filter out

Note that piem-lei-query-thread no longer sets piem-lei-buffer-mid
because the buffer is no longer tied to a single message ID, which is
okay because, unlike in show buffers, the value isn't actually used.

Suggested-by: Xinglu Chen <public@yoctocell.xyz>
Link: https://inbox.kyleam.com/piem/871r96am1q.fsf@yoctocell.xyz
 piem-lei.el | 41 +++++++++++++++++++++++++++--------------
 1 file changed, 27 insertions(+), 14 deletions(-)

diff --git a/piem-lei.el b/piem-lei.el
index 9779c972..63a2548e 100644
--- a/piem-lei.el
+++ b/piem-lei.el
@@ -176,7 +176,7 @@ (defvar piem-lei-show-mode-font-lock-keywords
 (defvar piem-lei-show-mode-map
   (let ((map (make-sparse-keymap)))
     (define-key map "s" #'piem-lei-q)
-    (define-key map "t" #'piem-lei-query-thread)
+    (define-key map "t" #'piem-lei-mid-thread)
   "Keymap for `piem-lei-show-mode'.")
@@ -376,7 +376,7 @@ (defvar piem-lei-query-mode-map
     (define-key map "n" #'piem-lei-query-next-line)
     (define-key map "p" #'piem-lei-query-previous-line)
     (define-key map "s" #'piem-lei-q)
-    (define-key map "t" #'piem-lei-query-thread)
+    (define-key map "t" #'piem-lei-mid-thread)
   "Keymap for `piem-lei-query-mode'.")
@@ -521,7 +521,8 @@ (transient-define-prefix piem-lei-q ()
-   ("s" "Search with lei" piem-lei-query)])
+   ("s" "Search" piem-lei-query)
+   ("t" "Search, threaded output" piem-lei-query-threads)])
 ;;;;; Threading
@@ -671,17 +672,20 @@ (defun piem-lei-query--slurp (args)
       (nreverse items))))
-(defvar piem-lei-query-threads--buffer-name "*lei-thread*")
+(defvar piem-lei-query-threads--buffer-name piem-lei-query--buffer-name)
-(defun piem-lei-query-thread (mid &optional args)
-  "Show thread containing message MID.
-ARGS is passed to the underlying `lei q' call."
+(defun piem-lei-query-threads (query &optional args pt-mid)
+  "Show threads containing matches for QUERY.
+ARGS is passed to the underlying `lei q' call.  If PT-MID is
+non-nil and matches the message ID of a result, move point to
+that line."
-   (if-let ((mid (piem-lei-get-mid)))
-       (list mid piem-lei-buffer-args)
-     (list (read-string "Message ID: " nil nil (piem-mid)) nil)))
-  (let* ((query (list (concat "mid:" mid)))
-         (records (piem-lei-query--slurp
+   (list (split-string-and-unquote
+          (read-string "Query: "
+                       piem-lei-query-initial-input
+                       'piem-lei-query-history))
+         (transient-args 'piem-lei-q)))
+  (let* ((records (piem-lei-query--slurp
                    (append args (list "--threads") query)))
          (msgs (piem-lei-query--thread records))
          depths pt-final subject-prev)
@@ -729,17 +733,26 @@ (defun piem-lei-query-thread (mid &optional args)
               (setq subject-prev nil))
-            (when (equal mid-msg mid)
+            (when (equal mid-msg pt-mid)
               (setq pt-final (line-beginning-position)))
             (insert ?\n)))
         (insert "End of lei-q results"))
       (goto-char (or pt-final (point-min)))
       (setq piem-lei-buffer-args args)
-      (setq piem-lei-buffer-mid mid)
       (setq  piem-lei-buffer-query query)
       (pop-to-buffer-same-window (current-buffer)))))
+(defun piem-lei-mid-thread (mid &optional args)
+  "Show thread containing message MID.
+ARGS is passed to the underlying `lei q' call."
+  (interactive
+   (if-let ((mid (piem-lei-get-mid)))
+       (list mid piem-lei-buffer-args)
+     (list (read-string "Message ID: " nil nil (piem-mid)) nil)))
+  (let ((piem-lei-query-threads--buffer-name "*lei-thread*"))
+    (piem-lei-query-threads (list (concat "mid:" mid)) args mid)))
 ;;;; piem integration

  parent reply	other threads:[~2021-12-28  2:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-28  2:20 [PATCH 0/6] lei q: Support displaying multiple threads Kyle Meyer
2021-12-28  2:20 ` [PATCH 1/6] lei q: Allow initial input for query to be customized Kyle Meyer
2021-12-28  2:20 ` [PATCH 2/6] lei q: Extract buffer names to variables Kyle Meyer
2021-12-28  2:20 ` Kyle Meyer [this message]
2021-12-28 16:03   ` [PATCH 3/6] lei q: Support displaying multiple threads Xinglu Chen
2021-12-28 17:26     ` Kyle Meyer
2021-12-28  2:20 ` [PATCH 4/6] lei q: Add date placeholder for ghost messages Kyle Meyer
2021-12-28  2:20 ` [PATCH 5/6] lei q: Separate different threads with newline Kyle Meyer
2021-12-28  2:20 ` [PATCH 6/6] lei q: Sort threads by date of initial message Kyle Meyer
2021-12-28 17:24   ` 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:

  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=20211228022037.206597-4-kyle@kyleam.com \
    --to=kyle@kyleam.com \
    --cc=piem@inbox.kyleam.com \
    --cc=public@yoctocell.xyz \


* 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


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).