From 51163f3e604919bd1bc0f4fed8e66ae3d78f9423 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Tue, 9 Apr 2024 19:55:03 +0300 Subject: [PATCH] mu4e-mark: query using when killing buffer or emacs Depending on mu4e-headers-leave-behavior, query user when killing a buffer or emacs when there's a buffer with outstanding marks. Fixes #2649. --- mu4e/mu4e-mark.el | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/mu4e/mu4e-mark.el b/mu4e/mu4e-mark.el index 2e633c5e..c3947a7c 100644 --- a/mu4e/mu4e-mark.el +++ b/mu4e/mu4e-mark.el @@ -1,6 +1,6 @@ ;;; mu4e-mark.el --- Marking messages -*- lexical-binding: t -*- -;; Copyright (C) 2011-2022 Dirk-Jan C. Binnema +;; Copyright (C) 2011-2024 Dirk-Jan C. Binnema ;; Author: Dirk-Jan C. Binnema ;; Maintainer: Dirk-Jan C. Binnema @@ -39,8 +39,11 @@ ;;; Variables & constants (defcustom mu4e-headers-leave-behavior 'ask - "What to do when user leaves the headers view. -That is when he e.g. quits, refreshes or does a new search. + "What to do when user leaves the current headers view. + +\"Leaving\" here means quitting the headers views, refreshing it +or even quitting mu4e or Emacs. + Value is one of the following symbols: - `ask' ask user whether to ignore the marks - `apply' automatically apply the marks before doing anything else @@ -90,7 +93,13 @@ is the target directory (for \"move\")") (defun mu4e--mark-initialize () "Initialize the marks-subsystem." - (set (make-local-variable 'mu4e--mark-map) (make-hash-table))) + (set (make-local-variable 'mu4e--mark-map) (make-hash-table)) + ;; ask user when kill buffer / emacs with live marks. + ;; (subject to mu4e-headers-leave-behavior) + (add-hook 'kill-buffer-query-functions + #'mu4e-mark-handle-when-leaving nil t) + (add-hook 'kill-emacs-query-functions + #'mu4e-mark-handle-when-leaving nil t)) (defun mu4e--mark-clear () "Clear the marks-subsystem." @@ -454,7 +463,8 @@ nil means \"don't do anything\"." ("ignore marks?" . ignore))))) ;; we determined what to do... now do it (when (eq what 'apply) - (mu4e-mark-execute-all t)))))) + (mu4e-mark-execute-all t))))) + t) ;; return t for compat with `kill-buffer-query-functions ;;; _ (provide 'mu4e-mark)