Resize headers window after displaying a message

This commit is contained in:
Mickey Petersen 2022-12-03 16:10:19 +00:00
parent d43c0030e3
commit 8ac172cd08
2 changed files with 32 additions and 1 deletions

View File

@ -112,6 +112,10 @@ specified a function as viewer."
:type 'integer
:group 'mu4e-view)
(defcustom mu4e-after-view-message-hook '(mu4e-resize-linked-headers-window)
"Hook run by `mu4e-view' after a message is rendered."
:type 'hook
:group 'mu4e-view)
@ -644,7 +648,9 @@ As a side-effect, a message that is being viewed loses its
(setq-local mu4e~headers-view-win (mu4e-display-buffer gnus-article-buffer nil))
(unless (window-live-p mu4e~headers-view-win)
(mu4e-error "Cannot get a message view"))
(select-window mu4e~headers-view-win))))
(select-window mu4e~headers-view-win)))
(with-current-buffer gnus-article-buffer
(run-hooks 'mu4e-after-view-message-hook)))
(defun mu4e-view-message-text (msg)
"Return the pristine MSG as a string."

View File

@ -242,5 +242,30 @@ for BUFFER-OR-NAME to be displayed in."
buffer-name
arg))))
(defun mu4e-resize-linked-headers-window ()
"Resizes the linked headers window belonging to a view.
Resizes the current headers view according to `mu4e-split-view'
and `mu4e-headers-visible-lines' or
`mu4e-headers-visible-columns'.
This function is best called from the hook
`mu4e-after-view-message-hook'."
(unless (mu4e-current-buffer-type-p 'view)
(error "Cannot resize as this is not a valid view buffer."))
(when-let (win (and mu4e-linked-headers-buffer
(get-buffer-window mu4e-linked-headers-buffer)))
;; This can fail for any number of reasons. If it does, we do
;; nothing. If the user has customized the window display we may
;; find it impossible to resize the window, and that should not be
;; cause for error.
(ignore-errors
(cond ((eq mu4e-split-view 'vertical)
(window-resize win (- mu4e-headers-visible-columns (window-width win nil))
t t nil))
((eq mu4e-split-view 'horizontal)
(set-window-text-height win mu4e-headers-visible-lines))))))
(provide 'mu4e-window)
;;; mu4e-window.el ends here