From 2526059d47ca4645976ca2bc91900ebcf5bb2f48 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sat, 5 Jun 2021 17:13:46 -0400 Subject: piem-lei-show: Let caller suppress displaying buffer piem-lei-show switches to the message buffer with pop-to-buffer, but that behavior won't work well in the context of a mode that gives an overview of lei-q search results. In that case, a wrapper command will want to control the display of the buffer so that it can keep a split window layout and avoid switching to the piem-lei-show-mode buffer. And more generally, Lisp callers are likely to want to handle the display themselves. Add an optional 'display' parameter that defaults to nil for non-interactive calls. Message-Id: <20210605211402.20304-3-kyle@kyleam.com> --- piem-lei.el | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/piem-lei.el b/piem-lei.el index 5b986fc..fe6ab79 100644 --- a/piem-lei.el +++ b/piem-lei.el @@ -30,10 +30,13 @@ ;;;; Message display -(defun piem-lei-show (mid) - "Show message for MID." +(defun piem-lei-show (mid &optional display) + "Show message for MID. +When called non-interactively, return the buffer but do not display it +unless DISPLAY is non-nil." (interactive - (list (read-string "Message ID: " nil nil (piem-mid)))) + (list (read-string "Message ID: " nil nil (piem-mid)) + 'display)) (with-current-buffer (get-buffer-create "*lei-show*") (let ((inhibit-read-only t)) (erase-buffer) @@ -44,7 +47,9 @@ (delete-region (line-beginning-position) (1+ (line-end-position)))) (piem-lei-show-mode)) - (pop-to-buffer (current-buffer)))) + (if display + (pop-to-buffer (current-buffer)) + (current-buffer)))) (define-derived-mode piem-lei-show-mode special-mode "lei-show" "Major mode for displaying message via lei." -- cgit v1.2.3