aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2021-12-27 21:20:34 -0500
committerKyle Meyer <kyle@kyleam.com>2021-12-28 12:08:35 -0500
commit601d79ec752dba957f4a27b993280bc1499676ef (patch)
treeacf3b3a0f56d3c320cb9d72ea922c98788379a92
parent8cb30023c1fbf7049cedb8df29dec8c42a332697 (diff)
downloadpiem-601d79ec752dba957f4a27b993280bc1499676ef.tar.gz
lei q: Support displaying multiple threads
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 --threads. 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 Message-Id: <20211228022037.206597-4-kyle@kyleam.com>
-rw-r--r--piem-lei.el41
1 files changed, 27 insertions, 14 deletions
diff --git a/piem-lei.el b/piem-lei.el
index 9779c97..63a2548 100644
--- a/piem-lei.el
+++ b/piem-lei.el
@@ -176,7 +176,7 @@ unless DISPLAY is non-nil."
(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)
map)
"Keymap for `piem-lei-show-mode'.")
@@ -376,7 +376,7 @@ line's message, scroll its text downward, passing ARG to
(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)
map)
"Keymap for `piem-lei-query-mode'.")
@@ -521,7 +521,8 @@ external (via `lei add-external')."
(piem-lei-q:--limit)
(piem-lei-q:--offset)]
["Actions"
- ("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 @@ Return a list with a `piem-lei-msg' object for each root."
(forward-line))
(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."
(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* ((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 @@ ARGS is passed to the underlying `lei q' call."
'font-lock-face
'piem-lei-query-thread-ghost))
(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)))
(piem-lei-query-mode)
(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