rc windowing: with-option to restore option value also after error

Today "with-option foo bar command-that-fails" fails with

	Error: 1:1: 'evaluate-commands': 1:1: 'with-option': 2:5: 'evaluate-commands': 4:9: 'evaluate-commands': 1:2: 'no-such-command': no such command

but leaks the option value. Fix this by resetting the option and
rethrowing the error.  Unfortunately the original stack trace is lost
(questionable behavior inherited from C++?).
This commit is contained in:
Johannes Altmanninger 2023-12-16 09:36:55 +01:00
parent 83fb65aef5
commit 1ce639f2f9

View File

@ -63,6 +63,7 @@ define-command with-option -params 3.. -docstring %{
evaluate-commands -save-regs s %{ evaluate-commands -save-regs s %{
evaluate-commands set-register s %exp{%%opt{%arg{1}}} evaluate-commands set-register s %exp{%%opt{%arg{1}}}
set-option current %arg{1} %arg{2} set-option current %arg{1} %arg{2}
try %{
evaluate-commands %sh{ evaluate-commands %sh{
shift 2 shift 2
for arg for arg
@ -70,6 +71,10 @@ define-command with-option -params 3.. -docstring %{
printf "'%s' " "$(printf %s "$arg" | sed "s/'/''/g")" printf "'%s' " "$(printf %s "$arg" | sed "s/'/''/g")"
done done
} }
} catch %{
set-option current %arg{1} %reg{s}
fail "with-option: %val{error}"
}
set-option current %arg{1} %reg{s} set-option current %arg{1} %reg{s}
} }
} }