From 7526777c7d186bab2773cecb238639951b256449 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sat, 11 Oct 2025 22:19:12 +0300 Subject: [PATCH] mu4e: implement mu4e-quit-hook As seen on r/emacs. --- NEWS.org | 3 +++ mu4e/mu4e.el | 13 ++++++++++++- mu4e/mu4e.texi | 5 ++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/NEWS.org b/NEWS.org index 23648a7d..c65f1a03 100644 --- a/NEWS.org +++ b/NEWS.org @@ -309,6 +309,9 @@ and connect to the SCM REPL with ~M-x mu4e-mu-scm-repl~ after restart (see their docstrings for details) + - 1.12.14: add ~mu4e-quit-hook~, a hook is just before quitting mu4e. See its + docstring for details. + *** scm - 1.12.12: add new guile/scheme binding in ~scm/~. These are to replace the diff --git a/mu4e/mu4e.el b/mu4e/mu4e.el index daaaa8d2..16708aa4 100644 --- a/mu4e/mu4e.el +++ b/mu4e/mu4e.el @@ -45,12 +45,22 @@ (require 'mu4e-notification) (require 'mu4e-server) ;; communication with backend - (when mu4e-speedbar-support (require 'mu4e-speedbar)) ;; support for speedbar (when mu4e-org-support (require 'mu4e-org)) ;; support for org-mode links +(defcustom mu4e-quit-hook nil + "Hook run just before quitting mu4e. + +This hook runs just before mu4e performs its own cleanup. + +Note that it only fires when mu4e actually terminates; i.e., +`mu4e-quit' _without_ the \"bury-only\" parameter." + :type 'hook + :package-version '(mu4e . "1.12.14") + :group 'mu4e) + ;; We can't properly use compose buffers that are revived using ;; desktop-save-mode; so let's turn that off. (with-eval-after-load 'desktop @@ -171,6 +181,7 @@ invoke FUNC (if available) afterwards." (defun mu4e--stop () "Stop mu4e." + (run-hooks 'mu4e-quit-hook) (when mu4e--update-timer (cancel-timer mu4e--update-timer) (setq mu4e--update-timer nil)) diff --git a/mu4e/mu4e.texi b/mu4e/mu4e.texi index 8ba02589..9fe60466 100644 --- a/mu4e/mu4e.texi +++ b/mu4e/mu4e.texi @@ -909,8 +909,7 @@ visible only if you have actually set up mail-queuing. @ref{Queuing mail} @item @t{[A]bout mu4e} provides general information about the program @item @t{[H]elp} shows help information for this view -@item Finally, @t{[q]uit mu4e} quits your @code{mu4e}-session@footnote{@t{mu4e-quit}; or with a @t{C-u} -prefix argument, it merely buries the buffer} +@item Finally, @t{[q]uit mu4e} quits your @code{mu4e}-session@footnote{@t{mu4e-quit}; or with a @t{C-u} prefix argument, it merely buries the buffer. A hook @code{mu4e-quit-hook} is available as well} @end itemize @node Headers view @@ -4359,7 +4358,7 @@ usually because one of the following reasons: changes in @code{mu4e} are not immediately visible in the command-line @command{mu}, since it can take a while before changes are committed to disk (for performance reasons). Note that quitting @code{mu4e} or invoking @t{mu4e-update-mail-and-index} -and @t{mu4e-update-index} trigger committing to disk as a side-effect. +and @t{mu4e-update-index} have the side-effect of committing changed data to disk. @item different options: @code{mu4e} defaults to having @t{mu4e-headers-include-related}, and @t{mu4e-headers-results-limit} set to 500. However, the command-line @command{mu