What is the correct way to stop all my Manipulate cells from breaking every time I issue ClearAll["Global`*"] command?
Here's an attempt below, it does not survive ClearAll["Global`*"], as the definition of clean does not get saved.
x = Range[100];
clean[x_] := Module[{y = 5}, x*5];
With[{xLocal = x, cleanLocal = clean},
Manipulate[
ListPlot[cleanLocal[xLocal], PlotLabel -> k], {k, 1, 5, 1},
SaveDefinitions -> True]
]
Here's an example of what I see (things break if ClearAll["Global`*"] is run in a different cell than Manipulate)

Withor some other localizing construct. You could put your definitions into a context other than Global (although I suspect that's not really the kind of thing you were looking for). – lericr Nov 22 '23 at 22:43With[{xLocal = Range[100], cleanLocal = Module[{y = 5}, #*5] &}, ... ]– lericr Nov 22 '23 at 22:46DynamicModulevia something likeDynamicModule[{x, clean}, x = Range[100]; clean[x_] := ...; Manipulate[...]]– Jason B. Nov 22 '23 at 23:16Withactually does.Withdoesn't transfer the definition ofxtoxLocal. It replaces every instance ofxLocalinside of theWithwithx. And, of course, it's thexthat gets cleared, resulting in what you see. I put "localize" in quotes to emphasize that it was a special type of localizing. I don't see how you're going to getWithto work the way you're trying. If you don't want to inline your definitions like I (and JasonB) suggested, then you need to find some other way to "hide" those definitions from the Global context. – lericr Nov 22 '23 at 23:57ClearAll["Global`*"]is a pretty blunt instrument. Perhaps use a more targeted clearing expression? – MarcoB Nov 23 '23 at 02:30SaveDefinitionsworks the way you think it does. The saved definitions are executed when theDynamicModuleis instantiated in the front end. If you change the defnition ofcleanwhile theManipulateis running,Maniupulatewill not re-execute the save definition. Sincecleanis global, its value is shared. Clear it, and it is undefined throughout the kernel. Copy a brokenManipulateoutput and paste it, and the saved definition will be executed again, restoring the original definition. Localize the symbolcleanand its definition inManipulateto protect it. – Goofy Nov 23 '23 at 03:37SaveDefinitionswas analogous toProtect/Protected! I was so confused. Yeah, saving a symbol's definition doesn't mean that you can't later clear it. – lericr Nov 23 '23 at 05:41