aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2021-06-05 17:13:57 -0400
committerKyle Meyer <kyle@kyleam.com>2021-06-07 00:12:07 -0400
commit792195a2c6debbc3d7ad69d6bc11536a0f393b10 (patch)
tree7bdf522d5358cd16f296ecbf5f25282a6eb5b0ff
parent653326e51503ba0bddcf9dc365003886527edbe2 (diff)
downloadpiem-792195a2c6debbc3d7ad69d6bc11536a0f393b10.tar.gz
lei query: Add next/previous line variants that update message buffer
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. Message-Id: <20210605211402.20304-14-kyle@kyleam.com>
-rw-r--r--piem-lei.el42
1 files changed, 42 insertions, 0 deletions
diff --git a/piem-lei.el b/piem-lei.el
index 3760176..37502d0 100644
--- a/piem-lei.el
+++ b/piem-lei.el
@@ -26,6 +26,7 @@
(require 'json)
(require 'message)
(require 'piem)
+(require 'seq)
(defgroup piem-lei nil
"lei integration for piem."
@@ -243,6 +244,47 @@ line."
(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