From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:863f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id +LOwDAArdmE7QAAAsNZ9tg (envelope-from ); Mon, 25 Oct 2021 03:56:48 +0000 Received: from out1.migadu.com ([2001:41d0:2:863f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id OACDCAArdmEwCwAAB5/wlQ (envelope-from ); Mon, 25 Oct 2021 03:56:48 +0000 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=1635134208; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KFtG2vggN52yd3LXhAILko5k4G39U51szaDvsfYA09U=; b=CGjpenj+xB+vaA3bKJDiwWe7NSIzhQ2YgHV4EBLp0FW5dfiQmiscvZbzYSqworX7l8dYe0 2XiypANY+NBR16vtMViXQMYpoiDMO13DpkRpGobviyaQ2PwedJu5Q6KJKn2Bzpw/kMIa2+ gsDLVY6BC2xQcy6d2oigzRzgs2zBBhiHTPpFGZmyYhipAtfspPgUl4Jtsz8RS/VN6sIKuR PQuuS+mn2r/ZMQR/V3E8/MD0W5VmelPtNxBZ8ZPz1Q75ZrtChneUJwo3HpDwup4fGnig3v fkYPR6tHu8RdN6QfUVQHCuVX0Wc0+TAem/buxH67bDpvIu6lgBqcDXfMe+UwnA== From: Kyle Meyer To: piem@inbox.kyleam.com Subject: [PATCH 06/10] lei: Add transient wrapper for piem-lei-query Date: Sun, 24 Oct 2021 23:56:26 -0400 Message-Id: <20211025035630.297598-7-kyle@kyleam.com> In-Reply-To: <20211025035630.297598-1-kyle@kyleam.com> References: <20211025035630.297598-1-kyle@kyleam.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: kyle@kyleam.com X-TUID: /S5f4xn99iBU Expose (most if not all) relevant arguments of lei-q in a new transient. The only somewhat tricky part here is propagating the original arguments so that piem-lei-query-thread and piem-lei-query-show can find messages that require a non-default source (e.g., an unregistered external or a remote source when there are local externals configured). While remote operations work, the current design is still focused on a setup where externals are configured locally, as described in <20210605211402.20304-1-kyle@kyleam.com> (e.g., there's no attempt to limit the number of times the server is hit). Using the key 's' (for search) is unfortunate given the command name is `lei q', but I think that's better than using 'q', which is pretty widely used for "quit" in Emacs buffers. --- TODO | 2 - piem-lei.el | 110 +++++++++++++++++++++++++++++++++++++++++++++------- piem.el | 3 +- 3 files changed, 98 insertions(+), 17 deletions(-) diff --git a/TODO b/TODO index 94ecd8d5..97d2d7f6 100644 --- a/TODO +++ b/TODO @@ -40,5 +40,3 @@ See and ** show: support replying ** transients for some other lei commands - -** transient wrapper around piem-lei-query diff --git a/piem-lei.el b/piem-lei.el index f3b16b65..1051bb5c 100644 --- a/piem-lei.el +++ b/piem-lei.el @@ -96,6 +96,12 @@ (defface piem-lei-show-cited-text-4 (defvar-local piem-lei-show-mid nil "Message ID shown in current buffer.") +(defvar-local piem-lei-buffer-args nil + "Non-query arguments that lei was called with.") + +(defvar-local piem-lei-buffer-query nil + "Query arguments that `lei q' was called with.") + (defun piem-lei-show--fontify-headers () (save-excursion (let (last-value-face) @@ -125,8 +131,11 @@ (defun piem-lei-show--fontify-headers () 'font-lock-face last-value-face)) (forward-line)))))) -(defun piem-lei-show (mid &optional display) +(defun piem-lei-show (mid &optional args display) "Show message for MID. + +ARGS is passed to the underlying `lei q' call. + When called non-interactively, return the buffer but do not display it unless DISPLAY is non-nil." (interactive @@ -136,12 +145,13 @@ (defun piem-lei-show (mid &optional display) (let ((inhibit-read-only t)) (erase-buffer) (piem-lei-insert-output - (list "q" "--format=text" (concat "mid:" mid))) + (append (list "q" "--format=text") args (list (concat "mid:" mid)))) (goto-char (point-min)) (when (looking-at-p "# blob:") (delete-region (line-beginning-position) (1+ (line-end-position)))) (piem-lei-show-mode) + (setq piem-lei-buffer-args args) (setq piem-lei-show-mid mid) (piem-lei-show--fontify-headers)) (if display @@ -157,7 +167,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-query) + (define-key map "s" #'piem-lei-q) (define-key map "t" #'piem-lei-query-thread) map) "Keymap for `piem-lei-show-mode'.") @@ -216,17 +226,18 @@ (defun piem-lei-query--format-date (data) 'font-lock-face 'piem-lei-query-date))) ;;;###autoload -(defun piem-lei-query (query) - "Call `lei q' with QUERY. +(defun piem-lei-query (query &optional args) + "Call `lei q' with QUERY and ARGS. QUERY is split according to `split-string-and-unquote'." (interactive (list (split-string-and-unquote - (read-string "Query: " "d:20.days.ago.. " 'piem-lei-query-history)))) + (read-string "Query: " "d:20.days.ago.. " 'piem-lei-query-history)) + (transient-args 'piem-lei-q))) (with-current-buffer (get-buffer-create "*lei-query*") (let ((inhibit-read-only t)) (erase-buffer) (piem-lei-insert-output - (list "q" "--format=ldjson" query)) + (append (list "q" "--format=ldjson") args query)) (goto-char (point-min)) (while (not (eobp)) (let ((data (piem-lei-query--read-json-item))) @@ -251,6 +262,8 @@ (defun piem-lei-query (query) (insert "End of lei-q results")) (goto-char (point-min)) (piem-lei-query-mode) + (setq piem-lei-buffer-args args) + (setq piem-lei-buffer-query query) (pop-to-buffer-same-window (current-buffer)))) (defun piem-lei-query-get-mid (&optional pos) @@ -266,7 +279,8 @@ (defun piem-lei-query-show () (display-buffer (piem-lei-show (or (piem-lei-query-get-mid) - (user-error "No message ID associated with current line"))) + (user-error "No message ID associated with current line")) + piem-lei-buffer-args) '(display-buffer-below-selected (inhibit-same-window . t) (window-height . 0.8)))) @@ -349,7 +363,7 @@ (defvar piem-lei-query-mode-map (define-key map (kbd "SPC") #'piem-lei-query-show-or-scroll-up) (define-key map "n" #'piem-lei-query-next-line) (define-key map "p" #'piem-lei-query-previous-line) - (define-key map "s" #'piem-lei-query) + (define-key map "s" #'piem-lei-q) (define-key map "t" #'piem-lei-query-thread) map) "Keymap for `piem-lei-query-mode'.") @@ -363,6 +377,70 @@ (define-derived-mode piem-lei-query-mode special-mode "lei-query" (setq buffer-read-only t) (setq-local line-move-visual t)) + +;;;;; lei-q transient + +(defun piem-lei-q-read-sort-key (&rest _ignore) + (pcase (read-char-choice "re[c]eived re[l]evance [d]ocid " + (list ?c ?l ?d)) + (?c "received") + (?l "relevance") + (?d "docid"))) + +(transient-define-argument piem-lei-q:--include () + :description "Include external in search" + :class 'transient-option + :shortarg "-I" + :argument "--include=") + +(transient-define-argument piem-lei-q:--only () + :description "Search only this location" + :class 'transient-option + :shortarg "-O" + :argument "--only=") + +(transient-define-argument piem-lei-q:--sort () + :description "Sort key for results" + :class 'transient-option + :shortarg "-s" + :argument "--sort=" + :reader #'piem-lei-q-read-sort-key) + +(transient-define-argument piem-lei-q:--limit () + :description "Limit number of matches (default: 10000)" + :class 'transient-option + :shortarg "-n" + :argument "--limit=" + :reader #'transient-read-number-N+) + +(transient-define-argument piem-lei-q:--offset () + :description "Shift start of results (default: 0)" + :class 'transient-option + :shortarg "-N" + :argument "--offset=" + :reader #'transient-read-number-N0) + +;;;###autoload (autoload 'piem-lei-q "piem-lei" nil t) +(transient-define-prefix piem-lei-q () + "Search for messages with `lei q'." + :man-page "lei-q" + :incompatible '(("--remote" "--no-remote") + ("--no-externals" "--no-local")) + ["Arguments" + (piem-lei-q:--include) + (piem-lei-q:--only) + ("-g" "Match locations literally" "--globoff") + ("xe" "Exclude results from externals" "--no-externals") + ("xl" "Exclude results from local sources" "--no-local") + ("xr" "Exclude results from remote sources" "--no-remote") + ("+r" "Include results from remote sources" "--remote") + (piem-lei-q:--sort) + ("-r" "Reverse search results" "--reverse") + (piem-lei-q:--limit) + (piem-lei-q:--offset)] + ["Actions" + ("s" "Search with lei" piem-lei-query)]) + ;;;;; Threading @@ -511,13 +589,15 @@ (defun piem-lei-query--slurp (args) (forward-line)) (nreverse items)))) -(defun piem-lei-query-thread (mid) - "Show thread containing message MID." +(defun piem-lei-query-thread (mid &optional args) + "Show thread containing message MID. +ARGS is passed to the underlying `lei q' call." (interactive - (list (or (piem-lei-get-mid) - (read-string "Message ID: " nil nil (piem-mid))))) + (if-let ((mid (piem-lei-get-mid))) + (list mid piem-lei-buffer-args) + (list (read-string "Message ID: " nil nil (piem-mid)) nil))) (let* ((records (piem-lei-query--slurp - (list "--threads" (concat "mid:" mid)))) + (append args (list "--threads") (list (concat "mid:" mid))))) (msgs (piem-lei-query--thread records)) depths pt-final subject-prev) (with-current-buffer (get-buffer-create "*lei-thread*") @@ -569,6 +649,8 @@ (defun piem-lei-query-thread (mid) (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-show-mid mid) (pop-to-buffer-same-window (current-buffer))))) diff --git a/piem.el b/piem.el index 16ccdfc5..31b9c71c 100644 --- a/piem.el +++ b/piem.el @@ -986,7 +986,8 @@ (transient-define-prefix piem-dispatch () [[("a" "apply patch" piem-am) ("b" "call b4-am" piem-b4-am)] [("i" "inject thread into maildir" piem-inject-thread-into-maildir) - ("l" "copy public-inbox link" piem-copy-mid-url)]]) + ("l" "copy public-inbox link" piem-copy-mid-url)] + [("s" "search with lei" piem-lei-q)]]) -- 2.33.1