this post was submitted on 13 Nov 2023
1 points (66.7% liked)

Emacs

310 readers
1 users here now

A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!

Get Emacs

Rules

  1. Posts should be emacs related
  2. Be kind please
  3. Yes, we already know: Google results for "emacs" and "vi" link to each other. We good.

Emacs Resources

Emacs Tutorials

Useful Emacs configuration files and distributions

Quick pain-saver tip

founded 1 year ago
MODERATORS
 

I'm wondering if there's any way to make a variable automatically save its old value, so that I can, e.g., write a minor mode that will automatically restore the old values of variables when it's deactivated (without having to declare a bunch of -old-value variables).

you are viewing a single comment's thread
view the rest of the comments
[–] JDRiverRun@alien.top 1 points 10 months ago

A variable watcher maybe.

    (add-variable-watcher
     'myvar
     (lambda (sym val op buf)
       (when (eq op 'set)
         (push val (get sym 'prior-values)))))