diff --git a/Marlin/src/core/utility.h b/Marlin/src/core/utility.h
index b59500f0cacf1d0132aad64995af50687aa3560c..b8e2ffa38f820d1fa09e10fdd9651bcdd4be3787 100644
--- a/Marlin/src/core/utility.h
+++ b/Marlin/src/core/utility.h
@@ -121,3 +121,16 @@ inline void serial_delay(const millis_t ms) {
 #endif
 
 void print_bin(const uint16_t val);
+
+template<typename T>
+class restorer {
+  T& ref_;
+  T  val_;
+public:
+  restorer(T& perm) : ref_(perm), val_(perm) {}
+  ~restorer() { restore(); }
+  inline void restore() { ref_ = val_; }
+};
+
+#define REMEMBER(X) restorer<typeof(X)> X##_restorer(X)
+#define RESTORE(X) X##_restorer.restore()