From 224b86c4280600e7367be2c465b0195086e31d99 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 7 Apr 2024 13:43:20 -0400 Subject: [PATCH] fix: map-y-or-n-p advice triggering too aggressively Given the right arguments, map-y-or-n-p won't actually prompt the user. Without a prompt, the issue this advice tries to address won't appear, causing it to randomly flash the minibuffer's background instead (particularly in calls to save-some-buffers, which will call map-y-or-n-p without prompting in some scenarios). This can be slow at worst and distracting at best. Fix: #50 --- solaire-mode.el | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/solaire-mode.el b/solaire-mode.el index 58787a9..b84c172 100644 --- a/solaire-mode.el +++ b/solaire-mode.el @@ -525,14 +525,24 @@ Meant to fix mismatched background on text in term buffers (should be used on ;; ;; This doesn't totally fix the issue, but makes it more tolerable (by ;; using `default's unremapped background). - (define-advice map-y-or-n-p (:around (orig-fn &rest args) fix-background) + (define-advice map-y-or-n-p (:around (orig-fn prompter &rest args) fix-background) "Fix ugly white background in `map-y-or-n-p' due to `solaire-mode'. ORIG-FN is `map-y-or-n-p' and ARGS are its arguments." - (unwind-protect - (progn - (solaire-mode-fix-minibuffer 'unset) - (apply orig-fn args)) - (solaire-mode-fix-minibuffer)))) + (let ((unset-p nil)) + (unwind-protect + (apply orig-fn + ;; This function won't actually prompt if PROMPTER returns a + ;; non-string, which avoids what solaire-mode is trying to fix. + (lambda (obj) + (let ((result (if (stringp prompter) + (format prompter obj) + (funcall prompter obj)))) + (when (and (not unset-p) (stringp result)) + (setq unset-p t) + (solaire-mode-fix-minibuffer 'unset)) + result)) + args) + (if unset-p (solaire-mode-fix-minibuffer)))))) (provide 'solaire-mode) ;;; solaire-mode.el ends here