From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:aacc::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id gEGQHEfpu2AFdwAAsNZ9tg (envelope-from ); Sat, 05 Jun 2021 21:14:47 +0000 Received: from out2.migadu.com ([2001:41d0:2:aacc::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id qKaFHEPpu2CPXQAAB5/wlQ (envelope-from ); Sat, 05 Jun 2021 21:14:43 +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=1622927683; 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=v/hBRYKh+O45r5o6NPdI5YJkEilaXMWctO1U2lwAbtc=; b=XhXV6eBE6+07XeVGqTlW57KlAEHMsvuUb3+9v5CzjVB3HhUXis6JBxQOfuDDwPXBJi/Oh1 YSZq2/jqLuH/0R1BA+9es9D/192aXCFYvj7Jv7upRmY9qNY1efOwmy0xwFU44lR4V1rOaR ngU5Jlp6s4toym4kNmxC5rHKnEJcE/vpxiSKbUBinyTsqVQq/ulCHcG6vVq02GeEKqMX6X 66016/1EJCxqBV5zHUfYgPLNmTc0PY62jRZoHirHAWAyT5tyq5ueMzysmBR7G8SLw8TbSr 4/eCIzamXxShii4b2WbW84UCJMW4HwRbCy0vuoxQIcHnIHANaVdSiEO+oaRrYA== From: Kyle Meyer To: piem@inbox.kyleam.com Subject: [PATCH 13/18] lei query: Add next/previous line variants that update message buffer Date: Sat, 5 Jun 2021 17:13:57 -0400 Message-Id: <20210605211402.20304-14-kyle@kyleam.com> In-Reply-To: <20210605211402.20304-1-kyle@kyleam.com> References: <20210605211402.20304-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: BEhwt2j+NIou Using next-line and previous-line directly is inconvenient for viewing results because the associated message buffer needs to be manually displayed even if a piem-lei-show-mode buffer is visible. Add commands that 1) automatically call piem-lei-query-show and 2) skip over ghost messages, because in that case there's nothing to display or otherwise act on. If the command is executed quickly, unconditionally showing the buffer is wasteful and won't perform well, so something like magit-update-other-window-delay should probably be added. --- piem-lei.el | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/piem-lei.el b/piem-lei.el index 3760176c..37502d07 100644 --- a/piem-lei.el +++ b/piem-lei.el @@ -26,6 +26,7 @@ (require 'iso8601) (require 'json) (require 'message) (require 'piem) +(require 'seq) (defgroup piem-lei nil "lei integration for piem." @@ -243,6 +244,47 @@ (defun piem-lei-query-show () (inhibit-same-window . t) (window-height . 0.8)))) +(defun piem-lei-query--get-visible-message-window () + (seq-some + (lambda (w) + (with-current-buffer (window-buffer w) + (and (derived-mode-p 'piem-lei-show-mode) + w))) + (window-list (selected-frame)))) + +(defun piem-lei-query-next-line (n) + "Move to the Nth next query result. +If a `piem-lei-show-mode' buffer is visible in the frame, update +it to display the message." + (interactive "p") + (unless (= n 0) + (pcase-let ((ntimes (abs n)) + (`(,move-fn ,pos-fn) + (if (> n 0) + (list #'next-single-property-change + #'line-end-position) + (list #'previous-single-property-change + #'line-beginning-position))) + (target nil)) + (while (and (> ntimes 0) + (setq target (funcall move-fn + (funcall pos-fn) + 'piem-lei-query-result))) + (cl-decf ntimes)) + (if (not target) + (ding) + (goto-char target) + (goto-char (line-beginning-position)) + (when (piem-lei-query--get-visible-message-window) + (piem-lei-query-show)))))) + +(defun piem-lei-query-previous-line (n) + "Move to the Nth previous query result. +If a `piem-lei-show-mode' buffer is visible in the frame, update +it to display the message." + (interactive "p") + (piem-lei-query-next-line (- n))) + (define-derived-mode piem-lei-query-mode special-mode "lei-query" "Major mode for displaying overview of `lei q' results." :group 'piem-lei -- 2.31.1