Based on the documentation, I am trying the following:
(let ((inhibit-quit t))
(my-fun)
(y-or-n-p "Prompt")
(cancel-effects-of-my-fun))
Here, my-fun
performs changes to configuration and cancel-effects-of-my-fun
restores the configuration to its original state. I need to make sure that (cancel-effects-of-my-fun)
is evaluated even if the user presses C-g
during the evaluation of (y-or-n-p "Prompt")
. The code above does not do the job. In fact, even setting inhibit-quit
globally does not have any effect. I tried (setq quit-flag nil)
, but that did not make a difference either. What am I missing? Is there a more idiomatic way to achieve what I am trying to achieve?
unwind-protect
looks interesting and I see it a lot in the built-in code, but I haven't played with it myself. – lawlist Aug 31 '17 at 18:57unwind-protect
did exactly what I needed! – AlwaysLearning Aug 31 '17 at 19:10y-or-n-p
signals aquit
error in case the user pressesC-g
, rather then settingquit-flag
like the ordinaryC-g
at top-level. That's why inhibiting it has no effect, it is not set anyway. – politza Sep 1 '17 at 21:15