Inside a function or macro, I frequently need specific SetOverwrite behavior. However, I prefer to have these subprograms clean up after themselves (not leaving non-return values on the stack, keeping the OutPath the same, not altering global states, etc.) so that I don't have to copy a stream of settings commands every time I want to do something—in order to keep the code more readable.
Is there a way to accomplish this with SetOverwrite
? Can I "detect" it, save it, and restore it somehow?
There's no GetOverwrite
function that I can see. The SetOverwrite docs refer to the "overwrite flag," though I can't find concrete references to what exactly that is. Is there a way I can get the value of this (or an arbitrary) flag?
You cannot save the current state of the flag in a variable, but SetOverwrite
allows you to use lastused
as an argument, which restores the value of the flag which was used before the last SetOverwrite
. So you cannot save the flag recursively, but you can set it temporary before File
and restore it after it:
${If} $something = "whatever"
SetOverwrite on
${Else}
SetOverwrite ifnewer
${EndIf}
File "foo.txt"
SetOverwrite lastused