Skip to content

Commit

Permalink
fix: map-y-or-n-p advice triggering too aggressively
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hlissner committed Apr 7, 2024
1 parent e8fcce7 commit 224b86c
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions solaire-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 224b86c

Please sign in to comment.