From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:306:f42::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id 8BicAJB0ymEBTQAAsNZ9tg (envelope-from ); Tue, 28 Dec 2021 02:21:04 +0000 Received: from out1.migadu.com ([2001:41d0:2:863f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id OJJxAJB0ymFjKQEAauVa8A (envelope-from ); Tue, 28 Dec 2021 03:21:04 +0100 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kyleam.com; s=key1; t=1640658063; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gFKi/fuSRaczh9uJbiot3QX76VK7JhGd3fnvQSFu9ZM=; b=vDYCn5gXK6piIlAYYH0Z9B+SdqAeZgNtEkOZdr8gxwglgXU2LmCaFbbIrmV3pCjA9FgwRK BZkKorafKpaSQFicbDzfKnsyE1JjZjL/iDOQaxZIxqZXtbTawk0nFnqJDF5YIjUoPG/h9P iZLRkQOcAXc29uw3Y8VnCpjZTeomJB8InT7bMFTapsFHymfkUJGChVM23zkqmB2YEleYuY YvNK8uI1H6iAf9ctdb3aGr9vRYmr7voJ43OnNlzOUo/6nVe11g8yBkq5m6gsWYpzY4CKyZ Y9bDu8yb51WX50nYdcS1MlD7ml7PSKjRYg+ydKAc7ZhFVNmMCgTr8z+Ko277sw== From: Kyle Meyer To: piem@inbox.kyleam.com Cc: Xinglu Chen Subject: [PATCH 3/6] lei q: Support displaying multiple threads Date: Mon, 27 Dec 2021 21:20:34 -0500 Message-Id: <20211228022037.206597-4-kyle@kyleam.com> In-Reply-To: <20211228022037.206597-1-kyle@kyleam.com> References: <20211228022037.206597-1-kyle@kyleam.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: kyleam.com X-TUID: 06xEue8IqSYh 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 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) map) "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) map) "Keymap for `piem-lei-query-mode'.") @@ -521,7 +521,8 @@ (transient-define-prefix piem-lei-q () (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 @@ (defun piem-lei-query--slurp (args) (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 @@ (defun piem-lei-query-thread (mid &optional args) '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 -- 2.34.0